|
|
@ -11,8 +11,9 @@ use Maatwebsite\Excel\Concerns\WithChunkReading; |
|
|
|
|
|
|
|
|
class ParkingSpaceRepairImport implements ToModel, WithChunkReading |
|
|
class ParkingSpaceRepairImport implements ToModel, WithChunkReading |
|
|
{ |
|
|
{ |
|
|
protected int $index = 1; |
|
|
protected int $index = 0; |
|
|
protected int $user_id; |
|
|
protected int $user_id; |
|
|
|
|
|
protected array $error = []; |
|
|
|
|
|
|
|
|
public function __construct($admin_user_id) |
|
|
public function __construct($admin_user_id) |
|
|
{ |
|
|
{ |
|
|
@ -21,37 +22,53 @@ class ParkingSpaceRepairImport implements ToModel, WithChunkReading |
|
|
|
|
|
|
|
|
public function model(array $row) |
|
|
public function model(array $row) |
|
|
{ |
|
|
{ |
|
|
if ($this->index == 1) { |
|
|
if (!$this->index) { |
|
|
$this->index += 1; |
|
|
$this->index += 1; |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
$space_number = $row[1]; |
|
|
$this->index += 1; |
|
|
|
|
|
$space_number = $row[1] ?? ''; |
|
|
if (empty($space_number)) { |
|
|
if (empty($space_number)) { |
|
|
|
|
|
$this->error[] = imports_error($this->index, 'import15'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
$floor_name = $row[2]; |
|
|
$floor_name = $row[2] ?? ''; |
|
|
if (empty($floor_name)) { |
|
|
if (empty($floor_name)) { |
|
|
|
|
|
$this->error[] = imports_error($this->index, 'import21'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
$parking_name = $row[3]; |
|
|
$parking_name = $row[3] ?? ''; |
|
|
if (empty($parking_name)) { |
|
|
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; |
|
|
return; |
|
|
} |
|
|
} |
|
|
$start_at = $row[4]; |
|
|
|
|
|
$start_times = strtotime($start_at); |
|
|
$start_times = strtotime($start_at); |
|
|
if (empty($start_at) || !$start_times) { |
|
|
if (!$start_times) { |
|
|
|
|
|
$this->error[] = imports_error($this->index, 'import30'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
$end_at = $row[5]; |
|
|
$end_at = $row[5] ?? ''; |
|
|
$end_times = strtotime($end_at); |
|
|
$end_times = strtotime($end_at); |
|
|
if (empty($end_at) || !$end_times) { |
|
|
if (empty($end_at)) { |
|
|
|
|
|
$this->error[] = imports_error($this->index, 'import31'); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (empty(!$end_times)) { |
|
|
|
|
|
$this->error[] = imports_error($this->index, 'import32'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
if ($start_times >= $end_times) { |
|
|
if ($start_times >= $end_times) { |
|
|
|
|
|
$this->error[] = imports_error($this->index, 'import13'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
$space_id = ParkingSpace::getValueId($space_number); |
|
|
$space_id = ParkingSpace::getValueId($space_number); |
|
|
if (empty($space_id)) { |
|
|
if (empty($space_id)) { |
|
|
|
|
|
$this->error[] = imports_error($this->index, 'import17'); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -68,4 +85,9 @@ class ParkingSpaceRepairImport implements ToModel, WithChunkReading |
|
|
{ |
|
|
{ |
|
|
return 1000; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析 |
|
|
return 1000; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function errorArr(): array |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->error; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|