checkAuthentication(); // 写操作日志 $this->writeOperationLog(); // 在调用前进行处理 return $proceedingJoinPoint->process(); } /** * @return void */ private function checkAuthentication(): void { $adminId = Context::get('admin_id'); $roleId = Context::get('role_id'); //如果没有id 说明没有登录 抛出异常 if (empty($adminId) || empty($roleId)) { throw new AdminException('请先登录'); } //超级管理员不需要鉴权 if ($roleId == 1) return; //todo 其他角色需要鉴权 } /** * 写入请求日志 * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ private function writeOperationLog(): void { $post = $this->request->all(); $logParam = !$post ? '{}' : json_encode($post); $userId = Context::get('user_id',0); $header = json_encode($this->request->getHeaders()); // 写静态日志 $this->log->requestAdminLog("\nadmin==path:{$this->request->getPathInfo()}\nuserId:$userId\nrequestData:$logParam\nheader:$header"); } }