Browse Source

导入车牌优化

master
wanghongjun 2 months ago
parent
commit
8e959e01d7
  1. 2
      app/Exports/ParkingLicensePlateImportTemplateExport.php
  2. 4
      app/Exports/ParkingVipListImportTemplateExport.php
  3. 11
      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']
]; ];
} }
} }

11
app/Imports/ParkingLicensePlateImport.php

@ -28,19 +28,17 @@ 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 = [ $where = [
'number' => $data[0], 'number' => $number,
'space_type_id' => $this->parkingSpaceType 'space_type_id' => $this->parkingSpaceType
]; ];
if (!ParkingLicensePlate::query()->where($where) if (!ParkingLicensePlate::query()->where($where)
->exists() ->exists()
) { ) {
$model = new ParkingLicensePlate([ $model = new ParkingLicensePlate([
'number' => $data[0], 'number' => $number,
'space_type_id' => $this->parkingSpaceType, 'space_type_id' => $this->parkingSpaceType,
'created_at' => get_datetime() 'created_at' => get_datetime()
]); ]);
@ -48,3 +46,4 @@ class ParkingLicensePlateImport implements ToModel, WithHeadingRow
} }
} }
} }
}

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