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.
97 lines
2.5 KiB
97 lines
2.5 KiB
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use App\Models\AdminFloor;
|
|
use App\Models\AdminFloorRegion;
|
|
use App\Models\Parking;
|
|
use App\Models\ParkingSpace;
|
|
use App\Models\ParkingSpaceAttributes;
|
|
use App\Models\ParkingSpaceType;
|
|
use App\Services\OperationLogService;
|
|
use App\Services\ParkingSpaceService;
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
|
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
|
|
|
class ParkingSpaceImport 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;
|
|
}
|
|
$parking = $row[1];
|
|
$floor = $row[2];
|
|
$region = $row[3];
|
|
$attr = $row[4];
|
|
$number = $row[5];
|
|
if (empty($parking)) {
|
|
return;
|
|
}
|
|
if (empty($floor)) {
|
|
return;
|
|
}
|
|
if (empty($region)) {
|
|
return;
|
|
}
|
|
if (empty($attr)) {
|
|
return;
|
|
}
|
|
if (empty($number)) {
|
|
return;
|
|
}
|
|
$parking_id = Parking::getValueId($parking);
|
|
if (!$parking_id) {
|
|
return;
|
|
}
|
|
$floor_id = AdminFloor::query()->where('status', 1)->where(
|
|
'building_floor',
|
|
$parking_id
|
|
)->value('id');
|
|
if (!$floor_id) {
|
|
return;
|
|
}
|
|
$region_id = AdminFloorRegion::query()->where('status', 1)->where(
|
|
'floor_id',
|
|
$floor_id
|
|
)->value('id');
|
|
$attr_id = ParkingSpaceAttributes::query()->where('attributes', $attr)
|
|
->value('id');
|
|
if (!$attr_id) {
|
|
return;
|
|
}
|
|
|
|
$create = $where = [
|
|
'number' => $number,
|
|
'floor_id' => $floor_id,
|
|
'region_id' => $region_id
|
|
];
|
|
if (ParkingSpace::query()->where($where)->exists()) {
|
|
return;
|
|
}
|
|
$create['space_type_id'] = 0;
|
|
$res = ParkingSpaceType::getDefaultData();
|
|
if ($res) {
|
|
$create['space_type_id'] = $res['id'];
|
|
}
|
|
$create['space_attr_id'] = $attr_id;
|
|
|
|
$service = new ParkingSpaceService(new OperationLogService());
|
|
$service->createData($create);
|
|
}
|
|
|
|
|
|
public function chunkSize(): int
|
|
{
|
|
return 1000; // 设置每次处理的行数,有助于避免内存问题并可能改善表头解析
|
|
}
|
|
}
|
|
|