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

105 lines
3.3 KiB

package statistics
import (
"fmt"
"server/call"
"server/common"
"server/db"
"server/modules/backend/app"
"server/modules/backend/models"
utils "server/modules/backend/util"
"server/modules/backend/values"
"time"
"github.com/gin-gonic/gin"
)
// 付费分析
func RechargeData(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := new(values.RechargeDataReq)
if !a.S(req) {
return
}
var oneDay int64 = 24 * 60 * 60
resp := values.RechargeDataResp1{}
su, eu := utils.GetQueryUnix(req.Start, req.End)
e := eu - int64(((req.Page-1)*req.Num)*24*60*60)
s := e - int64((req.Num-1)*24*60*60)
if s < su {
s = su
}
resp.Count = (eu - su) / (24 * 60 * 60)
for i := s; i < e; i += oneDay {
j := i + oneDay
resp.List = append([]values.OneRechargeData{GetRechargeData(i, j, req.ChannelID)}, resp.List...)
}
resp.Total = GetRechargeData(su, eu, req.ChannelID)
a.Data = resp
}
func GetRechargeData(start, end int64, channel *int) values.OneRechargeData {
var res values.OneRechargeData
res.Date = time.Unix(start, 0).Format("20060102")
if channel != nil {
res.Channel = *channel
}
// 新玩家数
res.NewCount = models.GetNewPlayerCountBySql(channel, start, end)
// s := time.Unix(start, 0).Format("2006-01-02")
// e := time.Unix(end, 0).Format("2006-01-02")
sqlr := fmt.Sprintf("(event = %v or event = %v) and status = %v and create_time >= %d and create_time < %d", common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, common.StatusROrderPay, start, end)
if channel != nil {
sqlr = fmt.Sprintf("(event = %v or event = %v) and status = %v and create_time >= %d and create_time < %d and channel_id = %v", common.CurrencyEventReCharge, common.CurrencyEventGMRecharge, common.StatusROrderPay, start, end, *channel)
}
// 充值订单数
res.RechargeCount = db.Mysql().Count(&common.RechargeOrder{}, sqlr)
// 充值用户数(新用户+老用户)
res.RechargePlayerNum = models.GetPayCount(&start, &end, channel, nil)
var gitTotal int64
db.Mysql().C().Model(&common.RechargeOrder{}).Where(sqlr).Count(&gitTotal)
allGift := call.GetConfigPayProduct()
for i := 0; i < len(allGift); i++ {
var count int64
db.Mysql().C().Model(&common.RechargeOrder{}).Where(sqlr+" AND productid = ?", allGift[i].ProductID).Count(&count)
var rec values.RechargeStatistics
rec.GiftBag = allGift[i].ProductID
rec.Count = count
rec.RechargePer = utils.GetPer(count, gitTotal)
res.RechargeStatisticsList = append(res.RechargeStatisticsList, rec)
}
// 充值总额
res.RechargeTotal = models.GetAmountTotalBySQL(start, end, channel)
sql := fmt.Sprintf("event = %v and status = %v and create_time >= '%v' and create_time < '%v'", common.CurrencyEventWithDraw, common.StatusROrderFinish, start, end)
if channel != nil {
sql += fmt.Sprintf(" and channel_id = %v", *channel)
}
res.WithdrawTotal = db.Mysql().Sum(&common.RechargeOrder{}, sql, "amount")
res.WRPer = utils.GetPer(res.WithdrawTotal, res.RechargeTotal)
res.Profit = res.RechargeTotal - res.WithdrawTotal
active := models.GetNewPlayerCountBySql(channel, start, end) + models.GetOldPlayerCountBySql(channel, start, end)
res.ARPU = utils.GetPoint(res.RechargeTotal, active)
res.ARPPU = utils.GetPoint(res.RechargeTotal, res.RechargePlayerNum)
res.RechargePer = utils.GetPer(res.RechargePlayerNum, active)
return res
}