优化/api/game/playStart接口
This commit is contained in:
@@ -65,18 +65,19 @@ class GameController extends OpenController
|
||||
* 开始游戏(抽奖一局)
|
||||
* POST /api/game/playStart
|
||||
* header: token(由 TokenMiddleware 注入 request->player_id)
|
||||
* body: rediction 必传,0=无 1=中奖
|
||||
* body: direction 必传,0=无 1=中奖
|
||||
*/
|
||||
public function playStart(Request $request): Response
|
||||
{
|
||||
$userId = (int) ($request->player_id ?? 0);
|
||||
$rediction = $request->post('rediction');
|
||||
if (empty($rediction)) {
|
||||
return $this->fail('请传递 rediction 参数', ReturnCode::PARAMS_ERROR);
|
||||
$direction = $request->post('direction');
|
||||
if (empty($direction)) {
|
||||
Log::error('传递的参数为direction = '.$direction);
|
||||
return $this->fail('请传递 direction 参数', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
$direction = (int) $rediction;
|
||||
$direction = (int) $direction;
|
||||
if (!in_array($direction, [0, 1], true)) {
|
||||
return $this->fail('rediction 必须为 0 或 1', ReturnCode::PARAMS_ERROR);
|
||||
return $this->fail('direction 必须为 0 或 1', ReturnCode::PARAMS_ERROR);
|
||||
}
|
||||
|
||||
$player = DicePlayer::find($userId);
|
||||
|
||||
@@ -38,7 +38,7 @@ class PlayStartLogic
|
||||
/**
|
||||
* 执行一局游戏
|
||||
* @param int $playerId 玩家ID
|
||||
* @param int $direction 方向 0=无/顺时针 1=中奖/逆时针(前端 rediction)
|
||||
* @param int $direction 方向 0=无/顺时针 1=中奖/逆时针(前端 direction)
|
||||
* @return array 成功返回 DicePlayRecord 数据;余额不足时抛 ApiException,message 为约定文案
|
||||
*/
|
||||
public function run(int $playerId, int $direction): array
|
||||
|
||||
Reference in New Issue
Block a user