|
@@ -39,7 +39,7 @@ class Category extends Api |
|
@@ -39,7 +39,7 @@ class Category extends Api |
39
|
}
|
39
|
}
|
40
|
$tree = Tree::instance();
|
40
|
$tree = Tree::instance();
|
41
|
$tree->init(collection($list)->toArray(), 'pid');
|
41
|
$tree->init(collection($list)->toArray(), 'pid');
|
42
|
- $list = $tree->getTreeArray(0);
|
42
|
+ $list = $this->getTreeList($tree->getTreeArray(0));
|
43
|
// 拼接全部分类,方便前端展示
|
43
|
// 拼接全部分类,方便前端展示
|
44
|
$all_list = [];
|
44
|
$all_list = [];
|
45
|
foreach($list as $v){
|
45
|
foreach($list as $v){
|
|
@@ -52,7 +52,7 @@ class Category extends Api |
|
@@ -52,7 +52,7 @@ class Category extends Api |
52
|
"id" => 0,
|
52
|
"id" => 0,
|
53
|
"pid" => 0,
|
53
|
"pid" => 0,
|
54
|
"name" => "全部",
|
54
|
"name" => "全部",
|
55
|
- "image" => "http://www.silk.top/uploads/20200715/a9c98c6c32fe55481fff5a0f730f9e0d.png",
|
55
|
+ "image" => cdnurl('/assets/img/qrcode.png',true),
|
56
|
"type_text" => "商品分类",
|
56
|
"type_text" => "商品分类",
|
57
|
"flag_text" => "",
|
57
|
"flag_text" => "",
|
58
|
"spacer" => "",
|
58
|
"spacer" => "",
|
|
@@ -61,13 +61,15 @@ class Category extends Api |
|
@@ -61,13 +61,15 @@ class Category extends Api |
61
|
"id" => 0,
|
61
|
"id" => 0,
|
62
|
"pid" => 0,
|
62
|
"pid" => 0,
|
63
|
"name" => "全部",
|
63
|
"name" => "全部",
|
64
|
- "image" => "http://www.silk.top/uploads/20200715/a9c98c6c32fe55481fff5a0f730f9e0d.png",
|
64
|
+ "image" => cdnurl('/assets/img/qrcode.png',true),
|
65
|
"type_text" => "商品分类",
|
65
|
"type_text" => "商品分类",
|
66
|
"flag_text" => "",
|
66
|
"flag_text" => "",
|
67
|
"spacer" => "",
|
67
|
"spacer" => "",
|
68
|
"childlist" => $all_list
|
68
|
"childlist" => $all_list
|
69
|
]
|
69
|
]
|
70
|
- ]
|
70
|
+ ],
|
|
|
71
|
+ "haschild" => 1,
|
|
|
72
|
+ "level" => 1
|
71
|
];
|
73
|
];
|
72
|
array_unshift($list,$all);
|
74
|
array_unshift($list,$all);
|
73
|
$this->success(__('成功'),compact('list'));
|
75
|
$this->success(__('成功'),compact('list'));
|
|
@@ -102,4 +104,22 @@ class Category extends Api |
|
@@ -102,4 +104,22 @@ class Category extends Api |
102
|
$list = \app\common\model\Goods::getList($where,$page,$rows);
|
104
|
$list = \app\common\model\Goods::getList($where,$page,$rows);
|
103
|
$this->success(__('成功'),compact('list'));
|
105
|
$this->success(__('成功'),compact('list'));
|
104
|
}
|
106
|
}
|
|
|
107
|
+
|
|
|
108
|
+ // 判断等级和是否有下级
|
|
|
109
|
+ public function getTreeList($data = [], $level = 1)
|
|
|
110
|
+ {
|
|
|
111
|
+ $arr = [];
|
|
|
112
|
+ $n = 0;
|
|
|
113
|
+ foreach ($data as $k => $v) {
|
|
|
114
|
+ $childlist = isset($v['childlist']) ? $v['childlist'] : [];
|
|
|
115
|
+ $v['haschild'] = $childlist ? 1 : 0;
|
|
|
116
|
+ $v['level'] = $v['pid'] == 0 ? 1 : $level+1;
|
|
|
117
|
+ $arr[$n] = $v;
|
|
|
118
|
+ if ($childlist) {
|
|
|
119
|
+ $arr[$n]['childlist'] = $this->getTreeList($childlist, $v['level']);
|
|
|
120
|
+ }
|
|
|
121
|
+ $n++;
|
|
|
122
|
+ }
|
|
|
123
|
+ return $arr;
|
|
|
124
|
+ }
|
105
|
} |
125
|
} |