Commit 41680f18 by 杨树贤

空格校验

parent 890df309
...@@ -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->importSupplierLevel(); $service->trimSupplierName();
} }
} }
...@@ -296,53 +296,53 @@ class DataService ...@@ -296,53 +296,53 @@ class DataService
public function importSupplierLevel() public function importSupplierLevel()
{ {
$filePath = 'public/data' . DIRECTORY_SEPARATOR . 'supplier_level.xlsx'; $filePath = 'public/data' . DIRECTORY_SEPARATOR . 'supplier_level.xlsx';
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) { Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel(); $supplierChannelModel = new SupplierChannelModel();
$reader->sheet('2021年评估', 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) { if ($key == 0) {
continue;
}
//判断如果有日志了就跳过
$logModel = new LogModel();
$supplierName = trim($item[1]);
$level = trim($item[2]);
//先去判断是否存在
$supplierLevelMap = $supplierChannelModel->where('supplier_name', $supplierName)
->select(['level', 'supplier_id'])->first();
if (empty($supplierLevelMap)) {
$number++;
echo '供应商不存在 : ' . $supplierName . PHP_EOL;
//然后修改excel
$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; continue;
} }
//判断如果有日志了就跳过 $supplierChannelModel->where('supplier_name', $supplierName)->update([
$logModel = new LogModel(); 'level' => $level,
$supplierName = trim($item[1]); ]);
$level = trim($item[2]); $sheet->cell('D' . ($key + 1), function ($cell) {
//先去判断是否存在 $cell->setValue('修改成功');
$supplierLevelMap = $supplierChannelModel->where('supplier_name', $supplierName) });
->select(['level','supplier_id'])->first(); $originLevel = $supplierLevelMap['level'];
if (empty($supplierLevelMap)) { $originLevel = $originLevel ?: '无';
$number++; $content = "admin将供应商等级 $originLevel 修改为 $level";
echo '供应商不存在 : ' . $supplierName . PHP_EOL; echo $content . PHP_EOL;
//然后修改excel $logService = new LogService();
$sheet->cell('D' . ($key + 1), function ($cell) { $logService->AddAdminLog($supplierId, LogModel::UPDATE_OPERATE, '脚本处理等级', $content);
$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('D' . ($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}个不存在的供应商");
}); }
var_dump("一共有${number}个不存在的供应商");
}); });
});
} }
...@@ -385,6 +385,19 @@ class DataService ...@@ -385,6 +385,19 @@ class DataService
} }
} }
public function trimSupplierName()
{
$suppliers = SupplierChannelModel::where('is_type', 0)->select([
'supplier_id',
'supplier_name'
])->get()->toArray();
foreach ($suppliers as $supplier) {
if (mb_strlen($supplier['supplier_name']) != mb_strlen(trim($supplier['supplier_name']))) {
echo '有空格的供应商 : ' . $supplier['supplier_name'] . mb_strlen($supplier['supplier_name']) . "_" . mb_strlen(trim($supplier['supplier_name'])) . PHP_EOL;
}
}
}
//从excel导入供应商 //从excel导入供应商
public function importSupplier() public function importSupplier()
{ {
...@@ -393,7 +406,7 @@ class DataService ...@@ -393,7 +406,7 @@ class DataService
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) { Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel(); $supplierChannelModel = new SupplierChannelModel();
$supplierService = new SupplierService(); $supplierService = new SupplierService();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel,$supplierService) { $reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel, $supplierService) {
$number = 0; $number = 0;
foreach ($reader->all()->toArray() as $key => $item) { foreach ($reader->all()->toArray() as $key => $item) {
$supplierName = trim($item[1]); $supplierName = trim($item[1]);
......
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