Commit 023e673f by 杨树贤

Merge branch 'ysx-供应商等级导入-20220316'

parents 5189ab44 c205fcd9
......@@ -31,6 +31,6 @@ class SetSupplierFollowUp extends Command
public function handle()
{
$service = new DataService();
$service->importMainBrandData();
$service->importSupplierLevel();
}
}
......@@ -295,40 +295,55 @@ class DataService
//导入等级修改供应商并且找出没有等级的供应商(针对正式的)
public function importSupplierLevel()
{
$filePath = public_path('data') . DIRECTORY_SEPARATOR . 'supplier_level.xls';
try {
$filePath = 'public/data' . DIRECTORY_SEPARATOR . 'supplier_level.xlsx';
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel) {
$reader->sheet('2021年评估', function ($sheet) use ($reader, $supplierChannelModel) {
$number = 0;
foreach ($reader->all()->toArray() as $key => $item) {
if ($key==0) {
continue;
}
//判断如果有日志了就跳过
$logModel = new LogModel();
$supplierName = trim($item[1]);
$level = trim($item[3]);
$level = trim($item[2]);
//先去判断是否存在
$exist = $supplierChannelModel->where('supplier_name', $supplierName)
->exists();
if (!$exist) {
$supplierLevelMap = $supplierChannelModel->where('supplier_name', $supplierName)
->select(['level','supplier_id'])->first();
if (empty($supplierLevelMap)) {
$number++;
echo '供应商不存在 : ' . $supplierName . PHP_EOL;
//然后修改excel
$sheet->cell('E' . ($key + 2), function ($cell) {
$cell->setValue('供应商不存在');
});
// $sheet->cell('D' . ($key + 1), function ($cell) {
// $cell->setValue('供应商不存在');
// });
} 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([
'level' => $level,
]);
$sheet->cell('E' . ($key + 2), function ($cell) {
$cell->setValue('修改成功');
});
// $sheet->cell('E' . ($key + 1), function ($cell) {
// $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}个不存在的供应商");
});
})->store('xls');
} catch (\Exception $exception) {
var_dump($exception);
}
});
}
//导入主营品牌数据
......
......@@ -29,6 +29,25 @@ class LogService
$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)
{
$model = new LogModel();
......
......@@ -46,7 +46,7 @@ Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService();
// $service->pushSupplierSKu();
// $service->makeSupplierSystemTag();
$service->importSupplier();
$service->importSupplierLevel();
// $service->transferFileData();
// $service->changeSupplierIsTypeByCheckChannelUidOrPurchaseUid();
// $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