# user — 用户(登录主体) > 模型 `app/models/user.py` | 关联接口 [auth-me](../api/auth-me.md) 等 auth 组 | [← 表索引](./README.md) 登录主体。极光一键登录与短信登录都映射到同一行,以 `phone` 唯一索引;注册即登录(phone 不存在则 insert,存在则更新 `last_login_at`)。后续加微信/Apple 登录新增 oauth_account 表,本表不动。 ## 字段 | 列 | 类型 | 约束 / 默认 | 说明 | |---|---|---|---| | `id` | Integer | PK, autoincrement | 用户主键 | | `phone` | String(20) | UNIQUE, index, NOT NULL | 手机号(登录主键;注销后置 `deleted_` 释放唯一约束) | | `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_claim` 的 `user_id` 均 → `user.id`。 ## 说明 - `nickname/avatar_url`(通用)与 `wechat_nickname/wechat_avatar_url`(微信)**分开存,不互相覆盖**。 - 注销账号:phone 改占位串、status=deleted,不物理删行(保留外键完整性)。