停车场管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

63 lines
1.6 KiB

<?php
namespace App\Imports;
use App\Models\ParkingVipList;
use App\Services\OperationLogService;
use App\Services\ParkingLicensePlateService;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Concerns\ToModel;
class ParkingVipListImport implements ToModel
{
protected int $index = 0;
protected array $error = [];
/**
* @var OperationLogService
*/
private OperationLogService $logService;
public function __construct()
{
$this->logService = new OperationLogService();
$this->logService->menuTitle = 'vip_list';
}
/**
* @param array $row
*/
public function model(array $row)
{
if (!$this->index) {
$this->index += 1;
return;
}
$this->index += 1;
$license = $row[1] ?? '';
if (empty($license)) {
$this->error[] = imports_error($this->index, 'import33');
return;
}
$license_id = (new ParkingLicensePlateService(
$this->logService
))->createLicenseId($license);
if (ParkingVipList::query()->where('license_id', $license_id)
->exists()
) {
$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;
}
}