From de55a00c58bd0c4cb17ae211f9d4b01be886186a Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Mon, 29 May 2023 09:52:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/product/StoreMicro.php | 6 +++++- app/listener/ProductCreate.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controller/api/store/product/StoreMicro.php b/app/controller/api/store/product/StoreMicro.php index d75e5a62..2c3e447b 100644 --- a/app/controller/api/store/product/StoreMicro.php +++ b/app/controller/api/store/product/StoreMicro.php @@ -51,10 +51,13 @@ class StoreMicro extends BaseController if($find['product_type']!=0){ return app('json')->fail('该商品不是普通商品'); } + $exist = Db::name('store_product')->where('old_product_id', $product_id)->where('mer_id', $mer_id)->find(); + if($exist){ + return app('json')->fail('已经导入过该商品了'); + } $find['attrValue']=Db::name('store_product_attr_value')->where('product_id',$find['product_id'])->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume')->select(); $find['content']=Db::name('store_product_content')->where('product_id',$find['product_id'])->value('content'); $find['is_show']=0; - $find['mer_status']=1; $find['mer_id']=$mer_id; $find['temp_id']=""; $find['give_coupon_ids']=[]; @@ -70,6 +73,7 @@ class StoreMicro extends BaseController $find['is_used']=1; $find['status']=1; $find['mer_status']=1; + $find['old_product_id']=$product_id; unset($find['product_id'],$find['create_time']); } $make = app()->make(ProductRepository::class); diff --git a/app/listener/ProductCreate.php b/app/listener/ProductCreate.php index b6be7f27..162836be 100644 --- a/app/listener/ProductCreate.php +++ b/app/listener/ProductCreate.php @@ -3,6 +3,7 @@ declare (strict_types=1); namespace app\listener; +use app\common\repositories\store\product\ProductRepository; use crmeb\services\RedisCacheService; use think\facade\Db; use think\facade\Log; @@ -96,11 +97,22 @@ class ProductCreate 'create_time'=>date('Y-m-d H:i:s'), 'image'=>$product_find['image'], 'slider_image'=>$product_find['slider_image'], + 'svip_price_type' => 0, ]; $product_id=Db::name('store_product')->insertGetId($datas); $content=Db::name('store_product_content')->where('product_id',$event['product']['product_id'])->find(); Db::name('store_product_content')->insert(['product_id'=>$product_id,'content'=>$content['content'],'type'=>$content['type']]); $spu_arr=Db::name('store_spu')->where('mer_id',$product_find['mer_id'])->where('product_id',$event['product']['product_id'])->select()->toArray(); + + $datas['attrValue']=Db::name('store_product_attr_value')->where('product_id',$product_find['product_id'])->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume')->select(); + /** @var ProductRepository $productRepository */ + $productRepository = app()->make(ProductRepository::class); + $settleParams = $productRepository->setAttrValue($datas, (int)$product_id, 0, 0,$datas['mer_id']); + $settleParams['cate'] = $productRepository->setMerCate([$datas['mer_cate_id'] ?? 0], (int)$product_id, (int)$datas['mer_id']); + $settleParams['attr'] = $productRepository->setAttr($datas['attr'] ?? [], (int)$product_id); + unset($datas['attrValue']); + $productRepository->save($product_id, $settleParams, $content,$datas,0); + foreach ($spu_arr as $k=>$v){ $spu_arr[$k]['product_id']=$product_id; $spu_arr[$k]['mer_id']=$mer_id;