处理商品同步到云仓的错误
This commit is contained in:
parent
ae200d7c75
commit
dda7eddaaa
@ -29,9 +29,9 @@ class Merchant extends BaseModel
|
|||||||
{
|
{
|
||||||
|
|
||||||
const TypeStore = 10; //镇街店铺
|
const TypeStore = 10; //镇街店铺
|
||||||
const TypeCloudWarehouse = 11; //里海云仓
|
const TypeCloudWarehouse = 11; //镇级云仓
|
||||||
const TypeSupplyChain = 12; //市级供应链
|
const TypeSupplyChain = 12; //市级供应链
|
||||||
const TypePlatform = 13; //供销平台
|
const TypePlatform = 13; //市级云仓
|
||||||
const TypeTeamServer = 14; //小组服务团
|
const TypeTeamServer = 14; //小组服务团
|
||||||
const TypeVillageServer = 15; //村服务团队
|
const TypeVillageServer = 15; //村服务团队
|
||||||
const TypeTownServer = 16; //镇服务团队
|
const TypeTownServer = 16; //镇服务团队
|
||||||
|
@ -242,7 +242,7 @@ class ProductRepository extends BaseRepository
|
|||||||
app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType);
|
app()->make(SpuRepository::class)->create($product, $result->product_id, $activity_id, $productType);
|
||||||
}
|
}
|
||||||
$product = $result;
|
$product = $result;
|
||||||
event('product.create',compact('product'));
|
event('product.create',compact('product', 'data', 'conType'));
|
||||||
return $result->product_id;
|
return $result->product_id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -474,9 +474,7 @@ class ProductRepository extends BaseRepository
|
|||||||
'pay_limit' => $data['pay_limit'] ?? 0,
|
'pay_limit' => $data['pay_limit'] ?? 0,
|
||||||
'svip_price_type' => $data['svip_price_type'] ?? 0,
|
'svip_price_type' => $data['svip_price_type'] ?? 0,
|
||||||
];
|
];
|
||||||
if($result['spec_type'] == 0){
|
$result['bar_code'] = $data['attrValue'][0]['bar_code'] ?? '';
|
||||||
$result['bar_code'] = $data['bar_code'] ?? '';
|
|
||||||
}
|
|
||||||
if (isset($data['mer_id']))
|
if (isset($data['mer_id']))
|
||||||
$result['mer_id'] = $data['mer_id'];
|
$result['mer_id'] = $data['mer_id'];
|
||||||
if (isset($data['old_product_id']))
|
if (isset($data['old_product_id']))
|
||||||
|
@ -3,123 +3,46 @@ declare (strict_types=1);
|
|||||||
|
|
||||||
namespace app\listener;
|
namespace app\listener;
|
||||||
|
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
use app\common\repositories\store\product\ProductRepository;
|
use app\common\repositories\store\product\ProductRepository;
|
||||||
use crmeb\services\RedisCacheService;
|
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use think\facade\Log;
|
|
||||||
|
|
||||||
class ProductCreate
|
class ProductCreate
|
||||||
{
|
{
|
||||||
|
|
||||||
public function handle($event)
|
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)) {
|
if (empty($merchant)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($merchant['type_id']==13 ||$merchant['type_id']==11){
|
if ($merchant['type_id'] == Merchant::TypePlatform || $merchant['type_id'] == Merchant::TypeCloudWarehouse) {
|
||||||
return false;
|
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');
|
$cityMerchant = Db::name('merchant')->where('status', 1)->where('mer_state', 1)->where('category_id', $merchant['category_id'])->where('type_id', Merchant::TypePlatform)->find();
|
||||||
if ($cityMerchantId) {
|
if ($cityMerchant) {
|
||||||
$is_product=0;
|
$where = ['mer_id' => $cityMerchant['mer_id']];
|
||||||
if ($product_find['bar_code']!='' &&in_array($product_find['product_type'],[0,98]) &&$product_find['spec_type']==0){
|
if ($product['bar_code'] != '' && in_array($product['product_type'], [0, 98]) && $product['spec_type'] == 0) {
|
||||||
$find=Db::name('store_product')->where('bar_code',$product_find['bar_code'])->where('mer_id',$cityMerchantId)->find();
|
$where['bar_code'] = $product['bar_code'];
|
||||||
if (!$find){
|
} else {
|
||||||
$is_product=1;
|
$where['store_name'] = $product['store_name'];
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$find=Db::name('store_product')->where('store_name',$product_find['store_name'])->where('mer_id',$cityMerchantId)->find();
|
|
||||||
if (!$find){
|
|
||||||
$is_product=1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($is_product==1){
|
$exist = Db::name('store_product')->where($where)->find();
|
||||||
$this->AddProduct($cityMerchantId,$product_find,$event);
|
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;
|
||||||
/*$is_product=0;
|
$productType = $cityMerchant['type_id'] == Merchant::TypeSupplyChain ? 98 : 0;
|
||||||
if ($merchant['type_id']==10){
|
$data['update_time'] = date('Y-m-d H:i:s');
|
||||||
$townMerchantId = Db::name('merchant')->where('status',1)->where('mer_state',1)->where('category_id',$merchant['category_id'])->where('type_id',11)->value('mer_id');
|
app()->make(ProductRepository::class)->create($data, $productType, $contentType);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user