作者 赵彬吉

update

@@ -8,6 +8,7 @@ use App\Helper\Arr; @@ -8,6 +8,7 @@ use App\Helper\Arr;
8 use App\Http\Controllers\Bside\BaseController; 8 use App\Http\Controllers\Bside\BaseController;
9 use App\Http\Logic\Bside\Product\ProductLogic; 9 use App\Http\Logic\Bside\Product\ProductLogic;
10 use App\Http\Requests\Bside\Product\ProductRequest; 10 use App\Http\Requests\Bside\Product\ProductRequest;
  11 +use App\Models\Product\CategoryRelated;
11 use App\Rules\Ids; 12 use App\Rules\Ids;
12 use Illuminate\Http\Request; 13 use Illuminate\Http\Request;
13 14
@@ -26,9 +27,13 @@ class ProductController extends BaseController @@ -26,9 +27,13 @@ class ProductController extends BaseController
26 if(!empty($this->param['search'])){ 27 if(!empty($this->param['search'])){
27 $map[] = ['title', 'like', "%{$this->param['search']}%"]; 28 $map[] = ['title', 'like', "%{$this->param['search']}%"];
28 } 29 }
29 - if(!empty($this->param['created_at'])){ 30 + if(!empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
30 $map[] = ['created_at', 'between', $this->param['created_at']]; 31 $map[] = ['created_at', 'between', $this->param['created_at']];
31 } 32 }
  33 + if(!empty($this->param['category_id'])){
  34 + $ids = CategoryRelated::where('cate_id', $this->param['category_id'])->pluck('product_id')->toArray();
  35 + $map[] = ['id', 'in', $ids];
  36 + }
32 $sort = ['id' => 'desc']; 37 $sort = ['id' => 'desc'];
33 $data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_at', 'updated_at']); 38 $data = $logic->getList($map, $sort, ['id', 'title', 'thumb', 'category_id', 'keywords', 'status', 'created_at', 'updated_at']);
34 return $this->success($data); 39 return $this->success($data);
@@ -24,6 +24,18 @@ class ProductLogic extends BaseLogic @@ -24,6 +24,18 @@ class ProductLogic extends BaseLogic
24 $this->model = new Product(); 24 $this->model = new Product();
25 } 25 }
26 26
  27 + public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
  28 + {
  29 + $data = parent::getList($map, $sort, $columns, $limit);
  30 + foreach ($data['list'] as &$v){
  31 + foreach ($v['category_id'] as $category_id){
  32 + $v['category_id_text'][] =(new CategoryLogic())->getCacheInfo($category_id)['title']??'';
  33 + }
  34 + $v['category_id_text'] = array_filter($v['category_id_text']);
  35 + }
  36 + return $this->success($data);
  37 + }
  38 +
27 public function save($param){ 39 public function save($param){
28 //封面取第一个图片 40 //封面取第一个图片
29 $param['thumb'] = $param['gallery'][0] ?? ''; 41 $param['thumb'] = $param['gallery'][0] ?? '';