1.优化查询用户信息接口/api/v1/getPlayerInfo,如果没有用户则创建

This commit is contained in:
2026-05-19 17:18:51 +08:00
parent 37c0035bfc
commit 9a43e1d8f2
3 changed files with 80 additions and 3 deletions

View File

@@ -148,7 +148,18 @@ class GameController extends BaseController
return $this->success($cached);
}
$player = DicePlayer::field(self::PLAYER_INFO_DB_FIELDS)->where('username', $username)->where('dept_id', $deptId)->find();
try {
$logic = new UserLogic();
$player = $logic->findOrCreatePlayerByUsername(
$username,
$this->agentAdminId($request),
$deptId > 0 ? $deptId : null
);
} catch (\plugin\saiadmin\exception\ApiException $e) {
return $this->fail($e->getMessage(), ReturnCode::PARAMS_ERROR);
}
$player = DicePlayer::field(self::PLAYER_INFO_DB_FIELDS)->where('id', (int) $player->id)->find();
if (!$player) {
return $this->fail('User not found', ReturnCode::PARAMS_ERROR);
}