调整排序
This commit is contained in:
parent
cf42b7e1d6
commit
cab9448700
@ -2521,6 +2521,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) {
|
||||
$product_type = 98; //供应链
|
||||
}
|
||||
try {
|
||||
foreach ($data as $datum) {
|
||||
|
||||
$find = Db::name('store_product')->where('mer_id', $merId)->where('store_name', $datum['value']['store_name'])->find();
|
||||
@ -2540,7 +2541,11 @@ class StoreOrderRepository extends BaseRepository
|
||||
if ($find) {
|
||||
$store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $find['product_id'])->where('bar_code', $datum['value']['bar_code'])->find();
|
||||
if ($store_product_attr_value) {
|
||||
Log::error('xls导入商品:已经导入过该规格了');
|
||||
$data['product_id'] = $find['product_id'];
|
||||
$data['mer_id'] = $merId;
|
||||
$data['store_name'] = $$datum['value']['store_name'];
|
||||
$data['content'] = 'xls导入商品:已经导入过该规格了';
|
||||
$this->create_product_import_log($data,0);
|
||||
continue;
|
||||
}
|
||||
$is_update = false;
|
||||
@ -2585,30 +2590,30 @@ class StoreOrderRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
/**查询商户分类 */
|
||||
$mer_cate_id=0;
|
||||
if( $datum['value']['cate_id_one_mer'] !=''&& $datum['value']['cate_id_one_two']!=''){
|
||||
$cate_id_one_mer = Db::name('store_category')->where('level',0)->where('mer_id', $merId)->where('cate_name', $datum['value']['cate_id_one_mer'])->value('store_category_id');
|
||||
$mer_cate_id = 0;
|
||||
if ($datum['value']['cate_id_one_mer'] != '' && $datum['value']['cate_id_one_two'] != '') {
|
||||
$cate_id_one_mer = Db::name('store_category')->where('level', 0)->where('mer_id', $merId)->where('cate_name', $datum['value']['cate_id_one_mer'])->value('store_category_id');
|
||||
/**有一级分类 */
|
||||
if($cate_id_one_mer){
|
||||
$cate_id_one_two = Db::name('store_category')->where('pid',$cate_id_one_mer)->where('level',1)->where('mer_id', $merId)->where('cate_name', $datum['value']['cate_id_one_two'])->value('store_category_id');
|
||||
if ($cate_id_one_mer) {
|
||||
$cate_id_one_two = Db::name('store_category')->where('pid', $cate_id_one_mer)->where('level', 1)->where('mer_id', $merId)->where('cate_name', $datum['value']['cate_id_one_two'])->value('store_category_id');
|
||||
/**有二级分类 */
|
||||
if($cate_id_one_two){
|
||||
$mer_cate_id =$cate_id_one_two;
|
||||
}else{
|
||||
$mer_cate = ['level'=>1,'pid' => $cate_id_one_mer, 'cate_name' => $datum['value']['cate_id_one_mer'], 'path' => '/' . $cate_id_one_mer . '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')];
|
||||
if ($cate_id_one_two) {
|
||||
$mer_cate_id = $cate_id_one_two;
|
||||
} else {
|
||||
$mer_cate = ['level' => 1, 'pid' => $cate_id_one_mer, 'cate_name' => $datum['value']['cate_id_one_mer'], 'path' => '/' . $cate_id_one_mer . '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')];
|
||||
$mer_cate_id = Db::name('store_category')->insertGetId($mer_cate);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$cate_id_one_mer_arr = ['pid' => 0, 'cate_name' => $datum['value']['cate_id_one_mer'], 'path' => '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')];
|
||||
$cate_id_one_mer = Db::name('store_category')->insertGetId($cate_id_one_mer_arr);
|
||||
$mer_cate = ['level'=>1,'pid' => $cate_id_one_mer, 'cate_name' => $datum['value']['cate_id_one_mer'], 'path' => '/' . $cate_id_one_mer . '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')];
|
||||
$mer_cate = ['level' => 1, 'pid' => $cate_id_one_mer, 'cate_name' => $datum['value']['cate_id_one_mer'], 'path' => '/' . $cate_id_one_mer . '/', 'mer_id' => $merId, 'sort' => 0, 'is_show' => 1, 'create_time' => date('Y-m-d H:i:s')];
|
||||
$mer_cate_id = Db::name('store_category')->insertGetId($mer_cate);
|
||||
}
|
||||
}
|
||||
$bar_code = (int) $datum['value']['bar_code'];
|
||||
$bar_code_where = ['is_used' => 1, 'status' => 1, 'is_del' => 0];
|
||||
$bar_code_field = 'id,store_name,bar_code,manu_address,price,stock,image,slider_image,spec,trademark,manu_name,manu_address,note';
|
||||
$library=null;
|
||||
$library = null;
|
||||
if ($bar_code) {
|
||||
$library = Db::name('product_library')->where('bar_code', $bar_code)->where($bar_code_where)->field($bar_code_field)
|
||||
->withAttr('slider_image', function ($value, $data) {
|
||||
@ -2617,30 +2622,26 @@ class StoreOrderRepository extends BaseRepository
|
||||
->find();
|
||||
if (!$library) {
|
||||
$ProductLibrary = app()->make(ProductLibrary::class);
|
||||
try {
|
||||
$ProductLibrary->caiji($bar_code);
|
||||
$library = Db::name('product_library')->where('bar_code', $bar_code)->where($bar_code_where)->field($bar_code_field)
|
||||
->withAttr('slider_image', function ($value, $data) {
|
||||
return $value ? explode(',', $value) : [];
|
||||
})
|
||||
->find();
|
||||
} catch (Exception $e) {
|
||||
Log::error('导入采集编码错误:' . $bar_code . '。' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
if($library){
|
||||
$image=$library['image'];
|
||||
$slider_image=$library['slider_image'];
|
||||
}else{
|
||||
$image='https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png';
|
||||
$slider_image=[
|
||||
if ($library) {
|
||||
$image = $library['image'];
|
||||
$slider_image = $library['slider_image'];
|
||||
} else {
|
||||
$image = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png';
|
||||
$slider_image = [
|
||||
0 => "https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/luzhou/static4/oa_app/23565656.png",
|
||||
];
|
||||
}
|
||||
$datas = [
|
||||
"image" =>$image,
|
||||
"slider_image" =>$slider_image,
|
||||
"image" => $image,
|
||||
"slider_image" => $slider_image,
|
||||
"store_name" => $datum['value']['store_name'],
|
||||
"store_info" => $datum['value']['store_name'],
|
||||
"keyword" => '',
|
||||
@ -2682,7 +2683,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
"cost" => $datum['value']['cost'],
|
||||
"ot_price" => $datum['value']['price'],
|
||||
"svip_price" => null,
|
||||
"procure_price" => $datum['value']['procure_price']??0,
|
||||
"procure_price" => $datum['value']['procure_price'] ?? 0,
|
||||
"stock" => 1,
|
||||
"bar_code" => (int)$datum['value']['bar_code'],
|
||||
"weight" => 0,
|
||||
@ -2705,12 +2706,37 @@ class StoreOrderRepository extends BaseRepository
|
||||
// 'product_type' => $product_type,
|
||||
// ];
|
||||
$make = app()->make(ProductRepository::class);
|
||||
$make->create($datas, $product_type);
|
||||
$product_id = $make->create($datas, $product_type);
|
||||
if ($product_id) {
|
||||
$data['product_id'] = $product_id;
|
||||
$data['mer_id'] = $merId;
|
||||
$data['store_name'] = $datum['value']['store_name'];
|
||||
$this->create_product_import_log($data);
|
||||
}
|
||||
// Queue::push(ProductImportJob::class, $data_list);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$data['product_id'] = $product_id;
|
||||
$data['mer_id'] = $merId;
|
||||
$data['store_name'] = $$datum['value']['store_name'];
|
||||
$data['content'] = $datum['value']['store_name'];
|
||||
$this->create_product_import_log($data, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function create_product_import_log($data, $status = 1)
|
||||
{
|
||||
$data = [
|
||||
'product_id' => $data['product_id'],
|
||||
'mer_id' => $data['mer_id'],
|
||||
'name' => $data['store_name'],
|
||||
'content' => $data['content'] ?? '',
|
||||
'status' => $status,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
Db::name('store_product_import')->insert($data);
|
||||
}
|
||||
|
||||
public function create_product_attr_value($find, $datum, $product_type, $attr_values, $merId, $sku)
|
||||
{
|
||||
|
@ -184,6 +184,7 @@ class StoreImport extends BaseController
|
||||
Queue::push(ImportPicJob::class,['mer_id'=>$mer_id,'path'=>$destination_path]);
|
||||
return app('json')->success('开始导入数据,请稍后在列表中查看!,如果未导入请检查格式');
|
||||
}
|
||||
|
||||
public function getXlsList($type_id,$path){
|
||||
if($type_id==12){
|
||||
$check =[
|
||||
|
@ -13,7 +13,7 @@ class ImportPicJob implements JobInterface
|
||||
{
|
||||
public function fire($job, $data)
|
||||
{
|
||||
Log::error('开始导入商品图片:'.$job->attempts());
|
||||
Log::error('开始导入商品图片:' . $job->attempts());
|
||||
if ($job->attempts() > 3) {
|
||||
$job->delete();
|
||||
$this->failed($data);
|
||||
@ -23,13 +23,13 @@ class ImportPicJob implements JobInterface
|
||||
$files = scandir($directory);
|
||||
$dir = 'def/' . date('Y-m-d');
|
||||
$upload = UploadService::create();
|
||||
|
||||
try {
|
||||
/**循环目录 */
|
||||
foreach ($files as $file) {
|
||||
if ($file === '.' || $file === '..' ||$file ==='__MACOSX') {
|
||||
if ($file === '.' || $file === '..' || $file === '__MACOSX') {
|
||||
continue;
|
||||
}
|
||||
if(!is_dir($directory . '/' . $file)){
|
||||
if (!is_dir($directory . '/' . $file)) {
|
||||
continue;
|
||||
}
|
||||
$files_two = scandir($directory . '/' . $file);
|
||||
@ -41,7 +41,7 @@ class ImportPicJob implements JobInterface
|
||||
$sku_arr = [];
|
||||
/**清洗图片 */
|
||||
foreach ($files_two as $file_two) {
|
||||
if ($file_two === '.' || $file_two === '..' ||$file_two ==='__MACOSX') {
|
||||
if ($file_two === '.' || $file_two === '..' || $file_two === '__MACOSX') {
|
||||
continue;
|
||||
}
|
||||
$arr = explode('.', $file_two);
|
||||
@ -67,7 +67,6 @@ class ImportPicJob implements JobInterface
|
||||
if ($sku) {
|
||||
$sku = implode(',', $sku);
|
||||
$sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,9 +74,8 @@ class ImportPicJob implements JobInterface
|
||||
$update = [];
|
||||
$update_content['title'] = '';
|
||||
$update_content['image'] = [];
|
||||
$find = Db::name('store_product')->where($where)->where('store_name',$file)->find();
|
||||
$find = Db::name('store_product')->where($where)->where('store_name', $file)->find();
|
||||
if ($find) {
|
||||
try {
|
||||
/**更新商品图片 */
|
||||
$image = $upload->to($dir)->stream(file_get_contents($image));
|
||||
$update['image'] = $image->filePath;
|
||||
@ -85,7 +83,7 @@ class ImportPicJob implements JobInterface
|
||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
||||
$update['slider_image'][] = $oss->filePath;
|
||||
}
|
||||
if(isset($update['slider_image'])){
|
||||
if (isset($update['slider_image'])) {
|
||||
$update['slider_image'] = implode(',', $update['slider_image']);
|
||||
}
|
||||
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
||||
@ -106,7 +104,7 @@ class ImportPicJob implements JobInterface
|
||||
$update_content['image'][] = $oss->filePath;
|
||||
}
|
||||
if ($store_product_content) {
|
||||
if(isset($update_content['image']) && !empty($update_content['image'])){
|
||||
if (isset($update_content['image']) && !empty($update_content['image'])) {
|
||||
Db::name('store_product_content')
|
||||
->where(['product_id' => $find['product_id']])
|
||||
->update(['content' => json_encode($update_content)]);
|
||||
@ -114,21 +112,37 @@ class ImportPicJob implements JobInterface
|
||||
} else {
|
||||
$update_content['product_id'] = $find['product_id'];
|
||||
Db::name('store_product_content')
|
||||
->insert(['product_id'=>$find['product_id'],'type'=>1,'content'=>json_encode($update_content)]);
|
||||
->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
halt($e->getMessage(), $e->getLine());
|
||||
}
|
||||
}
|
||||
$data['product_id'] = $find['product_id'];
|
||||
$data['mer_id'] = $data['mer_id'];
|
||||
$data['store_name'] = $find['store_name'];
|
||||
$data['content'] = $e->getMessage();
|
||||
$this->create_product_import_log($data, 0);
|
||||
}
|
||||
|
||||
$job->delete();
|
||||
|
||||
}
|
||||
|
||||
public function failed($data)
|
||||
{
|
||||
Log::error('导入商品图片失败:'.json_encode($data));
|
||||
Log::error('导入商品图片失败:' . json_encode($data));
|
||||
// TODO: Implement failed() method.
|
||||
}
|
||||
|
||||
public function create_product_import_log($data, $status = 1)
|
||||
{
|
||||
$data = [
|
||||
'product_id' => $data['product_id'],
|
||||
'mer_id' => $data['mer_id'],
|
||||
'name' => $data['store_name'],
|
||||
'content' => $data['content'] ?? '',
|
||||
'status' => $status,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
Db::name('store_product_import')->insert($data);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user