feat(wallet): 金币记录按 trace_id 聚合比价/领券看广告金币 #225

Merged
guke merged 14 commits from feat/coin-ledger-aggregate-ad-rewards into main 2026-08-07 19:12:59 +08:00

14 Commits

Author SHA1 Message Date
guke 8d938e9264 Merge origin/main: 消双 head — coin_transaction_trace_id 重挂父到 savings_record_trace_id
origin/main(#224) 的 savings_record_trace_id 与本分支 coin_transaction_trace_id 都以
comparison_updated_at 为父,汇合后 alembic 双 head(upgrade head 报 multiple heads)。
把本分支迁移重挂到 savings_record_trace_id 之上,线性化为单 head:
comparison_updated_at → savings_record_trace_id → coin_transaction_trace_id。
两迁移分别改 savings_record / coin_transaction,互不依赖,串行安全。

验证:alembic heads 单 head;scratch DB 从 base 全链 upgrade head 通过;
test_welfare / compare_record / admin_read / order_savings 共 66 项测试通过。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 18:53:55 +08:00
guke 6497099834 chore(test): 移除 test_welfare 死导入 import json
最终整体 review 的可选建议;本特性已多次触及该文件 import 区,顺手清掉先前的
F401 死导入,test_welfare.py lint 归零。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 16:22:40 +08:00
guke 773464dd62 docs(ad-feed): 更正 trace_id 注释(领券自 2026-07-15 也带)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 16:11:24 +08:00
guke 4c1821363c test(wallet): 防残组测试补跨游标前置断言(游标须落在会话两成员 id 间)
否则 seeding 顺序若变,用例会退化成非跨游标却仍通过、失守护意义。
(code-review Task 5 的建议)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 16:10:02 +08:00
guke 36fb654f33 test(wallet): 锁死金币记录分组分页不产生残组
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 16:04:50 +08:00
guke dbc62f6547 feat(wallet): 金币记录按 trace_id 聚合比价/领券看广告金币
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 15:51:17 +08:00
guke 062f2b8b2a feat(ad-feed): 发奖把本场 trace_id 写入金币流水
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 15:44:28 +08:00
guke daa8c89dc6 test(wallet): 回填测试补 EXISTS 守护边界(广告行 trace_id 空则不回填)
对齐 spec §8:2026-07-15 前老比价广告 ad 行 trace_id 为空时,回填须跳过、保持 NULL。
(code-review Task 2 的 minor 建议)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 15:42:09 +08:00
guke a424dd11a3 feat(wallet): 迁移加 coin_transaction.trace_id + 索引 + 回填历史
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 15:35:49 +08:00
guke e0d403c080 feat(wallet): coin_transaction 增 trace_id 列 + grant_coins 透传
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 15:28:41 +08:00
guke f4ef2ae9af docs(coin-ledger): 分步实施计划(TDD:列/迁移回填/发奖透传/聚合查询/防残组/注释)
6 个任务、逐步 test-first,含精确代码与命令;端点不改、admin 不动。
对应 spec docs/superpowers/specs/2026-08-07-coin-ledger-aggregate-ad-rewards-design.md

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 15:21:49 +08:00
guke 3a9a4a32d9 docs(coin-ledger): 自审优化——防残组回归/索引纠错/回填守护/admin 范围界定
- §11 明令禁止把分组 CTE 裁成 id<cursor(会话交错跨游标会算出"残组"与上页重复),
  补防残组回归测试;成本改口径为估算(非实测);去掉无效的 (user_id,trace_id) 索引建议
- §8 回填补幂等/大表分批/子查询唯一性守护
- §6 两类 biz_type 抽成常量 FEED_AD_SESSION_BIZ_TYPES 三处共用
- §3 显式界定:只改 App 用户接口,admin 的 list_all_coin_transactions 保持每条一行(审计)
- 记录未来读优化逃生口(会话聚合投影表)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 15:00:20 +08:00
guke dc1d14cb9c docs(coin-ledger): 自查补充分组键 biz_type 门控与 trace 唯一性说明
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 14:41:47 +08:00
guke 683eb08be9 docs(coin-ledger): 比价/领券看广告金币按会话汇总设计 spec
金币记录列表把一次比价/领券连续看广告的多条金币合并成一条,按 trace_id
聚合。纯后端:coin_transaction 加 trace_id 列 + 回填历史,/coin-transactions
分组游标分页返回合并行。领券自 2026-07-15 起结算已带 trace_id,无需改 Android。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-07 14:40:33 +08:00