印度包网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
7.4 KiB

package guser
import (
"fmt"
"reflect"
"server/call"
"server/common"
"server/db"
"server/modules/backend/models"
"server/modules/backend/util"
"server/modules/backend/values"
"server/modules/customer/app"
uutil "server/util"
"sort"
"strconv"
"github.com/gin-gonic/gin"
"github.com/liangdas/mqant/log"
"github.com/olivere/elastic/v7"
)
func GetGameUserInfo(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := new(values.GetGameUserInfoReq)
if !a.S(req) {
return
}
user := &common.PlayerDBInfo{}
switch req.Data.(type) {
case int, int64, float32, float64:
id := uutil.GetInt(req.Data)
if id <= 999999999 {
user.Id = id
} else {
user.Mobile = strconv.Itoa(id)
}
case string:
str := req.Data.(string)
if len(str) == 10 {
user.Mobile = str
} else {
id, err := strconv.Atoi(str)
if err != nil {
a.Code = values.CodeParam
a.Msg = "玩家不存在"
return
}
user.Id = id
}
}
err := db.Mysql().Get(user)
if err != nil {
log.Error("err:%v", err)
a.Code = values.CodeParam
a.Msg = "玩家不存在"
return
}
uid := user.Id
ur, _ := call.GetUserXInfo(uid, "online")
info := &common.RechargeInfo{UID: uid}
err = db.Mysql().Get(info)
if err != nil {
log.Error(err.Error())
}
control := &common.PlayerControl{UID: uid}
err = db.Mysql().Get(control)
if err != nil {
log.Error(err.Error())
}
lg := &common.LoginRecord{UID: uid}
err = db.Mysql().GetLast(lg)
if err != nil {
log.Error(err.Error())
}
pointControl := &common.ConfigPointControl{UID: uid}
db.Mysql().Get(pointControl)
per := 0
tar := ""
if control.NewControlFin == 1 {
if control.NewControlLevel == 0 {
control.NewControlLevel = 1
}
con := call.GetNewControlConfigByID(control.NewControlLevel)
if con != nil {
control.TargetValue = con.ControlNum
per = con.ControlPer
tar = fmt.Sprintf("%v", control.TargetValue)
}
} else {
if control.ControlSection > 0 {
re := &common.RechargeInfo{UID: uid}
db.Mysql().Get(re)
con := call.GetSignleControlConfigByRecharge(re.TotalCharge)
if con != nil {
rcon := reflect.ValueOf(con).Elem()
per = int(rcon.FieldByName(fmt.Sprintf("ControlPer%v", control.ControlSection)).Int())
}
}
tar = uutil.FormatFloat(float64(control.TargetValue)/100, 2)
}
black := &common.ConfigMillionBlack{UID: uid}
db.Mysql().Get(black)
resp := values.GetGameUserInfoResp{
UID: user.Id,
Nick: user.Nick,
Recharge: info.TotalCharge,
Withdraw: info.TotoalWithdraw,
Channel: user.ChannelID,
Phone: user.Mobile,
OpenID: *user.Openid,
Cash: user.Cash,
Total: user.BindCash + user.Cash,
Online: ur.Online == common.PlayerOnline,
Status: user.Status,
Birth: user.Birth,
// PlayCount: util.GetGUserPlayCount(uid),
IP: user.IP,
LastLogin: lg.Time,
Tag: user.Tag,
IsFinishNewControl: control.NewControlFin == 2,
NewControlLevel: control.NewControlLevel,
ControlLevel: control.ControlLevel,
ControlSection: control.ControlSection,
ControlValue: uutil.FormatFloat(float64(control.ControlValue)/100, 2),
ControlPer: per,
TargetValue: tar,
FreeAmount: uutil.FormatFloat(float64(control.FreeAmount)/100, 2),
PointControlValue: uutil.FormatFloat(float64(pointControl.CurControlNum)/100, 2),
PointControlTargetValue: uutil.FormatFloat(float64(pointControl.ControlNum), 2),
PointControlPer: pointControl.ControlPer,
UserGameData: GetUserGameInfo(user.Id),
Gpsadid: user.DeviceId,
Black: black,
}
_, err = db.Mysql().QueryAll(fmt.Sprintf("deviceid = '%s'", user.DeviceId), "", &common.PlayerDBInfo{}, &resp.SubAccount)
if err != nil {
log.Error(err.Error())
}
a.Data = resp
}
// 获取用户游戏信息
func GetUserGameInfo(uid int) []values.UserGameInfo {
q := elastic.NewBoolQuery()
q.Filter(elastic.NewRangeQuery("uid").Gte(uid))
q.Filter(elastic.NewRangeQuery("uid").Lt(uid + 1))
q.Filter(elastic.NewRangeQuery("event").Gte(common.CurrencyEventGameSettle))
q.Filter(elastic.NewRangeQuery("event").Lt(common.CurrencyEventGameBet))
totalGameCount, _ := db.ES().GroupBy(common.ESIndexBalance, "desc.keyword", q, len(common.Games))
q.Filter(elastic.NewRangeQuery("value").Gt(0))
winGameCount, _ := db.ES().GroupBy(common.ESIndexBalance, "desc.keyword", q, len(common.Games))
q = elastic.NewBoolQuery()
q.Filter(elastic.NewRangeQuery("uid").Gte(uid))
q.Filter(elastic.NewRangeQuery("uid").Lt(uid + 1))
q.Filter(elastic.NewRangeQuery("event").Gte(common.CurrencyEventGameSettle))
q.Filter(elastic.NewRangeQuery("event").Lt(common.CurrencyEventGameBet))
totalBulk := new(common.GroupSumBuckets)
db.ES().GroupSumBy(common.ESIndexBalance, "desc.keyword", q, &totalBulk, "", false, 5000, "value")
q.Filter(elastic.NewRangeQuery("value").Gt(0))
winBulk := new(common.GroupSumBuckets)
db.ES().GroupSumBy(common.ESIndexBalance, "desc.keyword", q, &winBulk, "", false, 5000, "value")
tmp := map[int]values.UserGameInfo{}
for _, v := range common.RoomGameIDs {
tmp[v] = values.UserGameInfo{GameId: v, WinPer: "0%"}
}
for _, v := range common.MillionGameIDs {
tmp[uutil.GetInt(v)] = values.UserGameInfo{GameId: uutil.GetInt(v), WinPer: "0%"}
}
for _, v := range totalGameCount.Buckets {
id := uutil.GetInt(v.Key)
m := tmp[id]
m.GameCount += int64(v.Doc_count)
tmp[id] = m
}
for _, v := range winGameCount.Buckets {
id := uutil.GetInt(v.Key)
m := tmp[id]
m.WinCount += int64(v.Doc_count)
m.LoseCount = m.GameCount - m.WinCount
tmp[id] = m
}
for _, v := range totalBulk.Buckets {
id := uutil.GetInt(v.Key)
m := tmp[id]
m.Profit += int64(v.Value.Value)
m.WinPer = util.GetPer(m.WinCount, m.GameCount)
tmp[id] = m
}
for _, v := range winBulk.Buckets {
id := uutil.GetInt(v.Key)
m := tmp[id]
m.WinProfit += int64(v.Value.Value)
m.LoseProfit = m.Profit - m.WinProfit
m.WinPer = util.GetPer(m.WinCount, m.GameCount)
tmp[id] = m
}
var res []values.UserGameInfo
total := values.UserGameInfo{}
for _, v := range tmp {
res = append(res, v)
total.GameCount += v.GameCount
total.WinCount += v.WinCount
total.LoseCount += v.LoseCount
total.Profit += v.Profit
total.WinProfit += v.WinProfit
total.LoseProfit += v.LoseProfit
}
total.WinPer = util.GetPer(total.WinCount, total.GameCount)
sort.Slice(res, func(i, j int) bool {
return res[i].GameCount > res[j].GameCount
})
// 汇总
res = append([]values.UserGameInfo{total}, res...)
return res
}
func getUserGameData(uid int, gameId *int, win, lost *bool) values.UserGameInfo {
var userGameInfo values.UserGameInfo
if gameId == nil {
userGameInfo.GameId = 0
} else {
userGameInfo.GameId = *gameId
}
userGameInfo.GameCount = models.GetWinGameCountByBalance(nil, nil, &uid, nil, gameId, nil, nil)
userGameInfo.WinCount = models.GetWinGameCountByBalance(nil, nil, &uid, nil, gameId, nil, win)
userGameInfo.LoseCount = models.GetWinGameCountByBalance(nil, nil, &uid, nil, gameId, nil, lost)
userGameInfo.Profit = models.GetGameProfitByUid(nil, nil, &uid, nil, gameId, nil, nil)
userGameInfo.WinProfit = models.GetGameProfitByUid(nil, nil, &uid, nil, gameId, nil, win)
userGameInfo.LoseProfit = models.GetGameProfitByUid(nil, nil, &uid, nil, gameId, nil, lost)
userGameInfo.WinPer = util.GetPer(userGameInfo.WinCount, userGameInfo.GameCount)
return userGameInfo
}