fruit_slot_race_charge_history_sum.go 3.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package main

import (
	"fmt"
	"git.hilo.cn/hilo-common/script/mysql"
	"github.com/tealeg/xlsx"
)

type FruitSlotRaceChargeHistoryData struct {
	UserId  uint64
	Code    string
	Area    string
	Country string
	Bet     uint64  // 5月份
	Dollar  float64 // 累充金额$
}

func ats42(a interface{}) string {
	return fmt.Sprintf("%v", a)
}

hujiebin's avatar
hujiebin committed
22 23
var start, end = "2024-05-13 05:00:00", "2024-05-20 05:00:00" // 左闭右开,沙特时间

24
func main() {
hujiebin's avatar
hujiebin committed
25

26 27
	var charges []FruitSlotRaceChargeHistoryData
	if err := mysql.ProdReadOnlyDB.Raw("select id as user_id,code,SUM(dollar) as dollar,country FROM " +
hujiebin's avatar
hujiebin committed
28
		"(select u.id,u.`code`,SUM(price) / 100 as dollar,u.country FROM pay_order p, `user` u  where  u.id = p.user_id AND p.`status` = 2 AND `type` = 0 AND p.created_time >= \"" + start + "\" AND p.created_time < \"" + end + "\" group by user_id" +
29
		" UNION ALL " +
hujiebin's avatar
hujiebin committed
30
		"select u.id,u.code,SUM(dollar) / 100 as dollar,u.country FROM dealer_transfer_detail d, `user` u where u.id = d.receiver_id AND d.created_time >= \"" + start + "\" AND d.created_time < \"" + end + "\" group by receiver_id " +
31
		" UNION ALL " +
hujiebin's avatar
hujiebin committed
32
		"select u.id,u.code,SUM(dollar) / 100 as dollar,u.country FROM dealer_transfer_detail_pink d, `user` u where u.id = d.receiver_id AND d.created_time >= \"" + start + "\" AND d.created_time < \"" + end + "\" group by receiver_id" +
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
		") t group by code order by dollar DESC").Find(&charges).Error; err != nil {
		panic(err)
	}
	type ResCountry struct {
		Name string
		Area int
	}
	var countries []ResCountry
	if err := mysql.ProdReadOnlyDB.Model(ResCountry{}).Find(&countries).Error; err != nil {
		panic(err)
	}
	countryMap := make(map[string]string)
	for _, c := range countries {
		countryMap[c.Name] = "阿语"
		if c.Area == 2 {
			countryMap[c.Name] = "非阿语"
		}
	}
	var userIds []uint64
	for _, v := range charges {
		userIds = append(userIds, v.UserId)
	}
	bets := GetBets(userIds)
	for i, uc := range charges {
		charges[i].Area = countryMap[uc.Country]
		charges[i].Bet = bets[uc.UserId]
	}

hujiebin's avatar
hujiebin committed
61
	excelFileName := fmt.Sprintf("./5月13日-5月19日水果机slot赛车数据.xlsx")
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
	xlFile := xlsx.NewFile()
	sheet, err := xlFile.AddSheet("data")
	if err != nil {
		panic(err)
	}
	row := sheet.AddRow()
	c1, c2, c3, c4, c5 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
	c1.Value, c2.Value, c3.Value, c4.Value, c5.Value = "用户ID", "区域", "国家", "5月水果机+Slot+赛车的总下注钻石额", "上周充值金额"
	for _, d := range charges {
		row := sheet.AddRow()
		c1, c2, c3, c4, c5 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
		c1.Value, c2.Value, c3.Value, c4.Value, c5.Value = d.Code, d.Area, d.Country, ats42(d.Bet), ats42(d.Dollar)
	}
	_ = xlFile.Save(excelFileName)
}

func GetBets(userIds []uint64) map[uint64]uint64 {
	type Bet struct {
		UserId uint64
		Num    uint64
	}
	var bets []Bet
	res := make(map[uint64]uint64)
hujiebin's avatar
hujiebin committed
85
	sql := "select user_id,SUM(num) num FROM diamond_account_detail_202405 where operate_type in (69,39,117) AND created_time >= \"" + start + "\" AND created_time < \"" + end + "\" and user_id in ? group by user_id"
86 87 88 89 90 91 92 93
	if err := mysql.ProdReadOnlyDB.Raw(sql, userIds).Find(&bets).Error; err != nil {
		panic(err)
	}
	for _, v := range bets {
		res[v.UserId] = v.Num
	}
	return res
}