responseService = $responseService; } public function search(): JsonResponse { try { $data = [ 'type_data' => get_select_data( AdminOperationLog::getActionArr(), true ) ]; return $this->responseService->success($data); } catch (Exception $e) { $m_prefix = __('exception.exception_handler.resource'); return $this->responseService->systemError( $m_prefix . ':' . $e->getMessage() ); } } /** * @param Request $request * @return JsonResponse */ public function index(Request $request): JsonResponse { try { $query = AdminOperationLog::query(); // 关键词搜索 if ($request->has('type')) { $type = $request->input('type'); $query->where('action', '=', $type); } if ($request->has('name')) { $name = $request->input('name'); $user_id = AdminUsers::query()->where('name', $name)->value( 'id' ); $user_id = $user_id ?: 0; $query->where('user_id', '=', $user_id); } if ($request->has('start_time')) { $start_time = $request->input('start_time'); $query->where('created_at', '>=', $start_time); } if ($request->has('end_time')) { $end_time = $request->input('end_time'); $query->where('created_at', '<=', $end_time); } // 分页 $page = $request->input('page', 1); $perPage = $request->input('per_page', 10); $total = $query->count(); $items = $query->latest()->forPage($page, $perPage)->get()->each( function ($item) { $actionArr = AdminOperationLog::getActionArr(); $item['operation_name'] = $item->user->value('name'); $item['action'] = $actionArr[$item['action']]; unset($item['user']); return $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() ); } } }