service = $service; } /** * 查询楼层 * @param Request $request * @return JsonResponse */ public function floorList(Request $request): JsonResponse { try { $building_floor = $request->get('building_floor', '1'); $data = [ 'floor_list' => AdminFloorService::getSelectList($building_floor) ]; return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } /** * 楼层栋 * @return JsonResponse */ public function buildingFloorList(): JsonResponse { try { $data = [ 'building_floor_list' => get_select_data( AdminFloorService::getBuildingFloor() ) ]; 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(); $saveData = $data['saveData'] ?? []; if (empty($saveData)) { throw new Exception(__('validation.map.d_empty')); } foreach ($saveData as $item) { $this->saveValidator($item, 1); $this->service->saveModel($item); } 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() ); } } }