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.
93 lines
2.8 KiB
93 lines
2.8 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 = 0;
|
|
protected int $user_id;
|
|
protected array $error = [];
|
|
|
|
public function __construct($admin_user_id)
|
|
{
|
|
$this->user_id = $admin_user_id;
|
|
}
|
|
|
|
public function model(array $row)
|
|
{
|
|
if (!$this->index) {
|
|
$this->index += 1;
|
|
return;
|
|
}
|
|
$this->index += 1;
|
|
$space_number = $row[1] ?? '';
|
|
if (empty($space_number)) {
|
|
$this->error[] = imports_error($this->index, 'import15');
|
|
return;
|
|
}
|
|
$floor_name = $row[2] ?? '';
|
|
if (empty($floor_name)) {
|
|
$this->error[] = imports_error($this->index, 'import21');
|
|
return;
|
|
}
|
|
$parking_name = $row[3] ?? '';
|
|
if (empty($parking_name)) {
|
|
$this->error[] = imports_error($this->index, 'import20');
|
|
return;
|
|
}
|
|
$start_at = $row[4] ?? '';
|
|
if (empty($start_at)) {
|
|
$this->error[] = imports_error($this->index, 'import29');
|
|
return;
|
|
}
|
|
$start_times = strtotime($start_at);
|
|
if (!$start_times) {
|
|
$this->error[] = imports_error($this->index, 'import30');
|
|
return;
|
|
}
|
|
$end_at = $row[5] ?? '';
|
|
$end_times = strtotime($end_at);
|
|
if (empty($end_at)) {
|
|
$this->error[] = imports_error($this->index, 'import31');
|
|
return;
|
|
}
|
|
if (empty(!$end_times)) {
|
|
$this->error[] = imports_error($this->index, 'import32');
|
|
return;
|
|
}
|
|
if ($start_times >= $end_times) {
|
|
$this->error[] = imports_error($this->index, 'import13');
|
|
return;
|
|
}
|
|
$space_id = ParkingSpace::getValueId($space_number);
|
|
if (empty($space_id)) {
|
|
$this->error[] = imports_error($this->index, 'import17');
|
|
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; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析
|
|
}
|
|
|
|
public function errorArr(): array
|
|
{
|
|
return $this->error;
|
|
}
|
|
}
|
|
|