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.
196 lines
6.8 KiB
196 lines
6.8 KiB
package statistics |
|
|
|
import ( |
|
"server/call" |
|
"server/common" |
|
"server/db" |
|
"server/modules/backend/app" |
|
"server/modules/backend/bdb" |
|
utils "server/modules/backend/util" |
|
"server/modules/backend/values" |
|
"server/util" |
|
"sort" |
|
"strconv" |
|
"strings" |
|
"sync" |
|
"time" |
|
|
|
"github.com/gin-gonic/gin" |
|
"github.com/olivere/elastic/v7" |
|
) |
|
|
|
// 应用概要 |
|
func ReviewAppSummary(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.ReviewAppSummaryReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
resp := values.ReviewAppSummaryResp{} |
|
|
|
su, eu := utils.GetQueryUnix(req.Start, req.End) |
|
zero := util.GetZeroTime(time.Now()).Unix() |
|
channelArr := call.GetChannelList() |
|
var tempChannelArr []int |
|
|
|
for k := 0; k < len(channelArr); k++ { |
|
if len(a.User.SChannels) > 0 { |
|
if !util.SliceContain(a.User.SChannels, channelArr[k].ChannelID) { |
|
continue |
|
} |
|
} |
|
if req.IsShow { |
|
if channelArr[k].Show == 2 { |
|
tempChannelArr = append(tempChannelArr, channelArr[k].ChannelID) |
|
} |
|
} else { |
|
if channelArr[k].Show != 2 { |
|
tempChannelArr = append(tempChannelArr, channelArr[k].ChannelID) |
|
} |
|
} |
|
} |
|
|
|
group := new(sync.WaitGroup) |
|
group.Add(len(tempChannelArr)) |
|
resp.PlatformData = make([]*values.ReviewData, len(tempChannelArr)) |
|
if eu >= zero { |
|
for m := 0; m < len(tempChannelArr); m++ { |
|
index := m |
|
util.Go(func() { |
|
one := values.GetReviewData(tempChannelArr[index]) |
|
if one == nil { |
|
one = GetReviewPlatformData(su, eu, &tempChannelArr[index]) |
|
} |
|
resp.PlatformData[index] = one |
|
group.Done() |
|
}) |
|
} |
|
} else { |
|
list := []*values.ReviewData{} |
|
q := elastic.NewBoolQuery() |
|
q.Filter(elastic.NewRangeQuery("Time").Gte(su)) |
|
q.Filter(elastic.NewRangeQuery("Time").Lt(eu)) |
|
db.ES().QueryList(common.ESIndexBackAppSummary, 0, 5000, q, &list) |
|
|
|
for m := range tempChannelArr { |
|
index := m |
|
util.Go(func() { |
|
var one *values.ReviewData |
|
for i, v := range list { |
|
if tempChannelArr[index] == v.PlatformID { |
|
one = list[i] |
|
break |
|
} |
|
} |
|
if one == nil { |
|
one = GetReviewPlatformData(su, eu, &tempChannelArr[index]) |
|
one.Time = su |
|
bdb.BackDB.Create(one) |
|
} |
|
resp.PlatformData[index] = one |
|
group.Done() |
|
}) |
|
} |
|
} |
|
group.Wait() |
|
resp.Total = &values.ReviewData{} |
|
// var newRigist, newPlayTime, oldPlayTime, activePlayTime, arppu, withdrawSuccess float64 |
|
var newRigist float64 |
|
if len(tempChannelArr) != 0 { |
|
resp.Total.NewCount = 0 |
|
resp.Total.DownloadCount = 0 |
|
// resp.Total.NewPlayCount = 0 |
|
resp.Total.NewPayCount = 0 |
|
resp.Total.NewPayRepeatCount = 0 |
|
resp.Total.NewPayAmount = 0 |
|
// resp.Total.OldCount = 0 |
|
// resp.Total.OldPayCount = 0 |
|
// resp.Total.OldPayAmount = 0 |
|
// resp.Total.OldPlayCount = 0 |
|
resp.Total.ActiveCount = 0 |
|
// resp.Total.ActivePlayCount = 0 |
|
resp.Total.ActivePayCount = 0 |
|
resp.Total.RechargeTotal = 0 |
|
resp.Total.WithdrawTotal = 0 |
|
// resp.Total.WithdrawCount = 0 |
|
resp.Total.WithdrawPlayerNum = 0 |
|
|
|
for i := 0; i < len(resp.PlatformData); i++ { |
|
resp.Total.NewCount += resp.PlatformData[i].NewCount |
|
resp.Total.DownloadCount += resp.PlatformData[i].DownloadCount |
|
// resp.Total.NewPlayCount += resp.PlatformData[i].NewPlayCount |
|
resp.Total.NewPayCount += resp.PlatformData[i].NewPayCount |
|
resp.Total.NewPayRepeatCount += resp.PlatformData[i].NewPayRepeatCount |
|
resp.Total.NewPayAmount += resp.PlatformData[i].NewPayAmount |
|
// resp.Total.OldCount += resp.PlatformData[i].OldCount |
|
// resp.Total.OldPayCount += resp.PlatformData[i].OldPayCount |
|
// resp.Total.OldPayAmount += resp.PlatformData[i].OldPayAmount |
|
// resp.Total.OldPlayCount += resp.PlatformData[i].OldPlayCount |
|
resp.Total.ActiveCount += resp.PlatformData[i].ActiveCount |
|
// resp.Total.ActivePlayCount += resp.PlatformData[i].ActivePlayCount |
|
resp.Total.ActivePayCount += resp.PlatformData[i].ActivePayCount |
|
resp.Total.RechargeTotal += resp.PlatformData[i].RechargeTotal |
|
resp.Total.WithdrawTotal += resp.PlatformData[i].WithdrawTotal |
|
// resp.Total.WithdrawCount += resp.PlatformData[i].WithdrawCount |
|
resp.Total.WithdrawPlayerNum += resp.PlatformData[i].WithdrawPlayerNum |
|
nr, _ := strconv.ParseFloat(strings.ReplaceAll(resp.PlatformData[i].NewRegisterPer, "%", ""), 64) |
|
newRigist += nr |
|
// np, _ := strconv.ParseFloat(resp.PlatformData[i].NewPlayTime, 64) |
|
// newPlayTime += np |
|
// op, _ := strconv.ParseFloat(resp.PlatformData[i].OldPlayTime, 64) |
|
// oldPlayTime += op |
|
// ap, _ := strconv.ParseFloat(resp.PlatformData[i].ActivePlayTime, 64) |
|
// activePlayTime += ap |
|
// ar, _ := strconv.ParseFloat(resp.PlatformData[i].ARPPU, 64) |
|
// arppu += ar |
|
// ws, _ := strconv.ParseFloat(strings.ReplaceAll(resp.PlatformData[i].EmailWithdrawSuccess, "%", ""), 64) |
|
// withdrawSuccess += ws |
|
} |
|
|
|
resp.Total.NewRegisterPer = utils.GetPer(resp.Total.NewCount, resp.Total.DownloadCount) |
|
resp.Total.NewPayPer = utils.GetPer(resp.Total.NewPayCount, resp.Total.NewCount) |
|
// resp.Total.NewPlayPer = utils.GetPer(resp.Total.NewPlayCount, resp.Total.NewCount) |
|
// resp.Total.NewARPU = utils.GetPoint(resp.Total.NewPayAmount, resp.Total.NewCount) |
|
// resp.Total.OldPayPer = utils.GetPer(resp.Total.OldPayCount, resp.Total.OldCount) |
|
// resp.Total.OldPlayPer = utils.GetPer(resp.Total.OldPlayCount, resp.Total.OldCount) |
|
// resp.Total.ActivePayPer = utils.GetPer(resp.Total.ActivePayCount, resp.Total.ActiveCount) |
|
// resp.Total.ActivePlayPer = utils.GetPer(resp.Total.ActivePlayCount, resp.Total.ActiveCount) |
|
// resp.Total.ActiveARPU = utils.GetPoint(resp.Total.RechargeTotal, resp.Total.ActiveCount) |
|
resp.Total.WithdrawPer = utils.GetPer(resp.Total.WithdrawTotal, resp.Total.RechargeTotal) |
|
|
|
resp.Total.NewRegisterPer = utils.GetPer(int64(newRigist*100), int64(len(tempChannelArr))*10000) |
|
// resp.Total.NewPlayTime = util.FormatFloat(newPlayTime/float64(len(tempChannelArr)), 2) |
|
// resp.Total.OldPlayTime = util.FormatFloat(oldPlayTime/float64(len(tempChannelArr)), 2) |
|
// resp.Total.ActivePlayTime = util.FormatFloat(activePlayTime/float64(len(tempChannelArr)), 2) |
|
// resp.Total.ARPPU = util.FormatFloat(arppu/float64(len(tempChannelArr)), 2) |
|
// resp.Total.EmailWithdrawSuccess = utils.GetPer(int64(withdrawSuccess*100), int64(len(tempChannelArr))*10000) |
|
} |
|
|
|
switch req.Sort { |
|
case 1: |
|
// 注册用户排序 |
|
sort.SliceStable(resp.PlatformData, func(i, j int) bool { |
|
return resp.PlatformData[i].NewCount > resp.PlatformData[j].NewCount |
|
}) |
|
case 2: |
|
// 活跃用户排序 |
|
sort.SliceStable(resp.PlatformData, func(i, j int) bool { |
|
return resp.PlatformData[i].ActiveCount > resp.PlatformData[j].ActiveCount |
|
}) |
|
case 3: |
|
// 充值数排序 |
|
sort.SliceStable(resp.PlatformData, func(i, j int) bool { |
|
return resp.PlatformData[i].RechargeTotal > resp.PlatformData[j].RechargeTotal |
|
}) |
|
default: |
|
// 注册用户排序 |
|
sort.SliceStable(resp.PlatformData, func(i, j int) bool { |
|
return resp.PlatformData[i].NewCount > resp.PlatformData[j].NewCount |
|
}) |
|
} |
|
|
|
a.Data = resp |
|
}
|
|
|