From 262c73067425cf4c1920a61735578a09108af7ae Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 11 Aug 2024 17:55:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=A3=80=E6=9F=A5=E4=B8=8E=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E5=A2=9E=E5=BC=BA=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoreBranchProductLists.php | 72 +++++++++++-------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/app/admin/lists/store_branch_product/StoreBranchProductLists.php b/app/admin/lists/store_branch_product/StoreBranchProductLists.php index b51b9c58..3cd42a71 100644 --- a/app/admin/lists/store_branch_product/StoreBranchProductLists.php +++ b/app/admin/lists/store_branch_product/StoreBranchProductLists.php @@ -11,13 +11,14 @@ use app\common\model\system_store\SystemStore; use app\common\lists\ListsSearchInterface; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\lists\ListsExcelInterface; +use app\common\lists\ListsSortInterface; /** * 门店商品辅助表 * Class StoreBranchProductLists * @package app\admin\listssystem_store */ -class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchInterface,ListsExcelInterface +class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface, ListsSortInterface { @@ -30,14 +31,29 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI public function setSearch(): array { return [ - '=' => ['product_id', 'cate_id','store_id','status'], - '%pipe_like%' => ['store_name_code'=>'store_name|bar_code'], + '=' => ['product_id', 'cate_id', 'store_id', 'status'], + '%pipe_like%' => ['store_name_code' => 'store_name|bar_code'], '%like%' => ['store_name'], - '<='=> ['stock'], + '<=' => ['stock'], ]; } - - + /** + * @notes 设置支持排序字段 + * @return string[] + * @remark 格式: ['前端传过来的字段名' => '数据库中的字段名']; + */ + public function setSortFields(): array + { + return ['stock' => 'stock',]; + } + /** + * @notes 设置默认排序 + * @return string[] + */ + public function setDefaultOrder(): array + { + return ['sort' => 'desc', 'stock' => 'desc', 'id' => 'desc']; + } /** * @notes 获取门店列表列表 * @return array @@ -49,32 +65,32 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI */ public function lists(): array { - $class_all=$this->request->get('class_all'); - $where=[]; - if($class_all){ - $arr=Cate::where('pid',$class_all)->column('id'); - if($arr){ - $arr2=Cate::where('pid','in',$arr)->column('id'); - $where[]=['cate_id','in',array_merge($arr,$arr2)]; + $class_all = $this->request->get('class_all'); + $where = []; + if ($class_all) { + $arr = Cate::where('pid', $class_all)->column('id'); + if ($arr) { + $arr2 = Cate::where('pid', 'in', $arr)->column('id'); + $where[] = ['cate_id', 'in', array_merge($arr, $arr2)]; } } - if(empty($where) && $class_all){ + if (empty($where) && $class_all) { //2或者1 - $where[]=['cate_id','=',$class_all]; + $where[] = ['cate_id', '=', $class_all]; } - if($where){ - $this->searchWhere[]=$where; + if ($where) { + $this->searchWhere[] = $where; } return StoreBranchProduct::where($this->searchWhere) - ->field(['id','store_id','product_id', 'image', 'store_name','store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost','purchase', 'status','batch','vip_price','manufacturer_information']) + ->field(['id', 'store_id', 'product_id', 'image', 'store_name', 'store_info', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost', 'purchase', 'status', 'batch', 'vip_price', 'manufacturer_information']) ->when(!empty($this->adminInfo['store_id']), function ($query) { $query->where('store_id', $this->adminInfo['store_id']); }) ->limit($this->limitOffset, $this->limitLength) - ->order(['sort' => 'desc','stock'=>'desc','id' => 'desc']) + ->order($this->sortOrder) ->select() ->each(function ($item) { - $item['system_store_name']=SystemStore::where('id',$item['store_id'])->value('name'); + $item['system_store_name'] = SystemStore::where('id', $item['store_id'])->value('name'); $item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name'); $item['cate_name'] = StoreCategory::where('id', $item['cate_id'])->value('name'); return $item; @@ -98,7 +114,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI ->count(); } - /** + /** * @notes 导出文件名 * @return string * @author 乔峰 @@ -106,9 +122,9 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI */ public function setFileName(): string { - if($this->request->get('store_id')){ - $name=SystemStore::where('id',$this->request->get('store_id'))->value('name'); - return $name.'商品列表'; + if ($this->request->get('store_id')) { + $name = SystemStore::where('id', $this->request->get('store_id'))->value('name'); + return $name . '商品列表'; } return '门店商品列表'; } @@ -122,16 +138,16 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI */ public function setExcelFields(): array { - $data=[ + $data = [ 'store_name' => '商品名称', 'store_info' => '规格', 'unit_name' => '单位', 'cate_name' => '分类', 'stock' => '库存', 'sales' => '销量', - 'purchase'=>'供货价', - 'cost'=>'商户价', - 'vip_price'=>'会员价', + 'purchase' => '供货价', + 'cost' => '商户价', + 'vip_price' => '会员价', 'price' => '零售价', ]; return $data;