|
@@ -213,4 +213,85 @@ class CategoryService
|
|
|
}
|
|
|
return $category->category_super_path;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Notes: 获取树状分类信息
|
|
|
+ * User: ZhouBenXu
|
|
|
+ * DateTime: 2024/7/2 下午2:52
|
|
|
+ * @param $parentId
|
|
|
+ * @return \support\Response
|
|
|
+ */
|
|
|
+ public static function getCategoryTree($parentId)
|
|
|
+ {
|
|
|
+ // 查询当前父级ID下的所有分类
|
|
|
+ $list = self::getAllCategories($parentId);
|
|
|
+ $allCategories = self::getTree($list,152);
|
|
|
+ return json_success('',$allCategories);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Notes: 获取指定分类下的所有分类
|
|
|
+ * User: ZhouBenXu
|
|
|
+ * DateTime: 2024/7/2 下午2:41
|
|
|
+ * @param $parentId
|
|
|
+ * @param $categories
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public static function getAllCategories($parentId = 0, $categories = [])
|
|
|
+ {
|
|
|
+ // 查询当前父级ID下的所有分类
|
|
|
+ $row = SysCategory::where('category_super_id', $parentId)->where('category_status', 'ACTIVED')->get()->toArray();
|
|
|
+ if(!empty($row)) {
|
|
|
+ foreach ($row as $key => $value) {
|
|
|
+ // 当前分类加入数组
|
|
|
+ $value['label'] = $value['category_name'];
|
|
|
+ $value['value'] = $value['category_id'];
|
|
|
+ $categories[] = $value;
|
|
|
+ // 递归查询子分类
|
|
|
+ $categories = self::getAllCategories($value['category_id'], $categories);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $categories;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Notes: 树状结构
|
|
|
+ * User: ZhouBenXu
|
|
|
+ * DateTime: 2024/7/2 下午2:51
|
|
|
+ * @param $list
|
|
|
+ * @param $id
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function getTree($list = [], $id = 0)
|
|
|
+ {
|
|
|
+ $tree = array();
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ if ($v['category_super_id'] == $id) {
|
|
|
+ if (!empty(self::getTree($list, $v['category_id']))) {
|
|
|
+ $v['children'] = self::getTree($list, $v['category_id']);
|
|
|
+ }
|
|
|
+ $tree[] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $tree;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Desc 分类详情
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/2/22 11:37
|
|
|
+ *
|
|
|
+ * @param $id
|
|
|
+ * @return \support\Response
|
|
|
+ */
|
|
|
+ public static function getCategoryInfos($ids)
|
|
|
+ {
|
|
|
+ $category = SysCategory::whereIn('category_id', $ids)->select(['category_id','category_name','category_super_id'])->get()->toArray();
|
|
|
+ if (!$category) {
|
|
|
+ return json_fail('分类不存在');
|
|
|
+ }
|
|
|
+ return $category;
|
|
|
+ }
|
|
|
+
|
|
|
}
|