php 实现店铺装修7

  type_id=0的情况

  type_id=1的情况                         type_id=2的情况

 

    /**
     * @title 店铺装修--商品分类
     * @param type_id 是 int 分类类型(0-全部、1-平台、2-特色)
     * @param store_id 是 string 店铺id
     * @param source 是 int 来源(1--h5、2--app)
     * @example FlagShipShopDecorate.goodsCategory? 调试参数:{"store_id":"115075399495199","username":"17721355485","check_code":"123456","method":"FlagShipShopDecorate.goodsCategory","type_id":"0"}
     * @return_param_explain id:分类id name:分类名称 path:分类path img:分类图片 child:当前分类下的子分类 ad_info: --id:广告id --ad_link_type:广告链接类型(1商品详情页、2关联模块、3商品列表、4H5页面、5蜂雷头条详情页、6订单详情、7零钱明细、8蜜汁明细、9订单列表) --ad_url:广告图片地址 --redirect_url:跳转参数(具体返回的参数值见log记录)
     * @method POST
     * @author 邹柯
     */  
    public function goodsCategory($res){
        //商品类型
        $type_id=$res['type_id'];
        if(empty($type_id)){
            $type_id=0;
        }
        if($type_id !=0 && $type_id !=1 && $type_id !=2){
            E('700416');
        }
        //店铺id
        $store_id=$res['store_id'];
        $proStoreGoods = new FlagShopCategoryModel();
        $list=$proStoreGoods->goodsCategory($store_id,$type_id);
        return $list;
    }

返回结果

{
    "status":"0",
    "errorCode":"0",
    "msg":"成功",
    "result":{
        "categoryInfo":[
            {
                "id":"1",
                "name":"平台商品",
                "sort":"1",
                "path":"1",
                "child":[
                    {
                        "id":"137",
                        "name":"bbb",
                        "sort":"137",
                        "path":"1/137",
                        "img":null,
                        "ad_info":null,
                        "child":null
                    },
                    {
                        "id":"135",
                        "name":"qq",
                        "sort":"135",
                        "path":"1/135",
                        "img":"http://img.test.feelee.cc//Public/Uploads/server/goodcate/20180521/56d0515269096035470.png",
                        "ad_info":null,
                        "child":[
                            {
                                "id":"136",
                                "name":"22",
                                "sort":"136",
                                "path":"1/135/136",
                                "img":null,
                                "child":null
                            }
                        ]
                    },
                    {
                        "id":"111",
                        "name":"333",
                        "sort":"111",
                        "path":"1/111",
                        "img":"http://img.test.feelee.cc//Public/Uploads/server/goodcate/20180330/5073615223769694245.png",
                        "ad_info":null,
                        "child":null
                    },
                    {
                        "id":"3",
                        "name":"斐讯商品",
                        "sort":"60",
                        "path":"1/3",
                        "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a544e68cd630.jpg",
                        "ad_info":null,
                        "child":[
                            {
                                "id":"109",
                                "name":"斐讯K3C+E1组合套装",
                                "sort":"109",
                                "path":"1/3/109",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180127/thumb_5a6c116632a50.jpg",
                                "child":null
                            },
                            {
                                "id":"108",
                                "name":"斐讯N1预售",
                                "sort":"108",
                                "path":"1/3/108",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180126/thumb_5a6af4332d384.jpeg",
                                "child":null
                            },
                            {
                                "id":"74",
                                "name":"斐讯K1S",
                                "sort":"74",
                                "path":"1/3/74",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a6084b29c0aa.jpg",
                                "child":null
                            },
                            {
                                "id":"63",
                                "name":"斐讯M1",
                                "sort":"73",
                                "path":"1/3/63",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180110/thumb_5a5604ff4abb0.jpg",
                                "child":null
                            },
                            {
                                "id":"62",
                                "name":"斐讯S7",
                                "sort":"72",
                                "path":"1/3/62",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180110/thumb_5a56100d49583.png",
                                "child":null
                            },
                            {
                                "id":"73",
                                "name":"斐讯K2mini",
                                "sort":"71",
                                "path":"1/3/73",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180117/thumb_5a5eab214942e.jpg",
                                "child":null
                            },
                            {
                                "id":"72",
                                "name":"斐讯 E1",
                                "sort":"70",
                                "path":"1/3/72",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180117/thumb_5a5eab29339fc.jpg",
                                "child":null
                            },
                            {
                                "id":"67",
                                "name":"斐讯K2",
                                "sort":"69",
                                "path":"1/3/67",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180117/thumb_5a5eab3190628.jpg",
                                "child":null
                            },
                            {
                                "id":"71",
                                "name":"斐讯K2P",
                                "sort":"68",
                                "path":"1/3/71",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180117/thumb_5a5eab3f31e9b.jpg",
                                "child":null
                            },
                            {
                                "id":"68",
                                "name":"斐讯K2C",
                                "sort":"67",
                                "path":"1/3/68",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180117/thumb_5a5eab46cbcdb.JPG",
                                "child":null
                            },
                            {
                                "id":"61",
                                "name":"路由器",
                                "sort":"63",
                                "path":"1/3/61",
                                "img":null,
                                "child":null
                            },
                            {
                                "id":"69",
                                "name":"斐讯K3",
                                "sort":"62",
                                "path":"1/3/69",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180117/thumb_5a5eab4eca5b7.jpg",
                                "child":null
                            },
                            {
                                "id":"70",
                                "name":"斐讯K3C",
                                "sort":"61",
                                "path":"1/3/70",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180117/thumb_5a5eab55d910e.jpg",
                                "child":null
                            }
                        ]
                    },
                    {
                        "id":"4",
                        "name":"热推爆品",
                        "sort":"43",
                        "path":"1/4",
                        "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a544e360cfac.jpg",
                        "ad_info":[
                            {
                                "id":"127",
                                "ad_url":"http://img.test.feelee.cc//Public/Uploads/img/I2/P001402/SKU/1002883101.jpg",
                                "ad_link_type":"1",
                                "redirect_url":{
                                    "itemid":"1000000001",
                                    "sno":"P001219-03",
                                    "store_id":"115075399495199"
                                }
                            },
                            {
                                "id":"128",
                                "ad_url":"http://img.test.feelee.cc//Public/Uploads/img/I2/P001402/SKU/1002883101.jpg",
                                "ad_link_type":"2",
                                "redirect_url":{
                                    "plate_type":"001"
                                }
                            },
                            {
                                "id":"129",
                                "ad_url":"http://img.test.feelee.cc//Public/Uploads/img/I2/P001402/SKU/1002883101.jpg",
                                "ad_link_type":"3",
                                "redirect_url":{
                                    "type":"2",
                                    "brand_id":"3",
                                    "cate_type":"44"
                                }
                            },
                            {
                                "id":"130",
                                "ad_url":"http://img.test.feelee.cc//Public/Uploads/img/I2/P001402/SKU/1002883101.jpg",
                                "ad_link_type":"4",
                                "redirect_url":{
                                    "url":"http://www.baidu.com"
                                }
                            }
                        ],
                        "child":null
                    },
                    {
                        "id":"40",
                        "name":"美妆个护",
                        "sort":"42",
                        "path":"1/40",
                        "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a544d22c52a6.jpg",
                        "ad_info":null,
                        "child":[
                            {
                                "id":"45",
                                "name":"面部护肤",
                                "sort":"89",
                                "path":"1/40/45",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180119/thumb_5a61b82e3a33b.jpg",
                                "child":null
                            },
                            {
                                "id":"88",
                                "name":"皮肤护理",
                                "sort":"88",
                                "path":"1/40/88",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180119/thumb_5a61274b149d3.png",
                                "child":null
                            },
                            {
                                "id":"85",
                                "name":"面膜",
                                "sort":"87",
                                "path":"1/40/85",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180119/thumb_5a61b821d335c.jpg",
                                "child":null
                            },
                            {
                                "id":"56",
                                "name":"彩妆",
                                "sort":"86",
                                "path":"1/40/56",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60a80ab4f35.jpg",
                                "child":null
                            },
                            {
                                "id":"89",
                                "name":"卸妆",
                                "sort":"85",
                                "path":"1/40/89",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60a8155a23c.jpg",
                                "child":null
                            },
                            {
                                "id":"86",
                                "name":"造型",
                                "sort":"84",
                                "path":"1/40/86",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60a1f3d0c1d.jpg",
                                "child":null
                            },
                            {
                                "id":"44",
                                "name":"洗发",
                                "sort":"58",
                                "path":"1/40/44",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60a65805294.jpg",
                                "child":[
                                    {
                                        "id":"46",
                                        "name":"面膜",
                                        "sort":"46",
                                        "path":"1/40/44/46",
                                        "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180119/thumb_5a61b82e3a33b.jpg"
                                    }
                                ]
                            },
                            {
                                "id":"87",
                                "name":"护发",
                                "sort":"57",
                                "path":"1/40/87",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180119/thumb_5a61b9af1907c.jpg",
                                "child":null
                            },
                            {
                                "id":"84",
                                "name":"染发",
                                "sort":"56",
                                "path":"1/40/84",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a609e4d93237.jpg",
                                "child":null
                            },
                            {
                                "id":"55",
                                "name":"沐浴",
                                "sort":"55",
                                "path":"1/40/55",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a544d9857c69.jpg",
                                "child":null
                            },
                            {
                                "id":"57",
                                "name":"口腔护理",
                                "sort":"45",
                                "path":"1/40/57",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60a1b4712a0.jpg",
                                "child":null
                            },
                            {
                                "id":"58",
                                "name":"女性护理",
                                "sort":"44",
                                "path":"1/40/58",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a544da6c7a0b.jpg",
                                "child":null
                            }
                        ]
                    },
                    {
                        "id":"41",
                        "name":"母婴用品",
                        "sort":"41",
                        "path":"1/41",
                        "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a544f09afb2b.jpg",
                        "ad_info":null,
                        "child":[
                            {
                                "id":"90",
                                "name":"牙刷/牙膏",
                                "sort":"90",
                                "path":"1/41/90",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60a73dcc5f1.jpg",
                                "child":null
                            },
                            {
                                "id":"83",
                                "name":"牙胶安抚",
                                "sort":"83",
                                "path":"1/41/83",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a608e1c23bbe.jpg",
                                "child":null
                            },
                            {
                                "id":"82",
                                "name":"洗发沐浴",
                                "sort":"82",
                                "path":"1/41/82",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a608f2ba41a7.jpg",
                                "child":null
                            },
                            {
                                "id":"78",
                                "name":"幼儿清洁",
                                "sort":"81",
                                "path":"1/41/78",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a608c73bb913.jpg",
                                "child":null
                            },
                            {
                                "id":"81",
                                "name":"幼儿餐具",
                                "sort":"80",
                                "path":"1/41/81",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a608bd269508.jpg",
                                "child":null
                            },
                            {
                                "id":"80",
                                "name":"尿布/湿巾",
                                "sort":"79",
                                "path":"1/41/80",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a6089fdb5756.jpg",
                                "child":null
                            },
                            {
                                "id":"75",
                                "name":"奶瓶/水杯",
                                "sort":"78",
                                "path":"1/41/75",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60892f2518a.jpg",
                                "child":null
                            },
                            {
                                "id":"76",
                                "name":"奶嘴/清洁",
                                "sort":"76",
                                "path":"1/41/76",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a6089986fa4b.jpg",
                                "child":null
                            },
                            {
                                "id":"79",
                                "name":"幼儿护肤",
                                "sort":"75",
                                "path":"1/41/79",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a608b8d1a367.jpg",
                                "child":null
                            },
                            {
                                "id":"47",
                                "name":"孕产用品",
                                "sort":"48",
                                "path":"1/41/47",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180111/thumb_5a572c1942e20.jpg",
                                "child":null
                            },
                            {
                                "id":"48",
                                "name":"防护/其他",
                                "sort":"47",
                                "path":"1/41/48",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a6089e8a299b.jpg",
                                "child":null
                            }
                        ]
                    },
                    {
                        "id":"42",
                        "name":"居家百货",
                        "sort":"40",
                        "path":"1/42",
                        "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a544fb000122.jpg",
                        "ad_info":null,
                        "child":[
                            {
                                "id":"107",
                                "name":"生活电器",
                                "sort":"107",
                                "path":"1/42/107",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180122/thumb_5a65600d573b7.jpg",
                                "child":null
                            },
                            {
                                "id":"94",
                                "name":"厨房用具",
                                "sort":"97",
                                "path":"1/42/94",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180122/thumb_5a656013846b7.jpg",
                                "child":null
                            },
                            {
                                "id":"49",
                                "name":"滤水壶",
                                "sort":"96",
                                "path":"1/42/49",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60ab0185e71.jpg",
                                "child":null
                            },
                            {
                                "id":"51",
                                "name":"杯子",
                                "sort":"95",
                                "path":"1/42/51",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a544f9fe5b62.jpg",
                                "child":null
                            },
                            {
                                "id":"93",
                                "name":"口罩",
                                "sort":"94",
                                "path":"1/42/93",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60ae5588f93.jpg",
                                "child":null
                            },
                            {
                                "id":"97",
                                "name":"便利贴",
                                "sort":"93",
                                "path":"1/42/97",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b0a81a056.jpg",
                                "child":null
                            },
                            {
                                "id":"96",
                                "name":"创可贴",
                                "sort":"92",
                                "path":"1/42/96",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b0a2e4cfe.jpg",
                                "child":null
                            },
                            {
                                "id":"95",
                                "name":"挂钩",
                                "sort":"91",
                                "path":"1/42/95",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b09d1ce3b.jpg",
                                "child":null
                            },
                            {
                                "id":"59",
                                "name":"汽车香水",
                                "sort":"51",
                                "path":"1/42/59",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60ab7d74b0a.jpg",
                                "child":null
                            },
                            {
                                "id":"92",
                                "name":"清洁工具",
                                "sort":"50",
                                "path":"1/42/92",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60add1ea5ae.jpg",
                                "child":null
                            },
                            {
                                "id":"106",
                                "name":"洗衣用品",
                                "sort":"49",
                                "path":"1/42/106",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b9fee32f2.jpg",
                                "child":null
                            }
                        ]
                    },
                    {
                        "id":"43",
                        "name":"数码外设",
                        "sort":"4",
                        "path":"1/43",
                        "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a54500c674dd.jpg",
                        "ad_info":null,
                        "child":[
                            {
                                "id":"54",
                                "name":"音响/耳机",
                                "sort":"105",
                                "path":"1/43/54",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b32458396.jpg",
                                "child":null
                            },
                            {
                                "id":"98",
                                "name":"插座",
                                "sort":"104",
                                "path":"1/43/98",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b3487a154.jpg",
                                "child":null
                            },
                            {
                                "id":"99",
                                "name":"键盘/鼠标",
                                "sort":"103",
                                "path":"1/43/99",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b316a866b.jpg",
                                "child":null
                            },
                            {
                                "id":"52",
                                "name":"Type-C数据线",
                                "sort":"102",
                                "path":"1/43/52",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a54501dcbc93.jpg",
                                "child":null
                            },
                            {
                                "id":"101",
                                "name":"HDMIi高清线",
                                "sort":"101",
                                "path":"1/43/101",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b58d5232d.jpg",
                                "child":null
                            },
                            {
                                "id":"100",
                                "name":"摄像头/麦克",
                                "sort":"100",
                                "path":"1/43/100",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b31c22cfd.jpg",
                                "child":null
                            },
                            {
                                "id":"104",
                                "name":"音频线",
                                "sort":"99",
                                "path":"1/43/104",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b83c92770.jpg",
                                "child":null
                            },
                            {
                                "id":"105",
                                "name":"手机壳",
                                "sort":"98",
                                "path":"1/43/105",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b9ae2cd8b.jpg",
                                "child":null
                            },
                            {
                                "id":"103",
                                "name":"网线转接器",
                                "sort":"54",
                                "path":"1/43/103",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b8fd43825.jpg",
                                "child":null
                            },
                            {
                                "id":"102",
                                "name":"网线",
                                "sort":"52",
                                "path":"1/43/102",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180118/thumb_5a60b7290c501.jpg",
                                "child":null
                            }
                        ]
                    },
                    {
                        "id":"60",
                        "name":"宠物生活",
                        "sort":"3",
                        "path":"1/60",
                        "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180109/thumb_5a5496b1d9b65.jpg",
                        "ad_info":null,
                        "child":[
                            {
                                "id":"66",
                                "name":"宠物保健",
                                "sort":"66",
                                "path":"1/60/66",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180111/thumb_5a572ce3cf29a.png",
                                "child":null
                            },
                            {
                                "id":"65",
                                "name":"爱宠用品",
                                "sort":"65",
                                "path":"1/60/65",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180110/thumb_5a5616e9232ab.jpg",
                                "child":null
                            },
                            {
                                "id":"64",
                                "name":"医疗保健",
                                "sort":"64",
                                "path":"1/60/64",
                                "img":"http://img.test.feelee.cc//Public/Uploads/product_type_img/20180110/thumb_5a560660d3efb.jpg",
                                "child":null
                            }
                        ]
                    }
                ]
            },
            {
                "id":"2",
                "name":"特色商品",
                "sort":"2",
                "path":"2",
                "child":[
                    {
                        "id":"39",
                        "name":"摄像头",
                        "sort":"5",
                        "path":"2/39",
                        "img":null,
                        "ad_info":null,
                        "child":null
                    },
                    {
                        "id":"38",
                        "name":"鼠标垫",
                        "sort":"4",
                        "path":"2/38",
                        "img":null,
                        "ad_info":null,
                        "child":null
                    },
                    {
                        "id":"37",
                        "name":"耳机",
                        "sort":"3",
                        "path":"2/37",
                        "img":null,
                        "ad_info":null,
                        "child":null
                    },
                    {
                        "id":"36",
                        "name":"鼠标",
                        "sort":"2",
                        "path":"2/36",
                        "img":null,
                        "ad_info":null,
                        "child":null
                    },
                    {
                        "id":"35",
                        "name":"键盘",
                        "sort":"1",
                        "path":"2/35",
                        "img":null,
                        "ad_info":null,
                        "child":null
                    }
                ]
            }
        ]
    }
}
<?php
namespace CommonModelDataModel;
use WebappModelFlagShipShopDecorateModel;

class FlagShopCategoryModel{
    //蜂店装修--分类
    public function goodsCategory($store_id,$type_id){
        if($type_id==1){
            $category_type=C('pingtai_goods');
        }elseif($type_id==2){
            $category_type=C('tese_goods');
        }else{
            $category_type=0;
        }

        //获取除顶级分类外的所有分类信息
        $allCategoryInfo=$this->getAllCategoryInfo($store_id,$category_type,$type_id);

        //获取所有的广告信息
        $allAdInfo=$this->getAllAdInfo($store_id,'me');
        //获取一级分类信息
        $cate_info=$this->getFirstCateInfo($category_type,$type_id);
        $ids=array();
        foreach ($cate_info as $k4 => $v4){
            $ids[$k4]  = $v4['id'];
        }
        array_multisort($ids, SORT_ASC,$cate_info);
        //组装分类信息--新
        $result['categoryInfo']=$this->getCateInfoNew($cate_info,$allAdInfo,$allCategoryInfo,$category_type,$store_id,2,1,null,1);
        $ob=new FlagShipShopDecorateModel();
        $user_id=session("user.user_id");
        $store=M('store');
        $s_where['id']=$store_id;
        $store_user_id=$store->where($s_where)->getField('user_id');
        $res=$ob->isParentUserId($user_id,$store_user_id);
        if($res===false){
            $result['categoryInfo'][0]['child']=null;
            $result['categoryInfo'][1]['child']=null;
        }
        return $result;
    }
    //组装分类信息--新
    private function getCateInfoNew($cate_info,$allAdInfo,$allCategoryInfo,$cate_type,$store_id,$source,$le,$cts,$ori){
        if($ori==1){
            $t1=1;
            $t2=2;
        }else{
            $t1=2;
            $t2=3;
        }
        //获取全部分类状态
        //组装分类信息
        foreach($cate_info as $k=>$v){
            //获取一级分类
            $categoryInfo=$this->getNextChildCategory($allAdInfo,$allCategoryInfo,$cate_type,$store_id,$source,$v['path'],$le,$cts); 
            if(empty($categoryInfo)){
                $cate_info[$k]['child']=null;
            }else{
                $cate_info[$k]['child']=$categoryInfo;
                foreach($categoryInfo as $k2=>$v2){
                    //获取二级分类                   
                    $categoryInfo2=$this->getNextChildCategory($allAdInfo,$allCategoryInfo,$cate_type,$store_id,$source,$v2['path'],$le+$t1,$cts); 
                    if(empty($categoryInfo2)){
                        $cate_info[$k]['child'][$k2]['child']=null;
                    }else{
                        $cate_info[$k]['child'][$k2]['child']=$categoryInfo2;
                        foreach($categoryInfo2 as $k3=>$v3){
                            //获取三级分类
                            $categoryInfo3=$this->getNextChildCategory($allAdInfo,$allCategoryInfo,$cate_type,$store_id,$source,$v3['path'],$le+$t2,$cts);  
                            if(empty($categoryInfo3)){
                                $cate_info[$k]['child'][$k2]['child'][$k3]['child']=null;
                            }else{
                                $cate_info[$k]['child'][$k2]['child'][$k3]['child']=$categoryInfo3;
                            }
                        }
                    }                    
               }
            } 
        }
        if(empty($ori)){
            if(!empty($cate_info)){
                //取得列的列表
                foreach ($cate_info as $k => $v){
                    $id[$k]  = $v['sort'];
                }
                array_multisort($id, SORT_DESC,$cate_info);
            } 
            $cate_info=array_merge($cate_info); 
        } 
        return $cate_info;
    }
    //获取所有分类信息
    private function getAllCategoryInfo($store_id,$category_type,$type_id){
        $store_goods_category=M('store_goods_category');
        $img_base=C('img_base');
        if($type_id==1){
            $where ="is_deleted=1 and is_open=1 and type_id='".$category_type."'";
        }elseif($type_id==2){
            $where ="is_deleted=1 and is_open=1 and (type_id='".$category_type."' and store_id='".$store_id."')";
        }else{
            $where ="is_deleted=1 and is_open=1 and (type_id=1 or (type_id=2 and store_id='".$store_id."'))";
        }
        $cate_info=$store_goods_category->field("id,name,store_id,sort,path,type_id,concat('$img_base',img) as img")
                    ->where($where)
                    ->order('sort desc')
                    ->select();
        return $cate_info;
    }
    //获取当前分类的下的下级分类
    private function getNextChildCategory($allAdInfo,$cate_info,$cate_type,$store_id,$source,$path,$le,$cts){ 
        foreach($cate_info as $k=>$v){  
            $cn=substr_count($v['path'],'/');
            if($path !=0){
                $pos=strpos("/".$v['path']."/","/".$path."/");
                if($pos===false){
                    unset($cate_info[$k]);
                    continue;
                }
                if($cts==1){
                    if($le==1){
                        if($cn <= $le || $cn >=$le+2){
                            unset($cate_info[$k]);
                            continue;
                        }  
                    }else{
                        if($cn < $le || $cn >=$le+1){
                            unset($cate_info[$k]);
                            continue;
                        }  
                    }                     
                }else{
                    if($cn <$le || $cn >=$le+1){
                        unset($cate_info[$k]);
                        continue;
                    }     
                }
                if($v['type_id']==0){
                    unset($cate_info[$k]);
                    continue;
                }
            } else{
                if($v['store_id'] != $store_id){
                    unset($cate_info[$k]);
                    continue;
                }
            }
            //组装广告信息
            if(empty($cts)){
                if($le==1){
                    $cate_info[$k]['ad_info']=array_merge($allAdInfo[$v['id']]);
                }                
            }
            unset($cate_info[$k]['store_id']);
            unset($cate_info[$k]['type_id']);
        }
        return array_merge($cate_info);
    }
    //获取所有的广告信息
    private function getAllAdInfo($store_id,$store_type,$source){
        $img_base=C('img_base');
        $where="is_deleted=0 and status=1";
        $category_ad_info=M('category_ad')->field("id,cate_id,concat('$img_base',ad_url) as ad_url,ad_link_type,ad_link_content")->where($where)->select();
        $cats_id=array_unique(array_column($category_ad_info,'cate_id'));
        if(!empty($cats_id)){
            foreach($cats_id as $k0=>$v0){
                foreach($category_ad_info as $k=>$v){
                    if($v['cate_id']==$v0){
                        $data[$v0][$k]['id']=$v['id'];
                        $data[$v0][$k]['ad_url']=$v['ad_url'];
                        $data[$v0][$k]['ad_link_type']=$v['ad_link_type'];
                        $ad_link_content_arr=json_decode($v['ad_link_content'],true);
                        $ad_link_type=$v['ad_link_type'];
                        switch($ad_link_type){
                           case 1: //商品详情页
                               //app
                               $ob=new PublicModel(); 
                               if($source==2){
                                   $inf2=$ob->shopDeal($store_id);
                               }else{ //h5
                                   $inf2=$ob->shopDealH5($store_id,$store_type);
                               }
                               $inf=$ob->getTeSeGoods($ad_link_content_arr['itemid']);
                               if(empty($inf)){//平台商品
                                    $store_id=$inf2;
                               }else{
                                    $store_id=$inf['store_id'];
                               }      
                               $data[$v0][$k]['redirect_url']=array(
                                   'itemid'=>$ad_link_content_arr['itemid'],
                                   'sno'=>$ad_link_content_arr['sno'],
                                   'store_id'=>$store_id
                               );
                               break; 
                           case 2://关联模块
                               $data[$v0][$k]['redirect_url']=array('plate_type'=>$ad_link_content_arr['plate_type']);  
                               break;
                           case 3://商品列表
                               $data[$v0][$k]['redirect_url']=array('type'=>$ad_link_content_arr['type'],'brand_id'=>$ad_link_content_arr['brand_id'],'cate_type'=>$ad_link_content_arr['cate_id']);  
                               break;
                           case 4://H5页面
                               $data[$v0][$k]['redirect_url']=array('url'=>$ad_link_content_arr['url']);
                               break;
                           case 5://蜂雷头条详情页
                               $headlines = M('headlines','t_',C('select_db')); 
                               $list2=$headlines->where(array('id'=>$ad_link_content_arr['id']))->field('id,title,content')->find();
                               $data[$v0][$k]['redirect_url']=array(
                                   'id'=>$ad_link_content_arr['id'],
                                   'title'=>$list2['title']
                               );   
                               break; 
                           default:
                               $data[$v0][$k]['redirect_url']=null;
                               break;
                        }
                        unset($category_ad_info[$k]['ad_link_content']);
                    }                        
                }                 
            }
        }else{
            $data=null;
        }  
        return $data;
    }
    //获取一级分类信息
    private function getFirstCateInfo($category_type,$type_id){
        $store_goods_category=M('store_goods_category');
        if($type_id==0){
            $where ="is_deleted=1 and is_open=1 and type_id=0";
        }else{
            $where ="is_deleted=1 and is_open=1 and id='".$category_type."'";
        }
        $cate_info=$store_goods_category->field('id,name,sort,path')
                ->where($where)
                ->order('sort desc')
                ->select();
        return $cate_info;
    }
}
原文地址:https://www.cnblogs.com/zouke1220/p/9298501.html