diff --git a/app/api/lists/goods/GoodsLists.php b/app/api/lists/goods/GoodsLists.php index bf2fcba..5bd6ab3 100644 --- a/app/api/lists/goods/GoodsLists.php +++ b/app/api/lists/goods/GoodsLists.php @@ -65,7 +65,9 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface public function lists(): array { $class_all=$this->request->get('class_all'); + $order_param = $this->request->get('order'); $where=[]; + $order = []; if($class_all){ $arr=[]; $arr2=[]; @@ -77,11 +79,22 @@ class GoodsLists extends BaseAdminDataLists implements ListsSearchInterface $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) - ->field(['id', 'name','brand','class','unit', 'sell', 'code','imgs',]) + ->field(['id', 'name','brand','class','unit', 'sell', 'code','imgs','sales']) ->limit($this->limitOffset, $this->limitLength) ->with(['className','brandName','unitName']) - ->order(['id' => 'desc']) + ->order($order) ->select() ->toArray(); }