From 48bf661a788c96cafc6f0d6cfd541726bd8b53f1 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 11 Jun 2024 15:52:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(cate):=20=E6=9B=B4=E6=96=B0=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=86=E7=B1=BB=E9=80=BB=E8=BE=91=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_product/StoreProductLogic.php | 36 ++++++---- app/api/lists/cate/CateLists.php | 67 +++++++------------ 2 files changed, 47 insertions(+), 56 deletions(-) diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 55d158f10..7d5299217 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -183,26 +183,34 @@ class StoreProductLogic extends BaseLogic /** * 更新商品分类 */ - public static function updateGoodsclass($id, $type = 0) + public static function updateGoodsclass($cate_id, $type = 0) { - $pid = StoreCategory::where('id', $id)->value('pid'); + $pid = StoreCategory::where('id', $cate_id)->value('pid'); if ($pid) { - $goodsclass = StoreCategory::where('id', $pid)->field('pid,children')->find(); - if ($goodsclass) { - if (count($goodsclass['children']) >= 1) { - if (!in_array($id, $goodsclass['children'])) { - $arr = $goodsclass['children']; - array_push($arr, $id); - StoreCategory::where('id', $pid)->update(['children' => $arr]); - if ($goodsclass['pid'] != 0 && $type == 0) { - self::updateGoodsclass($pid, 1); - } - } - } + //查二级分类 + $StoreCategory = StoreCategory::where('id', $pid)->find(); + if ($StoreCategory) { + $StoreCategory = StoreCategory::where('id', $StoreCategory['id'])->find(); + self::cate_update($cate_id,0,3); + self::cate_update($pid,0,2); + self::cate_update($StoreCategory['id'],0,1); + } else { + self::cate_update($cate_id,0,2); + self::cate_update($pid,0,1); } + } else { + self::cate_update($cate_id,0,1); } } + public static function cate_update($cate_id=0,$product_id=0,$leve=1){ + $find=Db::name('store_product_cate')->where(['store_id' => 1, 'cate_id' => $cate_id,'leve'=>$leve])->find(); + if($find){ + Db::name('store_product_cate')->where('id',$find['id'])->inc('count',1)->update(); + }else{ + Db::name('store_product_cate')->insert(['store_id' => 1, 'cate_id' => $cate_id,'count'=>1,'leve'=>$leve,'create_time'=>time(),'update_time'=>time()]); + } + } /** * 复制商品到门店 */ diff --git a/app/api/lists/cate/CateLists.php b/app/api/lists/cate/CateLists.php index 8d2b74a0d..d8d5184af 100644 --- a/app/api/lists/cate/CateLists.php +++ b/app/api/lists/cate/CateLists.php @@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists; use app\common\model\cate\Cate; use app\common\lists\ListsSearchInterface; use app\Request; +use think\facade\Db; /** * 商品分类列表 @@ -26,7 +27,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['pid', 'name', 'data', 'pic', 'sort'], + '=' => ['pid', 'name', 'data', 'store_id', 'sort'], ]; } @@ -42,36 +43,27 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - $pid=Request()->get('pid',0); - if($pid==0){ - $lists = Cate::where($this->searchWhere) - ->where('pid', 0) - ->where('children','<>',null) - ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) - ->limit($this->limitOffset, $this->limitLength) - ->order(['sort' => 'desc','id' => 'desc']) - ->select()->toArray(); - }else{ - $three=Request()->get('three',0); - if($three==0){ - $where[]=['children','<>','']; - $this->where=$where; - } - $lists = Cate::where($this->searchWhere) - ->where($this->where) - ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) - ->limit($this->limitOffset, $this->limitLength) - ->order(['sort' => 'desc','id' => 'desc']) - ->select()->toArray(); + $leve = Request()->get('leve', 1); + $this->searchWhere[] = ['leve', '=', $leve]; + $this->searchWhere[] = ['count', '>', 0]; + $cate_arr = Db::name('store_product_cate')->where($this->searchWhere)->column('cate_id'); + $lists = []; + if ($cate_arr) { + return Cate::where('id', 'in', $cate_arr) + ->field(['id', 'pid', 'name', 'data', 'pic', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->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(); + + // ->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'); @@ -87,17 +79,8 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - $pid=Request()->get('pid',0); - if($pid==0){ - return Cate::where($this->searchWhere)->where('pid', 0) - ->where('children','<>',null) - ->count(); - }else{ - return Cate::where($this->searchWhere) - ->where($this->where) - ->count(); - } + return Db::name('store_product_cate')->where($this->searchWhere) + ->count(); } - -} \ No newline at end of file +}