header('user-token'); if (empty($token)) { $auth = $request->header('authorization'); if ($auth && stripos($auth, 'Bearer ') === 0) { $token = trim(substr($auth, 7)); } } if (empty($token)) { return $this->fail('请携带 user-token'); } $userId = UserLogic::getUserIdFromToken($token); if ($userId === null) { return $this->fail('user-token 无效或已过期'); } $count = (int) $request->post('count', 0); if (!in_array($count, [1, 5, 10], true)) { return $this->fail('购买抽奖券错误'); } try { $logic = new GameLogic(); $data = $logic->buyLotteryTickets($userId, $count); return $this->success($data); } catch (\plugin\saiadmin\exception\ApiException $e) { return $this->fail($e->getMessage()); } } /** * 获取彩金池(中奖配置表) * GET /api/game/lotteryPool * header: auth-token * 返回 DiceRewardConfig 列表(彩金池/中奖配置) */ public function lotteryPool(Request $request): Response { $list = DiceRewardConfig::order('id', 'asc')->select()->toArray(); return $this->success($list); } }