|
|
|
@ -8,6 +8,7 @@ use App\Models\Parking; |
|
|
|
use App\Models\ParkingSpace; |
|
|
|
use App\Models\ParkingSpaceAttributes; |
|
|
|
use App\Models\ParkingSpaceType; |
|
|
|
use App\Services\AdminTranslationService; |
|
|
|
use App\Services\OperationLogService; |
|
|
|
use App\Services\ParkingSpaceService; |
|
|
|
use Maatwebsite\Excel\Concerns\ToModel; |
|
|
|
@ -15,8 +16,9 @@ use Maatwebsite\Excel\Concerns\WithChunkReading; |
|
|
|
|
|
|
|
class ParkingSpaceImport implements ToModel, WithChunkReading |
|
|
|
{ |
|
|
|
protected int $index = 1; |
|
|
|
protected int $index = 0; |
|
|
|
protected int $user_id; |
|
|
|
protected array $error = []; |
|
|
|
|
|
|
|
public function __construct($admin_user_id) |
|
|
|
{ |
|
|
|
@ -25,32 +27,42 @@ class ParkingSpaceImport implements ToModel, WithChunkReading |
|
|
|
|
|
|
|
public function model(array $row) |
|
|
|
{ |
|
|
|
if ($this->index == 1) { |
|
|
|
if (!$this->index) { |
|
|
|
$this->index += 1; |
|
|
|
return; |
|
|
|
} |
|
|
|
$this->index += 1; |
|
|
|
$parking = $row[1]; |
|
|
|
$floor = $row[2]; |
|
|
|
$region = $row[3]; |
|
|
|
$attr = $row[4]; |
|
|
|
$number = $row[5]; |
|
|
|
if (empty($parking)) { |
|
|
|
$this->error[] = imports_error($this->index, 'import20'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (empty($floor)) { |
|
|
|
$this->error[] = imports_error($this->index, 'import21'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (empty($region)) { |
|
|
|
$this->error[] = imports_error($this->index, 'import22'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (empty($attr)) { |
|
|
|
$this->error[] = imports_error($this->index, 'import23'); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (empty($number)) { |
|
|
|
$this->error[] = imports_error($this->index, 'import15'); |
|
|
|
return; |
|
|
|
} |
|
|
|
$parking_id = Parking::getValueId($parking); |
|
|
|
if (!$parking_id) { |
|
|
|
$parking_id = AdminTranslationService::getTypeId(3, $parking); |
|
|
|
if (!$parking_id) { |
|
|
|
$this->error[] = imports_error($this->index, 'import24'); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
$floor_id = AdminFloor::query()->where('status', 1)->where( |
|
|
|
@ -61,15 +73,30 @@ class ParkingSpaceImport implements ToModel, WithChunkReading |
|
|
|
$parking_id |
|
|
|
)->value('id'); |
|
|
|
if (!$floor_id) { |
|
|
|
$floor_id = AdminTranslationService::getTypeId(4, $floor); |
|
|
|
if (!$floor_id) { |
|
|
|
$this->error[] = imports_error($this->index, 'import25'); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
$region_id = AdminFloorRegion::query()->where('status', 1)->where( |
|
|
|
'floor_id', |
|
|
|
$floor_id |
|
|
|
)->where('name', $region)->value('id'); |
|
|
|
if (!$region_id) { |
|
|
|
$region_id = AdminTranslationService::getTypeId(5, $region); |
|
|
|
if (!$region_id) { |
|
|
|
$this->error[] = imports_error($this->index, 'import26'); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
$attr_id = ParkingSpaceAttributes::query()->where('attributes', $attr) |
|
|
|
->value('id'); |
|
|
|
if (!$attr_id) { |
|
|
|
$attr_id = AdminTranslationService::getTypeId(2, $attr); |
|
|
|
if (!$attr_id) { |
|
|
|
$this->error[] = imports_error($this->index, 'import27'); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
@ -79,6 +106,7 @@ class ParkingSpaceImport implements ToModel, WithChunkReading |
|
|
|
'region_id' => $region_id |
|
|
|
]; |
|
|
|
if (ParkingSpace::query()->where($where)->exists()) { |
|
|
|
$this->error[] = imports_error($this->index, 'import28'); |
|
|
|
return; |
|
|
|
} |
|
|
|
$create['space_type_id'] = 0; |
|
|
|
@ -92,9 +120,13 @@ class ParkingSpaceImport implements ToModel, WithChunkReading |
|
|
|
$service->createData($create); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function chunkSize(): int |
|
|
|
{ |
|
|
|
return 1000; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析 |
|
|
|
} |
|
|
|
|
|
|
|
public function errorArr(): array |
|
|
|
{ |
|
|
|
return $this->error; |
|
|
|
} |
|
|
|
} |
|
|
|
|