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>
1.9 KiB
1.9 KiB
withdraw_order — 提现单(现金 → 微信零钱)
模型
app/models/wallet.py| 关联接口 wallet-withdraw / wallet-withdraw-status | ← 表索引
提现状态机:pending → success / failed。扣现金 + 写 cash_transaction(withdraw) + 建本单在同一事务;失败/取消时退回现金并写 cash_transaction(withdraw_refund)。wechat_state 存微信侧原始状态,status 是归一化后的三态。
字段
| 列 | 类型 | 约束 / 默认 | 说明 |
|---|---|---|---|
id |
Integer | PK, autoincrement | |
user_id |
Integer | FK→user.id, index, NOT NULL | 归属用户 |
out_bill_no |
String(64) | UNIQUE, index, NOT NULL | 商户单号(幂等键 + 微信查单);客户端可传,不传则服务端生成 |
amount_cents |
Integer | NOT NULL | 提现金额(分) |
status |
String(16) | NOT NULL, default pending |
归一化状态:pending / success / failed |
wechat_state |
String(32) | nullable | 微信原始状态:WAIT_USER_CONFIRM / SUCCESS / FAIL / CANCELLED … |
transfer_bill_no |
String(64) | nullable | 微信转账单号 |
package_info |
String(512) | nullable | 待用户确认时返回 App 拉起确认页用 |
fail_reason |
String(256) | nullable | 失败技术原因(不外露,用户只看流水 remark) |
created_at |
DateTime(tz) | server_default now(), index | 发起时间 |
updated_at |
DateTime(tz) | server_default now(), onupdate now() | 更新时间 |
索引与约束
- PK:
id;UNIQUE + index:out_bill_no;index:user_id、created_at
关系
user_id→user.id(多对一)
说明
- 资金安全:原子扣款 +
out_bill_no幂等 + 模糊失败先查单再决定(绝不盲目退款)+ 孤儿单对账reconcile_pending_withdraws。详见 project_shaguabijia_app_server 提现段。 WITHDRAW_MIN_CENTS=10(0.1 元,微信地板)。