重新设计状态码规范

This commit is contained in:
2026-03-05 13:44:56 +08:00
parent 8d8cee696f
commit 5ab16243bd
6 changed files with 46 additions and 33 deletions

View File

@@ -31,7 +31,7 @@ class GameController extends OpenController
$userId = UserLogic::getUserIdFromRequest($request) ?? 0;
$count = (int) $request->post('count', 0);
if (!in_array($count, [1, 5, 10], true)) {
return $this->fail('购买抽奖券错误', ReturnCode::EMPTY_PARAMS);
return $this->fail('购买抽奖券错误', ReturnCode::PARAMS_ERROR);
}
try {
@@ -45,7 +45,7 @@ class GameController extends OpenController
$coin = $player ? (float) $player->coin : 0;
return $this->success(['coin' => $coin], $msg);
}
return $this->fail($msg, ReturnCode::EMPTY_PARAMS);
return $this->fail($msg, ReturnCode::BUSINESS_ERROR);
}
}
@@ -72,16 +72,16 @@ class GameController extends OpenController
$userId = UserLogic::getUserIdFromRequest($request) ?? 0;
$rediction = $request->post('rediction');
if ($rediction === '' || $rediction === null) {
return $this->fail('请传递 rediction 参数', ReturnCode::EMPTY_PARAMS);
return $this->fail('请传递 rediction 参数', ReturnCode::PARAMS_ERROR);
}
$direction = (int) $rediction;
if (!in_array($direction, [0, 1], true)) {
return $this->fail('rediction 必须为 0 或 1', ReturnCode::EMPTY_PARAMS);
return $this->fail('rediction 必须为 0 或 1', ReturnCode::PARAMS_ERROR);
}
$player = DicePlayer::find($userId);
if (!$player) {
return $this->fail('用户不存在', ReturnCode::EMPTY_PARAMS);
return $this->fail('用户不存在', ReturnCode::NOT_FOUND);
}
$minEv = (float) DiceRewardConfig::min('real_ev');
$minCoin = abs($minEv + 100);
@@ -95,7 +95,7 @@ class GameController extends OpenController
$data = $logic->run($userId, $direction);
return $this->success($data);
} catch (ApiException $e) {
return $this->fail($e->getMessage(), ReturnCode::EMPTY_PARAMS);
return $this->fail($e->getMessage(), ReturnCode::BUSINESS_ERROR);
} catch (\Throwable $e) {
$timeoutRecord = null;
try {