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.
46 lines
1.3 KiB
46 lines
1.3 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;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
|
|
class ParkingVipListImport implements ToModel, WithHeadingRow
|
|
{
|
|
|
|
/**
|
|
* @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 (isset($row['license_plate_no']) && $row['license_plate_no']) {
|
|
$license = $row['license_plate_no'];
|
|
$license_id = (new ParkingLicensePlateService($this->logService))->createLicenseId($license);
|
|
if (!ParkingVipList::query()->where('license_id', $license_id)
|
|
->exists()
|
|
) {
|
|
$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');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|