refactor(utils): 修复密码哈希比较逻辑错误 feat(user): 新增按状态筛选优惠券接口 docs: 添加虚拟发货与任务中心相关文档 fix(wechat): 修正Code2Session上下文传递问题 test: 补充订单折扣与积分转换测试用例 build: 更新配置文件与构建脚本 style: 清理多余的空行与注释
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package app
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
"bindbox-game/internal/code"
|
||
"bindbox-game/internal/pkg/core"
|
||
)
|
||
|
||
type redeemInventoryRequest struct {
|
||
InventoryIDs []int64 `json:"inventory_ids"`
|
||
}
|
||
|
||
type redeemInventoryResponse struct {
|
||
Points int64 `json:"points"`
|
||
}
|
||
|
||
// RedeemInventoryToPoints 资产兑换为积分
|
||
// @Summary 资产兑换为积分
|
||
// @Description 将资产按规则转换为积分,成功后资产不可再发货;默认兑换比率来自系统配置`points_exchange_per_cent`
|
||
// @Tags APP端.用户
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param user_id path integer true "用户ID"
|
||
// @Security LoginVerifyToken
|
||
// @Param RequestBody body redeemInventoryRequest true "请求参数:资产ID"
|
||
// @Success 200 {object} redeemInventoryResponse
|
||
// @Failure 400 {object} code.Failure "参数错误/资产不可用"
|
||
// @Router /api/app/users/{user_id}/inventory/redeem [post]
|
||
func (h *handler) RedeemInventoryToPoints() core.HandlerFunc {
|
||
return func(ctx core.Context) {
|
||
req := new(redeemInventoryRequest)
|
||
rsp := new(redeemInventoryResponse)
|
||
if err := ctx.ShouldBindJSON(req); err != nil || len(req.InventoryIDs) == 0 {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "参数错误"))
|
||
return
|
||
}
|
||
userID := int64(ctx.SessionUserInfo().Id)
|
||
pts, err := h.user.RedeemInventoriesToPoints(ctx.RequestContext(), userID, req.InventoryIDs)
|
||
if err != nil {
|
||
ctx.AbortWithError(core.Error(http.StatusBadRequest, 10023, err.Error()))
|
||
return
|
||
}
|
||
rsp.Points = pts
|
||
ctx.Payload(rsp)
|
||
}
|
||
}
|