Files
shaguabijia-app-server/docs/database/withdraw_order.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.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_idcreated_at

关系

  • user_iduser.id(多对一)

说明

  • 资金安全:原子扣款 + out_bill_no 幂等 + 模糊失败先查单再决定(绝不盲目退款)+ 孤儿单对账 reconcile_pending_withdraws。详见 project_shaguabijia_app_server 提现段。
  • WITHDRAW_MIN_CENTS=10(0.1 元,微信地板)。