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; + } }