...
|
...
|
@@ -39,7 +39,7 @@ class Category extends Api |
|
|
}
|
|
|
$tree = Tree::instance();
|
|
|
$tree->init(collection($list)->toArray(), 'pid');
|
|
|
$list = $tree->getTreeArray(0);
|
|
|
$list = $this->getTreeList($tree->getTreeArray(0));
|
|
|
// 拼接全部分类,方便前端展示
|
|
|
$all_list = [];
|
|
|
foreach($list as $v){
|
...
|
...
|
@@ -52,7 +52,7 @@ class Category extends Api |
|
|
"id" => 0,
|
|
|
"pid" => 0,
|
|
|
"name" => "全部",
|
|
|
"image" => "http://www.silk.top/uploads/20200715/a9c98c6c32fe55481fff5a0f730f9e0d.png",
|
|
|
"image" => cdnurl('/assets/img/qrcode.png',true),
|
|
|
"type_text" => "商品分类",
|
|
|
"flag_text" => "",
|
|
|
"spacer" => "",
|
...
|
...
|
@@ -61,13 +61,15 @@ class Category extends Api |
|
|
"id" => 0,
|
|
|
"pid" => 0,
|
|
|
"name" => "全部",
|
|
|
"image" => "http://www.silk.top/uploads/20200715/a9c98c6c32fe55481fff5a0f730f9e0d.png",
|
|
|
"image" => cdnurl('/assets/img/qrcode.png',true),
|
|
|
"type_text" => "商品分类",
|
|
|
"flag_text" => "",
|
|
|
"spacer" => "",
|
|
|
"childlist" => $all_list
|
|
|
]
|
|
|
]
|
|
|
],
|
|
|
"haschild" => 1,
|
|
|
"level" => 1
|
|
|
];
|
|
|
array_unshift($list,$all);
|
|
|
$this->success(__('成功'),compact('list'));
|
...
|
...
|
@@ -102,4 +104,22 @@ class Category extends Api |
|
|
$list = \app\common\model\Goods::getList($where,$page,$rows);
|
|
|
$this->success(__('成功'),compact('list'));
|
|
|
}
|
|
|
|
|
|
// 判断等级和是否有下级
|
|
|
public function getTreeList($data = [], $level = 1)
|
|
|
{
|
|
|
$arr = [];
|
|
|
$n = 0;
|
|
|
foreach ($data as $k => $v) {
|
|
|
$childlist = isset($v['childlist']) ? $v['childlist'] : [];
|
|
|
$v['haschild'] = $childlist ? 1 : 0;
|
|
|
$v['level'] = $v['pid'] == 0 ? 1 : $level+1;
|
|
|
$arr[$n] = $v;
|
|
|
if ($childlist) {
|
|
|
$arr[$n]['childlist'] = $this->getTreeList($childlist, $v['level']);
|
|
|
}
|
|
|
$n++;
|
|
|
}
|
|
|
return $arr;
|
|
|
}
|
|
|
} |
...
|
...
|
|