首页商品按销量价格排序

This commit is contained in:
weiz 2024-05-06 18:03:18 +08:00
parent aafadca94c
commit 68f32cc0d0

View File

@ -65,7 +65,9 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array public function lists(): array
{ {
$class_all=$this->request->get('class_all'); $class_all=$this->request->get('class_all');
$order_param = $this->request->get('order');
$where=[]; $where=[];
$order = [];
if($class_all){ if($class_all){
$arr=[]; $arr=[];
$arr2=[]; $arr2=[];
@ -77,11 +79,22 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface
$where[]=['class','=',$class_all]; $where[]=['class','=',$class_all];
} }
} }
if(!empty($order_param)){
if($order_param == 'asc'){
$order['sell'] = 'asc';
}elseif ($order_param == 'desc') {
$order['sell'] = 'desc';
}elseif ($order_param=='sales') {
$order['sales'] = 'desc';
}else{
$order['id'] = 'desc';
}
}
return Goods::where($this->searchWhere)->where($where) return Goods::where($this->searchWhere)->where($where)
->field(['id', 'name','brand','class','unit', 'sell', 'code','imgs',]) ->field(['id', 'name','brand','class','unit', 'sell', 'code','imgs','sales'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->with(['className','brandName','unitName']) ->with(['className','brandName','unitName'])
->order(['id' => 'desc']) ->order($order)
->select() ->select()
->toArray(); ->toArray();
} }