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

122 lines
3.4 KiB

package guser
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/liangdas/mqant/log"
"github.com/olivere/elastic/v7"
"server/common"
"server/db"
utils "server/modules/backend/util"
"server/modules/backend/values"
"server/modules/customer/app"
"server/util"
)
func ActiveUserList(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := new(values.ActiveUserListReq)
if !a.S(req) {
return
}
var resp values.ActiveUserListResp
su, eu := utils.GetQueryUnix(req.Start, req.End)
queryCount := " SELECT COUNT(*) FROM login_record WHERE "
str := fmt.Sprintf(" time >= %d AND time < %d ", su, eu)
if req.Channel != nil {
str += fmt.Sprintf(" AND channel_id = %d ", *req.Channel)
}
if req.Status != nil {
str += fmt.Sprintf(" AND status = %v ", req.Status)
}
var count int64
err := db.Mysql().QueryBySql(queryCount+str, &count)
if err != nil {
log.Error(err.Error())
}
sql := fmt.Sprintf(
`SELECT d.id,d.nick,d.status,d.birth,d.cash,d.bind_cash,d.online,d.time,IFNULL(c.total_charge,0) as total_charge,IFNULL(c.total_withdraw,0) as total_withdraw from
(SELECT id,nick,status,birth,cash,bind_cash,online,b.time from users as a
INNER JOIN
(SELECT uid,max(time) as time from login_record WHERE time >= %d and time < %d GROUP BY uid) as b
on a.id = b.uid
LIMIT %d,%d
) as d
LEFT JOIN
(SELECT uid,total_charge,total_withdraw from recharge_info) as c
on d.id = c.uid`, su, eu, (req.Page-1)*req.Num, req.Num)
list := []values.ActiveUserOne{}
if err := db.Mysql().C().Raw(sql).Scan(&list).Error; err != nil {
log.Error("err:%v", err)
}
uids := []interface{}{}
for _, v := range list {
uids = append(uids, v.ID)
resp.List = append(resp.List, values.ActiveUserInfo{
UID: int64(v.ID),
Nick: v.Nick,
Status: v.Status,
Birth: v.Birth,
LastLogin: v.Time,
Recharge: v.TotalCharge,
Withdraw: v.TotalWithdraw,
Cash: v.Cash,
TotalCash: v.Cash + v.BindCash,
Online: v.Online,
})
}
q := elastic.NewBoolQuery()
q.Filter(elastic.NewRangeQuery("time").Gte(list[0].Birth))
q.Filter(elastic.NewRangeQuery("event").Gte(common.CurrencyEventGameSettle))
q.Filter(elastic.NewRangeQuery("event").Lt(common.CurrencyEventGameBet))
q.Must(elastic.NewTermsQuery("uid", uids...))
totalGameCount, _ := db.ES().GroupBy(common.ESIndexBalance, "uid", q, len(list))
q.Filter(elastic.NewRangeQuery("value").Gt(0))
winGameCount, _ := db.ES().GroupBy(common.ESIndexBalance, "uid", q, len(list))
q = elastic.NewBoolQuery()
q.Filter(elastic.NewRangeQuery("time").Gte(su))
q.Filter(elastic.NewRangeQuery("time").Lt(eu))
q.Filter(elastic.NewRangeQuery("event").Gte(common.CurrencyEventGameSettle))
q.Filter(elastic.NewRangeQuery("event").Lt(common.CurrencyEventGameBet))
q.Must(elastic.NewTermsQuery("uid", uids...))
todayGameCount, _ := db.ES().GroupBy(common.ESIndexBalance, "uid", q, len(list))
for i, v := range resp.List {
for _, u := range totalGameCount.Buckets {
if util.GetInt64(u.Key) == v.UID {
resp.List[i].GameCount = int64(u.Doc_count)
break
}
}
var winCount int64
for _, u := range winGameCount.Buckets {
if util.GetInt64(u.Key) == v.UID {
winCount = int64(u.Doc_count)
break
}
}
resp.List[i].WinPer = utils.GetPer(winCount, resp.List[i].GameCount)
for _, u := range todayGameCount.Buckets {
if util.GetInt64(u.Key) == v.UID {
resp.List[i].TodayCount = int64(u.Doc_count)
break
}
}
}
resp.Count = count
a.Data = resp
}