feat: add note module and route fixes
This commit is contained in:
@@ -42,6 +42,36 @@ abstract class BaseController
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户载荷。
|
||||
*
|
||||
* 说明:
|
||||
* - 登录态由路由中间件 `\app\api\middleware\Auth` 统一校验
|
||||
* - 控制器只负责读取中间件已经注入的用户信息
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getLoginPayload(): array
|
||||
{
|
||||
$payload = $this->request->middleware('payload', []);
|
||||
|
||||
if (empty($payload['userid'])) {
|
||||
throw new \RuntimeException('未登录', 401);
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户 ID。
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getLoginUserId(): int
|
||||
{
|
||||
return (int) $this->getLoginPayload()['userid'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功响应
|
||||
* @param mixed $data 返回数据
|
||||
|
||||
Reference in New Issue
Block a user