package admin import ( "net/http" "strconv" "bindbox-game/internal/code" "bindbox-game/internal/pkg/core" ) type getDrawReceiptResponse struct { ID int64 `json:"id"` DrawLogID int64 `json:"draw_log_id"` AlgoVersion string `json:"algo_version"` RoundID int64 `json:"round_id"` DrawID int64 `json:"draw_id"` ClientID int64 `json:"client_id"` Timestamp int64 `json:"timestamp"` ServerSeedHash string `json:"server_seed_hash"` ServerSubSeed string `json:"server_sub_seed"` ClientSeed string `json:"client_seed"` Nonce int64 `json:"nonce"` ItemsRoot string `json:"items_root"` WeightsTotal int64 `json:"weights_total"` SelectedIndex int32 `json:"selected_index"` RandProof string `json:"rand_proof"` Signature string `json:"signature"` ItemsSnapshot string `json:"items_snapshot"` } func (h *handler) GetDrawReceipt() core.HandlerFunc { return func(ctx core.Context) { drawIDStr := ctx.Param("draw_id") if drawIDStr == "" { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递抽奖ID")) return } drawID, err := strconv.ParseInt(drawIDStr, 10, 64) if err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "抽奖ID格式错误")) return } // 查询抽奖收据 receipt, err := h.readDB.ActivityDrawReceipts.WithContext(ctx.RequestContext()). Where(h.readDB.ActivityDrawReceipts.DrawID.Eq(drawID)). First() if err != nil { ctx.AbortWithError(core.Error(http.StatusNotFound, code.GetDrawReceiptError, "未找到抽奖收据")) return } ctx.Payload(&getDrawReceiptResponse{ ID: receipt.ID, DrawLogID: receipt.DrawLogID, AlgoVersion: receipt.AlgoVersion, RoundID: receipt.RoundID, DrawID: receipt.DrawID, ClientID: receipt.ClientID, Timestamp: receipt.Timestamp, ServerSeedHash: receipt.ServerSeedHash, ServerSubSeed: receipt.ServerSubSeed, ClientSeed: receipt.ClientSeed, Nonce: receipt.Nonce, ItemsRoot: receipt.ItemsRoot, WeightsTotal: receipt.WeightsTotal, SelectedIndex: receipt.SelectedIndex, RandProof: receipt.RandProof, Signature: receipt.Signature, ItemsSnapshot: receipt.ItemsSnapshot, }) } } func (h *handler) GetDrawReceiptByLogID() core.HandlerFunc { return func(ctx core.Context) { logIDStr := ctx.Param("log_id") if logIDStr == "" { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递日志ID")) return } logID, err := strconv.ParseInt(logIDStr, 10, 64) if err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "日志ID格式错误")) return } // 查询抽奖收据 receipt, err := h.readDB.ActivityDrawReceipts.WithContext(ctx.RequestContext()). Where(h.readDB.ActivityDrawReceipts.DrawLogID.Eq(logID)). First() if err != nil { ctx.AbortWithError(core.Error(http.StatusNotFound, code.GetDrawReceiptError, "未找到抽奖收据")) return } ctx.Payload(&getDrawReceiptResponse{ ID: receipt.ID, DrawLogID: receipt.DrawLogID, AlgoVersion: receipt.AlgoVersion, RoundID: receipt.RoundID, DrawID: receipt.DrawID, ClientID: receipt.ClientID, Timestamp: receipt.Timestamp, ServerSeedHash: receipt.ServerSeedHash, ServerSubSeed: receipt.ServerSubSeed, ClientSeed: receipt.ClientSeed, Nonce: receipt.Nonce, ItemsRoot: receipt.ItemsRoot, WeightsTotal: receipt.WeightsTotal, SelectedIndex: receipt.SelectedIndex, RandProof: receipt.RandProof, Signature: receipt.Signature, ItemsSnapshot: receipt.ItemsSnapshot, }) } }