统一规范状态码
This commit is contained in:
@@ -7,6 +7,7 @@ use support\Request;
|
||||
use support\Response;
|
||||
use app\api\cache\UserCache;
|
||||
use app\api\logic\UserLogic;
|
||||
use app\api\util\ReturnCode;
|
||||
use plugin\saiadmin\basic\OpenController;
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,7 @@ class UserController extends OpenController
|
||||
$phone = $request->post('phone', '');
|
||||
$password = $request->post('password', '');
|
||||
if ($phone === '' || $password === '') {
|
||||
return $this->fail('请填写手机号和密码');
|
||||
return $this->fail('请填写手机号和密码', ReturnCode::EMPTY_PARAMS);
|
||||
}
|
||||
$logic = new UserLogic();
|
||||
$data = $logic->login($phone, $password);
|
||||
@@ -47,7 +48,7 @@ class UserController extends OpenController
|
||||
$password = $request->post('password', '');
|
||||
$nickname = $request->post('nickname');
|
||||
if ($phone === '' || $password === '') {
|
||||
return $this->fail('请填写手机号和密码');
|
||||
return $this->fail('请填写手机号和密码', ReturnCode::EMPTY_PARAMS);
|
||||
}
|
||||
$logic = new UserLogic();
|
||||
$data = $logic->register($phone, $password, $nickname ? (string) $nickname : null);
|
||||
@@ -74,12 +75,12 @@ class UserController extends OpenController
|
||||
}
|
||||
}
|
||||
if (empty($token)) {
|
||||
return $this->fail('请携带 user-token');
|
||||
return $this->fail('请携带 user-token', ReturnCode::MISSING_TOKEN);
|
||||
}
|
||||
if (UserLogic::logout($token)) {
|
||||
return $this->success('已退出登录');
|
||||
}
|
||||
return $this->fail('退出失败或 token 已失效');
|
||||
return $this->fail('退出失败或 token 已失效', ReturnCode::TOKEN_TIMEOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,15 +99,15 @@ class UserController extends OpenController
|
||||
}
|
||||
}
|
||||
if (empty($token)) {
|
||||
return $this->fail('请携带 user-token');
|
||||
return $this->fail('请携带 user-token', ReturnCode::MISSING_TOKEN);
|
||||
}
|
||||
$userId = UserLogic::getUserIdFromToken($token);
|
||||
if ($userId === null) {
|
||||
return $this->fail('user-token 无效或已过期');
|
||||
return $this->fail('user-token 无效或已过期', ReturnCode::TOKEN_TIMEOUT);
|
||||
}
|
||||
$user = UserLogic::getCachedUser($userId);
|
||||
if (empty($user)) {
|
||||
return $this->fail('用户不存在');
|
||||
return $this->fail('用户不存在', ReturnCode::EMPTY_PARAMS);
|
||||
}
|
||||
$fields = ['id', 'username', 'phone', 'uid', 'name', 'coin', 'total_draw_count'];
|
||||
$info = [];
|
||||
@@ -134,15 +135,15 @@ class UserController extends OpenController
|
||||
}
|
||||
}
|
||||
if (empty($token)) {
|
||||
return $this->fail('请携带 user-token');
|
||||
return $this->fail('请携带 user-token', ReturnCode::MISSING_TOKEN);
|
||||
}
|
||||
$userId = UserLogic::getUserIdFromToken($token);
|
||||
if ($userId === null) {
|
||||
return $this->fail('user-token 无效或已过期');
|
||||
return $this->fail('user-token 无效或已过期', ReturnCode::TOKEN_TIMEOUT);
|
||||
}
|
||||
$user = UserCache::getUser($userId);
|
||||
if (empty($user)) {
|
||||
return $this->fail('缓存已过期,请重新登录');
|
||||
return $this->fail('缓存已过期,请重新登录', ReturnCode::TOKEN_TIMEOUT);
|
||||
}
|
||||
$coin = $user['coin'] ?? null;
|
||||
if (is_string($coin) && is_numeric($coin)) {
|
||||
|
||||
Reference in New Issue
Block a user