header-bg.jpg
TP商城开发日记四
发表于 2017-02-26 01:08
|
分类于 印象笔记
|
评论次数 1
|
阅读次数 1563

attachment/2017/03/10/60461489118485.jpg

一 新建cargolist方法,进行查看货品列表

1 载入模板,用变量接收 关联类型属性表和商品属性表,然后对nid进行分组,过滤重复数据,查询出该商品的属性有几种

2 获取下拉框中的数据(属性值),关联2表进行查询但是不分组,用变量接收后,进行重组$group中的nvalue,

分配数据至列表页

3 IS_POST进行添加,将cspc转换成json数据存入数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public function cargoLists(){
    if(IS_POST){
        $_POST['goods_gid'] = $this->gid;
//            $_POST['cspc'] = implode(',',I('post.cspc'));
        $_POST['cspc'] = json_encode($_POST['cspc']);
//            p($_POST);die;
        $this->store(new cargoModel(),$_POST,function(){
            $this->success('成功添加货品');
        });
    }
    $cargoData = M('cargo')->select();
    foreach($cargoData as $k=>$v){
        $cargoData[$k]['cspc'] = json_decode($v['cspc'],true);
    }
//        p($cargoData);
    $this->assign('cargoData',$cargoData);
    $groupData = M('goods_attr')->join('shop_type_nature ON shop_goods_attr.type_nature_nid=shop_type_nature.nid')
        ->where("goods_gid=$this->gid and ntype=2")->group('nid')->select();
//        p($groupData);
    $selectData = M('goods_attr')->join('shop_type_nature ON shop_goods_attr.type_nature_nid=shop_type_nature.nid')
        ->where("goods_gid=$this->gid and ntype=2")->select();
//        p($selectData);
    foreach($groupData as $k=>$v){
        $groupData[$k]['nvalue'] = [];
        foreach($selectData as $kk=>$vv){
            if($v['nid'] == $vv['nid']){
                $groupData[$k]['nvalue'][] = $vv['avalue'];
            }
        }
    }
//        p($groupData);
    $this->assign('groupData',$groupData);
    $this->display();
}

三 新建delCargo方法,进行删除数据
1
2
3
4
5
6
7
8
9
public function delCargo(){
    $cid = I('get.cid');
    $result = M('cargo')->delete($cid);
    if($result != false){
        $this->success('删除成功');
    }else{
        $this->error('删除失败,SQL出错');
    }
}

发布评论
评论
共计 1条评论
最新评论
2018-03-28 11:42:08caonima[福建省福州市网友]
写的不错
0
0
回复