fix: 修复微信通知字段截断导致的编码错误 feat: 添加有效邀请相关字段和任务中心常量 refactor: 重构一番赏奖品格位逻辑 perf: 优化道具卡列表聚合显示 docs: 更新项目说明文档和API文档 test: 添加字符串截断工具测试
77 lines
2.7 KiB
Go
77 lines
2.7 KiB
Go
package app
|
|
|
|
import (
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
type listIssueChoicesResponse struct {
|
|
TotalSlots int64 `json:"total_slots"`
|
|
Claimed []int64 `json:"claimed"`
|
|
Available []int64 `json:"available"`
|
|
}
|
|
|
|
// ListIssueChoices 期位置选择列表
|
|
// @Summary 获取指定活动期的可选位置与已占用位置
|
|
// @Description 返回总位置数量、已占用位置列表以及当前可选位置列表。仅在活动玩法为 ichiban 时可用。
|
|
// @Tags APP端.活动
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param activity_id path integer true "活动ID"
|
|
// @Param issue_id path integer true "期ID"
|
|
// @Success 200 {object} listIssueChoicesResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Router /api/app/activities/{activity_id}/issues/{issue_id}/choices [get]
|
|
func (h *handler) ListIssueChoices() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
activityID, err := strconv.ParseInt(ctx.Param("activity_id"), 10, 64)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递活动ID"))
|
|
return
|
|
}
|
|
issueID, err := strconv.ParseInt(ctx.Param("issue_id"), 10, 64)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递期ID"))
|
|
return
|
|
}
|
|
act, err := h.readDB.Activities.WithContext(ctx.RequestContext()).Where(h.readDB.Activities.ID.Eq(activityID)).First()
|
|
if err != nil || act == nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.GetActivityError, "活动不存在"))
|
|
return
|
|
}
|
|
if act.PlayType != "ichiban" {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, 170101, "当前活动不支持位置选择"))
|
|
return
|
|
}
|
|
rewards, err := h.readDB.ActivityRewardSettings.WithContext(ctx.RequestContext()).ReadDB().Where(h.readDB.ActivityRewardSettings.IssueID.Eq(issueID)).Find()
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListIssueRewardsError, err.Error()))
|
|
return
|
|
}
|
|
// 一番赏:每种奖品 = 1个格位
|
|
total := int64(len(rewards))
|
|
var claimed0 []int64
|
|
if err := h.repo.GetDbR().Raw("SELECT slot_index FROM issue_position_claims WHERE issue_id = ?", issueID).Scan(&claimed0).Error; err != nil {
|
|
claimed0 = []int64{}
|
|
}
|
|
used := make(map[int64]struct{}, len(claimed0))
|
|
for _, s := range claimed0 {
|
|
used[s] = struct{}{}
|
|
}
|
|
avail := make([]int64, 0)
|
|
for i := int64(0); i < total; i++ {
|
|
if _, ok := used[i]; !ok {
|
|
avail = append(avail, i+1)
|
|
}
|
|
}
|
|
claimed := make([]int64, 0, len(claimed0))
|
|
for _, s := range claimed0 {
|
|
claimed = append(claimed, s+1)
|
|
}
|
|
rsp := &listIssueChoicesResponse{TotalSlots: total, Claimed: claimed, Available: avail}
|
|
ctx.Payload(rsp)
|
|
}
|
|
}
|