bindbox-game/.trae/documents/实现 APP 用户资产与奖品 API.md
邹方成 45815bfb7d chore: 清理无用文件与优化代码结构
refactor(utils): 修复密码哈希比较逻辑错误
feat(user): 新增按状态筛选优惠券接口
docs: 添加虚拟发货与任务中心相关文档
fix(wechat): 修正Code2Session上下文传递问题
test: 补充订单折扣与积分转换测试用例
build: 更新配置文件与构建脚本
style: 清理多余的空行与注释
2025-12-18 17:35:55 +08:00

36 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 目标
- 在 APP 端新增接口,直接返回当前登录用户在 `user_inventory` 表中的分页数据,用于“用户中奖数据”查询。
## 接口设计
- 路径:`GET /api/app/users/{user_id}/inventory`
- 鉴权:`AppTokenAuthVerify`,以会话 `ctx.SessionUserInfo().Id` 为准(参考 `internal/api/user/points_app.go:47`)。
- 入参query`page`默认1`page_size`默认20最大100
- 出参JSON
- `page``page_size``total`
- `list`:元素为 `model.UserInventory`,字段:`id,user_id,product_id,order_id,activity_id,reward_id,status,remark,created_at,updated_at`
## 数据来源
- 直接读取 `user_inventory` 表(模型:`internal/repository/mysql/model/user_inventory.gen.go:13`)。
- 分页与排序:按 `id DESC`,与管理端一致(参考 `internal/api/admin/users_admin.go:246-256` 的资产列表实现风格)。
## 实现方案
1. 新增 `internal/api/user/inventory_app.go`
- 定义 `listInventoryRequest/listInventoryResponse``list``[]*model.UserInventory`)。
- `handler.ListUserInventory()`
- 绑定分页参数→会话用户 ID→在 `h.readDB.UserInventory` 上过滤 `user_id``Count``Find``Order(ID.Desc)``Offset/Limit`)。
- 组装分页响应并 `ctx.Payload`
- Swagger 注释与现有风格一致(参考 `internal/api/user/coupons_app.go:34-46`)。
2. 路由注册(`internal/router/router.go:236` APP 认证组):
- `appAuthApiRouter.GET("/users/:user_id/inventory", userHandler.ListUserInventory())`
## 测试要点
- 正常:用户存在记录,分页与 `total` 正确。
- 空数据:返回 `list=[]``total=0`
- 边界参数:`page≤0`→重置为 1`page_size` 超上限→重置为 100。
- 鉴权:忽略路径 `user_id`,以会话用户为准。
## 参考代码位置
- 模型定义:`internal/repository/mysql/model/user_inventory.gen.go:13`
- 路由分组:`internal/router/router.go:236`
- 鉴权风格:`internal/api/user/points_app.go:47`