|
|
@ -2,14 +2,17 @@ |
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin; |
|
|
namespace App\Http\Controllers\Admin; |
|
|
|
|
|
|
|
|
|
|
|
use App\Exceptions\CustomException; |
|
|
use App\Exports\ParkingSpaceExport; |
|
|
use App\Exports\ParkingSpaceExport; |
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
|
use App\Models\AdminFloor; |
|
|
use App\Models\AdminFloor; |
|
|
|
|
|
use App\Models\AdminFloorRegion; |
|
|
|
|
|
use App\Models\Parking; |
|
|
use App\Models\ParkingLicensePlate; |
|
|
use App\Models\ParkingLicensePlate; |
|
|
use App\Models\ParkingPatternSpace; |
|
|
use App\Models\ParkingPatternSpace; |
|
|
use App\Models\ParkingSpace; |
|
|
use App\Models\ParkingSpace; |
|
|
use App\Models\ParkingSpaceAttributes; |
|
|
use App\Models\ParkingSpaceAttributes; |
|
|
use App\Models\ParkingSpaceType; |
|
|
use App\Models\ParkingSpaceType; |
|
|
|
|
|
use App\Services\AdminFloorService; |
|
|
use App\Services\ApiResponseService; |
|
|
use App\Services\ApiResponseService; |
|
|
use App\Services\EventCalendarService; |
|
|
use App\Services\EventCalendarService; |
|
|
use App\Services\ParkingSpaceService; |
|
|
use App\Services\ParkingSpaceService; |
|
|
@ -361,50 +364,211 @@ class ParkingSpaceController extends BaseController |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @return JsonResponse |
|
|
|
|
|
*/ |
|
|
|
|
|
public function create(): JsonResponse |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$data = [ |
|
|
|
|
|
'parking_list' => Parking::getData(), |
|
|
|
|
|
'space_attr_list' => ParkingSpaceAttributes::getData() |
|
|
|
|
|
]; |
|
|
|
|
|
return $this->responseService->success($data); |
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
return $this->responseService->systemError( |
|
|
|
|
|
__('exception.get_data_failed') . ':' . $e->getMessage() |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param Request $request |
|
|
|
|
|
* @return JsonResponse |
|
|
|
|
|
* @throws CustomException |
|
|
|
|
|
* @throws ValidationException |
|
|
|
|
|
*/ |
|
|
public function store(Request $request): JsonResponse |
|
|
public function store(Request $request): JsonResponse |
|
|
{ |
|
|
{ |
|
|
$data = $request->all(); |
|
|
try { |
|
|
if (ParkingSpace::query()->where('number', $data['number']) |
|
|
$this->saveValidator($request->all()); |
|
|
->exists() |
|
|
$this->service->createModel($request->all()); |
|
|
) { |
|
|
return $this->responseService->success( |
|
|
return $this->responseService->systemError('车位号码已存在'); |
|
|
null, |
|
|
|
|
|
__('admin.save_succeeded') |
|
|
|
|
|
); |
|
|
|
|
|
} catch (ValidationException|CustomException $e) { |
|
|
|
|
|
throw $e; |
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
return $this->responseService->systemError( |
|
|
|
|
|
__('admin.operation_failed') . ':' |
|
|
|
|
|
. $e->getMessage() |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
$floor_id = AdminFloor::query()->where('name', $data['floor_name']) |
|
|
} |
|
|
->value('id'); |
|
|
|
|
|
if (!$floor_id) { |
|
|
/** |
|
|
return $this->responseService->systemError('楼层不存在'); |
|
|
* @param array $data |
|
|
|
|
|
* @param int $id |
|
|
|
|
|
* @return void |
|
|
|
|
|
* @throws ValidationException |
|
|
|
|
|
*/ |
|
|
|
|
|
protected function saveValidator(array $data, int $id = 0): void |
|
|
|
|
|
{ |
|
|
|
|
|
$rules = [ |
|
|
|
|
|
'parking_id' => 'required', |
|
|
|
|
|
'floor_id' => 'required', |
|
|
|
|
|
'region_id' => 'required', |
|
|
|
|
|
'space_attr_id' => 'required', |
|
|
|
|
|
'number' => 'required' |
|
|
|
|
|
]; |
|
|
|
|
|
$messages = [ |
|
|
|
|
|
'parking_id.required' => __validation('parking_space.pi_empty'), |
|
|
|
|
|
'floor_id.required' => __validation('parking_space.fi_empty'), |
|
|
|
|
|
'region_id.required' => __validation('parking_space.ri_empty'), |
|
|
|
|
|
'space_attr_id.required' => __validation('parking_space.a_empty'), |
|
|
|
|
|
'number.required' => __validation('parking_space.n_empty') |
|
|
|
|
|
]; |
|
|
|
|
|
if ($id) { |
|
|
|
|
|
$this->validateId($id, ParkingSpace::class); |
|
|
} |
|
|
} |
|
|
$space_attr_id = ParkingSpaceAttributes::query()->where( |
|
|
$validator = Validator::make($data, $rules, $messages); |
|
|
'attributes', |
|
|
|
|
|
$data['attr_name'] |
|
|
if ($validator->fails()) { |
|
|
)->value('id'); |
|
|
throw new ValidationException($validator); |
|
|
if (!$space_attr_id) { |
|
|
|
|
|
return $this->responseService->systemError('车位属性不存在'); |
|
|
|
|
|
} |
|
|
} |
|
|
$space_type_id = ParkingSpaceType::getValueId($data['type_name']); |
|
|
} |
|
|
if (!$space_type_id) { |
|
|
|
|
|
return $this->responseService->systemError('车位类型不存在'); |
|
|
/** |
|
|
|
|
|
* @param string $id |
|
|
|
|
|
* @return JsonResponse |
|
|
|
|
|
*/ |
|
|
|
|
|
public function edit(string $id): JsonResponse |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$this->validateId($id, ParkingSpace::class); |
|
|
|
|
|
$item = ParkingSpace::query()->find($id, [ |
|
|
|
|
|
'id', |
|
|
|
|
|
'floor_id', |
|
|
|
|
|
'number', |
|
|
|
|
|
'region_id', |
|
|
|
|
|
'space_attr_id' |
|
|
|
|
|
]); |
|
|
|
|
|
$item['parking_id'] = AdminFloor::query()->where( |
|
|
|
|
|
'id', |
|
|
|
|
|
$item['floor_id'] |
|
|
|
|
|
)->value('building_floor'); |
|
|
|
|
|
$data = [ |
|
|
|
|
|
'parking_list' => Parking::getData(), |
|
|
|
|
|
'floor_list' => AdminFloorService::getSelectList( |
|
|
|
|
|
$item['parking_id'], |
|
|
|
|
|
[ |
|
|
|
|
|
'id as floor_id', |
|
|
|
|
|
'name as floor_name' |
|
|
|
|
|
] |
|
|
|
|
|
), |
|
|
|
|
|
'floor_region_list' => AdminFloorRegion::getFloorRegion( |
|
|
|
|
|
$item['floor_id'] |
|
|
|
|
|
), |
|
|
|
|
|
'space_attr_list' => ParkingSpaceAttributes::getData(), |
|
|
|
|
|
'item' => $item |
|
|
|
|
|
]; |
|
|
|
|
|
return $this->responseService->success($data); |
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
return $this->responseService->systemError( |
|
|
|
|
|
__('exception.get_data_failed') . ':' . $e->getMessage() |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param Request $request |
|
|
|
|
|
* @param string $id |
|
|
|
|
|
* @return JsonResponse |
|
|
|
|
|
* @throws ValidationException |
|
|
|
|
|
*/ |
|
|
|
|
|
public function update(Request $request, string $id): JsonResponse |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$this->saveValidator($request->all(), $id); |
|
|
|
|
|
$this->service->updateModel($request->all(), $id); |
|
|
|
|
|
return $this->responseService->success( |
|
|
|
|
|
null, |
|
|
|
|
|
__('admin.update_succeeded') |
|
|
|
|
|
); |
|
|
|
|
|
} catch (ValidationException $e) { |
|
|
|
|
|
throw $e; |
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
return $this->responseService->systemError( |
|
|
|
|
|
__('admin.operation_failed') . ':' |
|
|
|
|
|
. $e->getMessage() |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
$license_plate_id = 0; |
|
|
} |
|
|
$status = 0; |
|
|
|
|
|
if (isset($data['license_plate'])) { |
|
|
/** |
|
|
$license_plate_id = ParkingLicensePlate::getValueId( |
|
|
* @param string $id |
|
|
$data['license_plate'] |
|
|
* @return JsonResponse |
|
|
|
|
|
* @throws ValidationException |
|
|
|
|
|
*/ |
|
|
|
|
|
public function destroy(string $id): JsonResponse |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$this->validateId($id, ParkingSpace::class); |
|
|
|
|
|
$this->service->deleteModel($id); |
|
|
|
|
|
return $this->responseService->success( |
|
|
|
|
|
null, |
|
|
|
|
|
__('admin.delete_succeeded') |
|
|
|
|
|
); |
|
|
|
|
|
} catch (ValidationException $e) { |
|
|
|
|
|
throw $e; |
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
return $this->responseService->systemError( |
|
|
|
|
|
__('admin.operation_failed') . ':' |
|
|
|
|
|
. $e->getMessage() |
|
|
); |
|
|
); |
|
|
if ($license_plate_id) { |
|
|
} |
|
|
$status = 1; |
|
|
} |
|
|
} else { |
|
|
|
|
|
return $this->responseService->systemError('车牌号码不存在'); |
|
|
/** |
|
|
|
|
|
* @param Request $request |
|
|
|
|
|
* @return JsonResponse |
|
|
|
|
|
* @throws CustomException |
|
|
|
|
|
* @throws ValidationException |
|
|
|
|
|
*/ |
|
|
|
|
|
public function batchDelete(Request $request): JsonResponse |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$data = $request->all(); |
|
|
|
|
|
$rules = [ |
|
|
|
|
|
'ids' => 'required|array', |
|
|
|
|
|
]; |
|
|
|
|
|
$messages = [ |
|
|
|
|
|
'ids.required' => __validation( |
|
|
|
|
|
'parking_repair_list.ids_empty' |
|
|
|
|
|
), |
|
|
|
|
|
'ids.array' => __validation( |
|
|
|
|
|
'parking_repair_list.ids_array' |
|
|
|
|
|
), |
|
|
|
|
|
]; |
|
|
|
|
|
$validator = Validator::make($data, $rules, $messages); |
|
|
|
|
|
|
|
|
|
|
|
if ($validator->fails()) { |
|
|
|
|
|
throw new ValidationException($validator); |
|
|
} |
|
|
} |
|
|
|
|
|
$ids = $data['ids']; |
|
|
|
|
|
$this->service->batchDeleteModel($ids); |
|
|
|
|
|
return $this->responseService->success( |
|
|
|
|
|
null, |
|
|
|
|
|
__('admin.delete_succeeded') |
|
|
|
|
|
); |
|
|
|
|
|
} catch (ValidationException|CustomException $e) { |
|
|
|
|
|
throw $e; |
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
return $this->responseService->systemError( |
|
|
|
|
|
__('admin.operation_failed') . ':' |
|
|
|
|
|
. $e->getMessage() |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
$this->service->createData([ |
|
|
|
|
|
'floor_id' => $floor_id, |
|
|
|
|
|
'number' => $data['number'], |
|
|
|
|
|
'space_attr_id' => $space_attr_id, |
|
|
|
|
|
'space_type_id' => $space_type_id, |
|
|
|
|
|
'license_plate_id' => $license_plate_id, |
|
|
|
|
|
'status' => $status |
|
|
|
|
|
]); |
|
|
|
|
|
return $this->responseService->success('', __('admin.operation_successful')); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|