Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
285c3d5bcd
@ -2501,19 +2501,9 @@ 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']);
|
||||
@ -2529,13 +2519,13 @@ class StoreOrderRepository extends BaseRepository
|
||||
];
|
||||
}
|
||||
$array_values = array_values($attr);
|
||||
$attr_implode= implode(',', $array_values);
|
||||
$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;
|
||||
$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();
|
||||
@ -2544,8 +2534,8 @@ class StoreOrderRepository extends BaseRepository
|
||||
$datas['mer_id'] = $merId;
|
||||
$datas['store_name'] = $datum['value']['store_name'];
|
||||
$datas['content'] = 'xls导入商品:已经导入过该规格了';
|
||||
$this->create_product_import_log($datas,0);
|
||||
continue;
|
||||
$this->create_product_import_log($datas, 0);
|
||||
return false;
|
||||
}
|
||||
foreach ($attr as $kk => $vv) {
|
||||
/**查询当前规格属性是否存在 */
|
||||
@ -2635,9 +2625,9 @@ class StoreOrderRepository extends BaseRepository
|
||||
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'];
|
||||
$procure_price = 0;
|
||||
if (!empty($datum['value']['procure_price'])) {
|
||||
$procure_price = $datum['value']['procure_price'];
|
||||
}
|
||||
$datas = [
|
||||
"image" => $image,
|
||||
@ -2701,10 +2691,6 @@ class StoreOrderRepository extends BaseRepository
|
||||
"mer_status" => 1,
|
||||
"rate" => 3,
|
||||
];
|
||||
// $data_list = [
|
||||
// 'data' => $datas,
|
||||
// 'product_type' => $product_type,
|
||||
// ];
|
||||
$make = app()->make(ProductRepository::class);
|
||||
$product_id = $make->create($datas, $product_type);
|
||||
if ($product_id) {
|
||||
@ -2713,22 +2699,21 @@ class StoreOrderRepository extends BaseRepository
|
||||
$datas['store_name'] = $datum['value']['store_name'];
|
||||
$this->create_product_import_log($datas);
|
||||
}
|
||||
// Queue::push(ProductImportJob::class, $data_list);
|
||||
}
|
||||
}
|
||||
} 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();
|
||||
$this->create_product_import_log($datas, 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();
|
||||
$this->create_product_import_log($datas, 0);
|
||||
}
|
||||
}
|
||||
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