Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
285c3d5bcd
@ -2501,234 +2501,219 @@ class StoreOrderRepository extends BaseRepository
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function setProduct(array $arrary, $merId,$type_id=0)
|
||||
public function setProduct($datum, $merId, $product_type)
|
||||
{
|
||||
//读取excel
|
||||
$data = SpreadsheetExcelService::instance()->_import($arrary['path'], $arrary['sql'], $arrary['where'], 1);
|
||||
if (!$data) return false;
|
||||
unset($data[0]);
|
||||
$product_type = 0;
|
||||
if ($type_id == 12) {
|
||||
$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();
|
||||
$attr_one = explode('|', $datum['value']['attr_one']);
|
||||
$attr_two = explode('|', $datum['value']['attr_two']);
|
||||
$attr = [];
|
||||
$arr = [];
|
||||
|
||||
$find = Db::name('store_product')->where('mer_id', $merId)->where('store_name', $datum['value']['store_name'])->find();
|
||||
$attr_one = explode('|', $datum['value']['attr_one']);
|
||||
$attr_two = explode('|', $datum['value']['attr_two']);
|
||||
$attr = [];
|
||||
$arr = [];
|
||||
|
||||
foreach ($attr_one as $key => $value) {
|
||||
$attr[$value] = $attr_two[$key];
|
||||
$arr[] = [
|
||||
'value' => $value,
|
||||
'detail' => [$attr_two[$key] ?? []],
|
||||
'inputVisible' => false
|
||||
];
|
||||
}
|
||||
$array_values = array_values($attr);
|
||||
$attr_implode= implode(',', $array_values);
|
||||
if ($find) {
|
||||
$store_product_attr_value_where['product_id']=$find['product_id'];
|
||||
if($datum['value']['bar_code']!=''){
|
||||
$store_product_attr_value_where['bar_code']=$datum['value']['bar_code'];
|
||||
}else{
|
||||
$store_product_attr_value_where['sku']=$attr_implode;
|
||||
}
|
||||
$is_update = false;
|
||||
$store_product_attr_value = Db::name('store_product_attr_value')->where($store_product_attr_value_where)->find();
|
||||
if ($store_product_attr_value) {
|
||||
$datas['product_id'] = $find['product_id'];
|
||||
$datas['mer_id'] = $merId;
|
||||
$datas['store_name'] = $datum['value']['store_name'];
|
||||
$datas['content'] = 'xls导入商品:已经导入过该规格了';
|
||||
$this->create_product_import_log($datas,0);
|
||||
continue;
|
||||
}
|
||||
foreach ($attr as $kk => $vv) {
|
||||
/**查询当前规格属性是否存在 */
|
||||
$attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)
|
||||
->find();
|
||||
if ($attr_values_find) {
|
||||
$attr_values = $attr_values_find['attr_values'];
|
||||
$attr_values = explode('-!-', $attr_values);
|
||||
if (!in_array($vv, $attr_values)) {
|
||||
$attr_values[] = $vv;
|
||||
$attr_values = implode('-!-', $attr_values);
|
||||
//更新规格属性
|
||||
Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]);
|
||||
}
|
||||
} else {
|
||||
$datas = [
|
||||
'product_id' => $find['product_id'],
|
||||
'attr_name' => $kk, 'attr_values' => $vv,
|
||||
];
|
||||
Db::name('store_product_attr')->insert($datas);
|
||||
}
|
||||
}
|
||||
if ($is_update == false) {
|
||||
$this->create_product_attr_value($find, $datum, $product_type, $attr, $merId, $attr_implode);
|
||||
}
|
||||
foreach ($attr_one as $key => $value) {
|
||||
$attr[$value] = $attr_two[$key];
|
||||
$arr[] = [
|
||||
'value' => $value,
|
||||
'detail' => [$attr_two[$key] ?? []],
|
||||
'inputVisible' => false
|
||||
];
|
||||
}
|
||||
$array_values = array_values($attr);
|
||||
$attr_implode = implode(',', $array_values);
|
||||
if ($find) {
|
||||
$store_product_attr_value_where['product_id'] = $find['product_id'];
|
||||
if ($datum['value']['bar_code'] != '') {
|
||||
$store_product_attr_value_where['bar_code'] = $datum['value']['bar_code'];
|
||||
} else {
|
||||
//默认其他分类
|
||||
$cate_id = 1726;
|
||||
$spec_type = 1;
|
||||
$detail = $attr;
|
||||
|
||||
/**查询平台分类 */
|
||||
$cate_id_one = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_one'])->value('store_category_id');
|
||||
if ($cate_id_one) {
|
||||
$cate_id_two = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_two'])->value('store_category_id');
|
||||
if ($cate_id_two) {
|
||||
$cate_id = $cate_id_two;
|
||||
$store_product_attr_value_where['sku'] = $attr_implode;
|
||||
}
|
||||
$is_update = false;
|
||||
$store_product_attr_value = Db::name('store_product_attr_value')->where($store_product_attr_value_where)->find();
|
||||
if ($store_product_attr_value) {
|
||||
$datas['product_id'] = $find['product_id'];
|
||||
$datas['mer_id'] = $merId;
|
||||
$datas['store_name'] = $datum['value']['store_name'];
|
||||
$datas['content'] = 'xls导入商品:已经导入过该规格了';
|
||||
$this->create_product_import_log($datas, 0);
|
||||
return false;
|
||||
}
|
||||
foreach ($attr as $kk => $vv) {
|
||||
/**查询当前规格属性是否存在 */
|
||||
$attr_values_find = Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)
|
||||
->find();
|
||||
if ($attr_values_find) {
|
||||
$attr_values = $attr_values_find['attr_values'];
|
||||
$attr_values = explode('-!-', $attr_values);
|
||||
if (!in_array($vv, $attr_values)) {
|
||||
$attr_values[] = $vv;
|
||||
$attr_values = implode('-!-', $attr_values);
|
||||
//更新规格属性
|
||||
Db::name('store_product_attr')->where('product_id', $find['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]);
|
||||
}
|
||||
} else {
|
||||
$datas = [
|
||||
'product_id' => $find['product_id'],
|
||||
'attr_name' => $kk, 'attr_values' => $vv,
|
||||
];
|
||||
Db::name('store_product_attr')->insert($datas);
|
||||
}
|
||||
/**查询商户分类 */
|
||||
$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_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);
|
||||
}
|
||||
}
|
||||
if ($is_update == false) {
|
||||
$this->create_product_attr_value($find, $datum, $product_type, $attr, $merId, $attr_implode);
|
||||
}
|
||||
} else {
|
||||
//默认其他分类
|
||||
$cate_id = 1726;
|
||||
$spec_type = 1;
|
||||
$detail = $attr;
|
||||
|
||||
/**查询平台分类 */
|
||||
$cate_id_one = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_one'])->value('store_category_id');
|
||||
if ($cate_id_one) {
|
||||
$cate_id_two = Db::name('store_category')->where('mer_id', 0)->where('cate_name', $datum['value']['cate_id_two'])->value('store_category_id');
|
||||
if ($cate_id_two) {
|
||||
$cate_id = $cate_id_two;
|
||||
}
|
||||
}
|
||||
/**查询商户分类 */
|
||||
$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_two) {
|
||||
$mer_cate_id = $cate_id_one_two;
|
||||
} 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_id = Db::name('store_category')->insertGetId($mer_cate);
|
||||
}
|
||||
} 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_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;
|
||||
if ($bar_code) {
|
||||
}
|
||||
$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;
|
||||
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) {
|
||||
return $value ? explode(',', $value) : [];
|
||||
})
|
||||
->find();
|
||||
if (!$library) {
|
||||
$ProductLibrary = app()->make(ProductLibrary::class);
|
||||
$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();
|
||||
if (!$library) {
|
||||
$ProductLibrary = app()->make(ProductLibrary::class);
|
||||
$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();
|
||||
}
|
||||
}
|
||||
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",
|
||||
];
|
||||
}
|
||||
$procure_price=0;
|
||||
if(!empty($datum['value']['procure_price'])){
|
||||
$procure_price=$datum['value']['procure_price'];
|
||||
}
|
||||
$datas = [
|
||||
"image" => $image,
|
||||
"slider_image" => $slider_image,
|
||||
"store_name" => $datum['value']['store_name'],
|
||||
"store_info" => $datum['value']['store_name'],
|
||||
"keyword" => '',
|
||||
"bar_code" => $bar_code,
|
||||
"guarantee_template_id" => "",
|
||||
"cate_id" => $cate_id,
|
||||
"mer_cate_id" => [
|
||||
0 => $mer_cate_id
|
||||
],
|
||||
'product_type' => $product_type,
|
||||
"unit_name" => $datum['value']['unit_name'],
|
||||
"sort" => 0,
|
||||
"is_show" => "",
|
||||
"is_good" => 0,
|
||||
"is_gift_bag" => 0,
|
||||
"integral_rate" => -1,
|
||||
"video_link" => "",
|
||||
"temp_id" => "",
|
||||
"content" => "",
|
||||
"spec_type" => $spec_type,
|
||||
"extension_type" => 0,
|
||||
"attr" => $arr,
|
||||
"mer_labels" => [],
|
||||
"delivery_way" => [
|
||||
0 => "2",
|
||||
1 => "1"
|
||||
],
|
||||
"delivery_free" => 0,
|
||||
"param_temp_id" => [],
|
||||
"extend" => [],
|
||||
"brand_id" => "",
|
||||
"once_max_count" => 0,
|
||||
"once_min_count" => 0,
|
||||
"pay_limit" => 0,
|
||||
"attrValue" => [
|
||||
[
|
||||
"image" => $image,
|
||||
"price" => $datum['value']['price'],
|
||||
"cost" => $datum['value']['cost'],
|
||||
"ot_price" => $datum['value']['price'],
|
||||
"svip_price" => null,
|
||||
"procure_price" => $procure_price,
|
||||
"stock" => 1,
|
||||
"bar_code" => (int)$datum['value']['bar_code'],
|
||||
"weight" => 0,
|
||||
"volume" => 0,
|
||||
"detail" => $detail,
|
||||
],
|
||||
],
|
||||
"give_coupon_ids" => [],
|
||||
"type" => 0,
|
||||
"svip_price" => 0,
|
||||
"svip_price_type" => 0,
|
||||
"params" => [],
|
||||
"mer_id" => $merId,
|
||||
"status" => 1,
|
||||
"mer_status" => 1,
|
||||
"rate" => 3,
|
||||
}
|
||||
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",
|
||||
];
|
||||
// $data_list = [
|
||||
// 'data' => $datas,
|
||||
// 'product_type' => $product_type,
|
||||
// ];
|
||||
$make = app()->make(ProductRepository::class);
|
||||
$product_id = $make->create($datas, $product_type);
|
||||
if ($product_id) {
|
||||
$datas['product_id'] = $product_id;
|
||||
$datas['mer_id'] = $merId;
|
||||
$datas['store_name'] = $datum['value']['store_name'];
|
||||
$this->create_product_import_log($datas);
|
||||
}
|
||||
// Queue::push(ProductImportJob::class, $data_list);
|
||||
}
|
||||
$procure_price = 0;
|
||||
if (!empty($datum['value']['procure_price'])) {
|
||||
$procure_price = $datum['value']['procure_price'];
|
||||
}
|
||||
$datas = [
|
||||
"image" => $image,
|
||||
"slider_image" => $slider_image,
|
||||
"store_name" => $datum['value']['store_name'],
|
||||
"store_info" => $datum['value']['store_name'],
|
||||
"keyword" => '',
|
||||
"bar_code" => $bar_code,
|
||||
"guarantee_template_id" => "",
|
||||
"cate_id" => $cate_id,
|
||||
"mer_cate_id" => [
|
||||
0 => $mer_cate_id
|
||||
],
|
||||
'product_type' => $product_type,
|
||||
"unit_name" => $datum['value']['unit_name'],
|
||||
"sort" => 0,
|
||||
"is_show" => "",
|
||||
"is_good" => 0,
|
||||
"is_gift_bag" => 0,
|
||||
"integral_rate" => -1,
|
||||
"video_link" => "",
|
||||
"temp_id" => "",
|
||||
"content" => "",
|
||||
"spec_type" => $spec_type,
|
||||
"extension_type" => 0,
|
||||
"attr" => $arr,
|
||||
"mer_labels" => [],
|
||||
"delivery_way" => [
|
||||
0 => "2",
|
||||
1 => "1"
|
||||
],
|
||||
"delivery_free" => 0,
|
||||
"param_temp_id" => [],
|
||||
"extend" => [],
|
||||
"brand_id" => "",
|
||||
"once_max_count" => 0,
|
||||
"once_min_count" => 0,
|
||||
"pay_limit" => 0,
|
||||
"attrValue" => [
|
||||
[
|
||||
"image" => $image,
|
||||
"price" => $datum['value']['price'],
|
||||
"cost" => $datum['value']['cost'],
|
||||
"ot_price" => $datum['value']['price'],
|
||||
"svip_price" => null,
|
||||
"procure_price" => $procure_price,
|
||||
"stock" => 1,
|
||||
"bar_code" => (int)$datum['value']['bar_code'],
|
||||
"weight" => 0,
|
||||
"volume" => 0,
|
||||
"detail" => $detail,
|
||||
],
|
||||
],
|
||||
"give_coupon_ids" => [],
|
||||
"type" => 0,
|
||||
"svip_price" => 0,
|
||||
"svip_price_type" => 0,
|
||||
"params" => [],
|
||||
"mer_id" => $merId,
|
||||
"status" => 1,
|
||||
"mer_status" => 1,
|
||||
"rate" => 3,
|
||||
];
|
||||
$make = app()->make(ProductRepository::class);
|
||||
$product_id = $make->create($datas, $product_type);
|
||||
if ($product_id) {
|
||||
$datas['product_id'] = $product_id;
|
||||
$datas['mer_id'] = $merId;
|
||||
$datas['store_name'] = $datum['value']['store_name'];
|
||||
$this->create_product_import_log($datas);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$datas['product_id'] = $product_id??0;
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$datas['product_id'] = $product_id ?? 0;
|
||||
$datas['mer_id'] = $merId;
|
||||
$datas['store_name'] = $datum['value']['store_name'];
|
||||
$datas['content'] = $e->getMessage().'line:'.$e->getLine();
|
||||
$datas['content'] = $e->getMessage() . 'line:' . $e->getLine();
|
||||
$this->create_product_import_log($datas, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function create_product_import_log($data, $status = 1)
|
||||
{
|
||||
$data = [
|
||||
'product_id' => $data['product_id']??0,
|
||||
'product_id' => $data['product_id'] ?? 0,
|
||||
'mer_id' => $data['mer_id'],
|
||||
'name' => $data['store_name'],
|
||||
'content' => $data['content'] ?? '',
|
||||
@ -2740,9 +2725,9 @@ class StoreOrderRepository extends BaseRepository
|
||||
|
||||
public function create_product_attr_value($find, $datum, $product_type, $attr_values, $merId, $sku)
|
||||
{
|
||||
$procure_price=0;
|
||||
if(!empty($datum['value']['procure_price'])){
|
||||
$procure_price=$datum['value']['procure_price'];
|
||||
$procure_price = 0;
|
||||
if (!empty($datum['value']['procure_price'])) {
|
||||
$procure_price = $datum['value']['procure_price'];
|
||||
}
|
||||
$attrValue['stock'] = 1;
|
||||
$unique = app(ProductRepository::class)->setUnique($find['product_id'], $datum['value']['bar_code'], $product_type);
|
||||
|
@ -16,7 +16,7 @@ use app\common\repositories\store\order\StoreImportDeliveryRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use crmeb\jobs\ImportSpreadsheetExcelJob;
|
||||
use crmeb\jobs\ImportPicJob;
|
||||
use crmeb\jobs\ImportProductJob;
|
||||
use crmeb\jobs\ImportProductXlsJob;
|
||||
use crmeb\services\ExcelService;
|
||||
use crmeb\services\SpreadsheetExcelService;
|
||||
use crmeb\services\UploadService;
|
||||
@ -223,7 +223,8 @@ class StoreImport extends BaseController
|
||||
'L1'=>'商品条码',
|
||||
'M1'=>'商品品牌',
|
||||
];
|
||||
SpreadsheetExcelService::instance()->checkImport($path,$check);
|
||||
$a=SpreadsheetExcelService::instance()->checkImport($path,$check,true);
|
||||
|
||||
$data = [
|
||||
'mer_id' => $this->request->merId(),
|
||||
'data' => [
|
||||
@ -234,7 +235,7 @@ class StoreImport extends BaseController
|
||||
]
|
||||
];
|
||||
// app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id'],$type_id);
|
||||
Queue::push(ImportProductJob::class,['mer_id'=>$data['mer_id'],'data'=>$data['data'],'type_id'=>$type_id]);
|
||||
Queue::push(ImportProductXlsJob::class,['mer_id'=>$data['mer_id'],'data'=>$data['data'],'type_id'=>$type_id]);
|
||||
|
||||
}else{
|
||||
$check =[
|
||||
@ -251,7 +252,7 @@ class StoreImport extends BaseController
|
||||
'K1'=>'商品条码',
|
||||
'L1'=>'商品品牌',
|
||||
];
|
||||
SpreadsheetExcelService::instance()->checkImport($path,$check);
|
||||
SpreadsheetExcelService::instance()->checkImport($path,$check,true);
|
||||
$data = [
|
||||
'mer_id' => $this->request->merId(),
|
||||
'data' => [
|
||||
@ -261,7 +262,7 @@ class StoreImport extends BaseController
|
||||
'where' => ['store_name' => 'A'],
|
||||
]
|
||||
];
|
||||
Queue::push(ImportProductJob::class,['mer_id'=>$data['mer_id'],'data'=>$data['data'],'type_id'=>$type_id]);
|
||||
Queue::push(ImportProductXlsJob::class,['mer_id'=>$data['mer_id'],'data'=>$data['data'],'type_id'=>$type_id]);
|
||||
// app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id'],$type_id);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class OrderTake
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e->getMessage() . 'lien:' . $e->getLine());
|
||||
Log::error('收货后的逻辑:'.$e->getMessage() . 'lien:' . $e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ class ProductCreate
|
||||
|
||||
public function handle($event)
|
||||
{
|
||||
Log::error(json_encode($event));
|
||||
$product = $event['product'];
|
||||
// $data = $event['data'];
|
||||
// $contentType = $event['conType'];
|
||||
|
@ -53,7 +53,7 @@ class paySuccess
|
||||
}
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
Log::error($e->getMessage().'lien:'.$e->getLine());
|
||||
Log::error('支付后逻辑报错:'.$e->getMessage().'lien:'.$e->getLine());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class ImportPicJob implements JobInterface
|
||||
{
|
||||
public function fire($job, $data)
|
||||
{
|
||||
Log::error('开始导入商品图片:' . $job->attempts());
|
||||
Log::info('开始导入商品图片:' . $job->attempts());
|
||||
if ($job->attempts() > 3) {
|
||||
$job->delete();
|
||||
$this->failed($data);
|
||||
|
@ -10,12 +10,12 @@ class ImportProductJob implements JobInterface
|
||||
{
|
||||
public function fire($job, $data)
|
||||
{
|
||||
Log::error('开始导入商品:' . $job->attempts());
|
||||
Log::info('开始导入商品:');
|
||||
if ($job->attempts() > 1) {
|
||||
$job->delete();
|
||||
$this->failed($data);
|
||||
}
|
||||
app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id'],$data['type_id']);
|
||||
app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id'],$data['product_type']);
|
||||
$job->delete();
|
||||
}
|
||||
|
||||
|
64
crmeb/jobs/ImportProductXlsJob.php
Normal file
64
crmeb/jobs/ImportProductXlsJob.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace crmeb\jobs;
|
||||
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use think\facade\Log;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use think\facade\Db;
|
||||
use crmeb\services\SpreadsheetExcelService;
|
||||
use think\facade\Queue;
|
||||
|
||||
class ImportProductXlsJob implements JobInterface
|
||||
{
|
||||
public function fire($job, $data)
|
||||
{
|
||||
Log::info('开始读取excel商品:' . $job->attempts());
|
||||
if ($job->attempts() > 1) {
|
||||
$job->delete();
|
||||
$this->failed($data);
|
||||
}
|
||||
$arrary = $data['data'];
|
||||
//读取excel
|
||||
$excel_data = SpreadsheetExcelService::instance()->_import($arrary['path'], $arrary['sql'], $arrary['where'], 1);
|
||||
if (!$excel_data) return false;
|
||||
unset($excel_data[0]);
|
||||
$product_type = 0;
|
||||
if ($data['type_id'] == 12) {
|
||||
$product_type = 98; //供应链
|
||||
}
|
||||
try {
|
||||
foreach ($excel_data as $datum) {
|
||||
|
||||
Queue::push(ImportProductJob::class,['data'=>$datum,'mer_id'=>$data['mer_id'],'product_type'=>$product_type]);
|
||||
// $StoreOrderRepository->setProduct();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$job->delete();
|
||||
$datas['product_id'] = $product_id ?? 0;
|
||||
$datas['mer_id'] = $data['mer_id'];
|
||||
$datas['store_name'] = $datum['value']['store_name'];
|
||||
$datas['content'] = $e->getMessage() . 'line:' . $e->getLine();
|
||||
$this->create_product_import_log($datas, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public function failed($data)
|
||||
{
|
||||
Log::error('读取excel失败:' . json_encode($data));
|
||||
// TODO: Implement failed() method.
|
||||
}
|
||||
|
||||
public function create_product_import_log($data, $status = 1)
|
||||
{
|
||||
$data = [
|
||||
'product_id' => $data['product_id'] ?? 0,
|
||||
'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);
|
||||
}
|
||||
}
|
@ -369,12 +369,19 @@ class SpreadsheetExcelService
|
||||
* @author Qinii
|
||||
* @day 5/7/21
|
||||
*/
|
||||
public function checkImport($filePath,$check = [])
|
||||
public function checkImport($filePath,$check = [],$is_limit=false,$count=1000)
|
||||
{
|
||||
$ext = ucfirst(pathinfo($filePath, PATHINFO_EXTENSION));
|
||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($ext);
|
||||
$spreadsheet = $reader->load($filePath);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
if($is_limit==true){
|
||||
$limit=$sheet->getHighestRow();
|
||||
if($limit>$count){
|
||||
throw new ValidateException('导入的条数超过限制数量:'.$count);
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($check)){
|
||||
foreach ($check as $s => $c){
|
||||
$_c = $sheet->getCell($s)->getValue();
|
||||
|
Loading…
x
Reference in New Issue
Block a user