@@ -0,0 +1,69 @@
|
||||
package active2023ctrl
|
||||
|
||||
import (
|
||||
"91porn-server/app/appg"
|
||||
"91porn-server/app/service/active2023ser"
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/constant/redisconst"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/v/usermod"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// UserInfo doc
|
||||
// @Summary 抽奖
|
||||
// @Description 抽奖
|
||||
// @Tags annou
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /api/app/active2023/lottery [post]
|
||||
func Lottery(ctx *gin.Context) {
|
||||
uid, err := common.GetUID(ctx)
|
||||
if err != nil && err != common.ErrUserNotExist {
|
||||
common.ServeJSON(ctx, stderr.UserIsNotExists, nil)
|
||||
return
|
||||
}
|
||||
if uid == 0 {
|
||||
common.ServeJSON(ctx, stderr.UserIsNotExists, nil)
|
||||
return
|
||||
}
|
||||
var req active2023ser.LotteryReq
|
||||
if err = ctx.ShouldBind(&req); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, nil)
|
||||
return
|
||||
}
|
||||
if len(req.Prizes) == 0 {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, "获奖为空")
|
||||
return
|
||||
}
|
||||
userInfo, err := usermod.RefreshCacheAndGetUser(uid) // 因为抽奖可能会频繁刷新用户权益, 因此需要刷新用户缓存以保证获取用户最新信息
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, "")
|
||||
return
|
||||
}
|
||||
if userInfo == nil {
|
||||
common.ServeJSON(ctx, stderr.UserIsNotExists, "用户不存在")
|
||||
return
|
||||
}
|
||||
redisKey := redisconst.GetUserActive2023RedisKey(uid)
|
||||
success, err := appg.Redis.Setnx_NewOK(redisKey, "1", redisconst.GetUserActive2023Expred())
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, "")
|
||||
return
|
||||
}
|
||||
if !success {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, "请求过于频繁, 请稍后再试")
|
||||
return
|
||||
}
|
||||
defer func() { _, _ = appg.Redis.Del(redisKey) }()
|
||||
if err = active2023ser.Lottery(userInfo, req); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("lottery success", log.Any("uid", uid), log.Any("count", req.Count), log.Any("gold cost", req.Gold), log.Any("prizes", req.Prizes))
|
||||
common.ServeJSON(ctx, stderr.Success, "")
|
||||
}
|
||||
Reference in New Issue
Block a user