From 2d189279cfaa8361a0e604c1bca725c16033d739 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 11 Jun 2024 17:09:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=AE=A1=E7=90=86=E9=80=BB=E8=BE=91=E5=92=8C=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_product/StoreProductLogic.php | 53 ++++++++----------- app/api/lists/cate/CateLists.php | 2 +- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 7d5299217..e056f2088 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -66,26 +66,22 @@ class StoreProductLogic extends BaseLogic "unique" => setUnique($res['id'], '', 0), 'sales' => 0, ]); - StoreCategory::where('id', $params['cate_id'])->inc('three')->update(); - Db::commit(); if ($params['is_store_all'] == 1) { $store_arr = SystemStore::where('is_show', 1)->column('id'); - foreach($store_arr as $store_id){ - Redis::send('store-storage', ['product_arr' => ['id'=>$res['id'],'stock'=>0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]); + foreach ($store_arr as $store_id) { + Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]); } // Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $store_arr]); } else { if (is_array($params['store_arr']) && count($params['store_arr']) > 0) { - foreach($params['store_arr'] as $key =>$store_id){ - Redis::send('store-storage', ['product_arr' => ['id'=>$res['id'],'stock'=>0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]); + foreach ($params['store_arr'] as $key => $store_id) { + Redis::send('store-storage', ['product_arr' => ['id' => $res['id'], 'stock' => 0], 'store_id' => $store_id, 'admin_id' => Request()->adminId]); } // Redis::send('copy-product', ['product_id' => $res['id'], 'store_arr' => $params['store_arr']]); } } - - return true; } catch (\Exception $e) { Db::rollback(); @@ -185,30 +181,27 @@ class StoreProductLogic extends BaseLogic */ public static function updateGoodsclass($cate_id, $type = 0) { - $pid = StoreCategory::where('id', $cate_id)->value('pid'); - if ($pid) { + $one = StoreCategory::where('id', $cate_id)->find(); + if ($one) { //查二级分类 - $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); + $two = StoreCategory::where('id', $one['pid'])->find(); + if ($two) { + if ($two['pid'] != 0) { + self::cate_update($cate_id,$two['id'],0,3); + self::cate_update($two['id'],$two['pid'],0,2); + self::cate_update($two['pid'],0,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()]); + public static function cate_update($cate_id = 0,$pid=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(['pid'=>$pid,'store_id' => 1, 'cate_id' => $cate_id, 'count' => 1, 'leve' => $leve, 'create_time' => time(), 'update_time' => time()]); } } /** @@ -277,10 +270,11 @@ class StoreProductLogic extends BaseLogic /** * 增加库存 */ - public static function stock($data){ + public static function stock($data) + { Db::startTrans(); try { - $find=StoreBranchProduct::where(['id' => $data['id']])->find(); + $find = StoreBranchProduct::where(['id' => $data['id']])->find(); SystemStoreStorage::create([ 'product_id' => $find['product_id'], 'store_id' => $find['store_id'], @@ -294,6 +288,5 @@ class StoreProductLogic extends BaseLogic self::setError($e->getMessage()); return false; } - } } diff --git a/app/api/lists/cate/CateLists.php b/app/api/lists/cate/CateLists.php index 3be5babd5..e79f1c98f 100644 --- a/app/api/lists/cate/CateLists.php +++ b/app/api/lists/cate/CateLists.php @@ -27,7 +27,7 @@ class CateLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => [ 'name', 'data', 'store_id', 'sort'], + '=' => ['name', 'data', 'store_id', 'sort', 'pid'], ]; }