Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 40s
feat(pay): 添加支付API基础结构 feat(miniapp): 创建支付测试小程序页面与配置 feat(wechatpay): 配置微信支付参数与证书 fix(guild): 修复成员列表查询条件 docs: 更新代码规范文档与需求文档 style: 统一前后端枚举显示与注释格式 refactor(admin): 重构用户奖励发放接口参数处理 test(title): 添加称号效果参数验证测试
84 lines
2.6 KiB
Go
84 lines
2.6 KiB
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"bindbox-game/internal/pkg/validation"
|
|
)
|
|
|
|
type batchDrawRequest struct {
|
|
UserIDs []int64 `json:"user_ids" binding:"required,min=1,max=1000,dive,min=1"`
|
|
}
|
|
|
|
type batchDrawResponse struct {
|
|
Draws []drawResultItem `json:"draws"`
|
|
}
|
|
|
|
type drawResultItem struct {
|
|
UserID int64 `json:"user_id"`
|
|
DrawID int64 `json:"draw_id"`
|
|
RewardID int64 `json:"reward_id"`
|
|
RewardName string `json:"reward_name"`
|
|
IsWinner bool `json:"is_winner"`
|
|
Receipt interface{} `json:"receipt"`
|
|
}
|
|
|
|
func (h *handler) BatchDrawForUsers() core.HandlerFunc {
|
|
// 批量抽奖(应用头衔效果并返回收据)
|
|
// @Summary 批量抽奖
|
|
// @Description 对指定期为一组用户执行抽奖,返回每次抽奖结果与收据
|
|
// @Tags 管理端.活动
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param activity_id path integer true "活动ID"
|
|
// @Param issue_id path integer true "期ID"
|
|
// @Param RequestBody body batchDrawRequest true "请求参数"
|
|
// @Success 200 {object} batchDrawResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Security LoginVerifyToken
|
|
// @Router /api/admin/activities/{activity_id}/issues/{issue_id}/batch_draw [post]
|
|
return func(ctx core.Context) {
|
|
activityIDStr := ctx.Param("activity_id")
|
|
if activityIDStr == "" {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递活动ID"))
|
|
return
|
|
}
|
|
issueIDStr := ctx.Param("issue_id")
|
|
if issueIDStr == "" {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递期ID"))
|
|
return
|
|
}
|
|
if _, err := strconv.ParseInt(issueIDStr, 10, 64); err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
|
return
|
|
}
|
|
issueID, _ := strconv.ParseInt(issueIDStr, 10, 64)
|
|
_, _ = strconv.ParseInt(activityIDStr, 10, 64)
|
|
req := new(batchDrawRequest)
|
|
if err := ctx.ShouldBindJSON(req); err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
|
return
|
|
}
|
|
items, err := h.activity.BatchDrawForUsers(ctx.RequestContext(), issueID, req.UserIDs)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ExecuteDrawError, err.Error()))
|
|
return
|
|
}
|
|
out := make([]drawResultItem, len(items))
|
|
for i, it := range items {
|
|
out[i] = drawResultItem{
|
|
UserID: it.UserID,
|
|
DrawID: it.DrawID,
|
|
RewardID: it.RewardID,
|
|
RewardName: it.RewardName,
|
|
IsWinner: it.IsWinner,
|
|
Receipt: it.Receipt,
|
|
}
|
|
}
|
|
ctx.Payload(&batchDrawResponse{Draws: out})
|
|
}
|
|
}
|