停车场管理系统
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.2 KiB

<?php
namespace App\Imports;
use App\Models\ParkingVipList;
use App\Services\OperationLogService;
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();
}
/**
* @param array $row
* @return ParkingVipList
*/
public function model(array $row): ParkingVipList
{
foreach ($row as $license) {
if (!ParkingVipList::query()->where('license', $license)
->exists()
) {
$model = new ParkingVipList([
'license' => $license,
'user_id' => Auth::guard('sanctum')->user()['id'],
'created_at' => get_datetime()
]);
$this->logService->logCreated($model, '创建VIP名单');
return $model;
}
break;
}
return new ParkingVipList();
}
}