da7ce69494
- 新增 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>
2.0 KiB
2.0 KiB
savings_record — 省钱记录(profile 省钱战绩源)
模型
app/models/savings.py| 关联接口 savings-summary / savings-battle / savings-records | ← 表索引
profile 页「累计帮你省了 / 省钱战绩 / 省钱明细」的唯一数据源:真正下单成交后省了多少记一行。
⚠️ 当前为 demo 假数据:
crud/savings.py:ensure_seeded按 user_id 幂等灌 ~23 条(source='demo'),聚合(SUM/分组/连续天数)是生产级真实计算。真数据要靠**"用户真下单"信号**(app 目前无:AI 比价止于结算页/结果展示,付款用户手动)——不是把比价记录comparison_record喂过来(那是"比价行为",这是"成交省钱",两个维度)。详见 project_shaguabijia_app_server。
字段
| 列 | 类型 | 约束 / 默认 | 说明 |
|---|---|---|---|
id |
Integer | PK, autoincrement | |
user_id |
Integer | FK→user.id, index, NOT NULL | 归属用户 |
order_amount_cents |
Integer | NOT NULL | 订单到手价(分) |
saved_amount_cents |
Integer | NOT NULL | 本单省下(分,可为 0) |
platform |
String(32) | nullable | 下单平台(美团外卖/淘宝闪购/京东外卖) |
title |
String(128) | nullable | 标题 |
shop_name |
String(128) | nullable | 店铺名 |
dishes |
JSON(PG: JSONB) | NOT NULL, default [] | 菜名列表(前 2 道展示,其余"还有 N 道") |
source |
String(16) | NOT NULL, default compare |
来源:demo(演示)/ compare(真实下单上报,待启用) |
created_at |
DateTime(tz) | server_default now(), index | 时间 |
索引与约束
- PK:
id;index:user_id、created_at
关系
user_id→user.id(多对一)
说明
dishes用JSON().with_variant(JSONB(),"postgresql")(SQLite 退化 JSON)。beat_percent(超过百分之多少用户)按各用户累计省下金额做真实分位;为有可比人群造了 5 个种子用户(register_channel='seed')。