Add user profile management for smoking data
- Introduced new API endpoints `GET /api/v1/smoke/profile` and `PUT /api/v1/smoke/profile` for retrieving and updating user smoking profiles. - Added a new database table `fa_smoke_user_profile` to store user-specific smoking data, including daily smoking habits and motivations. - Updated the smoke handler and service to integrate user profile data into AI advice generation. - Enhanced documentation to reflect the new user profile features and their usage.
This commit is contained in:
@@ -237,3 +237,87 @@ curl -X GET 'http://127.0.0.1:8080/api/v1/smoke/logs/5202' \
|
||||
说明:
|
||||
- 该接口用于记录“已完成观看广告”,落库到 `fa_smoke_ai_advice_unlocks`(`uid + unlock_date` 唯一)。
|
||||
- `ad_watched_at` 可由后端取当前时间;如需审计/对账可保留前端上报并做校验。
|
||||
|
||||
## 10) 获取用户基础信息(首次进入:判断是否需要补全)
|
||||
|
||||
`GET /api/v1/smoke/profile`
|
||||
|
||||
说明:
|
||||
- 首次进入小程序建议先调用该接口:若 `exists=false` 或 `is_completed=false`,前端进入“信息补全”流程。
|
||||
- `baseline_interval_minutes` 用于建立初始基准:在用户清醒时段内的“平均间隔(分钟)”。计算:`awake_minutes / baseline_cigs_per_day`。
|
||||
- 若未提供作息时间(起床/入睡),后端会用默认清醒时长 `16*60=960` 分钟参与计算。
|
||||
|
||||
成功响应(示例):
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"exists": true,
|
||||
"profile": {
|
||||
"id": 1,
|
||||
"created_at": "2026-01-05T10:00:00+08:00",
|
||||
"updated_at": "2026-01-05T10:00:00+08:00",
|
||||
"baseline_cigs_per_day": 20,
|
||||
"smoking_years": 8,
|
||||
"pack_price_cent": 2500,
|
||||
"smoke_motivations": ["压力大", "社交"],
|
||||
"quit_motivations": ["身体健康", "省钱"],
|
||||
"wake_up_time": "07:30",
|
||||
"sleep_time": "23:30",
|
||||
"onboarding_completed_at": "2026-01-05T10:00:00+08:00"
|
||||
},
|
||||
"is_completed": true,
|
||||
"awake_minutes": 960,
|
||||
"baseline_interval_minutes": 48
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
当 `exists=false`(尚未补全)时,响应示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"exists": false,
|
||||
"is_completed": false,
|
||||
"awake_minutes": 960,
|
||||
"baseline_interval_minutes": 0
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
字段用途(补全页面可参考):
|
||||
- `baseline_cigs_per_day`(基础烟量/日均抽烟支数):建立初始基准,计算初始建议间隔时长。
|
||||
- `smoking_years`(烟龄/年)+ `pack_price_cent`(单包价格/分):用于看板计算“已省金额”和“恢复时长”等指标(公式可在看板端实现)。
|
||||
- `smoke_motivations`(抽烟动机):如 `压力大/无聊/社交/提神`,用于 AI 在分析 remark 时更有针对性。
|
||||
- `quit_motivations`(戒烟动力):如 `身体健康/家人孩子/省钱`,当用户产生动摇时 AI 可用这些信息做“情感阻断/自我提醒”。
|
||||
- `wake_up_time` + `sleep_time`(作息时间):用于自动规避睡眠时间,防止在用户睡觉时提醒其“坚持”。
|
||||
|
||||
## 11) 补全/更新用户基础信息(Upsert)
|
||||
|
||||
`PUT /api/v1/smoke/profile`
|
||||
|
||||
说明:
|
||||
- 字段按需传;首次进入建议一次性补全。
|
||||
- 作息时间格式:`HH:MM`(24 小时制),例如 `07:30`、`23:10`。
|
||||
- `pack_price_cent` 为“分”;若前端用“元”,请乘以 100。
|
||||
|
||||
请求体(示例):
|
||||
|
||||
```json
|
||||
{
|
||||
"baseline_cigs_per_day": 20,
|
||||
"smoking_years": 8,
|
||||
"pack_price_cent": 2500,
|
||||
"smoke_motivations": ["压力大", "社交"],
|
||||
"quit_motivations": ["身体健康", "省钱"],
|
||||
"wake_up_time": "07:30",
|
||||
"sleep_time": "23:30"
|
||||
}
|
||||
```
|
||||
|
||||
成功响应:同 `GET /api/v1/smoke/profile`(返回最新 `profile` + `is_completed` + `baseline_interval_minutes`)。
|
||||
|
||||
Reference in New Issue
Block a user