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) }