service = $service; } public function index(Request $request): JsonResponse { try { $query = ParkingAlarmInformation::query(); if ($request->has('keyword')) { $keyword = $request->input('keyword'); if ($keyword) { $query->where(function ($q) use ($keyword) { $q->orWhere('name', $keyword); $q->orWhere('condition', $keyword); $q->orWhere('content', $keyword); $q->orWhere('remark', $keyword); }); } } if ($request->has('type')) { $type = $request->input('type'); if ($type) { $query->where('type', $type); } } if ($request->has('notice_type')) { $notice_type = $request->input('notice_type'); if ($notice_type) { $query->where('notice_type', $notice_type); } } if ($request->has('level')) { $level = $request->input('level'); if ($level) { $query->where('level', $level); } } // 分页 $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); $total = $query->count(); $query->orderBy('id'); $items = $query->latest()->forPage($page, $perPage)->select() ->get()->each(function ($item) { return $this->service->getItem($item); }); return $this->responseService->success([ 'items' => $items, 'total' => $total, 'page' => $page, 'per_page' => $perPage, 'last_page' => ceil($total / $perPage), ]); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function show(string $id): JsonResponse { try { $data = ParkingAlarmInformation::query()->find($id)->toArray(); $data = $this->service->getItem($data); return $this->responseService->success($data); } catch (Exception $e) { return $this->responseService->systemError( __('exception.get_data_failed') . ':' . $e->getMessage() ); } } public function search(): JsonResponse { try { $data = [ 'type_list' => get_select_data( $this->service->getTypeArr() ), 'notice_type_list' => get_select_data( $this->service->getNoticeTypeArr() ), 'level_list' => get_select_data( $this->service->getLevelArr() ), 'handler_user_list' => get_select_data( $this->service->getHandlerUserArr() ) ]; return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } public function allocation(Request $request): JsonResponse { try { $data = $request->all(); $this->validateId($data['id'] ?? 0, ParkingAlarmInformation::class); $this->service->allocation( $data['id'], $data['handler_user'] ); return $this->responseService->success( null, __('admin.operation_successful') ); } catch (ValidationException|CustomException $e) { throw $e; } catch (Exception $e) { return $this->responseService->systemError( __('admin.operation_failed') . ':' . $e->getMessage() ); } } public function editRemark(Request $request): JsonResponse { try { $data = $request->all(); $this->validateId($data['id'] ?? 0, ParkingAlarmInformation::class); $this->service->editRemark( $data['id'], $data['remark'] ?? '' ); return $this->responseService->success( null, __('admin.operation_successful') ); } catch (ValidationException|CustomException $e) { throw $e; } catch (Exception $e) { return $this->responseService->systemError( __('admin.operation_failed') . ':' . $e->getMessage() ); } } }