From b95964cbaf30da9f5c36534a3567b1dc6aed2ade Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Thu, 27 Jun 2024 15:26:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A1=A8=E5=AD=98=E5=82=A8=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/cate/CateLists.php | 56 +++++++++++++++++--------- app/api/lists/product/ProductLists.php | 31 +++++++------- 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/app/api/lists/cate/CateLists.php b/app/api/lists/cate/CateLists.php index e924419bf..7139e303d 100644 --- a/app/api/lists/cate/CateLists.php +++ b/app/api/lists/cate/CateLists.php @@ -6,6 +6,7 @@ namespace app\api\lists\cate; use app\admin\lists\BaseAdminDataLists; use app\common\model\cate\Cate; use app\common\lists\ListsSearchInterface; +use app\common\model\store_branch_product\StoreBranchProduct; use app\Request; use think\facade\Db; @@ -27,7 +28,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['name', 'data', 'store_id', 'sort', 'pid'], + '=' => ['name', 'data', 'store_id', 'sort'], ]; } @@ -44,10 +45,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function lists(): array { $level = Request()->get('level', 1); - $this->searchWhere[] = ['level', '=', $level]; - $this->searchWhere[] = ['count', '>', 0]; - $this->searchWhere[] = ['delete_time', '=', null]; - $cate_arr = Db::name('store_product_cate')->where($this->searchWhere)->column('cate_id'); + $pid = $this->request->get('pid',0); + $this->searchWhere[] = ['stock', '>', 0]; + $this->searchWhere[] = ['status', '=', 1]; + if($pid == 0 && $level ==1){ + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('top_cate_id'); + } + if($pid && $level ==2){ + $this->searchWhere[] = ['top_cate_id','=',$pid]; + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('two_cate_id'); + } + + if($pid && $level ==3){ + $this->searchWhere[] = ['two_cate_id','=',$pid]; + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('cate_id'); + } $lists = []; if ($cate_arr) { return Cate::where('id', 'in', $cate_arr) @@ -56,18 +71,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface ->order(['sort' => 'desc', 'id' => 'desc']) ->select()->toArray(); } - - // ->each(function ($item) { - // $a = Goodsclass::where('pid', $item['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select(); - // $item['children'] = $a; - // foreach ($a as $k => &$v) { - // $b = Goodsclass::where('pid', $v['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select(); - // $v['children'] = $b; - // } - // })->toArray(); - return $lists; - // return linear_to_tree($lists, 'children'); } @@ -80,8 +84,24 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { + $level = Request()->get('level', 1); + $pid = $this->request->get('pid',0); + if($pid == 0 && $level ==1){ + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('top_cate_id'); + } - return Db::name('store_product_cate')->where($this->searchWhere) - ->count(); + if($pid && $level ==2){ + $this->searchWhere[] = ['top_cate_id','=',$pid]; + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('two_cate_id'); + } + + if($pid && $level ==3){ + $this->searchWhere[] = ['two_cate_id','=',$pid]; + $cate_arr = StoreBranchProduct::where($this->searchWhere)->distinct() + ->column('cate_id'); + } + return Cate::where('id', 'in', $cate_arr)->count(); } } diff --git a/app/api/lists/product/ProductLists.php b/app/api/lists/product/ProductLists.php index a2aec1a21..9d299fedd 100644 --- a/app/api/lists/product/ProductLists.php +++ b/app/api/lists/product/ProductLists.php @@ -33,13 +33,10 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L public function setSearch(): array { return [ - '=' => ['store_id', 'cate_id'], - '%pipe_like%' => ['store_name' => 'store_name|bar_code'], - ]; - return [ - '=' => ['store_id', 'cate_id'], + '=' => ['store_id', 'cate_id','top_cate_id','two_cate_id'], '%pipe_like%' => ['store_name' => 'store_name|bar_code'], ]; + } /** * @notes 设置支持排序字段 @@ -74,17 +71,17 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L */ public function lists(): array { - $class_all = $this->request->get('class_all'); - if ($class_all) { - //查3级别的 - $arr = Cate::where('pid', $class_all)->column('id'); - if ($arr) { - $arr2 = Cate::where('pid', 'in', $arr)->column('id'); - $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; - } else { - $this->searchWhere[] = ['cate_id', '=', $class_all]; - } - } +// $class_all = $this->request->get('class_all'); +// if ($class_all) { +// //查3级别的 +// $arr = Cate::where('pid', $class_all)->column('id'); +// if ($arr) { +// $arr2 = Cate::where('pid', 'in', $arr)->column('id'); +// $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; +// } else { +// $this->searchWhere[] = ['cate_id', '=', $class_all]; +// } +// } $order = $this->request->get('order',''); $field = $this->request->get('field',''); if(empty($order)||empty($field)){ @@ -92,7 +89,7 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L }else{ $order = [$field => $order]; } - $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch'; + $fields = 'id,product_id,cate_id,store_name,cost,store_id,vip_price,purchase,price,bar_code,image,sales,store_info,delete_time,unit,batch,top_cate_id,two_cate_id'; $this->searchWhere[] = ['status', '=', 1]; $this->searchWhere[] = ['stock', '>', 0];