|
|
@ -11,11 +11,12 @@ use Maatwebsite\Excel\Concerns\ToModel; |
|
|
class ParkingVipListImport implements ToModel |
|
|
class ParkingVipListImport implements ToModel |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
protected int $index = 0; |
|
|
|
|
|
protected array $error = []; |
|
|
/** |
|
|
/** |
|
|
* @var OperationLogService |
|
|
* @var OperationLogService |
|
|
*/ |
|
|
*/ |
|
|
private OperationLogService $logService; |
|
|
private OperationLogService $logService; |
|
|
protected int $index = 1; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct() |
|
|
public function __construct() |
|
|
{ |
|
|
{ |
|
|
@ -28,23 +29,35 @@ class ParkingVipListImport implements ToModel |
|
|
*/ |
|
|
*/ |
|
|
public function model(array $row) |
|
|
public function model(array $row) |
|
|
{ |
|
|
{ |
|
|
if ($this->index == 1) { |
|
|
if (!$this->index) { |
|
|
$this->index += 1; |
|
|
$this->index += 1; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
if (isset($row[1]) && $row[1]) { |
|
|
$this->index += 1; |
|
|
$license = $row[1]; |
|
|
$license = $row[1] ?? ''; |
|
|
$license_id = (new ParkingLicensePlateService($this->logService))->createLicenseId($license); |
|
|
if (empty($license)) { |
|
|
if (!ParkingVipList::query()->where('license_id', $license_id) |
|
|
$this->error[] = imports_error($this->index, 'import33'); |
|
|
->exists() |
|
|
return; |
|
|
) { |
|
|
} |
|
|
$model = ParkingVipList::query()->create([ |
|
|
$license_id = (new ParkingLicensePlateService( |
|
|
'license_id' => $license_id, |
|
|
$this->logService |
|
|
'user_id' => Auth::guard('sanctum')->user()['id'], |
|
|
))->createLicenseId($license); |
|
|
'created_at' => get_datetime() |
|
|
if (ParkingVipList::query()->where('license_id', $license_id) |
|
|
]); |
|
|
->exists() |
|
|
$this->logService->logCreated($model, 'vip_list.create'); |
|
|
) { |
|
|
} |
|
|
$this->error[] = imports_error($this->index, 'import37'); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
$model = ParkingVipList::query()->create([ |
|
|
|
|
|
'license_id' => $license_id, |
|
|
|
|
|
'user_id' => Auth::guard('sanctum')->user()['id'], |
|
|
|
|
|
'created_at' => get_datetime() |
|
|
|
|
|
]); |
|
|
|
|
|
$this->logService->logCreated($model, 'vip_list.create'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function errorArr(): array |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->error; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|