Commit 2057e602 authored by hujiebin's avatar hujiebin

Update fruit_machine_charge.go

parent 5cda68e6
...@@ -15,6 +15,9 @@ type FruitDayChargeData struct { ...@@ -15,6 +15,9 @@ type FruitDayChargeData struct {
DayChargeUserIds []uint64 // 当日充值用户id DayChargeUserIds []uint64 // 当日充值用户id
DayChargeMoney int64 // 当日充值金额 DayChargeMoney int64 // 当日充值金额
ChargeRecycle float64 // 充值用户回收 M ChargeRecycle float64 // 充值用户回收 M
Top100DayChargeCnt int // 投注榜TOP100的充值用户数
Top100DayChargeMoney int64 // 投注榜TOP100的当日充值金额
Top100ChargeRecycle float64 // 投注榜TOP100的回收
} }
func ats2(a interface{}) string { func ats2(a interface{}) string {
...@@ -33,10 +36,20 @@ func main() { ...@@ -33,10 +36,20 @@ func main() {
var data []FruitDayChargeData var data []FruitDayChargeData
for startTime.Before(endTime) { for startTime.Before(endTime) {
var userIds []uint64 var userIds []uint64
var top100UserIds []uint64
date := startTime.Format("2006-01-02") date := startTime.Format("2006-01-02")
if err := mysql.ProdReadOnlyDB.Table("fruit_machine_stake").Where("`date` = ?", date).Group("user_id").Select("user_id").Scan(&userIds).Error; err != nil { if err := mysql.ProdReadOnlyDB.Table("fruit_machine_stake").Where("`date` = ?", date).Group("user_id").Select("user_id").Scan(&userIds).Error; err != nil {
panic(err) panic(err)
} }
if err := mysql.ProdReadOnlyDB.Table("fruit_machine_stake").Where("`date` = ?", date).Group("user_id").
Order("SUM(stake) DESC").Limit(100).
Select("user_id").Scan(&top100UserIds).Error; err != nil {
panic(err)
}
top100UserIdMap := make(map[uint64]struct{})
for _, userId := range top100UserIds {
top100UserIdMap[userId] = struct{}{}
}
um1, err := GetDateChargeUserAndMoney(date, userIds) um1, err := GetDateChargeUserAndMoney(date, userIds)
if err != nil { if err != nil {
panic(err) panic(err)
...@@ -46,19 +59,33 @@ func main() { ...@@ -46,19 +59,33 @@ func main() {
panic(err) panic(err)
} }
userChargeNum := make(map[uint64]struct{}) userChargeNum := make(map[uint64]struct{})
top100UserChargeNum := make(map[uint64]struct{})
userChargeMoney := int64(0) userChargeMoney := int64(0)
top100UserChargeMoney := int64(0)
for _, um := range um1 { for _, um := range um1 {
userChargeNum[um.UserId] = struct{}{} userChargeNum[um.UserId] = struct{}{}
userChargeMoney += um.Money userChargeMoney += um.Money
if _, ok := top100UserIdMap[um.UserId]; ok {
top100UserChargeNum[um.UserId] = struct{}{}
top100UserChargeMoney += um.Money
}
} }
for _, um := range um2 { for _, um := range um2 {
userChargeNum[um.UserId] = struct{}{} userChargeNum[um.UserId] = struct{}{}
userChargeMoney += um.Money userChargeMoney += um.Money
if _, ok := top100UserIdMap[um.UserId]; ok {
top100UserChargeNum[um.UserId] = struct{}{}
top100UserChargeMoney += um.Money
}
} }
var chargeUserIds []uint64 var chargeUserIds []uint64
for userId := range userChargeNum { for userId := range userChargeNum {
chargeUserIds = append(chargeUserIds, userId) chargeUserIds = append(chargeUserIds, userId)
} }
var top100ChargeUserIds []uint64
for userId := range top100UserChargeNum {
top100ChargeUserIds = append(top100ChargeUserIds, userId)
}
userNum, err := GetFruitUserNum(date) userNum, err := GetFruitUserNum(date)
if err != nil { if err != nil {
panic(err) panic(err)
...@@ -71,6 +98,10 @@ func main() { ...@@ -71,6 +98,10 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
top100FruitChargeRecycle, err := GetFruitChargeRecycle(date, top100ChargeUserIds)
if err != nil {
panic(err)
}
data = append(data, FruitDayChargeData{ data = append(data, FruitDayChargeData{
Date: date, Date: date,
FruitUserNum: userNum, FruitUserNum: userNum,
...@@ -79,6 +110,9 @@ func main() { ...@@ -79,6 +110,9 @@ func main() {
DayChargeUserIds: userIds, DayChargeUserIds: userIds,
DayChargeMoney: userChargeMoney, DayChargeMoney: userChargeMoney,
ChargeRecycle: float64(fruitChargeRecycle) * 0.05 / 1000000, // 1M ChargeRecycle: float64(fruitChargeRecycle) * 0.05 / 1000000, // 1M
Top100DayChargeCnt: len(top100UserChargeNum),
Top100DayChargeMoney: top100UserChargeMoney,
Top100ChargeRecycle: float64(top100FruitChargeRecycle) * 0.05 / 1000000, // 1M
}) })
startTime = startTime.AddDate(0, 0, 1) startTime = startTime.AddDate(0, 0, 1)
} }
...@@ -87,12 +121,14 @@ func main() { ...@@ -87,12 +121,14 @@ func main() {
xlFile := xlsx.NewFile() xlFile := xlsx.NewFile()
sheet, _ := xlFile.AddSheet("charge") sheet, _ := xlFile.AddSheet("charge")
row := sheet.AddRow() row := sheet.AddRow()
c1, c2, c3, c4, c5, c6 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell() c1, c2, c3, c4, c5, c6, c7, c8, c9 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value = "日期", "参与人数", "总回收 M", "当日充值用户数", "当日充值金额(美分)", "充值用户回收 M" c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value, c7.Value, c8.Value, c9.Value = "日期", "参与人数", "总回收 M", "当日充值用户数", "当日充值金额(美分)", "充值用户回收 M",
"投注榜TOP100的充值用户数", "投注榜TOP100的当日充值金额(美分)", "投注榜TOP100的回收"
for _, d := range data { for _, d := range data {
row := sheet.AddRow() row := sheet.AddRow()
c1, c2, c3, c4, c5, c6 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell() c1, c2, c3, c4, c5, c6, c7, c8, c9 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value = d.Date, ats2(d.FruitUserNum), ats2(d.Recycle), ats2(d.DayChargeCnt), ats2(d.DayChargeMoney), ats2(d.ChargeRecycle) c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value = d.Date, ats2(d.FruitUserNum), ats2(d.Recycle), ats2(d.DayChargeCnt), ats2(d.DayChargeMoney), ats2(d.ChargeRecycle)
c7.Value, c8.Value, c9.Value = ats2(d.Top100DayChargeCnt), ats2(d.Top100DayChargeMoney), ats2(d.Top100ChargeRecycle)
} }
_ = xlFile.Save(excelFileName) _ = xlFile.Save(excelFileName)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment