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

135 lines
3.5 KiB

1 year ago
package models
import (
"server/common"
"server/db"
"github.com/liangdas/mqant/log"
"github.com/olivere/elastic/v7"
)
// 付费用户数
func GetRecharge(start, end *int64, isNew bool, channel ...*int) int64 {
q := NewQ(start, end, nil)
q.Filter(elastic.NewRangeQuery("Amount").Gt(0))
if isNew {
q.Must(elastic.NewMatchQuery("IsNew", true))
}
q.Must(elastic.NewMatchQuery("Type", 1))
getChannelQ(q, channel...)
return db.ES().CountCard(common.ESIndexBackPlayerPayData, "UID", q)
}
// 付费总额
func GetRechargeTotal(start, end *int64, isNew bool, channel ...*int) int64 {
q := NewQ(start, end, channel...)
if isNew {
q.Must(elastic.NewMatchQuery("IsNew", true))
}
q.Must(elastic.NewMatchQuery("Type", 1))
total, err := db.ES().SumBy(common.ESIndexBackPlayerPayData, "Amount", q)
if err != nil {
log.Error("err:%v", err)
return 0
}
return int64(total)
}
// 付费玩家数量 Gt
func GetPayCount(start, end *int64, channel *int, isNew *bool) int64 {
q := NewQ(start, end, nil, channel)
if isNew != nil {
q.Must(elastic.NewMatchQuery("IsNew", true))
}
q.Must(elastic.NewMatchQuery("Type", 1))
q.Filter(elastic.NewRangeQuery("Amount").Gt(0))
return db.ES().CountCard(common.ESIndexBackPlayerPayData, "UID", q)
}
// 获取付费人数 Gt
func GetRechargePlayers(start, end *int64, channel *int, isNew *bool, field string) int64 {
q := NewQ(start, end, nil, channel)
if isNew != nil {
q.Must(elastic.NewMatchQuery("IsNew", *isNew))
}
q.Must(elastic.NewMatchQuery("Type", 1))
q.Filter(elastic.NewRangeQuery("Amount").Gt(0))
return db.ES().CountCard(common.ESIndexBackPlayerPayData, field, q)
}
// 付费总额
func GetRechargeTotalByUid(uid *int) int64 {
q := NewQ(nil, nil, nil, nil)
if uid != nil {
q.Must(elastic.NewMatchQuery("UID", *uid))
}
q.Must(elastic.NewMatchQuery("Type", 1))
total, err := db.ES().SumBy(common.ESIndexBackPlayerPayData, "Amount", q)
if err != nil {
log.Error("err:%v", err)
return 0
}
return int64(total)
}
// 退出总额
func GetWithdrawTotalByUid(uid *int) int64 {
q := NewQ(nil, nil, nil, nil)
if uid != nil {
q.Must(elastic.NewMatchQuery("UID", *uid))
}
q.Must(elastic.NewMatchQuery("Type", 2))
total, err := db.ES().SumBy(common.ESIndexBackPlayerPayData, "Amount", q)
if err != nil {
log.Error("err:%v", err)
return 0
}
return int64(total)
}
func GetWithdrawPlayer(start, end *int64, channel *int, isNew *bool, firstWithdraw bool) int64 {
q := NewQ(start, end, nil, channel)
if isNew != nil {
q.Must(elastic.NewMatchQuery("IsNew", *isNew))
}
if firstWithdraw {
q.Filter(elastic.NewRangeQuery("FirstAmount").Gt(0))
}
q.Must(elastic.NewMatchQuery("Type", 2))
q.Filter(elastic.NewRangeQuery("Amount").Gt(0))
return db.ES().CountCard(common.ESIndexBackPlayerPayData, "UID", q)
}
func GetWithdrawCount(start, end *int64, channel *int, isNew *bool, field string) int64 {
q := NewQ(start, end, nil, channel)
if isNew != nil {
q.Must(elastic.NewMatchQuery("IsNew", *isNew))
}
q.Must(elastic.NewMatchQuery("Type", 2))
q.Filter(elastic.NewRangeQuery("Amount").Gt(0))
res, err := db.ES().SumBy(common.ESIndexBackPlayerPayData, field, q)
if err != nil {
log.Error(err.Error())
}
return int64(res)
}
// 获取玩家首充金额
func GetUserFirstRecharge(uid int) int64 {
q := NewQ(nil, nil, nil, nil)
q.Must(elastic.NewMatchQuery("UID", uid))
q.Must(elastic.NewMatchQuery("Type", 1))
total, err := db.ES().SumBy(common.ESIndexBackPlayerPayData, "FirstAmount", q)
if err != nil {
log.Error("err:%v", err)
return 0
}
return int64(total)
}