后台商品同步

This commit is contained in:
mkm 2023-05-17 10:35:04 +08:00
parent 0f94b7e7bf
commit 12ab4de6df
4 changed files with 129 additions and 18 deletions

View File

@ -6,24 +6,26 @@ use crmeb\basic\BaseController;
class StoreMicro extends BaseController
{
function seach_bar_code($code){
$user = $this->request->userInfo();
$mer_id =Db::name('store_service')->where('uid',$user['uid'])->where('status',1)->value('mer_id');
$find=Db::name('store_product_attr_value')->where('mer_id',$mer_id)->where('bar_code',$code)->find();
if (!$find){
$store_product=Db::name('store_product')->where('product_type',98)->where('bar_code',$code)->find();
if (!$store_product){
return app('json')->fail('平台没有该条形码,请自行录入');
function seach_bar_code($code='',$name='',$mer_id){
$category_id=Db::name('merchant')->where('mer_id',$mer_id)->value('category_id');
$mer_id=Db::name('merchant')->where('category_id',$category_id)->where('type_id',13)->value('mer_id');
if($code!=''){
$find=Db::name('store_product')->where('mer_id',$mer_id)->where('bar_code',$code)->select();
}else{
$find=Db::name('store_product')->where('mer_id',$mer_id)->where('store_name','like','%'.$name.'%')->select();
}
if (count($find)==0){
if($code!=''){
$store_product['key']['bar_code']=$code;
}else{
$store_product['key']['store_name']=$name;
}
$store_product['attr_value']=Db::name('store_product_attr_value')->where('product_id',$store_product['product_id'])->find();
$store_product['is_mer_show']=0;
return app('json')->success(['data'=>$store_product]);
};
$store_product=Db::name('store_product')->where('product_id',$find['product_id'])->find();
$store_product['attr_value']=$find;
$store_product['is_mer_show']=1;
return app('json')->success(['data'=>$store_product]);
$store_product['key']['is_mer_show']=0;
}else{
$store_product['key']['is_mer_show']=1;
}
$store_product['list']=$find;
return app('json')->success($store_product);
}
public function eadtProduct(){

View File

@ -22,6 +22,7 @@ use think\App;
use crmeb\basic\BaseController;
use app\common\repositories\store\order\StoreImportRepository;
use think\facade\Db;
use think\facade\Queue;
class StoreImport extends BaseController
@ -124,6 +125,45 @@ class StoreImport extends BaseController
]
];
break;
case 'store_category':
$check =[
'A1'=>'名称1',
'B1'=>'名称2',
'C1'=>'名称3',];
SpreadsheetExcelService::instance()->checkImport($path,$check);
$datas = [
'mer_id' => $this->request->merId(),
'data' => [
'path' => $path,
'sql' => ['name1' => 'A', 'name2' => 'B', 'name3' => 'C'],
'where' => ['name1' => 'A','name2' => 'B',],
]
];
$data = SpreadsheetExcelService::instance()->_import($datas['data']['path'], $datas['data']['sql'], $datas['data']['where'], 1);
if (!$data) return false;
unset($data[0]);
foreach ($data as $k => $v) {
$mer_cate_id=Db::name('store_category')->where('mer_id',0)->where('cate_name',trim($v['where']['name1']))->value('store_category_id');
if (!$mer_cate_id ||$mer_cate_id==0){
$mer_cate=['pid'=>0,'cate_name'=>trim($v['where']['name1']),'path'=>'/','mer_id'=>0,'sort'=>0,'is_show'=>1,'create_time'=>date('Y-m-d H:i:s')];
$mer_cate_id=Db::name('store_category')->insertGetId($mer_cate);
}
$mer_cate_id_two=Db::name('store_category')->where('mer_id',0)->where('pid',$mer_cate_id)->where('level',1)
->where('cate_name',trim($v['where']['name2']))->value('store_category_id');
if (!$mer_cate_id_two ||$mer_cate_id_two==0){
$mer_cate=['pid'=>$mer_cate_id,'cate_name'=>trim($v['where']['name2']),'path'=>'/'.$mer_cate_id.'/','mer_id'=>0,'sort'=>0,'is_show'=>1,'level'=>1,'create_time'=>date('Y-m-d H:i:s')];
$mer_cate_id_two=Db::name('store_category')->insertGetId($mer_cate);
}
$arr_name3=explode(" ",$v['value']['name3']);
$mer_cate=[];
foreach ($arr_name3 as $k3=>$v3){
$mer_cate[]=['pid'=>$mer_cate_id_two,'cate_name'=>trim($v3),'path'=>'/'.$mer_cate_id.'/'.$mer_cate_id_two.'/','mer_id'=>0,'sort'=>0,'is_show'=>1,'level'=>2,'create_time'=>date('Y-m-d H:i:s')];
}
Db::name('store_category')->insertAll($mer_cate);
}
return app('json')->success('开始导入数据,请稍后在列表中查看!');
default:
$data = SpreadsheetExcelService::instance()->_import($path,[],[],0);
break;

View File

@ -63,7 +63,8 @@ return [
'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class],
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
'community_address'=>[\app\listener\CommunityAddress::class],
'order.paySuccess'=>[\app\listener\OrderPaySuccess::class]
'order.paySuccess'=>[\app\listener\OrderPaySuccess::class],
'product.create'=>[\app\listener\ProductCreate::class],
],
'subscribe' => [],

View File

@ -0,0 +1,68 @@
<?php
declare (strict_types=1);
namespace app\listener;
use think\facade\Db;
use think\facade\Log;
class ProductCreate
{
public function handle($event)
{
$merchant=Db::name('merchant')->where('mer_id',$event['product']['mer_id'])->find();
if ($merchant['type_id']==13){
return false;
}
$mer_id=Db::name('merchant')->where('category_id',$merchant['category_id'])->where('type_id',13)->value('mer_id');
$product_find=Db::name('store_product')->where('product_id',$event['product']['product_id'])->where('mer_id',$event['product']['mer_id'])->find();
$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',$mer_id)->find();
if (!$find){
$is_product=1;
}
}else{
$find=Db::name('store_product')->where('store_name',$product_find['store_name'])->where('mer_id',$mer_id)->find();
if (!$find){
$is_product=1;
}
}
if ($is_product==1){
$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'],
];
$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();
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);
}
return false;
}
}