作者 lyh

gx

... ... @@ -29,62 +29,54 @@ class ProductController extends BaseController
public function index(Product $product)
{
// $map = [];
// if(!empty($this->param['search'])){
// $map[] = ['title', 'like', "%{$this->param['search']}%"];
// }
// if(!empty($this->param['created_at'][0])){
// $this->param['created_at'][0] .= ' 00:00:00';
// }
// if(!empty($this->param['created_at'][1])){
// $this->param['created_at'][1] .= ' 23:59:59';
// }
// if(empty($this->param['created_at'][0]) && !empty($this->param['created_at'][1])){
// $map[] = ['created_at', '>=', $this->param['created_at'][0]];
// }
// if(!empty($this->param['created_at'][0]) && empty($this->param['created_at'][1])){
// $map[] = ['created_at', '<=', $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];
// }
// if(!empty($this->param['keyword_id'])){
// $ids = KeywordRelated::where('keyword_id', $this->param['keyword_id'])->pluck('product_id')->toArray();
// $map[] = ['id', 'in', $ids];
// }
// if(isset($this->param['status'])){
// $map[] = ['status', $this->param['status']];
// }
// $sort = ['id' => 'desc'];
if(isset($this->map['title']) && !empty($this->map['title'])){
$this->map['title'] = ['like','%'.$this->map['title'].'%'];
}
$filed = ['id', 'project_id', 'title', 'thumb', 'product_type' , 'route' ,'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'];
$lists = $product->lists($this->map,$this->page,$this->row,$this->order,$filed);
if(!empty($lists['list'])){
foreach ($lists['list'] as &$v){
$v['thumb']['image_link'] = getImageUrl($v['thumb']['url']);//图片统一
$v['category_id_text'] = '';
$v['keyword_id_text'] = '';
if(!empty($v['category_id'])){
$category_arr = explode(',',$v['category_id']);
$categoryModel = new Category();
$category_data = $categoryModel->list(['id'=>['in',$category_arr]]);
}
if(!empty($v['keyword_id'])){
$keyword_arr = explode(',',$v['keyword_id']);
$keywordModel = new Keyword();
$keyword_data = $keywordModel->list(['id'=>['in',$keyword_arr]]);
}
$v['status_text'] = Product::statusMap()[$info['status']] ?? '';
$v['created_uid_text'] = (new User())->read(['id'=>$v['created_uid']])['name'] ?? '';
foreach ($lists['list'] as $k=>$v){
//处理参数
$v = $this->handleParam($v);
$lists['lists'][$k] = $v;
}
}
return $this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :处理列表参数
* @name :handleParam
* @author :lyh
* @method :post
* @time :2023/8/17 9:15
*/
public function handleParam($v){
$v['thumb']['image_link'] = getImageUrl($v['thumb']['url']);//图片统一
$v['category_id_text'] = '';
$v['keyword_id_text'] = '';
if(!empty($v['category_id'])){
$category_arr = explode(',',$v['category_id']);
$categoryModel = new Category();
$category_data = $categoryModel->list(['id'=>['in',$category_arr]],'id',['title']);
foreach ($category_data as $v1){
$v['category_id_text'] .= $v1['title'].',';
}
$v['category_id_text'] = trim($v['category_id_text'],',');
}
if(!empty($v['keyword_id'])){
$keyword_arr = explode(',',$v['keyword_id']);
$keywordModel = new Keyword();
$keyword_data = $keywordModel->list(['id'=>['in',$keyword_arr]]);
foreach ($keyword_data as $v1){
$v['keyword_id_text'] .= $v1['title'].',';
}
$v['keyword_id_text'] = trim($v['keyword_id_text'],',');
}
$v['status_text'] = Product::statusMap()[$info['status']] ?? '';
$v['created_uid_text'] = (new User())->read(['id'=>$v['created_uid']])['name'] ?? '';
return $v;
}
public function info(Request $request, ProductLogic $logic){
$request->validate([
... ...