Files
shaguabijia-app-server/docs/database/user.md
T
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

2.0 KiB

user — 用户(登录主体)

模型 app/models/user.py | 关联接口 auth-me 等 auth 组 | ← 表索引

登录主体。极光一键登录与短信登录都映射到同一行,以 phone 唯一索引;注册即登录(phone 不存在则 insert,存在则更新 last_login_at)。后续加微信/Apple 登录新增 oauth_account 表,本表不动。

字段

类型 约束 / 默认 说明
id Integer PK, autoincrement 用户主键
phone String(20) UNIQUE, index, NOT NULL 手机号(登录主键;注销后置 deleted_<id> 释放唯一约束)
register_channel String(20) NOT NULL, default jverify 注册渠道:jverify / sms
nickname String(64) nullable 通用昵称(用户改资料设)
avatar_url String(512) nullable 通用头像相对 URL(/media/avatars/...)
wechat_openid String(64) UNIQUE, index, nullable 微信 openid(绑定后存,提现转账用);一微信一账号
wechat_nickname String(64) nullable 微信昵称(绑定时拉,展示在提现绑定卡)
wechat_avatar_url String(512) nullable 微信头像 URL
status String(20) NOT NULL, default active active / disabled / deleted
created_at DateTime(tz) server_default now() 注册时间
last_login_at DateTime(tz) default utcnow(应用层) 最近登录时间

索引与约束

  • PK: id
  • UNIQUE + index: phone
  • UNIQUE + index: wechat_openid(允许多个 NULL = 多个未绑定用户)

关系

  • 被引用方: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_claimuser_id 均 → user.id

说明

  • nickname/avatar_url(通用)与 wechat_nickname/wechat_avatar_url(微信)分开存,不互相覆盖
  • 注销账号:phone 改占位串、status=deleted,不物理删行(保留外键完整性)。