Commit 14dc0f93 by mushishixian

导入供应商脚本

parent a4071db3
...@@ -361,7 +361,7 @@ class DataService ...@@ -361,7 +361,7 @@ class DataService
'main_brands' => implode(',', $mainBrandIds), 'main_brands' => implode(',', $mainBrandIds),
]); ]);
if ($result) { if ($result) {
var_dump('更新供应商主营品牌成功,供应商 : '.$supplierName); var_dump('更新供应商主营品牌成功,供应商 : ' . $supplierName);
} }
} }
}); });
...@@ -370,6 +370,52 @@ class DataService ...@@ -370,6 +370,52 @@ class DataService
var_dump($exception); var_dump($exception);
} }
} }
//从excel导入供应商
public function importSupplier()
{
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_import.xls';
try {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel();
$supplierService = new SupplierService();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel,$supplierService) {
$number = 0;
foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[1]);
//先去判断是否存在
$exist = $supplierChannelModel->where('supplier_name', $supplierName)
->exists();
if (!$exist) {
$number++;
//往库里面插入
$data = [
'supplier_name' => $supplierName,
'create_uid' => 1000,
'create_time' => time(),
'status' => 2,
'is_type' => 1,
'create_name' => 'admin',
];
$supplierId = $supplierChannelModel->insertGetId($data);
$supplierService->saveSupplierCode($supplierId);
//然后修改excel
$sheet->cell('E' . ($key + 2), function ($cell) {
$cell->setValue('供应商不存在,已经新增');
});
} else {
$sheet->cell('E' . ($key + 2), function ($cell) {
$cell->setValue('供应商已经存在,不做新增');
});
}
}
var_dump("一共新增了${number}个不存在的供应商");
});
})->store('xls');
} catch (\Exception $exception) {
var_dump($exception);
}
}
} }
...@@ -46,7 +46,7 @@ Route::match(['get', 'post'], '/test', function () { ...@@ -46,7 +46,7 @@ Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService(); $service = new \App\Http\Services\DataService();
// $service->pushSupplierSKu(); // $service->pushSupplierSKu();
// $service->makeSupplierSystemTag(); // $service->makeSupplierSystemTag();
$service->importMainBrandData(); $service->importSupplier();
// $service->transferFileData(); // $service->transferFileData();
// $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid(); // $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid();
// $service->replaceStandardBrandId(); // $service->replaceStandardBrandId();
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment