Browse Source

导入车牌优化

master
wanghongjun 1 month ago
parent
commit
8e959e01d7
  1. 2
      app/Exports/ParkingLicensePlateImportTemplateExport.php
  2. 4
      app/Exports/ParkingVipListImportTemplateExport.php
  3. 33
      app/Imports/ParkingLicensePlateImport.php
  4. 4
      app/Imports/ParkingVipListImport.php

2
app/Exports/ParkingLicensePlateImportTemplateExport.php

@ -9,7 +9,7 @@ class ParkingLicensePlateImportTemplateExport implements FromArray
public function array(): array public function array(): array
{ {
return [ return [
[__('exports.global.index'), __('exports.vip_list.license')], ['No.', 'License Plate No.'],
['1', '测A88888'] ['1', '测A88888']
]; ];
} }

4
app/Exports/ParkingVipListImportTemplateExport.php

@ -10,8 +10,8 @@ class ParkingVipListImportTemplateExport implements FromArray
public function array(): array public function array(): array
{ {
return [ return [
[__('exports.vip_list.license')], ['No.', 'License Plate No.'],
['测A88888'] ['1', '测A88887']
]; ];
} }
} }

33
app/Imports/ParkingLicensePlateImport.php

@ -28,23 +28,22 @@ class ParkingLicensePlateImport implements ToModel, WithHeadingRow
*/ */
public function model(array $row) public function model(array $row)
{ {
$data = []; if (isset($row['license_plate_no']) && $row['license_plate_no']) {
foreach ($row as $value) { $number = $row['license_plate_no'];
$data[] = $value; $where = [
} 'number' => $number,
$where = [ 'space_type_id' => $this->parkingSpaceType
'number' => $data[0], ];
'space_type_id' => $this->parkingSpaceType if (!ParkingLicensePlate::query()->where($where)
]; ->exists()
if (!ParkingLicensePlate::query()->where($where) ) {
->exists() $model = new ParkingLicensePlate([
) { 'number' => $number,
$model = new ParkingLicensePlate([ 'space_type_id' => $this->parkingSpaceType,
'number' => $data[0], 'created_at' => get_datetime()
'space_type_id' => $this->parkingSpaceType, ]);
'created_at' => get_datetime() $this->logService->logCreated($model, 'license_plate.create');
]); }
$this->logService->logCreated($model, 'license_plate.create');
} }
} }
} }

4
app/Imports/ParkingVipListImport.php

@ -27,7 +27,8 @@ class ParkingVipListImport implements ToModel, WithHeadingRow
*/ */
public function model(array $row) public function model(array $row)
{ {
foreach ($row as $license) { if (isset($row['license_plate_no']) && $row['license_plate_no']) {
$license = $row['license_plate_no'];
if (!ParkingVipList::query()->where('license', $license) if (!ParkingVipList::query()->where('license', $license)
->exists() ->exists()
) { ) {
@ -38,7 +39,6 @@ class ParkingVipListImport implements ToModel, WithHeadingRow
]); ]);
$this->logService->logCreated($model, 'vip_list.create'); $this->logService->logCreated($model, 'vip_list.create');
} }
break;
} }
} }
} }

Loading…
Cancel
Save