Files
shaguabijia-app-server/docs/database/savings_record.md
T
OuYingJun1024 bb58fb2a29 docs(database): 新建 docs/database 表文档 — 13 张表全量 + 索引
按"一表一文件"建库表文档(协作规范第 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>
2026-05-31 20:44:54 +08:00

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_idcreated_at

关系

  • user_iduser.id(多对一)

说明

  • dishesJSON().with_variant(JSONB(),"postgresql")(SQLite 退化 JSON)。
  • beat_percent(超过百分之多少用户)按各用户累计省下金额做真实分位;为有可比人群造了 5 个种子用户(register_channel='seed')。