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): 添加称号效果参数验证测试
160 lines
6.1 KiB
Go
160 lines
6.1 KiB
Go
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"bindbox-game/internal/pkg/validation"
|
|
)
|
|
|
|
type issueCommitResponse struct {
|
|
AlgoVersion string `json:"algo_version"`
|
|
IssueID int64 `json:"issue_id"`
|
|
ServerSeedHash string `json:"server_seed_hash"`
|
|
ItemsRoot string `json:"items_root"`
|
|
WeightsTotal int64 `json:"weights_total"`
|
|
StateVersion int32 `json:"state_version"`
|
|
}
|
|
|
|
// CommitIssueRandom 提交期随机承诺
|
|
// @Summary 提交期随机承诺
|
|
// @Description 为指定期生成并提交随机承诺(包含主种子哈希、奖项根、总权重)
|
|
// @Tags 管理端.活动
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param activity_id path integer true "活动ID"
|
|
// @Param issue_id path integer true "期ID"
|
|
// @Success 200 {object} issueCommitResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Security LoginVerifyToken
|
|
// @Router /api/admin/activities/{activity_id}/issues/{issue_id}/commit_random [post]
|
|
func (h *handler) CommitIssueRandom() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
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)
|
|
cm, err := h.activity.CommitIssueRandom(ctx.RequestContext(), issueID)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.CommitIssueRandomError, err.Error()))
|
|
return
|
|
}
|
|
ctx.Payload(&issueCommitResponse{
|
|
AlgoVersion: cm.AlgoVersion,
|
|
IssueID: cm.IssueID,
|
|
ServerSeedHash: hexStr(cm.ServerSeedHash[:]),
|
|
ItemsRoot: hexStr(cm.ItemsRoot[:]),
|
|
WeightsTotal: cm.WeightsTotal,
|
|
})
|
|
}
|
|
}
|
|
|
|
// GetIssueRandomCommit 获取期随机承诺
|
|
// @Summary 获取期随机承诺
|
|
// @Description 查询指定期当前有效的随机承诺详情
|
|
// @Tags 管理端.活动
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param activity_id path integer true "活动ID"
|
|
// @Param issue_id path integer true "期ID"
|
|
// @Success 200 {object} issueCommitResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Security LoginVerifyToken
|
|
// @Router /api/admin/activities/{activity_id}/issues/{issue_id}/commit_random [get]
|
|
func (h *handler) GetIssueRandomCommit() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
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)
|
|
cm, err := h.activity.GetIssueRandomCommit(ctx.RequestContext(), issueID)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.GetIssueRandomCommitError, err.Error()))
|
|
return
|
|
}
|
|
if cm == nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.GetIssueRandomCommitError, "未找到承诺"))
|
|
return
|
|
}
|
|
ctx.Payload(&issueCommitResponse{
|
|
AlgoVersion: cm.AlgoVersion,
|
|
IssueID: cm.IssueID,
|
|
ServerSeedHash: hexStr(cm.ServerSeedHash[:]),
|
|
ItemsRoot: hexStr(cm.ItemsRoot[:]),
|
|
WeightsTotal: cm.WeightsTotal,
|
|
StateVersion: cm.StateVersion,
|
|
})
|
|
}
|
|
}
|
|
|
|
// GetIssueRandomCommitHistory 获取期随机承诺历史
|
|
// @Summary 获取期随机承诺历史
|
|
// @Description 查询指定期的历史承诺记录列表(包含版本与哈希)
|
|
// @Tags 管理端.活动
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param activity_id path integer true "活动ID"
|
|
// @Param issue_id path integer true "期ID"
|
|
// @Success 200 {array} issueCommitResponse
|
|
// @Failure 400 {object} code.Failure
|
|
// @Security LoginVerifyToken
|
|
// @Router /api/admin/activities/{activity_id}/issues/{issue_id}/commit_random/history [get]
|
|
func (h *handler) GetIssueRandomCommitHistory() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
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)
|
|
history, err := h.activity.GetIssueRandomCommitHistory(ctx.RequestContext(), issueID)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.GetIssueRandomCommitError, err.Error()))
|
|
return
|
|
}
|
|
|
|
// 转换响应格式
|
|
response := make([]*issueCommitResponse, 0, len(history))
|
|
for _, commit := range history {
|
|
response = append(response, &issueCommitResponse{
|
|
AlgoVersion: commit.AlgoVersion,
|
|
IssueID: commit.IssueID,
|
|
ServerSeedHash: hexStr(commit.ServerSeedHash[:]),
|
|
ItemsRoot: hexStr(commit.ItemsRoot[:]),
|
|
WeightsTotal: commit.WeightsTotal,
|
|
StateVersion: commit.StateVersion,
|
|
})
|
|
}
|
|
ctx.Payload(response)
|
|
}
|
|
}
|
|
|
|
func hexStr(b []byte) string {
|
|
const hextable = "0123456789abcdef"
|
|
dst := make([]byte, len(b)*2)
|
|
j := 0
|
|
for _, v := range b {
|
|
dst[j] = hextable[v>>4]
|
|
dst[j+1] = hextable[v&0x0f]
|
|
j += 2
|
|
}
|
|
return string(dst)
|
|
} |