邹方成 c8b04e2bc6 feat(活动): 新增抽奖记录等级筛选功能并优化展示信息
refactor(抽奖记录): 重构抽奖记录列表接口,支持按等级筛选
新增用户昵称、头像及奖品名称、图片等展示字段
优化分页逻辑,默认返回最新100条记录

feat(游戏): 添加扫雷游戏验证和结算接口
新增游戏票据验证和结算相关接口定义及Swagger文档

docs(API): 更新Swagger文档
更新抽奖记录和游戏相关接口的文档描述

style(路由): 添加游戏路由注释
添加扫雷游戏接口路由的占位注释
2025-12-21 23:45:01 +08:00

113 lines
4.2 KiB
Go

package app
import (
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/pkg/validation"
"bindbox-game/internal/pkg/logger"
"bindbox-game/internal/repository/mysql"
"bindbox-game/internal/repository/mysql/dao"
"net/http"
)
type storeHandler struct {
logger logger.CustomLogger
readDB *dao.Query
}
func NewStore(logger logger.CustomLogger, db mysql.Repo) *storeHandler {
return &storeHandler{logger: logger, readDB: dao.Use(db.GetDbR())}
}
type listStoreItemsRequest struct {
Kind string `form:"kind"`
Page int `form:"page"`
PageSize int `form:"page_size"`
}
type listStoreItem struct {
ID int64 `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
MainImage string `json:"main_image"`
Price int64 `json:"price"`
InStock bool `json:"in_stock"`
Status int32 `json:"status"`
DiscountType int32 `json:"discount_type"`
DiscountValue int64 `json:"discount_value"`
MinSpend int64 `json:"min_spend"`
Supported bool `json:"supported"`
}
type listStoreItemsResponse struct {
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
List []listStoreItem `json:"list"`
}
// ListStoreItemsForApp 获取积分商城商品列表
// @Summary 获取积分商城商品列表
// @Description 分页获取积分商城商品列表,支持按类型筛选(product/item_card/coupon)
// @Tags APP端.积分商城
// @Accept x-www-form-urlencoded
// @Produce json
// @Security LoginVerifyToken
// @Param kind query string false "商品类型: product(默认), item_card, coupon"
// @Param page query int false "页码" default(1)
// @Param page_size query int false "每页数量" default(20)
// @Success 200 {object} listStoreItemsResponse
// @Failure 400 {object} code.Failure
// @Router /api/app/store/items [get]
func (h *storeHandler) ListStoreItemsForApp() core.HandlerFunc {
return func(ctx core.Context) {
req := new(listStoreItemsRequest)
if err := ctx.ShouldBindForm(req); err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
return
}
if req.Page <= 0 { req.Page = 1 }
if req.PageSize <= 0 { req.PageSize = 20 }
if req.PageSize > 100 { req.PageSize = 100 }
var total int64
var list []listStoreItem
offset := (req.Page - 1) * req.PageSize
limit := req.PageSize
switch req.Kind {
case "item_card":
q := h.readDB.SystemItemCards.WithContext(ctx.RequestContext()).ReadDB().Where(h.readDB.SystemItemCards.Status.Eq(1))
total, _ = q.Count()
rows, _ := q.Order(h.readDB.SystemItemCards.ID.Desc()).Offset(offset).Limit(limit).Find()
list = make([]listStoreItem, len(rows))
for i, it := range rows {
list[i] = listStoreItem{ID: it.ID, Kind: "item_card", Name: it.Name, Price: it.Price, Status: it.Status, Supported: true}
}
case "coupon":
q := h.readDB.SystemCoupons.WithContext(ctx.RequestContext()).ReadDB().Where(h.readDB.SystemCoupons.Status.Eq(1))
total, _ = q.Count()
rows, _ := q.Order(h.readDB.SystemCoupons.ID.Desc()).Offset(offset).Limit(limit).Find()
list = make([]listStoreItem, len(rows))
for i, it := range rows {
list[i] = listStoreItem{ID: it.ID, Kind: "coupon", Name: it.Name, DiscountType: it.DiscountType, DiscountValue: it.DiscountValue, MinSpend: it.MinSpend, Status: it.Status, Supported: it.DiscountType == 1}
}
default: // product
q := h.readDB.Products.WithContext(ctx.RequestContext()).ReadDB().Where(h.readDB.Products.Status.Eq(1))
total, _ = q.Count()
rows, _ := q.Order(h.readDB.Products.ID.Desc()).Offset(offset).Limit(limit).Find()
list = make([]listStoreItem, len(rows))
for i, it := range rows {
list[i] = listStoreItem{ID: it.ID, Kind: "product", Name: it.Name, MainImage: parseFirstImage(it.ImagesJSON), Price: it.Price, InStock: it.Stock > 0 && it.Status == 1, Status: it.Status, Supported: true}
}
}
ctx.Payload(&listStoreItemsResponse{
Total: total,
Page: req.Page,
PageSize: req.PageSize,
List: list,
})
}
}