作者 赵彬吉

update

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