diff --git a/backend/app/routers/websocket.py b/backend/app/routers/websocket.py index 53f81ad..0cb15d8 100644 --- a/backend/app/routers/websocket.py +++ b/backend/app/routers/websocket.py @@ -215,12 +215,12 @@ async def broadcast_pool_updates(streamer_id: int): # 获取最新奖池数据 pool_data = get_pool_cache(chest.id) - # 计算赔率 + # 计算赔率 - 修改为只对获胜方抽水 total = pool_data["pool_a"] + pool_data["pool_b"] if total > 0: - distributable = total * 0.9 - odds_a = round(distributable / pool_data["pool_a"], 2) if pool_data["pool_a"] > 0 else 0 - odds_b = round(distributable / pool_data["pool_b"], 2) if pool_data["pool_b"] > 0 else 0 + # 赔率计算改为:(自己奖池 + 对方奖池 * 0.9) / 自己奖池 + odds_a = round((pool_data["pool_a"] + pool_data["pool_b"] * 0.9) / pool_data["pool_a"], 2) if pool_data["pool_a"] > 0 else 0 + odds_b = round((pool_data["pool_b"] + pool_data["pool_a"] * 0.9) / pool_data["pool_b"], 2) if pool_data["pool_b"] > 0 else 0 else: odds_a = odds_b = 0 diff --git a/backend/app/schemas/game.py b/backend/app/schemas/game.py index c481f87..89a4c5a 100644 --- a/backend/app/schemas/game.py +++ b/backend/app/schemas/game.py @@ -37,16 +37,16 @@ class ChestResponse(ChestBase): """计算A边赔率 (1 : X)""" if self.pool_a == 0: return 0.0 - distributable = self.total_pool * 0.9 - return round(distributable / self.pool_a, 2) + # 修改赔率计算方式,只对获胜方抽水 + return round((self.pool_a + self.pool_b * 0.9) / self.pool_a, 2) @property def odds_b(self) -> float: """计算B边赔率 (1 : X)""" if self.pool_b == 0: return 0.0 - distributable = self.total_pool * 0.9 - return round(distributable / self.pool_b, 2) + # 修改赔率计算方式,只对获胜方抽水 + return round((self.pool_b + self.pool_a * 0.9) / self.pool_b, 2) class Config: from_attributes = True diff --git a/backend/app/services/game_service.py b/backend/app/services/game_service.py index 68f0d71..a6725da 100644 --- a/backend/app/services/game_service.py +++ b/backend/app/services/game_service.py @@ -424,10 +424,12 @@ class GameService: print(f"平台抽水转账失败: {str(e)}") # 可以在这里添加更详细的错误处理逻辑,比如发送告警通知 - # 计算赔率 + # 计算赔率 - 修改为只对获胜方抽水 winner_pool = chest.pool_a if winner == "A" else chest.pool_b + loser_pool = chest.pool_b if winner == "A" else chest.pool_a if winner_pool > 0: - odds = distributable / winner_pool + # 赔率计算改为:(获胜方奖池 + 失败方奖池 * 0.9) / 获胜方奖池 + odds = (winner_pool + loser_pool * 0.9) / winner_pool # 结算给获胜方 for bet in bets: diff --git a/frontend/src/pages/ChestPage.tsx b/frontend/src/pages/ChestPage.tsx index 37fe0d8..2545168 100644 --- a/frontend/src/pages/ChestPage.tsx +++ b/frontend/src/pages/ChestPage.tsx @@ -275,8 +275,9 @@ const ChestPage = () => { } const totalPool = chest.pool_a + chest.pool_b; - const oddsA = totalPool > 0 ? (totalPool * 0.9) / chest.pool_a : 0; - const oddsB = totalPool > 0 ? (totalPool * 0.9) / chest.pool_b : 0; + // 修改赔率计算方式,只对获胜方抽水 + const oddsA = totalPool > 0 ? (chest.pool_a + chest.pool_b * 0.9) / chest.pool_a : 0; + const oddsB = totalPool > 0 ? (chest.pool_b + chest.pool_a * 0.9) / chest.pool_b : 0; // 计算用户在当前宝箱各选项上的累计下注金额 const userBetsOnA = bets @@ -388,9 +389,9 @@ const ChestPage = () => { disabled={chest.status !== 0} />
- - + +