|
@@ -14,6 +14,12 @@ class Category extends Base |
|
@@ -14,6 +14,12 @@ class Category extends Base |
|
14
|
//设置关联表名
|
14
|
//设置关联表名
|
|
15
|
protected $table = 'gl_product_category';
|
15
|
protected $table = 'gl_product_category';
|
|
16
|
|
16
|
|
|
|
|
17
|
+ /**
|
|
|
|
18
|
+ * 子分类
|
|
|
|
19
|
+ * @var array
|
|
|
|
20
|
+ */
|
|
|
|
21
|
+ protected $child_ids_arr = [];
|
|
|
|
22
|
+
|
|
17
|
public function getImageAttribute($value)
|
23
|
public function getImageAttribute($value)
|
|
18
|
{
|
24
|
{
|
|
19
|
return Upload::path2url($value);
|
25
|
return Upload::path2url($value);
|
|
@@ -23,4 +29,37 @@ class Category extends Base |
|
@@ -23,4 +29,37 @@ class Category extends Base |
|
23
|
{
|
29
|
{
|
|
24
|
$this->attributes['image'] = Upload::url2path($value);
|
30
|
$this->attributes['image'] = Upload::url2path($value);
|
|
25
|
}
|
31
|
}
|
|
|
|
32
|
+
|
|
|
|
33
|
+
|
|
|
|
34
|
+ /**
|
|
|
|
35
|
+ * 获取指定分类的所有子分类IDS(包括自己)
|
|
|
|
36
|
+ * @param $id
|
|
|
|
37
|
+ * @return array
|
|
|
|
38
|
+ * @author zbj
|
|
|
|
39
|
+ * @date 2023/4/28
|
|
|
|
40
|
+ */
|
|
|
|
41
|
+ public function getChildIdsArr($id)
|
|
|
|
42
|
+ {
|
|
|
|
43
|
+ $this->child_ids_arr = [$id];
|
|
|
|
44
|
+ return $this->getChildrenIdArr($id);
|
|
|
|
45
|
+ }
|
|
|
|
46
|
+
|
|
|
|
47
|
+ /**
|
|
|
|
48
|
+ * 递归获取指定分类的所有子孙
|
|
|
|
49
|
+ * @param $id
|
|
|
|
50
|
+ * @return array
|
|
|
|
51
|
+ * @author zbj
|
|
|
|
52
|
+ * @date 2023/4/28
|
|
|
|
53
|
+ */
|
|
|
|
54
|
+ protected function getChildrenIdArr($id)
|
|
|
|
55
|
+ {
|
|
|
|
56
|
+ $list = parent::where("pid", $id)->pluck('pid', 'id');
|
|
|
|
57
|
+ if ($list) {
|
|
|
|
58
|
+ foreach ($list as $id => $pid) {
|
|
|
|
59
|
+ $this->child_ids_arr[] = $id;
|
|
|
|
60
|
+ $this->getChildrenIdArr($id);
|
|
|
|
61
|
+ }
|
|
|
|
62
|
+ }
|
|
|
|
63
|
+ return $this->child_ids_arr;
|
|
|
|
64
|
+ }
|
|
26
|
} |
65
|
} |