app = $app; $this->request = $app->request; } protected function validate(array $data, $validate, array $message = [], bool $batch = false): array { if (is_array($validate)) { $validator = new Validate(); $validator->rule($validate); } else { $validator = new $validate(); } $validator->message($message)->batch($batch); if (!$validator->check($data)) { throw new ValidateException($validator->getError()); } return $data; } protected function getCurrentSmtUserId(): int { $userId = (int) $this->request->middleware('smt_user_id', 0); if ($userId <= 0) { throw new \RuntimeException('未登录或登录已过期', 401); } return $userId; } protected function getCurrentSmtUser(): array { $user = $this->request->middleware('smt_user', []); if (!is_array($user) || empty($user['id'])) { throw new \RuntimeException('未登录或登录已过期', 401); } return $user; } }