diff --git a/app/Imports/ParkingLicensePlateImport.php b/app/Imports/ParkingLicensePlateImport.php index 769549a..311cbc3 100644 --- a/app/Imports/ParkingLicensePlateImport.php +++ b/app/Imports/ParkingLicensePlateImport.php @@ -4,6 +4,7 @@ namespace App\Imports; use App\Models\ParkingLicensePlate; use App\Services\OperationLogService; +use App\Services\ParkingLicensePlateService; use Maatwebsite\Excel\Concerns\ToModel; class ParkingLicensePlateImport implements ToModel @@ -39,6 +40,15 @@ class ParkingLicensePlateImport implements ToModel //$this->error[] = imports_error($this->index, 'import33'); return; } + $licensePlateService = new ParkingLicensePlateService( + $this->logService + ); + $error_str = $licensePlateService->validateLicensePlate( + $number + ); + if ($error_str) { + $this->error[] = $error_str; + } $where = [ 'number' => $number, 'space_type_id' => $this->parkingSpaceType diff --git a/app/Imports/ParkingVipListImport.php b/app/Imports/ParkingVipListImport.php index 85b00e0..d3416d2 100644 --- a/app/Imports/ParkingVipListImport.php +++ b/app/Imports/ParkingVipListImport.php @@ -39,9 +39,16 @@ class ParkingVipListImport implements ToModel $this->error[] = imports_error($this->index, 'import33'); return; } - $license_id = (new ParkingLicensePlateService( + $licensePlateService = new ParkingLicensePlateService( $this->logService - ))->createLicenseId($license); + ); + $error_str = $licensePlateService->validateLicensePlate( + $license + ); + if ($error_str) { + $this->error[] = $error_str; + } + $license_id = $licensePlateService->createLicenseId($license); if (!$license_id) { $this->error[] = imports_error($this->index, 'import38'); return; diff --git a/app/Imports/ParkingWhitelistImport.php b/app/Imports/ParkingWhitelistImport.php index a5075b0..cbc1b0a 100644 --- a/app/Imports/ParkingWhitelistImport.php +++ b/app/Imports/ParkingWhitelistImport.php @@ -7,6 +7,7 @@ use App\Models\ParkingChannel; use App\Models\ParkingSpaceType; use App\Services\AdminTranslationService; use App\Services\OperationLogService; +use App\Services\ParkingLicensePlateService; use App\Services\ParkingWhitelistService; use Maatwebsite\Excel\Concerns\ToModel; use Maatwebsite\Excel\Concerns\WithChunkReading; @@ -36,6 +37,15 @@ class ParkingWhitelistImport implements ToModel, WithChunkReading $this->error[] = imports_error($this->index, 'import33'); return; } + $licensePlateService = new ParkingLicensePlateService( + new OperationLogService() + ); + $error_str = $licensePlateService->validateLicensePlate( + $license_plate + ); + if ($error_str) { + $this->error[] = $error_str; + } $parking_name = $row[2] ?? ''; if (empty($parking_name)) { $this->error[] = imports_error($this->index, 'import20'); diff --git a/app/Services/ParkingLicensePlateService.php b/app/Services/ParkingLicensePlateService.php index addb9b3..a94a21f 100644 --- a/app/Services/ParkingLicensePlateService.php +++ b/app/Services/ParkingLicensePlateService.php @@ -213,6 +213,8 @@ class ParkingLicensePlateService if (!preg_match($pattern, $plate)) { return __validation('parking_space.hk_plate'); } + } else { + return __validation('parking_space.error_plate'); } return ''; } diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 2757c4c..6e0b10a 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -89,7 +89,8 @@ return [ 'a_empty' => 'Parking space attribute cannot be empty', 'n_empty' => 'The parking number cannot be empty', 'zh_plate' => 'Invalid license plate format; please check if it contains the prohibited letters I or O.', - 'hk_plate' => 'Invalid license plate format; please check if it contains the prohibited letters I, O, or Q.' + 'hk_plate' => 'Invalid license plate format; please check if it contains the prohibited letters I, O, or Q.', + 'error_plate' => 'License plate not recognized; please enter the correct license plate number.' ], 'map' => [ 'f_empty' => 'The floor number cannot be empty', diff --git a/resources/lang/zh-CN/validation.php b/resources/lang/zh-CN/validation.php index 32f0a18..b31793f 100644 --- a/resources/lang/zh-CN/validation.php +++ b/resources/lang/zh-CN/validation.php @@ -89,7 +89,8 @@ return [ 'a_empty' => '车位属性不能为空', 'n_empty' => '车位号码不能为空', 'zh_plate' => '车牌格式无效,请检查是否包含禁用的字母 I 或 O。', - 'hk_plate' => '车牌格式无效,请检查是否包含禁用的字母 I、O 或 Q。' + 'hk_plate' => '车牌格式无效,请检查是否包含禁用的字母 I、O 或 Q。', + 'error_plate' => '无法识别的车牌,请填写正确车牌。' ], 'map' => [ 'f_empty' => '楼层编号不能为空', diff --git a/resources/lang/zh-TW/validation.php b/resources/lang/zh-TW/validation.php index fc1f39d..37311e4 100644 --- a/resources/lang/zh-TW/validation.php +++ b/resources/lang/zh-TW/validation.php @@ -89,7 +89,8 @@ return [ 'a_empty' => '車位内容不能為空', 'n_empty' => '車位號碼不能為空', 'zh_plate' => '車牌格式無效,請檢查是否包含已禁用的字母 I 或 O。', - 'hk_plate' => '車牌格式無效,請檢查是否包含已禁用的字母 I、O 或 Q。' + 'hk_plate' => '車牌格式無效,請檢查是否包含已禁用的字母 I、O 或 Q。', + 'error_plate' => '無法辨識的車牌,請填寫正確車牌。' ], 'map' => [ 'f_empty' => '樓層編號不能為空',