bb58fb2a29
按"一表一文件"建库表文档(协作规范第 11 条):字段(类型/约束/默认)+ 索引与约束 + 关系 + 说明,从 model 的 Mapped 定义扒准。 - README 索引:13 张表总览 + 通用约定(主键/外键/金额分/北京时间日期串/JSONB variant) - 覆盖 user / coin_account / coin_transaction / cash_transaction / withdraw_order / signin_record / user_task / savings_record / ad_reward_record / ad_ecpm_record / feedback / comparison_record / comparison_milestone_claim - savings_record 文档强调"成交省钱"≠"比价行为",与 comparison_record 互不喂数据 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
28 lines
1.3 KiB
Markdown
28 lines
1.3 KiB
Markdown
# coin_transaction — 金币流水账本
|
|
|
|
> 模型 `app/models/wallet.py` | 关联接口 [wallet-coin-transactions](../api/wallet-coin-transactions.md) | [← 表索引](./README.md)
|
|
|
|
金币每次变动一笔流水,记变动后余额,用于对账与「金币明细」展示。
|
|
|
|
## 字段
|
|
| 列 | 类型 | 约束 / 默认 | 说明 |
|
|
|---|---|---|---|
|
|
| `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_id`、`created_at`
|
|
|
|
## 关系
|
|
- `user_id` → `user.id`(多对一)
|
|
|
|
## 说明
|
|
- 明细接口按 `id` 倒序游标分页。
|
|
- 各 `biz_type` 取值由各业务写入(签到/任务/兑换/看广告/比价里程碑),无独立枚举约束,靠写入方约定。
|