refactor(utils): 修复密码哈希比较逻辑错误 feat(user): 新增按状态筛选优惠券接口 docs: 添加虚拟发货与任务中心相关文档 fix(wechat): 修正Code2Session上下文传递问题 test: 补充订单折扣与积分转换测试用例 build: 更新配置文件与构建脚本 style: 清理多余的空行与注释
119 lines
4.1 KiB
Go
119 lines
4.1 KiB
Go
package app
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
"bindbox-game/internal/code"
|
||
"bindbox-game/internal/pkg/core"
|
||
"bindbox-game/internal/pkg/validation"
|
||
"bindbox-game/internal/repository/mysql/model"
|
||
usersvc "bindbox-game/internal/service/user"
|
||
)
|
||
|
||
type listUserItemCardsRequest struct {
|
||
Page int `form:"page"`
|
||
PageSize int `form:"page_size"`
|
||
Status *int32 `form:"status"` // 1未使用 2已使用 3已过期,不传默认1
|
||
}
|
||
|
||
type listUserItemCardsResponse struct {
|
||
Page int `json:"page"`
|
||
PageSize int `json:"page_size"`
|
||
Total int64 `json:"total"`
|
||
List []*usersvc.ItemCardWithTemplate `json:"list"`
|
||
}
|
||
|
||
// ListUserItemCards 获取用户道具卡列表
|
||
// @Summary 获取用户道具卡列表
|
||
// @Description 获取指定用户的道具卡列表,支持分页和状态过滤
|
||
// @Tags APP端.用户
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param user_id path integer true "用户ID"
|
||
// @Security LoginVerifyToken
|
||
// @Param page query integer false "页码,默认1"
|
||
// @Param page_size query integer false "每页条数,默认10"
|
||
// @Param status query integer false "状态:1未使用 2已使用 3已过期,不传默认1"
|
||
// @Success 200 {object} listUserItemCardsResponse
|
||
// @Failure 400 {object} code.Failure "参数错误"
|
||
// @Failure 401 {object} code.Failure "未授权"
|
||
// @Failure 500 {object} code.Failure "服务器内部错误"
|
||
// @Router /api/app/users/{user_id}/item_cards [get]
|
||
func (h *handler) ListUserItemCards() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(listUserItemCardsRequest)
|
||
rsp := new(listUserItemCardsResponse)
|
||
if err := ctx.ShouldBindForm(req); err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
||
return
|
||
}
|
||
userID := int64(ctx.SessionUserInfo().Id)
|
||
|
||
// 默认查询未使用的道具卡
|
||
status := int32(1)
|
||
if req.Status != nil && *req.Status > 0 {
|
||
status = *req.Status
|
||
}
|
||
|
||
items, total, err := h.user.ListUserItemCardsWithTemplateByStatus(ctx.RequestContext(), userID, status, req.Page, req.PageSize)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10008, err.Error()))
|
||
return
|
||
}
|
||
rsp.Page = req.Page
|
||
rsp.PageSize = req.PageSize
|
||
rsp.Total = total
|
||
rsp.List = items
|
||
ctx.Payload(rsp)
|
||
}
|
||
}
|
||
|
||
type listUserItemCardUsesRequest struct {
|
||
Page int `form:"page"`
|
||
PageSize int `form:"page_size"`
|
||
}
|
||
|
||
type listUserItemCardUsesResponse struct {
|
||
Page int `json:"page"`
|
||
PageSize int `json:"page_size"`
|
||
Total int64 `json:"total"`
|
||
List []*model.ActivityDrawEffects `json:"list"`
|
||
}
|
||
|
||
// ListUserItemCardUses 获取用户道具卡使用记录
|
||
// @Summary 获取用户道具卡使用记录
|
||
// @Description 获取指定用户的道具卡使用记录,支持分页
|
||
// @Tags APP端.用户
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param user_id path integer true "用户ID"
|
||
// @Security LoginVerifyToken
|
||
// @Param page query integer false "页码,默认1"
|
||
// @Param page_size query integer false "每页条数,默认10"
|
||
// @Success 200 {object} listUserItemCardUsesResponse
|
||
// @Failure 400 {object} code.Failure "参数错误"
|
||
// @Failure 401 {object} code.Failure "未授权"
|
||
// @Failure 500 {object} code.Failure "服务器内部错误"
|
||
// @Router /api/app/users/{user_id}/item_cards/uses [get]
|
||
func (h *handler) ListUserItemCardUses() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(listUserItemCardUsesRequest)
|
||
rsp := new(listUserItemCardUsesResponse)
|
||
if err := ctx.ShouldBindForm(req); err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
||
return
|
||
}
|
||
userID := int64(ctx.SessionUserInfo().Id)
|
||
items, total, err := h.user.ListUserItemCardUses(ctx.RequestContext(), userID, req.Page, req.PageSize)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10009, err.Error()))
|
||
return
|
||
}
|
||
rsp.Page = req.Page
|
||
rsp.PageSize = req.PageSize
|
||
rsp.Total = total
|
||
rsp.List = items
|
||
ctx.Payload(rsp)
|
||
}
|
||
}
|