Files
shaguabijia-app-server/docs/database/coin_transaction.md
ouzhou da7ce69494 feat(ad): eCPM 上报接口 + 冷却策略解耦纯函数 + savings JSONB 跨库修复 (#8)
- 新增 POST /api/v1/ad/ecpm-report:激励视频展示后客户端上报本次 eCPM,落 ad_ecpm_record 做内部收益统计(model/repository/schema/alembic 迁移 + 接口文档)
- 看广告冷却策略抽到 app/core/ad_cooldown.py 纯函数;ad_reward.today_status 只取数据,换策略只改这一处
- savings.dishes 改 JSON().with_variant(JSONB,"postgresql"):SQLite 无 visit_JSONB 会让 create_all 编译崩,修复后测试套件恢复

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: OuYingJun1024 <1034284404@qq.com>
Reviewed-on: #8
Co-authored-by: ouzhou <ouzhou@wonderable.ai>
Co-committed-by: ouzhou <ouzhou@wonderable.ai>
2026-06-01 22:23:15 +08:00

1.3 KiB

coin_transaction — 金币流水账本

模型 app/models/wallet.py | 关联接口 wallet-coin-transactions | ← 表索引

金币每次变动一笔流水,记变动后余额,用于对账与「金币明细」展示。

字段

类型 约束 / 默认 说明
id Integer PK, autoincrement
user_id Integer FK→user.id, index, NOT NULL 归属用户
amount Integer NOT NULL 正=入账(赚),负=出账(花/兑换)
balance_after Integer NOT NULL 本笔变动后金币余额(对账用)
biz_type String(32) NOT NULL 业务类型:signin / task_<key> / exchange_out / ad_reward / compare_milestone
ref_id String(64) nullable 关联业务 id(签到日期 / 任务 key / trans_id / 里程碑序号等)
remark String(128) nullable 备注
created_at DateTime(tz) server_default now(), index 时间

索引与约束

  • PK: id;index: user_idcreated_at

关系

  • user_iduser.id(多对一)

说明

  • 明细接口按 id 倒序游标分页。
  • biz_type 取值由各业务写入(签到/任务/兑换/看广告/比价里程碑),无独立枚举约束,靠写入方约定。