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.
137 lines
3.8 KiB
137 lines
3.8 KiB
package es |
|
|
|
import ( |
|
"server/common" |
|
"strconv" |
|
|
|
"github.com/liangdas/mqant/log" |
|
"github.com/olivere/elastic/v7" |
|
) |
|
|
|
// QueryPlayerBalance 查询玩家牌局流水记录 |
|
func (ES *EsClient) QueryPlayerBalance(uid, page, num, event int, start, end *int64, ret *[]common.CurrencyBalance, gameID ...int) (int64, error) { |
|
q := elastic.NewBoolQuery() |
|
q.Must(elastic.NewMatchQuery("uid", uid)) |
|
q.Must(elastic.NewMatchQuery("event", event)) |
|
if start != nil { |
|
q.Filter(elastic.NewRangeQuery("time").Gte(*start)) |
|
} |
|
if end != nil { |
|
q.Filter(elastic.NewRangeQuery("time").Lt(*end)) |
|
} |
|
// querys := []*elastic.BoolQuery{} |
|
if gameID != nil { |
|
q.Must(elastic.NewTermsQuery("desc.keyword", gameID[0])) |
|
} |
|
// for _, v := range gameID { |
|
// // querys = append(querys, q.Should(elastic.NewMatchQuery("desc.keyword", v))) |
|
// // q.Must(q.Should(elastic.NewMatchQuery("desc.keyword", v))) |
|
// log.Debug("gameID:%v", v) |
|
// q.Must(elastic.NewMatchQuery("desc.keyword", v)) |
|
// } |
|
// if len(querys) > 0 { |
|
// q.Must(querys...) |
|
// } |
|
count, err := ES.QueryList(common.ESIndexBalance, page, num, q, ret, "time", false) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
return 0, err |
|
} |
|
return count, err |
|
} |
|
|
|
// QueryPlayerAllBalance 查询玩家所有流水记录 |
|
func (ES *EsClient) QueryPlayerAllBalance(uid *int, page, num int, start, end *int64, ret *[]common.CurrencyBalance) (int64, error) { |
|
q := elastic.NewBoolQuery() |
|
if uid != nil { |
|
q.Must(elastic.NewMatchQuery("uid", uid)) |
|
} |
|
if start != nil { |
|
q.Filter(elastic.NewRangeQuery("time").Gte(*start)) |
|
} |
|
if end != nil { |
|
q.Filter(elastic.NewRangeQuery("time").Lt(*end)) |
|
} |
|
|
|
count, err := ES.QueryList(common.ESIndexBalance, page, num, q, ret, "time", false) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
return 0, err |
|
} |
|
return count, err |
|
} |
|
|
|
// QueryPlayerBalance 查询玩家控杀流水记录 |
|
func (ES *EsClient) QueryPlayerControlBalance(uid, page, num int, start, end *int64, ret *[]common.CurrencyBalance, controlType *int, gameID ...int) (int64, error) { |
|
q := elastic.NewBoolQuery() |
|
q.Must(elastic.NewMatchQuery("uid", uid)) |
|
q.Must(elastic.NewMatchQuery("event", common.CurrencyEventGameSettle)) |
|
q.Filter(elastic.NewRangeQuery("control_type").Gt(0)) |
|
if start != nil { |
|
q.Filter(elastic.NewRangeQuery("time").Gte(*start)) |
|
} |
|
if end != nil { |
|
q.Filter(elastic.NewRangeQuery("time").Lt(*end)) |
|
} |
|
if gameID != nil { |
|
q.Must(elastic.NewTermsQuery("desc.keyword", gameID[0])) |
|
} |
|
|
|
if controlType != nil { |
|
q.Must(elastic.NewTermsQuery("control_type", *controlType)) |
|
} |
|
|
|
count, err := ES.QueryList(common.ESIndexBalance, page, num, q, ret, "time", false) |
|
if err != nil { |
|
log.Error("err:%v", err) |
|
return 0, err |
|
} |
|
return count, err |
|
} |
|
|
|
// 通过流水表查询盈亏 |
|
func (ES *EsClient) GetProfit(start, end *int64, channel *int, gameId *int, roomId *int, event *int) int64 { |
|
q := NewQt(start, end, nil, channel) |
|
|
|
if event != nil { |
|
q.Must(elastic.NewMatchQuery("event", *event)) |
|
} |
|
|
|
if gameId != nil { |
|
q.Must(elastic.NewMatchQuery("desc.keyword", strconv.Itoa(*gameId))) |
|
} |
|
|
|
if roomId != nil { |
|
q.Must(elastic.NewMatchQuery("room_name.keyword", strconv.Itoa(*roomId))) |
|
} |
|
million, err := ES.SumBy(common.ESIndexBalance, "value", q) |
|
if err != nil { |
|
log.Error("查询盈亏失败, error : [%s]", err.Error()) |
|
return 0 |
|
} |
|
return -int64(million) |
|
} |
|
|
|
func NewQt(start, end *int64, channel ...*int) *elastic.BoolQuery { |
|
q := elastic.NewBoolQuery() |
|
if start != nil { |
|
q.Filter(elastic.NewRangeQuery("time").Gte(*start)) |
|
} |
|
if end != nil { |
|
q.Filter(elastic.NewRangeQuery("time").Lt(*end)) |
|
} |
|
if len(channel) > 0 { |
|
var valueArr []interface{} |
|
for _, v := range channel { |
|
if v == nil { |
|
continue |
|
} |
|
valueArr = append(valueArr, *v) |
|
} |
|
if len(valueArr) > 0 { |
|
q.Must(elastic.NewTermsQuery("ChannelID", valueArr...)) |
|
} |
|
} |
|
|
|
return q |
|
}
|
|
|