model = new LogModel(); } /** * 查看 * * @return Response */ public function index() { if (!$this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $logs = $this->model ->with(['agent']) ->where($where) ->order($sort, $order) ->paginate($limit); $morphs = [ 'user' => UserModel::class, 'admin' => AdminModel::class, 'system' => AdminModel::class ]; $logs = morph_to($logs, $morphs, ['oper_type', 'oper_id']); $logsArray = $logs->toArray(); // 格式化操作人信息 foreach ($logsArray['data'] as &$log) { $log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null); } $result = ['total' => $logsArray['total'], 'rows' => $logsArray['data']]; return json($result); } }