|
|
|
@ -3,7 +3,11 @@ |
|
|
|
namespace App\Imports; |
|
|
|
|
|
|
|
use App\Models\ParkingLicensePlate; |
|
|
|
use App\Models\ParkingSpaceType; |
|
|
|
use App\Services\ApiResponseService; |
|
|
|
use App\Services\OperationLogService; |
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Maatwebsite\Excel\Concerns\ToModel; |
|
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow; |
|
|
|
|
|
|
|
@ -23,17 +27,31 @@ class ParkingLicensePlateImport implements ToModel, WithHeadingRow |
|
|
|
|
|
|
|
/** |
|
|
|
* @param array $row |
|
|
|
* @return ParkingLicensePlate |
|
|
|
* @return ParkingLicensePlate|JsonResponse |
|
|
|
*/ |
|
|
|
public function model(array $row): ParkingLicensePlate |
|
|
|
public function model(array $row): ParkingLicensePlate|JsonResponse |
|
|
|
{ |
|
|
|
$request = new Request(); |
|
|
|
$parking_space_type = $request->post('parking_space_type', ''); |
|
|
|
if (empty($parking_space_type)) { |
|
|
|
return (new ApiResponseService())->businessError( |
|
|
|
__('validation.parking_space.type_id_empty') |
|
|
|
); |
|
|
|
} |
|
|
|
if (!ParkingSpaceType::query()->where('id', $parking_space_type) |
|
|
|
->exists() |
|
|
|
) { |
|
|
|
return (new ApiResponseService())->businessError( |
|
|
|
__('exception.exception_handler.resource') |
|
|
|
); |
|
|
|
} |
|
|
|
$data = []; |
|
|
|
foreach ($row as $value) { |
|
|
|
$data[] = $value; |
|
|
|
} |
|
|
|
$where = [ |
|
|
|
'number' => $data[0], |
|
|
|
'space_type_id' => $data[1] |
|
|
|
'space_type_id' => $parking_space_type |
|
|
|
]; |
|
|
|
if (!ParkingLicensePlate::query()->where($where) |
|
|
|
->exists() |
|
|
|
|