Browse Source

维修车位返回错误提示

master
wanghongjun 1 day ago
parent
commit
bf396ea154
  1. 11
      app/Http/Controllers/Admin/ParkingSpaceRepairController.php
  2. 10
      app/Imports/ParkingSpaceImport.php
  3. 40
      app/Imports/ParkingSpaceRepairImport.php
  4. 6
      resources/lang/en/imports.php
  5. 6
      resources/lang/zh-CN/imports.php
  6. 14
      resources/lang/zh-TW/imports.php

11
app/Http/Controllers/Admin/ParkingSpaceRepairController.php

@ -387,18 +387,25 @@ class ParkingSpaceRepairController extends BaseController
// 4. 执行导入(使用存储后的绝对路径)
// storage_path('app') 获取 storage/app 的绝对路径
$model = new ParkingSpaceRepairImport($this->adminUserId);
Excel::import(
new ParkingSpaceRepairImport($this->adminUserId),
$model,
storage_path('app/' . $path)
);
// 5. (可选)导入完成后删除临时文件
Storage::delete($path);
// 6. 返回错误行
$error_arr = $model->errorArr();
if ($error_arr) {
throw new CustomException(implode("<br>", $error_arr));
}
return $this->responseService->success(
__('controller.import.success')
);
} catch (ValidationException $e) {
} catch (ValidationException|CustomException $e) {
throw $e;
} catch (Exception $e) {
return $this->responseService->systemError(

10
app/Imports/ParkingSpaceImport.php

@ -32,11 +32,11 @@ class ParkingSpaceImport implements ToModel, WithChunkReading
return;
}
$this->index += 1;
$parking = $row[1];
$floor = $row[2];
$region = $row[3];
$attr = $row[4];
$number = $row[5];
$parking = $row[1] ?? '';
$floor = $row[2] ?? '';
$region = $row[3] ?? '';
$attr = $row[4] ?? '';
$number = $row[5] ?? '';
if (empty($parking)) {
$this->error[] = imports_error($this->index, 'import20');
return;

40
app/Imports/ParkingSpaceRepairImport.php

@ -11,8 +11,9 @@ use Maatwebsite\Excel\Concerns\WithChunkReading;
class ParkingSpaceRepairImport implements ToModel, WithChunkReading
{
protected int $index = 1;
protected int $index = 0;
protected int $user_id;
protected array $error = [];
public function __construct($admin_user_id)
{
@ -21,37 +22,53 @@ class ParkingSpaceRepairImport implements ToModel, WithChunkReading
public function model(array $row)
{
if ($this->index == 1) {
if (!$this->index) {
$this->index += 1;
return;
}
$space_number = $row[1];
$this->index += 1;
$space_number = $row[1] ?? '';
if (empty($space_number)) {
$this->error[] = imports_error($this->index, 'import15');
return;
}
$floor_name = $row[2];
$floor_name = $row[2] ?? '';
if (empty($floor_name)) {
$this->error[] = imports_error($this->index, 'import21');
return;
}
$parking_name = $row[3];
$parking_name = $row[3] ?? '';
if (empty($parking_name)) {
$this->error[] = imports_error($this->index, 'import20');
return;
}
$start_at = $row[4] ?? '';
if (empty($start_at)) {
$this->error[] = imports_error($this->index, 'import29');
return;
}
$start_at = $row[4];
$start_times = strtotime($start_at);
if (empty($start_at) || !$start_times) {
if (!$start_times) {
$this->error[] = imports_error($this->index, 'import30');
return;
}
$end_at = $row[5];
$end_at = $row[5] ?? '';
$end_times = strtotime($end_at);
if (empty($end_at) || !$end_times) {
if (empty($end_at)) {
$this->error[] = imports_error($this->index, 'import31');
return;
}
if (empty(!$end_times)) {
$this->error[] = imports_error($this->index, 'import32');
return;
}
if ($start_times >= $end_times) {
$this->error[] = imports_error($this->index, 'import13');
return;
}
$space_id = ParkingSpace::getValueId($space_number);
if (empty($space_id)) {
$this->error[] = imports_error($this->index, 'import17');
return;
}
@ -68,4 +85,9 @@ class ParkingSpaceRepairImport implements ToModel, WithChunkReading
{
return 1000; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析
}
public function errorArr(): array
{
return $this->error;
}
}

6
resources/lang/en/imports.php

@ -28,5 +28,9 @@ return [
'import25' => 'The floor does not exist.',
'import26' => 'The region does not exist.',
'import27' => 'Parking space attributes do not exist',
'import28' => 'The parking space number for the assigned floor already exists.'
'import28' => 'The parking space number for the assigned floor already exists.',
'import29' => 'The repair start time cannot be empty.',
'import30' => 'Repair start time data error',
'import31' => 'The repair end time cannot be empty.',
'import32' => 'Repair end time data error'
];

6
resources/lang/zh-CN/imports.php

@ -28,5 +28,9 @@ return [
'import25' => '所属楼层不存在',
'import26' => '所属区域不存在',
'import27' => '车位属性不存在',
'import28' => '所属楼层车位号已存在'
'import28' => '所属楼层车位号已存在',
'import29' => '维修开始时间不能为空',
'import30' => '维修开始时间数据错误',
'import31' => '维修结束时间不能为空',
'import32' => '维修结束时间数据错误'
];

14
resources/lang/zh-TW/imports.php

@ -6,13 +6,13 @@ return [
'import3' => '模式名稱不能為空',
'import4' => '模式名稱不存在',
'import5' => '開始日期不能為空',
'import6' => '開始日期資料錯誤',
'import6' => '開始日期數據錯誤',
'import7' => '開始時間不能為空',
'import8' => '開始時間資料錯誤',
'import8' => '開始時間數據錯誤',
'import9' => '結束日期不能為空',
'import10' => '結束日期資料錯誤',
'import10' => '結束日期數據錯誤',
'import11' => '結束時間不能為空',
'import12' => '結束時間資料錯誤',
'import12' => '結束時間數據錯誤',
'import13' => '開始時間不能大於結束時間',
'import14' => '目前時段已有活動,不可上傳',
'import15' => '車位號碼不能為空',
@ -28,5 +28,9 @@ return [
'import25' => '所屬樓層不存在',
'import26' => '所屬區域不存在',
'import27' => '車位屬性不存在',
'import28' => '所屬樓層車位號碼已存在'
'import28' => '所屬樓層車位號碼已存在',
'import29' => '維修開始時間不能為空',
'import30' => '維修開始時間數據錯誤',
'import31' => '維修結束時間不能為空',
'import32' => '維修結束時間數據錯誤'
];

Loading…
Cancel
Save