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 返回数据
|
||||
|
||||
@@ -117,12 +117,9 @@ class Auth extends BaseController
|
||||
public function me()
|
||||
{
|
||||
try {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
$userid = $this->getLoginUserId();
|
||||
|
||||
$result = $this->authService->getUserInfo($payload['userid']);
|
||||
$result = $this->authService->getUserInfo($userid);
|
||||
|
||||
return Response::success($result);
|
||||
} catch (\Exception $e) {
|
||||
@@ -146,10 +143,7 @@ class Auth extends BaseController
|
||||
public function password()
|
||||
{
|
||||
try {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
$userid = $this->getLoginUserId();
|
||||
|
||||
$data = $this->request->post();
|
||||
|
||||
@@ -164,7 +158,7 @@ class Auth extends BaseController
|
||||
])->check($data);
|
||||
|
||||
$this->authService->changePassword(
|
||||
$payload['userid'],
|
||||
$userid,
|
||||
$data['old_password'],
|
||||
$data['new_password']
|
||||
);
|
||||
|
||||
@@ -40,10 +40,7 @@ class Platform extends BaseController
|
||||
public function accounts()
|
||||
{
|
||||
try {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload || empty($payload['userid'])) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
$userid = $this->getLoginUserId();
|
||||
|
||||
$platformInput = $this->request->get('platform');
|
||||
$platform = null;
|
||||
@@ -56,7 +53,7 @@ class Platform extends BaseController
|
||||
$platform = (int) $platformInput;
|
||||
}
|
||||
|
||||
$result = $this->platformService->getAccountList((int) $payload['userid'], $platform);
|
||||
$result = $this->platformService->getAccountList($userid, $platform);
|
||||
|
||||
return Response::success($result);
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
@@ -45,12 +45,9 @@ class PublishPlan extends BaseController
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload || empty($payload['userid'])) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
$userid = $this->getLoginUserId();
|
||||
|
||||
$result = $this->publishPlanService->getPlanList((int) $payload['userid'], [
|
||||
$result = $this->publishPlanService->getPlanList($userid, [
|
||||
'status' => (string) $this->request->get('status', 'all'),
|
||||
'page' => (int) $this->request->get('page', 1),
|
||||
'page_size' => (int) $this->request->get('page_size', 20),
|
||||
@@ -74,12 +71,9 @@ class PublishPlan extends BaseController
|
||||
public function start(int $id)
|
||||
{
|
||||
try {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload || empty($payload['userid'])) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
$userid = $this->getLoginUserId();
|
||||
|
||||
$result = $this->publishPlanService->startPlan((int) $payload['userid'], $id);
|
||||
$result = $this->publishPlanService->startPlan($userid, $id);
|
||||
|
||||
return Response::success($result, '设置成功');
|
||||
} catch (\Exception $exception) {
|
||||
@@ -100,12 +94,9 @@ class PublishPlan extends BaseController
|
||||
public function stop(int $id)
|
||||
{
|
||||
try {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload || empty($payload['userid'])) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
$userid = $this->getLoginUserId();
|
||||
|
||||
$result = $this->publishPlanService->stopPlan((int) $payload['userid'], $id);
|
||||
$result = $this->publishPlanService->stopPlan($userid, $id);
|
||||
|
||||
return Response::success($result, '设置成功');
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
@@ -46,12 +46,9 @@ class VideoWork extends BaseController
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$payload = $this->request->payload ?? null;
|
||||
if (!$payload || empty($payload['userid'])) {
|
||||
return Response::error('未登录', 401);
|
||||
}
|
||||
$userid = $this->getLoginUserId();
|
||||
|
||||
$result = $this->videoWorkService->getVideoList((int) $payload['userid'], [
|
||||
$result = $this->videoWorkService->getVideoList($userid, [
|
||||
'platform' => $this->request->get('platform', 'all'),
|
||||
'vuid' => $this->request->get('vuid', 'all'),
|
||||
'page' => (int) $this->request->get('page', 1),
|
||||
|
||||
Reference in New Issue
Block a user