作者 lyh

gx

@@ -29,62 +29,54 @@ class ProductController extends BaseController @@ -29,62 +29,54 @@ class ProductController extends BaseController
29 29
30 public function index(Product $product) 30 public function index(Product $product)
31 { 31 {
32 -// $map = [];  
33 -// if(!empty($this->param['search'])){  
34 -// $map[] = ['title', 'like', "%{$this->param['search']}%"];  
35 -// }  
36 -// if(!empty($this->param['created_at'][0])){  
37 -// $this->param['created_at'][0] .= ' 00:00:00';  
38 -// }  
39 -// if(!empty($this->param['created_at'][1])){  
40 -// $this->param['created_at'][1] .= ' 23:59:59';  
41 -// }  
42 -// if(empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){  
43 -// $map[] = ['created_at', '>=', $this->param['created_at'][0]];  
44 -// }  
45 -// if(!empty($this->param['created_at'][0]) && empty($this->param['created_at'][1])){  
46 -// $map[] = ['created_at', '<=', $this->param['created_at']];  
47 -// }  
48 -// if(!empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){  
49 -// $map[] = ['created_at', 'between', [$this->param['created_at']]];  
50 -// }  
51 -// if(!empty($this->param['category_id'])){  
52 -// $ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray();  
53 -// $map[] = ['id', 'in', $ids];  
54 -// }  
55 -// if(!empty($this->param['keyword_id'])){  
56 -// $ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray();  
57 -// $map[] = ['id', 'in', $ids];  
58 -// }  
59 -// if(isset($this->param['status'])){  
60 -// $map[] = ['status', $this->param['status']];  
61 -// }  
62 -// $sort = ['id' => 'desc']; 32 + if(isset($this->map['title']) && !empty($this->map['title'])){
  33 + $this->map['title'] = ['like','%'.$this->map['title'].'%'];
  34 + }
63 $filed = ['id', 'project_id', 'title', 'thumb', 'product_type' , 'route' ,'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at']; 35 $filed = ['id', 'project_id', 'title', 'thumb', 'product_type' , 'route' ,'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'];
64 $lists = $product->lists($this->map,$this->page,$this->row,$this->order,$filed); 36 $lists = $product->lists($this->map,$this->page,$this->row,$this->order,$filed);
65 if(!empty($lists['list'])){ 37 if(!empty($lists['list'])){
66 - foreach ($lists['list'] as &$v){  
67 - $v['thumb']['image_link'] = getImageUrl($v['thumb']['url']);//图片统一  
68 - $v['category_id_text'] = '';  
69 - $v['keyword_id_text'] = '';  
70 - if(!empty($v['category_id'])){  
71 - $category_arr = explode(',',$v['category_id']);  
72 - $categoryModel = new Category();  
73 - $category_data = $categoryModel->list(['id'=>['in',$category_arr]]);  
74 - }  
75 - if(!empty($v['keyword_id'])){  
76 - $keyword_arr = explode(',',$v['keyword_id']);  
77 - $keywordModel = new Keyword();  
78 - $keyword_data = $keywordModel->list(['id'=>['in',$keyword_arr]]);  
79 - }  
80 - $v['status_text'] = Product::statusMap()[$info['status']] ?? '';  
81 - $v['created_uid_text'] = (new User())->read(['id'=>$v['created_uid']])['name'] ?? ''; 38 + foreach ($lists['list'] as $k=>$v){
  39 + //处理参数
  40 + $v = $this->handleParam($v);
  41 + $lists['lists'][$k] = $v;
82 } 42 }
83 } 43 }
84 return $this->response('success',Code::SUCCESS,$lists); 44 return $this->response('success',Code::SUCCESS,$lists);
85 } 45 }
86 46
87 - 47 + /**
  48 + * @remark :处理列表参数
  49 + * @name :handleParam
  50 + * @author :lyh
  51 + * @method :post
  52 + * @time :2023/8/17 9:15
  53 + */
  54 + public function handleParam($v){
  55 + $v['thumb']['image_link'] = getImageUrl($v['thumb']['url']);//图片统一
  56 + $v['category_id_text'] = '';
  57 + $v['keyword_id_text'] = '';
  58 + if(!empty($v['category_id'])){
  59 + $category_arr = explode(',',$v['category_id']);
  60 + $categoryModel = new Category();
  61 + $category_data = $categoryModel->list(['id'=>['in',$category_arr]],'id',['title']);
  62 + foreach ($category_data as $v1){
  63 + $v['category_id_text'] .= $v1['title'].',';
  64 + }
  65 + $v['category_id_text'] = trim($v['category_id_text'],',');
  66 + }
  67 + if(!empty($v['keyword_id'])){
  68 + $keyword_arr = explode(',',$v['keyword_id']);
  69 + $keywordModel = new Keyword();
  70 + $keyword_data = $keywordModel->list(['id'=>['in',$keyword_arr]]);
  71 + foreach ($keyword_data as $v1){
  72 + $v['keyword_id_text'] .= $v1['title'].',';
  73 + }
  74 + $v['keyword_id_text'] = trim($v['keyword_id_text'],',');
  75 + }
  76 + $v['status_text'] = Product::statusMap()[$info['status']] ?? '';
  77 + $v['created_uid_text'] = (new User())->read(['id'=>$v['created_uid']])['name'] ?? '';
  78 + return $v;
  79 + }
88 80
89 public function info(Request $request, ProductLogic $logic){ 81 public function info(Request $request, ProductLogic $logic){
90 $request->validate([ 82 $request->validate([