印度包网
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.
 
 
 

231 lines
8.3 KiB

package guser
import (
"fmt"
"server/call"
"server/common"
"server/db"
"server/modules/backend/models"
utils "server/modules/backend/util"
"server/modules/backend/values"
"server/modules/customer/app"
"server/util"
"time"
"github.com/gin-gonic/gin"
"github.com/liangdas/mqant/log"
"github.com/olivere/elastic/v7"
)
func GetGameUserList(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := new(values.GetGameUserListReq)
if !a.S(req) {
return
}
su, eu := utils.GetQueryUnix(req.Start, req.End)
var sqlList, sqlTotal, sqlCount string
if req.ExcWithdraw {
// list
sqlList = fmt.Sprintf("SELECT a.id AS UID,"+ // 用户uid
"a.nick AS Nick,"+ // 用户昵称
"a.status AS Status,"+ // 用户状态
"a.mobile AS Phone,"+ // 用户手机号
"a.birth AS Birth,"+ // 用户生日
"(a.cash+a.bind_cash) AS TotalCash,"+ // 用户总金额
"a.cash AS Cash,"+ // 用户可提现现金
"IFNULL(b.total_charge,0) AS Recharge,"+ // 用户充值金额
"IFNULL(b.total_withdraw,0) AS Withdraw,"+ // 用户提现金额
"a.online AS Online "+ // 用户是否在线
"FROM users AS a LEFT JOIN recharge_info AS b ON a.id = b.uid WHERE b.total_withdraw >= b.total_charge AND a.role <> 100 AND a.birth >= %d AND a.birth < %d", su, eu)
// total
sqlTotal = fmt.Sprintf("SELECT SUM(a.cash+a.bind_cash) AS CashTotal,"+ // 总金额
"SUM(a.cash) AS WithdrawableTotal,"+ // 总可提现现金
"SUM(b.total_charge) AS RechargeTotal,"+ // 总充值
"SUM(b.total_withdraw) AS WithdrawHistoryTotal, "+ // 历史提现
"COUNT((IF(a.cash>=10000,TRUE,NULL))) AS WithdrawPlayerCount "+ // 提现玩家数量
"FROM users AS a LEFT JOIN recharge_info AS b ON a.id = b.uid WHERE b.total_withdraw >= b.total_charge AND a.role <> 100 AND a.birth >= %d AND a.birth < %d", su, eu)
// count
sqlCount = fmt.Sprintf("SELECT count(*) FROM users AS a LEFT JOIN recharge_info AS b ON a.id = b.uid WHERE b.total_withdraw >= b.total_charge AND a.role<>100 AND a.birth >= %d AND a.birth < %d", su, eu)
} else {
// list
sqlList = fmt.Sprintf("SELECT a.id AS UID,"+ // 用户uid
"a.nick AS Nick,"+ // 用户昵称
"a.status AS Status,"+ // 用户状态
"a.mobile AS Phone,"+ // 用户手机号
"a.birth AS Birth,"+ // 用户生日
"(a.cash+a.bind_cash) AS TotalCash,"+ // 用户总金额
"a.cash AS Cash,"+ // 用户可提现现金
"IFNULL(b.total_charge,0) AS Recharge,"+ // 用户充值金额
"IFNULL(b.total_withdraw,0) AS Withdraw,"+ // 用户提现金额
"a.online AS Online "+ // 用户是否在线
"FROM users AS a LEFT JOIN recharge_info AS b ON a.id = b.uid WHERE a.role <> 100 AND a.birth >= %d AND a.birth < %d", su, eu)
// total
sqlTotal = fmt.Sprintf("SELECT SUM(a.cash+a.bind_cash) AS CashTotal,"+ // 总金额
"SUM(a.cash) AS WithdrawableTotal,"+ // 总可提现现金
"SUM(b.total_charge) AS RechargeTotal,"+ // 总充值
"SUM(b.total_withdraw) AS WithdrawHistoryTotal, "+ // 历史提现
"COUNT((IF(a.cash>=10000,TRUE,NULL))) AS WithdrawPlayerCount "+ // 提现玩家数量
"FROM users AS a LEFT JOIN recharge_info AS b ON a.id = b.uid WHERE a.role <> 100 AND a.birth >= %d AND a.birth < %d", su, eu)
// count
sqlCount = fmt.Sprintf("SELECT count(*) FROM users WHERE role<>100 AND birth >= %d AND birth < %d", su, eu)
}
order := "a.birth"
sort := ""
if req.Order != nil {
if *req.Order < 0 {
sort = " desc"
*req.Order = -*req.Order
}
switch *req.Order {
case 1: // 1是按玩家充值金额排序
order = "b.total_charge"
case 2: // 2是按金币数量排序
order = "a.cash+a.bind_cash"
case 3: // 3是按可提现总额排序
order = "a.cash"
case 4: // 4是按历史提现金额排序
order = "b.total_withdraw"
case 5: // 5是按注册时间排序
order = "a.birth"
default:
a.Code = values.CodeParam
a.Msg = "排序参数不合法"
return
}
}
if req.Channel != nil {
sqlList += fmt.Sprintf(" and a.channel_id = %d ", *req.Channel)
sqlTotal += fmt.Sprintf(" and a.channel_id = %d ", *req.Channel)
sqlCount += fmt.Sprintf(" and channel_id = %d ", *req.Channel)
}
if req.Status != nil {
sqlList += fmt.Sprintf(" and a.status = %v", *req.Status)
sqlCount += fmt.Sprintf(" and status = %v", *req.Status)
sqlTotal += fmt.Sprintf(" and status = %v", *req.Status)
}
if req.Online != nil {
sqlList += fmt.Sprintf(" and a.online = %v", *req.Online)
sqlCount += fmt.Sprintf(" and online = %v", *req.Online)
sqlTotal += fmt.Sprintf(" and online = %v", *req.Online)
}
if req.CoinLimit != nil {
CoinLimit := *req.CoinLimit
if len(CoinLimit) < 2 {
sqlList += fmt.Sprintf(" and %d <= (a.cash + a.bind_cash) and (a.cash + a.bind_cash) <= %d", 0, 3000)
sqlCount += fmt.Sprintf(" and %d <= (cash + bind_cash) and (cash + bind_cash) <= %d", 0, 3000)
sqlTotal += fmt.Sprintf(" and %d <= (cash + bind_cash) and (cash + bind_cash) <= %d", 0, 3000)
} else {
if CoinLimit[1] == 0 {
sqlList += fmt.Sprintf(" and %d <= (a.cash + a.bind_cash) ", CoinLimit[0])
sqlCount += fmt.Sprintf(" and %d <= (cash + bind_cash) ", CoinLimit[0])
sqlTotal += fmt.Sprintf(" and %d <= (cash + bind_cash) ", CoinLimit[0])
} else {
sqlList += fmt.Sprintf(" and %d <= (a.cash + a.bind_cash) and (a.cash + a.bind_cash) <= %d", CoinLimit[0], CoinLimit[1])
sqlCount += fmt.Sprintf(" and %d <= (cash + bind_cash) and (cash + bind_cash) <= %d", CoinLimit[0], CoinLimit[1])
sqlTotal += fmt.Sprintf(" and %d <= (cash + bind_cash) and (cash + bind_cash) <= %d", CoinLimit[0], CoinLimit[1])
}
}
}
sqlList += fmt.Sprintf(" ORDER BY %v %v LIMIT %v OFFSET %v", order, sort, req.Num, (req.Page-1)*req.Num)
resp := values.GetGameUserListResp{}
if err := db.Mysql().C().Raw(sqlList).Scan(&resp.List).Error; err != nil {
log.Error("err:%v", err)
a.Code = values.CodeRetry
return
}
// isWin := true
uids := []interface{}{}
for i, v := range resp.List {
lg := &common.LoginRecord{UID: v.UID}
err := db.Mysql().GetLast(lg)
if err != nil {
log.Error(err.Error())
}
resp.List[i].LastLogin = lg.Time
uids = append(uids, v.UID)
// winCount := models.GetWinGameCountByBalance(nil, nil, &resp.List[i].UID, req.Channel, nil, nil, &isWin)
// resp.List[i].GameCount = models.GetGameCountByBalance(nil, nil, &resp.List[i].UID, req.Channel, nil, nil)
// resp.List[i].WinPer = utils.GetPer(winCount, resp.List[i].GameCount)
controlInfo := &common.PlayerControl{UID: v.UID}
err = db.Mysql().GetLast(controlInfo)
if err != nil {
log.Error(err.Error())
}
resp.List[i].ControlInfo = *controlInfo
data := common.CurrencyBalance{}
q := elastic.NewBoolQuery()
q.Filter(elastic.NewRangeQuery("uid").Gte(resp.List[i].UID))
q.Filter(elastic.NewRangeQuery("uid").Lt(resp.List[i].UID + 1))
q.Filter(elastic.NewRangeQuery("event").Gte(common.CurrencyEventGameSettle))
q.Filter(elastic.NewRangeQuery("event").Lt(common.CurrencyEventGameBet))
err = db.ES().QueryOne(common.ESIndexBalance, q, &data, "id", false)
if err != nil {
log.Error("err:%v", err)
resp.List[i].PlayerStatus = nil
} else {
if data.Time >= (time.Now().Unix() - 60) {
resp.List[i].PlayerStatus = map[string]string{
"gameId": data.Desc,
"roomId": data.RoomName,
}
}
}
user, _ := call.GetUserInfo(v.UID)
resp.List[i].AccountCount = int(db.Mysql().Count(&common.PlayerDBInfo{}, fmt.Sprintf("deviceid = '%v'", user.DeviceId)))
}
total := models.GetGameCountByUIDs(uids, false)
win := models.GetGameCountByUIDs(uids, true)
for i, v := range resp.List {
for _, u := range total.Buckets {
if util.GetInt(u.Key) == v.UID {
resp.List[i].GameCount = int64(u.Doc_count)
break
}
}
var winCount int64
for _, u := range win.Buckets {
if util.GetInt(u.Key) == v.UID {
winCount = int64(u.Doc_count)
break
}
}
resp.List[i].WinPer = utils.GetPer(winCount, resp.List[i].GameCount)
}
if err := db.Mysql().C().Raw(sqlCount).Scan(&resp.Count).Error; err != nil {
log.Error("err:%v", err)
a.Code = values.CodeRetry
return
}
if err := db.Mysql().C().Raw(sqlTotal).Scan(&resp.Total).Error; err != nil {
log.Error("err:%v", err)
a.Code = values.CodeRetry
return
}
resp.Total.WithdrawPlayerPer = utils.GetPer(resp.Total.WithdrawPlayerCount, resp.Count)
resp.Total.UnRechargePlayerCash, resp.Total.UnRechargePlayerAmount = models.GetUnRechargePlayerAmount(req.Channel, su, eu)
a.Data = resp
}