Commit 41680f18 by 杨树贤

空格校验

parent 890df309
......@@ -31,6 +31,6 @@ class SetSupplierFollowUp extends Command
public function handle()
{
$service = new DataService();
$service->importSupplierLevel();
$service->trimSupplierName();
}
}
......@@ -296,53 +296,53 @@ class DataService
public function importSupplierLevel()
{
$filePath = 'public/data' . DIRECTORY_SEPARATOR . 'supplier_level.xlsx';
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel();
$reader->sheet('2021年评估', function ($sheet) use ($reader, $supplierChannelModel) {
$number = 0;
foreach ($reader->all()->toArray() as $key => $item) {
if ($key==0) {
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new 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[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;
}
//判断如果有日志了就跳过
$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;
}
$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);
}
$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
}
}
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导入供应商
public function importSupplier()
{
......@@ -393,7 +406,7 @@ class DataService
Excel::selectSheetsByIndex(0)->load($filePath, function ($reader) {
$supplierChannelModel = new SupplierChannelModel();
$supplierService = new SupplierService();
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel,$supplierService) {
$reader->sheet('供应商清单', function ($sheet) use ($reader, $supplierChannelModel, $supplierService) {
$number = 0;
foreach ($reader->all()->toArray() as $key => $item) {
$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