Commit dbd77533 by 杨树贤

完成导入脚本

parent f9ab0d66
...@@ -31,6 +31,6 @@ class SetSupplierFollowUp extends Command ...@@ -31,6 +31,6 @@ class SetSupplierFollowUp extends Command
public function handle() public function handle()
{ {
$service = new DataService(); $service = new DataService();
$service->importMainBrandData(); $service->importSupplierLevel();
} }
} }
...@@ -295,40 +295,55 @@ class DataService ...@@ -295,40 +295,55 @@ class DataService
//导入等级修改供应商并且找出没有等级的供应商(针对正式的) //导入等级修改供应商并且找出没有等级的供应商(针对正式的)
public function importSupplierLevel() public function importSupplierLevel()
{ {
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_level.xls'; $filePath = 'public/data' . DIRECTORY_SEPARATOR . 'supplier_level.xlsx';
try {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) { Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel(); $supplierChannelModel = new SupplierChannelModel();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel) { $reader->sheet('2021年评估', function ($sheet) use ($reader, $supplierChannelModel) {
$number = 0; $number = 0;
foreach ($reader->all()->toArray() as $key => $item) { foreach ($reader->all()->toArray() as $key => $item) {
if ($key==0) {
continue;
}
//判断如果有日志了就跳过
$logModel = new LogModel();
$supplierName = trim($item[1]); $supplierName = trim($item[1]);
$level = trim($item[3]); $level = trim($item[2]);
//先去判断是否存在 //先去判断是否存在
$exist = $supplierChannelModel->where('supplier_name', $supplierName) $supplierLevelMap = $supplierChannelModel->where('supplier_name', $supplierName)
->exists(); ->select(['level','supplier_id'])->first();
if (!$exist) { if (empty($supplierLevelMap)) {
$number++; $number++;
echo '供应商不存在 : ' . $supplierName . PHP_EOL;
//然后修改excel //然后修改excel
$sheet->cell('E' . ($key + 2), function ($cell) { // $sheet->cell('D' . ($key + 1), function ($cell) {
$cell->setValue('供应商不存在'); // $cell->setValue('供应商不存在');
}); // });
} else { } else {
$supplierLevelMap = $supplierLevelMap->toArray();
$supplierId = $supplierLevelMap['supplier_id'];
$existLog = $logModel->where('supplier_id', $supplierId)->where('action', '脚本处理等级')->exists();
if ($existLog) {
continue;
}
$supplierChannelModel->where('supplier_name', $supplierName)->update([ $supplierChannelModel->where('supplier_name', $supplierName)->update([
'level' => $level, 'level' => $level,
]); ]);
$sheet->cell('E' . ($key + 2), function ($cell) { // $sheet->cell('E' . ($key + 1), function ($cell) {
$cell->setValue('修改成功'); // $cell->setValue('修改成功');
}); // });
$originLevel = $supplierLevelMap['level'];
$originLevel = $originLevel ?: '无';
$content = "admin将供应商等级 $originLevel 修改为 $level";
echo $content . PHP_EOL;
$logService = new LogService();
$logService->AddAdminLog($supplierId, LogModel::UPDATE_OPERATE, '脚本处理等级', $content);
} }
} }
var_dump("一共有${number}个不存在的供应商"); var_dump("一共有${number}个不存在的供应商");
}); });
})->store('xls'); });
} catch (\Exception $exception) {
var_dump($exception);
}
} }
//导入主营品牌数据 //导入主营品牌数据
......
...@@ -29,6 +29,25 @@ class LogService ...@@ -29,6 +29,25 @@ class LogService
$model->insert($data); $model->insert($data);
} }
//添加日志
public function AddAdminLog($supplierId, $type, $action, $content, $remark = '')
{
$adminId = 1000;
$adminName = 'admin';
$data = [
'supplier_id' => $supplierId,
'type' => $type,
'action' => $action,
'content' => $content,
'remark' => $remark,
'admin_id' => $adminId,
'admin_name' => $adminName,
'add_time' => time(),
];
$model = new LogModel();
$model->insert($data);
}
public function getLogs($supplierId, $type = '', $limit = 100) public function getLogs($supplierId, $type = '', $limit = 100)
{ {
$model = new LogModel(); $model = new LogModel();
......
...@@ -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->importSupplier(); $service->importSupplierLevel();
// $service->transferFileData(); // $service->transferFileData();
// $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid(); // $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid();
// $service->replaceStandardBrandId(); // $service->replaceStandardBrandId();
......
No preview for this file type
No preview for this file type
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