作者 lyh

gx

@@ -36,18 +36,49 @@ class CategoryController extends BaseController @@ -36,18 +36,49 @@ class CategoryController extends BaseController
36 $filed = ['id', 'project_id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at']; 36 $filed = ['id', 'project_id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'];
37 $list = $category->list($this->map,'id',$filed); 37 $list = $category->list($this->map,'id',$filed);
38 if(!empty($list)){ 38 if(!empty($list)){
39 - $data = array();  
40 - foreach ($list as $v){  
41 - $v = (array)$v;  
42 - if ($v['pid'] == 0) {  
43 - $v['sub'] = _get_child($v['id'], $list);  
44 - $data[] = $v;  
45 - } 39 + foreach ($list as $k =>$v){
  40 + $v = $this->handleParam($category,$v);
  41 + $list[$k] = $v;
46 } 42 }
  43 + $data = $this->getListSon($list);
47 } 44 }
48 return $this->response('success',Code::SUCCESS,$data); 45 return $this->response('success',Code::SUCCESS,$data);
49 } 46 }
50 47
  48 + /**
  49 + * @remark :分类处理参数
  50 + * @name :handleParam
  51 + * @author :lyh
  52 + * @method :post
  53 + * @time :2023/8/17 11:10
  54 + */
  55 + public function handleParam(&$category,$v){
  56 + $v['url'] = $this->user['domain'] . $v['route'] ;
  57 + $cate_ids = $category->getChildIdsArr($v['id']);
  58 + $v['product_num'] = CategoryRelated::whereIn('cate_id', $cate_ids)->distinct()->count('product_id');
  59 + $v['image_link'] = getImageUrl($v['image']);
  60 + return $v;
  61 + }
  62 +
  63 + /**
  64 + * @remark :无分页子集处理
  65 + * @name :getListSon
  66 + * @author :lyh
  67 + * @method :post
  68 + * @time :2023/8/17 11:12
  69 + */
  70 + public function getListSon(&$list){
  71 + $data = array();
  72 + foreach ($list as $v){
  73 + $v = (array)$v;
  74 + if ($v['pid'] == 0) {
  75 + $v['sub'] = _get_child($v['id'], $list);
  76 + $data[] = $v;
  77 + }
  78 + }
  79 + return $data;
  80 + }
  81 +
51 public function info(Request $request, CategoryLogic $logic){ 82 public function info(Request $request, CategoryLogic $logic){
52 $request->validate([ 83 $request->validate([
53 'id'=>'required' 84 'id'=>'required'
@@ -27,19 +27,19 @@ class CategoryLogic extends BaseLogic @@ -27,19 +27,19 @@ class CategoryLogic extends BaseLogic
27 $this->model = new Category(); 27 $this->model = new Category();
28 } 28 }
29 29
30 -// public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)  
31 -// {  
32 -// $data = parent::getList($map, $sort, $columns, $limit);  
33 -// foreach ($data as &$v){  
34 -// $v['url'] = $this->getProjectDomain() . $v['route'] ;  
35 -// $v['product_num'] = $this->getProductNum($v['id']);  
36 -// $v['image_link'] = getImageUrl($v['image']);  
37 -// }  
38 -// if(!$map){  
39 -// $data = Arr::listToTree($data);  
40 -// }  
41 -// return $this->success($data);  
42 -// } 30 + public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
  31 + {
  32 + $data = parent::getList($map, $sort, $columns, $limit);
  33 + foreach ($data as &$v){
  34 + $v['url'] = $this->getProjectDomain() . $v['route'] ;
  35 + $v['product_num'] = $this->getProductNum($v['id']);
  36 + $v['image_link'] = getImageUrl($v['image']);
  37 + }
  38 + if(!$map){
  39 + $data = Arr::listToTree($data);
  40 + }
  41 + return $this->success($data);
  42 + }
43 43
44 public function getInfo($id) 44 public function getInfo($id)
45 { 45 {