From abd9e2cb82afa8cf25c715dcef852be5a9098461 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Thu, 27 Jun 2024 15:41:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=8D=E5=88=B6=E5=92=8C?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_product/StoreProductLogic.php | 3 ++ app/queue/redis/StoreStorageSend.php | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 6887fa881..1220fab27 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -310,6 +310,7 @@ class StoreProductLogic extends BaseLogic $attr_value = StoreProductAttrValue::where('product_id', $id)->findOrEmpty(); Db::startTrans(); try { + $dealCate = self::dealChangeCate($find['cate_id']); $product = [ 'product_id' => $find['id'], 'image' => $find['image'], @@ -318,6 +319,8 @@ class StoreProductLogic extends BaseLogic 'keyword' => $find['keyword'], 'bar_code' => $find['bar_code'], 'cate_id' => $find['cate_id'], + 'top_cate_id' => $dealCate['top_cate_id'], + 'two_cate_id' => $dealCate['two_cate_id'], 'price' => $find['price'], 'unit' => $find['unit'], 'store_id' => $store_id, diff --git a/app/queue/redis/StoreStorageSend.php b/app/queue/redis/StoreStorageSend.php index 02e7eefe6..04f5ad9ba 100644 --- a/app/queue/redis/StoreStorageSend.php +++ b/app/queue/redis/StoreStorageSend.php @@ -46,6 +46,7 @@ class StoreStorageSend implements Consumer $attr_value = StoreProductAttrValue::where('product_id', $product_arr['id'])->findOrEmpty(); Db::startTrans(); try { + $dealCate = self::dealChangeCate($find['cate_id']); $product = [ 'product_id' => $find['id'], 'image' => $find['image'], @@ -54,6 +55,8 @@ class StoreStorageSend implements Consumer 'keyword' => $find['keyword'], 'bar_code' => $find['bar_code'], 'cate_id' => $find['cate_id'], + 'top_cate_id' => $dealCate['top_cate_id'], + 'two_cate_id' => $dealCate['two_cate_id'], 'price' => $find['price'], // 'cost' => $find['cost'], //v1.0 'cost' => $find['cost'], @@ -179,4 +182,31 @@ class StoreStorageSend implements Consumer Log::error('store-storage队列消费失败: ' . $e->getMessage() . ',line:' . $e->getLine() . ',file:' . $e->getFile()); return $package; } + + /* + * 传入三级或者二级分类返还上级分类 一级那全是相同 + */ + public static function dealChangeCate($cate_id) + { + $value =[]; + $last_cate = Db::name('store_category')->where('id',$cate_id)->value('pid'); + if(!empty($last_cate)){ + //2 + $value['two_cate_id'] = $last_cate; + //1 + $first_cate = Db::name('store_category')->where('id',$value['two_cate_id'])->value('pid'); + if(empty($first_cate)){//顶级了 + $value['two_cate_id'] = $cate_id; + $value['top_cate_id'] = $last_cate; + }else{ + $value['top_cate_id'] = $first_cate; + } + + }else{ + //1-2 选的1级目录 + $value['two_cate_id'] = $cate_id; + $value['top_cate_id'] = $cate_id; + } + return $value; + } }