[ 'id' => '事件ID', 'user_id' => '用户ID', 'user_name' => '用户名', 'node_id' => '节点ID', 'node_name' => '节点名', 'ip' => 'IP', 'location' => 'IP归属地', 'first_time' => '首次连接', 'last_time' => '最后连接', ], ]; /** * 后台在线 IP 页面 * * @throws Exception */ public function index(ServerRequest $request, Response $response, array $args): Response|ResponseInterface { return $response->write( $this->view() ->assign('details', self::$details) ->fetch('admin/log/online.tpl') ); } /** * 后台在线 IP 页面 AJAX * * @throws InvalidDatabaseException */ public function ajax(ServerRequest $request, Response $response, array $args): Response|ResponseInterface { $length = $request->getParam('length'); $page = $request->getParam('start') / $length + 1; $draw = $request->getParam('draw'); $onlines = OnlineLog::where('last_time', '>', time() - 90)->orderByDesc('last_time')->paginate($length, '*', '', $page); $total = OnlineLog::where('last_time', '>', time() - 90)->count(); foreach ($onlines as $online) { $online->user_name = $online->userName(); $online->node_name = $online->nodeName(); $online->ip = $online->ip(); $online->location = Tools::getIpLocation($online->ip); $online->first_time = Tools::toDateTime($online->first_time); $online->last_time = Tools::toDateTime($online->last_time); } return $response->withJson([ 'draw' => $draw, 'recordsTotal' => $total, 'recordsFiltered' => $total, 'onlines' => $onlines, ]); } }