service = $service; } /** * 查询楼层 * @return JsonResponse */ public function floorList(): JsonResponse { try { $data = [ 'floor_list' => AdminFloorService::getSelectList() ]; return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } /** * 查询车位号码 * @param $id * @return JsonResponse */ public function getParkingSpaceList($id): JsonResponse { try { $this->saveValidator(['floor_id' => $id]); $list = ParkingSpaceService::getSelectList($id); $data = [ 'parking_space_list' => $list ]; return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } /** * @param array $data * @param int $is_save * @return void * @throws ValidationException */ protected function saveValidator(array $data, int $is_save = 0): void { $rules = [ 'floor_id' => 'required|numeric', ]; $messages = [ 'floor_id.required' => __('validation.map.f_empty'), 'floor_id.numeric' => __('validation.map.f_number') ]; if ($is_save) { $rules['parking_space_id'] = 'required|numeric'; $messages['parking_space_id.required'] = __('validation.map.p_empty'); $messages['parking_space_id.numeric'] = __('validation.map.p_number'); } $validator = Validator::make($data, $rules, $messages); if ($validator->fails()) { throw new ValidationException($validator); } } public function save(Request $request): JsonResponse { try { $data = $request->all(); $this->saveValidator($data, 1); $this->service->saveModel($data); return $this->responseService->success([], __('admin.save_succeeded')); } catch (Exception $e) { $m_prefix = __('admin.save_failed'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function index(Request $request): JsonResponse { try { $data = $request->all(); $this->saveValidator($data); $list = $this->service->getList($data); return $this->responseService->success($list); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } }