response = $response; } /** * 是否需要登录 * @return bool */ public function needLogin(): bool { return $this->need_login; } /** * 处理请求 * @param Message $data * @return Message */ abstract public function handle(Message $data): Message; /** * 更新用户活动时间 * 在需要登录的Handler中调用此方法来更新用户活动时间 * * @return void */ protected function updateUserActivityTime(): void { try { if ($this->needLogin() && $this->user_id > 0) { UserActivityService::updateActivityTime($this->user_id); Log::debug('用户活动时间已更新', [ 'user_id' => $this->user_id, 'handler' => static::class ]); } } catch (\Exception $e) { Log::error('更新用户活动时间失败', [ 'user_id' => $this->user_id, 'handler' => static::class, 'error' => $e->getMessage() ]); } } }