From dda7eddaaad2d8bd5e4e94acb6259bb0a11a101c Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 7 Jun 2023 10:49:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=95=86=E5=93=81=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=88=B0=E4=BA=91=E4=BB=93=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/system/merchant/Merchant.php | 4 +- .../store/product/ProductRepository.php | 6 +- app/listener/ProductCreate.php | 123 ++++-------------- 3 files changed, 27 insertions(+), 106 deletions(-) diff --git a/app/common/model/system/merchant/Merchant.php b/app/common/model/system/merchant/Merchant.php index fdaf5872..55e3b47a 100644 --- a/app/common/model/system/merchant/Merchant.php +++ b/app/common/model/system/merchant/Merchant.php @@ -29,9 +29,9 @@ class Merchant extends BaseModel { const TypeStore = 10; //镇街店铺 - const TypeCloudWarehouse = 11; //里海云仓 + const TypeCloudWarehouse = 11; //镇级云仓 const TypeSupplyChain = 12; //市级供应链 - const TypePlatform = 13; //供销平台 + const TypePlatform = 13; //市级云仓 const TypeTeamServer = 14; //小组服务团 const TypeVillageServer = 15; //村服务团队 const TypeTownServer = 16; //镇服务团队 diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index c770076f..a4d46e2f 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -242,7 +242,7 @@ class ProductRepository extends BaseRepository app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType); } $product = $result; - event('product.create',compact('product')); + event('product.create',compact('product', 'data', 'conType')); return $result->product_id; }); } @@ -474,9 +474,7 @@ class ProductRepository extends BaseRepository 'pay_limit' => $data['pay_limit'] ?? 0, 'svip_price_type' => $data['svip_price_type'] ?? 0, ]; - if($result['spec_type'] == 0){ - $result['bar_code'] = $data['bar_code'] ?? ''; - } + $result['bar_code'] = $data['attrValue'][0]['bar_code'] ?? ''; if (isset($data['mer_id'])) $result['mer_id'] = $data['mer_id']; if (isset($data['old_product_id'])) diff --git a/app/listener/ProductCreate.php b/app/listener/ProductCreate.php index afe14699..609382e3 100644 --- a/app/listener/ProductCreate.php +++ b/app/listener/ProductCreate.php @@ -3,123 +3,46 @@ declare (strict_types=1); namespace app\listener; +use app\common\model\system\merchant\Merchant; use app\common\repositories\store\product\ProductRepository; -use crmeb\services\RedisCacheService; use think\facade\Db; -use think\facade\Log; class ProductCreate { public function handle($event) { - $merchant=Db::name('merchant')->where('status',1)->where('is_del',0)->where('mer_id',$event['product']['mer_id'])->find(); + $product = $event['product']; + $data = $event['data']; + $contentType = $event['conType']; + $merchant = Db::name('merchant')->where('status', 1)->where('is_del', 0)->where('mer_id', $product['mer_id'])->find(); if (empty($merchant)) { return false; } - if ($merchant['type_id']==13 ||$merchant['type_id']==11){ + if ($merchant['type_id'] == Merchant::TypePlatform || $merchant['type_id'] == Merchant::TypeCloudWarehouse) { return false; } - $product_find=Db::name('store_product')->where('product_id',$event['product']['product_id'])->where('mer_id',$event['product']['mer_id'])->find(); + //市级云仓 - $cityMerchantId = Db::name('merchant')->where('status',1)->where('mer_state',1)->where('category_id',$merchant['category_id'])->where('type_id',13)->value('mer_id'); - if ($cityMerchantId) { - $is_product=0; - if ($product_find['bar_code']!='' &&in_array($product_find['product_type'],[0,98]) &&$product_find['spec_type']==0){ - $find=Db::name('store_product')->where('bar_code',$product_find['bar_code'])->where('mer_id',$cityMerchantId)->find(); - if (!$find){ - $is_product=1; - } - }else{ - $find=Db::name('store_product')->where('store_name',$product_find['store_name'])->where('mer_id',$cityMerchantId)->find(); - if (!$find){ - $is_product=1; - } + $cityMerchant = Db::name('merchant')->where('status', 1)->where('mer_state', 1)->where('category_id', $merchant['category_id'])->where('type_id', Merchant::TypePlatform)->find(); + if ($cityMerchant) { + $where = ['mer_id' => $cityMerchant['mer_id']]; + if ($product['bar_code'] != '' && in_array($product['product_type'], [0, 98]) && $product['spec_type'] == 0) { + $where['bar_code'] = $product['bar_code']; + } else { + $where['store_name'] = $product['store_name']; } - if ($is_product==1){ - $this->AddProduct($cityMerchantId,$product_find,$event); - } - } - //镇街云仓 - //不再导入镇街云仓 - /*$is_product=0; - if ($merchant['type_id']==10){ - $townMerchantId = Db::name('merchant')->where('status',1)->where('mer_state',1)->where('category_id',$merchant['category_id'])->where('type_id',11)->value('mer_id'); - if ($townMerchantId){ - if ($product_find['bar_code']!='' &&in_array($product_find['product_type'],[0,98]) &&$product_find['spec_type']==0){ - $find=Db::name('store_product')->where('bar_code',$product_find['bar_code'])->where('mer_id',$townMerchantId)->find(); - if (!$find){ - $is_product=1; - } - }else{ - $find=Db::name('store_product')->where('store_name',$product_find['store_name'])->where('mer_id',$townMerchantId)->find(); - if (!$find){ - $is_product=1; - } - } - if ($is_product==1){ - $this->AddProduct($townMerchantId,$product_find,$event); - } - } - - }*/ - } - - public function CloudMerchanSpu($data,$event){ - $RedisCacheService = app()->make(RedisCacheService::class); - $exists=$RedisCacheService->exists('CloudMerchanSpu'.$data['mer_id']); - if ($exists){ - $RedisCacheService->SADD ('CloudMerchanSpu'.$data['mer_id'], $event['product']['product_id']); - }else{ - $Spu_arr=Db::name('store_spu')->where('mer_id',$data['mer_id'])->where('status',1)->column('product_id'); - foreach ($Spu_arr as $k=>$v){ - $RedisCacheService->SADD ('CloudMerchanSpu'.$data['mer_id'], $v); + $exist = Db::name('store_product')->where($where)->find(); + if (!$exist) { + $data['mer_id'] = $cityMerchant['mer_id']; + $data['status'] = $cityMerchant['is_audit'] ? 0 : 1; + $data['mer_status'] = ($cityMerchant['is_del'] || !$cityMerchant['mer_state'] || !$cityMerchant['status']) ? 0 : 1; + $data['rate'] = 3; + $productType = $cityMerchant['type_id'] == Merchant::TypeSupplyChain ? 98 : 0; + $data['update_time'] = date('Y-m-d H:i:s'); + app()->make(ProductRepository::class)->create($data, $productType, $contentType); } } } - public function AddProduct($mer_id,$product_find,$event){ - $datas=[ - 'mer_id'=>$mer_id, - 'status'=>1, - 'brand_id'=>0, - 'is_show'=>0, - 'store_name'=>$product_find['store_name'], - 'store_info'=>$product_find['store_info'], - 'keyword'=>$product_find['keyword'], - 'bar_code'=>$product_find['bar_code'], - 'cate_id'=>$product_find['cate_id'], - 'unit_name'=>$product_find['unit_name'], - 'price'=>$product_find['price'], - 'stock'=>$product_find['stock'], - 'cost'=>$product_find['cost'], - 'ot_price'=>$product_find['ot_price'], - 'spec_type'=>$product_find['spec_type'], - '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; - $spu_arr[$k]['product_type']=0; - $spu_arr[$k]['create_time']=date('Y-m-d H:i:s'); - unset($spu_arr[$k]['spu_id']); - } - Db::name('store_spu')->insertAll($spu_arr); - } }