package guser import ( "fmt" "server/db" "server/modules/backend/app" "server/modules/backend/models" utils "server/modules/backend/util" "server/modules/backend/values" "server/util" "github.com/gin-gonic/gin" "github.com/liangdas/mqant/log" ) 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 userSql, shareInfoSql, vipSql, rechargeInfoSql, cashSql []string userSql = append(userSql, fmt.Sprintf("birth >= %d", su), fmt.Sprintf("birth < %d", eu)) if req.UID > 0 { userSql = append(userSql, fmt.Sprintf("id = %d", req.UID)) } if req.Channel > 0 { userSql = append(userSql, fmt.Sprintf("channel_id = %d", req.Channel)) } if req.Country != "" { userSql = append(userSql, fmt.Sprintf("country = %s", req.Country)) } if req.Phone != "" { userSql = append(userSql, fmt.Sprintf("mobile = %s", req.Phone)) } if req.Status > 0 { userSql = append(userSql, fmt.Sprintf("status = %d", req.Status)) } if req.Platform > 0 { userSql = append(userSql, fmt.Sprintf("platform = %d", req.Platform)) } if req.Online > 0 { userSql = append(userSql, fmt.Sprintf("online = %d", req.Online)) } if len(req.LastLogin) > 0 { userSql = append(userSql, fmt.Sprintf("last_login >= %d", req.LastLogin[0])) if len(req.LastLogin) > 1 { userSql = append(userSql, fmt.Sprintf("last_login < %d", req.LastLogin[1])) } } if req.UP > 0 { shareInfoSql = append(shareInfoSql, fmt.Sprintf("up1 = %d", req.UP)) } if len(req.VIP) > 0 { vipSql = append(vipSql, fmt.Sprintf("level >= %d", req.VIP[0])) if len(req.VIP) > 1 { vipSql = append(vipSql, fmt.Sprintf("level <= %d", req.VIP[1])) } } if req.IsRecharge > 0 { if req.IsRecharge == 1 { rechargeInfoSql = append(rechargeInfoSql, "total_recharge > 0") } else { rechargeInfoSql = append(rechargeInfoSql, "total_recharge = 0") } } if len(req.Recharge) > 0 { rechargeInfoSql = append(rechargeInfoSql, fmt.Sprintf("total_recharge >= %d", req.Recharge[0])) if len(req.Recharge) > 1 { rechargeInfoSql = append(rechargeInfoSql, fmt.Sprintf("total_recharge <= %d", req.Recharge[1])) } } if len(req.RechargeCount) > 0 { rechargeInfoSql = append(rechargeInfoSql, fmt.Sprintf("total_recharge_count >= %d", req.RechargeCount[0])) if len(req.RechargeCount) > 1 { rechargeInfoSql = append(rechargeInfoSql, fmt.Sprintf("total_recharge_count <= %d", req.RechargeCount[1])) } } if len(req.Withdraw) > 0 { rechargeInfoSql = append(rechargeInfoSql, fmt.Sprintf("total_withdraw >= %d", req.Withdraw[0])) if len(req.Withdraw) > 1 { rechargeInfoSql = append(rechargeInfoSql, fmt.Sprintf("total_withdraw <= %d", req.Withdraw[1])) } } if len(req.Cash) > 0 { cashSql = append(cashSql, fmt.Sprintf("brl >= %d", req.Cash[0])) if len(req.Cash) > 1 { cashSql = append(cashSql, fmt.Sprintf("brl <= %d", req.Cash[1])) } } linkB := "LEFT JOIN" if len(shareInfoSql) > 0 { linkB = "INNER JOIN" } linkC := "LEFT JOIN" if len(vipSql) > 0 { linkC = "INNER JOIN" } linkD := "LEFT JOIN" if len(rechargeInfoSql) > 0 { linkD = "INNER JOIN" } baseSql := fmt.Sprintf(` (SELECT id,channel_id,country,mobile,status,platform,birth,last_login,tag,online from users %s)a %s (SELECT uid,up1 from share_info %s)b on a.id = b.uid %s (SELECT uid,level from vip_data %s)c on a.id = c.uid %s (SELECT uid,total_recharge,total_recharge_count,total_withdraw,total_withdraw_count,total_recharge-total_withdraw as diff from recharge_info %s)d on a.id = d.uid INNER JOIN (SELECT uid,brl from player_currency %s)e on a.id = e.uid `, models.LinkMysqlCondi(userSql), linkB, models.LinkMysqlCondi(shareInfoSql), linkC, models.LinkMysqlCondi(vipSql), linkD, models.LinkMysqlCondi(rechargeInfoSql), models.LinkMysqlCondi(cashSql)) // 拉列表语句 sql := `SELECT a.id as UID,a.channel_id as ChannelID,a.country as Country,c.level as Level,a.mobile as Mobile,b.up1 as Up,a.status as Status, a.platform as Platform,a.online as Online,d.total_recharge as TotalRecharge,d.total_recharge_count as TotalRechargeCount,d.total_withdraw as TotalWithdraw, d.total_withdraw_count as TotalWithdrawCount,e.brl as Brl,d.diff as Diff,a.last_login as LastLogin,a.birth as Birth,a.tag as Tag From ` + baseSql // 求和语句 sqlCount := `SELECT count(*) From ` + baseSql // 排序 if req.Order != 0 { orderSql := "order by" abs := util.Abs(int64(req.Order)) switch abs { case 1: orderSql += " d.total_recharge" case 2: orderSql += " d.total_recharge_count" case 3: orderSql += " d.total_withdraw" case 4: orderSql += " e.brl" case 5: orderSql += " d.diff" case 6: orderSql += " a.last_login" case 7: orderSql += " a.birth" } if req.Order < 0 { orderSql += " desc" } sql += orderSql } else { sql += " order by a.id desc" } // 分页 sql += fmt.Sprintf(" limit %d,%d", (req.Page-1)*req.Num, req.Num) resp := values.GetGameUserListResp{} if err := db.Mysql().C().Raw(sql).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} // 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) // 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 } a.Data = resp }