--- todos: - id: "ddl" content: "patch_wallet_phase_game_stat.sql + InitDB 分片建表" status: pending - id: "model-service" content: "WalletPhaseGameStatModel + WalletPhaseGameStatService(inc + 首充标记)" status: pending - id: "wire-logic" content: "WalletLogic bet/win/首充同事务挂载写入" status: pending isProject: false --- # 充值前后游戏统计表(精简版) ## 目标 一张表回答四个数:**充值前下注、充值前派奖、充值后下注、充值后派奖**。RTP 读时算,不存库。钱包怎么通知 activity **后面再说**。 --- ## 表结构 **表名**:`wallet_phase_game_stat` **分片**:与 `wallet_stat` 一致,`wallet_{db}.wallet_phase_game_stat_{table}` **主键**:`(uid, currency)` ```sql CREATE TABLE `wallet_phase_game_stat_{t}` ( `uid` BIGINT NOT NULL, `currency` CHAR(5) NOT NULL DEFAULT 'rp', `first_recharge_at` DATETIME NULL COMMENT '首充时间,NULL=尚未充值', `pre_bet_amount` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '充值前累计下注,*1000', `pre_win_amount` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '充值前累计派奖,*1000', `post_bet_amount` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '充值后累计下注,*1000', `post_win_amount` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '充值后累计派奖,*1000', `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`uid`, `currency`) ) COMMENT='用户充值前后游戏统计'; ``` **刻意不做的字段**(需要时再加): - 笔数 `*_count` - `post_valid_bet_amount` / FS 分项 - `first_recharge_order_no` - `last_bet_at` 等时间戳 --- ## 阶段判定 **边界 = 是否已首充**,看 `first_recharge_at` 或 `RechargeExchangeService::isRecharge(uid)`: - 未首充 → 累加 `pre_*` - 已首充 → 累加 `post_*` --- ## 写入口径 与 [`WalletLogic`](slot-wallet/app/api/logic/WalletLogic.php) 现有路径对齐,**仅在 biz_id 幂等通过、新写入流水时**同事务累加: | 动作 | 未首充 | 已首充 | |------|--------|--------| | 试玩下注 `executeTrialBet` | `pre_bet += fee` | — | | 试玩派奖 `executeTrialWin` | `pre_win += fee` | — | | 真金下注 `BetService` / FS代付 | — | `post_bet += fee` | | 真金派奖 `WinService`(`is_end=1`) | — | `post_win += fee` | | 首充 commit | 写 `first_recharge_at` | — | 中间派奖(`is_end=0`)不写。 --- ## RTP 读时计算,不入库: ``` pre_rtp = pre_win_amount / pre_bet_amount (bet=0 → null) post_rtp = post_win_amount / post_bet_amount ``` --- ## 代码落点 | 文件 | 内容 | |------|------| | `slot-wallet/db/patch_wallet_phase_game_stat.sql` | DDL | | `slot-wallet/app/model/multi/WalletPhaseGameStatModel.php` | 分片 + `inc` | | `slot-wallet/app/service/wallet/WalletPhaseGameStatService.php` | 判定阶段、累加、首充标记 | | `WalletLogic::bet()` / `win()` / 首充 | 同事务调用 | **本轮不改**:`TrialValidBetNotifyService`、activity、MQ。 --- ## 验收 1. 首充前只涨 `pre_*`,首充后只涨 `post_*` 2. 幂等重入不重计 3. 四个金额 + 两个 RTP 可查询