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

71 lines
1.9 KiB

<?php
namespace App\Imports;
use App\Models\Parking;
use App\Models\ParkingSpace;
use App\Services\OperationLogService;
use App\Services\ParkingSpaceRepairService;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithChunkReading;
class ParkingSpaceRepairImport implements ToModel, WithChunkReading
{
protected int $index = 1;
protected int $user_id;
public function __construct($admin_user_id)
{
$this->user_id = $admin_user_id;
}
public function model(array $row)
{
if ($this->index == 1) {
$this->index += 1;
return;
}
$space_number = $row[1];
if (empty($space_number)) {
return;
}
$floor_name = $row[2];
if (empty($floor_name)) {
return;
}
$parking_name = $row[3];
if (empty($parking_name)) {
return;
}
$start_at = $row[4];
$start_times = strtotime($start_at);
if (empty($start_at) || !$start_times) {
return;
}
$end_at = $row[5];
$end_times = strtotime($end_at);
if (empty($end_at) || !$end_times) {
return;
}
if ($start_times >= $end_times) {
return;
}
$space_id = ParkingSpace::getValueId($space_number);
if (empty($space_id)) {
return;
}
$service = new ParkingSpaceRepairService(new OperationLogService());
$service->createModel([
'admin_user_id' => $this->user_id,
'parking_space_name' => $space_number,
'start_at' => date("Y-m-d H:i:s", $start_times),
'end_at' => date("Y-m-d H:i:s", $end_times)
]);
}
public function chunkSize(): int
{
return 1000; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析
}
}