ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 接口情况 作者:ncgis 时间:20150416 作用:获取商品分类 提交方法:GET 提交参数:version[可选] 所在文件:productclassify 接口地址:http://test.lingsq.com/index.php/api?method=lingsqapi.api.productclassify.getclassify&version=[version] 正式地址:http://www.lingsq.com/index.php/api?method=lingsqapi.api.productclassify.getclassify&version=[version] 返回数据样式: ~~~ { "data": { "item": [ { "cat_id": "54", "parent_id": "0", "cat_name": "个人护理", "child_count": "7", "cat_logo": "", "children": [ { "cat_id": "55", "parent_id": "54", "cat_name": "身体护理/沐浴用品", "child_count": "3", "cat_logo": "", "children": [ { "cat_id": "156", "parent_id": "55", "cat_name": "沐浴露", "child_count": "0", "cat_logo": "" }, { "cat_id": "159", "parent_id": "55", "cat_name": "润肤露", "child_count": "0", "cat_logo": "" }, { "cat_id": "164", "parent_id": "55", "cat_name": "香皂", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "56", "parent_id": "54", "cat_name": "面部护理", "child_count": "3", "cat_logo": "", "children": [ { "cat_id": "157", "parent_id": "56", "cat_name": "洗面乳", "child_count": "0", "cat_logo": "" }, { "cat_id": "158", "parent_id": "56", "cat_name": "面膜", "child_count": "0", "cat_logo": "" }, { "cat_id": "60", "parent_id": "56", "cat_name": "乳液", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "57", "parent_id": "54", "cat_name": "口腔护理", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "160", "parent_id": "57", "cat_name": "牙膏", "child_count": "0", "cat_logo": "" }, { "cat_id": "161", "parent_id": "57", "cat_name": "牙刷", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "58", "parent_id": "54", "cat_name": "女性护理", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "162", "parent_id": "58", "cat_name": "日用卫生巾", "child_count": "0", "cat_logo": "" }, { "cat_id": "163", "parent_id": "58", "cat_name": "夜用卫生巾", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "59", "parent_id": "54", "cat_name": "男士护理", "child_count": "1", "cat_logo": "", "children": [ { "cat_id": "165", "parent_id": "59", "cat_name": "洗面奶", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "52", "parent_id": "54", "cat_name": "美妆", "child_count": "1", "cat_logo": "", "children": [ { "cat_id": "53", "parent_id": "52", "cat_name": "彩妆/香氛/美容工具", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "61", "parent_id": "54", "cat_name": "洗发护发", "child_count": "4", "cat_logo": "", "children": [ { "cat_id": "152", "parent_id": "61", "cat_name": "洗发乳", "child_count": "0", "cat_logo": "" }, { "cat_id": "154", "parent_id": "61", "cat_name": "损伤修复", "child_count": "0", "cat_logo": "" }, { "cat_id": "62", "parent_id": "61", "cat_name": "精华素", "child_count": "0", "cat_logo": "" }, { "cat_id": "153", "parent_id": "61", "cat_name": "去屑护发", "child_count": "0", "cat_logo": "" } ] } ] }, { "cat_id": "1", "parent_id": "0", "cat_name": "进口食品", "child_count": "7", "cat_logo": "http://test.lingsq.com/public/images/public/0f/de/7e/102fbc501c523a607f73735445fb4494.png?1428375120#h", "children": [ { "cat_id": "4", "parent_id": "1", "cat_name": "进口糖果", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "8", "parent_id": "4", "cat_name": "进口坚果", "child_count": "0", "cat_logo": "" }, { "cat_id": "9", "parent_id": "4", "cat_name": "进口蜜饯", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "12", "parent_id": "1", "cat_name": "进品饮料", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "10", "parent_id": "12", "cat_name": "进口冲饮", "child_count": "0", "cat_logo": "" }, { "cat_id": "13", "parent_id": "12", "cat_name": "进口咖啡", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "14", "parent_id": "1", "cat_name": "进品酒", "child_count": "3", "cat_logo": "", "children": [ { "cat_id": "11", "parent_id": "14", "cat_name": "葡萄酒", "child_count": "0", "cat_logo": "" }, { "cat_id": "15", "parent_id": "14", "cat_name": "伏特加", "child_count": "0", "cat_logo": "" }, { "cat_id": "16", "parent_id": "14", "cat_name": "鸡尾酒", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "17", "parent_id": "1", "cat_name": "进口调味", "child_count": "6", "cat_logo": "", "children": [ { "cat_id": "98", "parent_id": "17", "cat_name": "卤料", "child_count": "0", "cat_logo": "" }, { "cat_id": "99", "parent_id": "17", "cat_name": "胡椒粉", "child_count": "0", "cat_logo": "" }, { "cat_id": "106", "parent_id": "17", "cat_name": "醋", "child_count": "0", "cat_logo": "" }, { "cat_id": "100", "parent_id": "17", "cat_name": "五香粉", "child_count": "0", "cat_logo": "" }, { "cat_id": "101", "parent_id": "17", "cat_name": "味精", "child_count": "0", "cat_logo": "" }, { "cat_id": "102", "parent_id": "17", "cat_name": "鸡精", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "3", "parent_id": "1", "cat_name": "进口奶制品", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "2", "parent_id": "3", "cat_name": "进口奶粉", "child_count": "0", "cat_logo": "" }, { "cat_id": "151", "parent_id": "3", "cat_name": "进口牛奶", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "6", "parent_id": "1", "cat_name": "进口饼干/糕点", "child_count": "3", "cat_logo": "", "children": [ { "cat_id": "145", "parent_id": "6", "cat_name": "进口威化饼", "child_count": "0", "cat_logo": "" }, { "cat_id": "146", "parent_id": "6", "cat_name": "进口夹心饼", "child_count": "0", "cat_logo": "" }, { "cat_id": "147", "parent_id": "6", "cat_name": "进口曲奇饼", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "7", "parent_id": "1", "cat_name": "进口零食", "child_count": "1", "cat_logo": "", "children": [ { "cat_id": "5", "parent_id": "7", "cat_name": "进口巧克力", "child_count": "0", "cat_logo": "" } ] } ] }, { "cat_id": "18", "parent_id": "0", "cat_name": "进口生鲜", "child_count": "1", "cat_logo": "http://test.lingsq.com/public/images/public/0f/de/7e/102fbc501c523a607f73735445fb4494.png?1428375120#h", "children": [ { "cat_id": "20", "parent_id": "18", "cat_name": "有机蔬菜", "child_count": "0", "cat_logo": "" }, { "cat_id": "21", "parent_id": "18", "cat_name": "肉类禽蛋", "child_count": "0", "cat_logo": "" }, { "cat_id": "22", "parent_id": "18", "cat_name": "素食冻品", "child_count": "0", "cat_logo": "" }, { "cat_id": "23", "parent_id": "18", "cat_name": "烘烤甜品", "child_count": "0", "cat_logo": "" }, { "cat_id": "24", "parent_id": "18", "cat_name": "进口水果", "child_count": "0", "cat_logo": "" }, { "cat_id": "19", "parent_id": "18", "cat_name": "时令蔬果", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "25", "parent_id": "0", "cat_name": "食品", "child_count": "12", "cat_logo": "", "children": [ { "cat_id": "30", "parent_id": "25", "cat_name": "粮油", "child_count": "5", "cat_logo": "", "children": [ { "cat_id": "125", "parent_id": "30", "cat_name": "橄榄油", "child_count": "0", "cat_logo": "" }, { "cat_id": "116", "parent_id": "30", "cat_name": "米/杂粮", "child_count": "0", "cat_logo": "" }, { "cat_id": "117", "parent_id": "30", "cat_name": "粉面", "child_count": "0", "cat_logo": "" }, { "cat_id": "124", "parent_id": "30", "cat_name": "油", "child_count": "0", "cat_logo": "" }, { "cat_id": "126", "parent_id": "30", "cat_name": "玉米油", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "31", "parent_id": "25", "cat_name": "干货", "child_count": "3", "cat_logo": "", "children": [ { "cat_id": "136", "parent_id": "31", "cat_name": "蔬菜类干货", "child_count": "0", "cat_logo": "" }, { "cat_id": "137", "parent_id": "31", "cat_name": "干果类干货", "child_count": "0", "cat_logo": "" }, { "cat_id": "155", "parent_id": "31", "cat_name": "饯肉类干货", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "39", "parent_id": "25", "cat_name": "饮料", "child_count": "9", "cat_logo": "", "children": [ { "cat_id": "103", "parent_id": "39", "cat_name": "果汁", "child_count": "0", "cat_logo": "" }, { "cat_id": "104", "parent_id": "39", "cat_name": "碳酸饮料", "child_count": "0", "cat_logo": "" }, { "cat_id": "105", "parent_id": "39", "cat_name": "功能性饮料", "child_count": "0", "cat_logo": "" }, { "cat_id": "129", "parent_id": "39", "cat_name": "水", "child_count": "0", "cat_logo": "" }, { "cat_id": "171", "parent_id": "39", "cat_name": "含乳饮品", "child_count": "0", "cat_logo": "" }, { "cat_id": "35", "parent_id": "39", "cat_name": "冲调", "child_count": "0", "cat_logo": "" }, { "cat_id": "36", "parent_id": "39", "cat_name": "奶制品", "child_count": "0", "cat_logo": "" }, { "cat_id": "120", "parent_id": "39", "cat_name": "即饮茶饮料", "child_count": "0", "cat_logo": "" }, { "cat_id": "128", "parent_id": "39", "cat_name": "运动饮料", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "187", "parent_id": "25", "cat_name": "冷冻食品", "child_count": "3", "cat_logo": "", "children": [ { "cat_id": "188", "parent_id": "187", "cat_name": "水饺", "child_count": "0", "cat_logo": "" }, { "cat_id": "189", "parent_id": "187", "cat_name": "汤圆", "child_count": "0", "cat_logo": "" }, { "cat_id": "190", "parent_id": "187", "cat_name": "面点", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "26", "parent_id": "25", "cat_name": "休闲食品", "child_count": "7", "cat_logo": "", "children": [ { "cat_id": "173", "parent_id": "26", "cat_name": "果仁", "child_count": "0", "cat_logo": "" }, { "cat_id": "28", "parent_id": "26", "cat_name": "巧克力", "child_count": "0", "cat_logo": "" }, { "cat_id": "29", "parent_id": "26", "cat_name": "饼干/糕点", "child_count": "5", "cat_logo": "" }, { "cat_id": "110", "parent_id": "26", "cat_name": "豆干/肉类小食", "child_count": "0", "cat_logo": "" }, { "cat_id": "127", "parent_id": "26", "cat_name": "蜜饯", "child_count": "0", "cat_logo": "" }, { "cat_id": "143", "parent_id": "26", "cat_name": "海产/海苔", "child_count": "0", "cat_logo": "" }, { "cat_id": "174", "parent_id": "26", "cat_name": "果冻/布丁", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "27", "parent_id": "25", "cat_name": "糖果", "child_count": "3", "cat_logo": "", "children": [ { "cat_id": "123", "parent_id": "27", "cat_name": "槟榔", "child_count": "0", "cat_logo": "" }, { "cat_id": "142", "parent_id": "27", "cat_name": "凉果", "child_count": "0", "cat_logo": "" }, { "cat_id": "144", "parent_id": "27", "cat_name": "坚果", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "32", "parent_id": "25", "cat_name": "调味", "child_count": "7", "cat_logo": "", "children": [ { "cat_id": "180", "parent_id": "32", "cat_name": "火锅酱", "child_count": "0", "cat_logo": "" }, { "cat_id": "118", "parent_id": "32", "cat_name": "调味酱", "child_count": "0", "cat_logo": "" }, { "cat_id": "130", "parent_id": "32", "cat_name": "酱油", "child_count": "0", "cat_logo": "" }, { "cat_id": "131", "parent_id": "32", "cat_name": "醋", "child_count": "0", "cat_logo": "" }, { "cat_id": "132", "parent_id": "32", "cat_name": "调味用油", "child_count": "0", "cat_logo": "" }, { "cat_id": "133", "parent_id": "32", "cat_name": "调味粉", "child_count": "0", "cat_logo": "" }, { "cat_id": "176", "parent_id": "32", "cat_name": "调味料", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "33", "parent_id": "25", "cat_name": "奶制品", "child_count": "3", "cat_logo": "", "children": [ { "cat_id": "113", "parent_id": "33", "cat_name": "纯牛奶", "child_count": "0", "cat_logo": "" }, { "cat_id": "114", "parent_id": "33", "cat_name": "酸奶", "child_count": "0", "cat_logo": "" }, { "cat_id": "115", "parent_id": "33", "cat_name": "风味奶", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "34", "parent_id": "25", "cat_name": "速食", "child_count": "5", "cat_logo": "", "children": [ { "cat_id": "181", "parent_id": "34", "cat_name": "八宝粥", "child_count": "0", "cat_logo": "" }, { "cat_id": "182", "parent_id": "34", "cat_name": "罐头", "child_count": "0", "cat_logo": "" }, { "cat_id": "183", "parent_id": "34", "cat_name": "即食粉类、米线", "child_count": "0", "cat_logo": "" }, { "cat_id": "121", "parent_id": "34", "cat_name": "即食面", "child_count": "0", "cat_logo": "" }, { "cat_id": "122", "parent_id": "34", "cat_name": "火腿肠", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "37", "parent_id": "25", "cat_name": "冲调食品", "child_count": "6", "cat_logo": "", "children": [ { "cat_id": "175", "parent_id": "37", "cat_name": "茶叶", "child_count": "0", "cat_logo": "" }, { "cat_id": "178", "parent_id": "37", "cat_name": "面包酱", "child_count": "0", "cat_logo": "" }, { "cat_id": "179", "parent_id": "37", "cat_name": "婴儿食品", "child_count": "0", "cat_logo": "" }, { "cat_id": "38", "parent_id": "37", "cat_name": "保健品", "child_count": "2", "cat_logo": "" }, { "cat_id": "119", "parent_id": "37", "cat_name": "冲饮", "child_count": "0", "cat_logo": "" }, { "cat_id": "177", "parent_id": "37", "cat_name": "奶粉", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "107", "parent_id": "25", "cat_name": "酒", "child_count": "4", "cat_logo": "", "children": [ { "cat_id": "134", "parent_id": "107", "cat_name": "啤酒", "child_count": "0", "cat_logo": "" }, { "cat_id": "135", "parent_id": "107", "cat_name": "果酒", "child_count": "0", "cat_logo": "" }, { "cat_id": "108", "parent_id": "107", "cat_name": "黄酒", "child_count": "0", "cat_logo": "" }, { "cat_id": "109", "parent_id": "107", "cat_name": "白酒", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "184", "parent_id": "25", "cat_name": "煮食", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "185", "parent_id": "184", "cat_name": "挂面", "child_count": "0", "cat_logo": "" }, { "cat_id": "186", "parent_id": "184", "cat_name": "米粉", "child_count": "0", "cat_logo": "" } ] } ] }, { "cat_id": "49", "parent_id": "0", "cat_name": "纸品", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "191", "parent_id": "49", "cat_name": "纸品纸景", "child_count": "0", "cat_logo": "" }, { "cat_id": "192", "parent_id": "49", "cat_name": "纸品纸巾", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "50", "parent_id": "192", "cat_name": "纸品", "child_count": "0", "cat_logo": "" }, { "cat_id": "51", "parent_id": "192", "cat_name": "湿巾", "child_count": "0", "cat_logo": "" } ] } ] }, { "cat_id": "63", "parent_id": "0", "cat_name": "女装", "child_count": "2", "cat_logo": "", "children": [ { "cat_id": "65", "parent_id": "63", "cat_name": "上衣", "child_count": "5", "cat_logo": "", "children": [ { "cat_id": "167", "parent_id": "65", "cat_name": "针织衫", "child_count": "0", "cat_logo": "" }, { "cat_id": "168", "parent_id": "65", "cat_name": "衬衫", "child_count": "0", "cat_logo": "" }, { "cat_id": "64", "parent_id": "65", "cat_name": "外套", "child_count": "0", "cat_logo": "" }, { "cat_id": "67", "parent_id": "65", "cat_name": "毛线衫", "child_count": "0", "cat_logo": "" }, { "cat_id": "166", "parent_id": "65", "cat_name": "T恤", "child_count": "0", "cat_logo": "" } ] }, { "cat_id": "66", "parent_id": "63", "cat_name": "下装", "child_count": "4", "cat_logo": "", "children": [ { "cat_id": "169", "parent_id": "66", "cat_name": "牛仔裤", "child_count": "0", "cat_logo": "" }, { "cat_id": "170", "parent_id": "66", "cat_name": "休闲裤", "child_count": "0", "cat_logo": "" }, { "cat_id": "68", "parent_id": "66", "cat_name": "裙装", "child_count": "0", "cat_logo": "" }, { "cat_id": "69", "parent_id": "66", "cat_name": "西裤", "child_count": "0", "cat_logo": "" } ] } ] } ], "version": "1432538842" }, "errNo": 1, "errMsg": "ok", "res": "" } { "data": { "version": 1432538842 }, "errNo": 1, "errMsg": "ok", "res": "" } ~~~ 数据解释: ~~~ cat_id:分类id parent_id: 所在父类id cat_name:分类名称 cat_logo:分类小图 ~~~ ## 实现代码 ~~~ public function getClassify() { $version=intval($_GET["version"]); $flag=true; $mdl_goodsCat = app::get('b2c')->model('goods_cat'); if(!empty($version)) { $filter["lasttime|than"]=$version; $arr=$mdl_goodsCat->getList('lasttime',$filter); if(count($arr)>=1) { $flag=true; } else { $setting['errNo'] = 1; $setting['errMsg'] = $this->errMsg($setting['errNo']); $setting["data"]['version']=$version; return $setting; } } if($flag) { $setting['cat'] = $mdl_goodsCat->get_subcat_list(0,"false"); foreach($setting['cat'] as $k=>$v) { $gCat = $mdl_goodsCat->dump($v['cat_id']); $children = $this->getTreeListCat($v['cat_id']); $setting['cat'][$k]['children'] = $children; } $arr=$mdl_goodsCat->getList('lasttime'); if($arr>=1) { foreach($arr as $key=>$v) { if($version<=$v["lasttime"]) { $version=$v["lasttime"]; } } } $setting['data']["item"]=$this->unsettree($setting['cat'],array("goods_count","hidden","is_leaf","p_order","profit_point","seo_title","seo_keywords","seo_description","gallery_template","cat_path","addon","disabled","finder","gallery_setting","seo_info","tabs","type_id")); unset($setting['cat']); $setting['data']["version"]=$version; $setting['errNo'] = 1; $setting['errMsg'] = $this->errMsg($setting['errNo']); return $setting; } } function getTreeListCat($cat_id) { $mdl_goodsCat = app::get('b2c')->model('goods_cat'); $children = $mdl_goodsCat->get_subcat_list($cat_id); foreach($children as $k=>$v){ $children_2 = $mdl_goodsCat->get_subcat_list($v['cat_id']); if(!empty($children_2)){ $children[$k]['children'] = $children_2; } } return $children; } function unsettree($tree,$parm) { foreach($tree as $key=>$v) { $tree[$key]=$v; if($key==="cat_logo") { if(!empty($tree[$key])) { $tree[$key]=base_storager::image_path($tree[$key],"s"); } } if(is_array($v)) { $tree[$key]=$this->unsettree($v,$parm); } else { if(in_array($key,$parm,true)) { unset($tree[$key]); } } if(in_array($key,$parm,true)) { unset($tree[$key]); } } return $tree; } ~~~ 修改的文件 ~~~ app/b2c/controller/admin/goods/cat.php 行179 app/b2c/model/goods/cat.php 行393 app/b2c/dbschema/goods_cat.php 行21 app/b2c/view/admin/goods/category/info.html 行70 ~~~