@@ -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, "")
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package active2023ctrl
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/crypt"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/active2023mod"
|
||||
"91porn-server/models/v/usermod"
|
||||
"91porn-server/models/v/walletmod"
|
||||
|
||||
"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/user_info [get]
|
||||
func UserInfo(ctx *gin.Context) {
|
||||
uid, err := common.GetUID(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrNoToken, nil)
|
||||
return
|
||||
}
|
||||
userInfo, err := usermod.FindUserByUID(uid)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, "")
|
||||
return
|
||||
}
|
||||
if userInfo == nil {
|
||||
common.ServeJSON(ctx, stderr.UserIsNotExists, "用户不存在")
|
||||
return
|
||||
}
|
||||
w, err := walletmod.GetWallet(uid)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, err.Error())
|
||||
return
|
||||
}
|
||||
totalRecharge, balance := int64(0), int64(0)
|
||||
if w != nil {
|
||||
totalRecharge = w.Consumption / 10
|
||||
balance = w.Amount + w.Income
|
||||
}
|
||||
active2023userInfo, err := active2023mod.GetActive2023UserInfoByID(nil, int64(uid))
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, err.Error())
|
||||
return
|
||||
}
|
||||
var lotteryTimes int64
|
||||
if active2023userInfo != nil {
|
||||
lotteryTimes = active2023userInfo.LotteryRemain
|
||||
}
|
||||
token := ctx.Request.Header.Get("Authorization")
|
||||
st := struct {
|
||||
UID uint64 `json:"uid"`
|
||||
UserName string `json:"user_name"`
|
||||
AppID int32 `json:"app_id"`
|
||||
TotalRecharge int64 `json:"total_recharge"` // 用户累计充值金额
|
||||
Balance int64 `json:"balance"` // 金币余额
|
||||
Token string `json:"token"`
|
||||
}{
|
||||
UID: userInfo.UID,
|
||||
UserName: userInfo.Name,
|
||||
AppID: commod.KFK_APPID,
|
||||
TotalRecharge: totalRecharge,
|
||||
Balance: balance,
|
||||
Token: token,
|
||||
}
|
||||
ct, _ := json.Marshal(st)
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"code": stderr.Success,
|
||||
"hash": false,
|
||||
"msg": "success",
|
||||
"tip": "",
|
||||
"data": struct {
|
||||
UID uint64 `json:"uid"`
|
||||
Data string `json:"data"`
|
||||
LotteryTimes int64 `json:"lottery_times"`
|
||||
}{
|
||||
UID: userInfo.UID,
|
||||
Data: encrypt(ct),
|
||||
LotteryTimes: lotteryTimes,
|
||||
},
|
||||
"time": time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
|
||||
})
|
||||
}
|
||||
|
||||
// 字段加密. 加密协议: AES-CBC-PCK5
|
||||
func encrypt(bts []byte) string {
|
||||
xpass, _ := crypt.AESCBCPck5Encrypt(bts, []byte("nU7cLOX7t3yJHq8yeIMCfO9emiOWtdlN"))
|
||||
return base64.StdEncoding.EncodeToString(xpass)
|
||||
}
|
||||
Reference in New Issue
Block a user