package main import ( "fmt" "git.hilo.cn/hilo-common/script/model" "git.hilo.cn/hilo-common/script/mysql" "github.com/tealeg/xlsx" ) type H5GameData struct { Game string // 游戏名字 Date string // 日期 UserId uint64 // 用户原始id Code string // 用户ID Stake uint64 // 下注 Award uint64 // 奖励 GoldCharge uint64 // 当日金币充值 DiamondCharge uint64 // 当日钻石充值 } func ats31(a interface{}) string { return fmt.Sprintf("%v", a) } func main() { wheel() fruit() } func wheel() { type GameListRank struct { Date string GameId uint64 UserId uint64 Stake uint64 Award uint64 } var rows []GameListRank // 摩天轮sql if err := mysql.ProdReadOnlyDB.Model(GameListRank{}).Where("game_id = 11").Find(&rows).Error; err != nil { panic(err) } var userIds []uint64 for _, v := range rows { userIds = append(userIds, v.UserId) } var users []model.User if err := mysql.ProdReadOnlyDB.Model(model.User{}).Where("id in ?", userIds).Find(&users).Error; err != nil { panic(err) } var uM = make(map[uint64]model.User) for i := range users { uM[users[i].Id] = users[i] } var data []H5GameData for _, row := range rows { data = append(data, H5GameData{ Game: "摩天轮", Date: row.Date, UserId: row.UserId, Stake: row.Stake, Award: row.Award, Code: uM[row.UserId].Code, GoldCharge: getChargeGolds(row.UserId, row.Date), DiamondCharge: getChargeDiamonds(row.UserId, row.Date), }) } excelFileName := fmt.Sprintf("./摩天轮.xlsx") xlFile := xlsx.NewFile() sheet, _ := xlFile.AddSheet("charge") row := sheet.AddRow() c1, c2, c3, c4, c5, c6, c7, c8 := 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, c7.Value, c8.Value = "游戏名字", "日期", "用户原始id", "用户ID", "下注", "奖励", "当日金币充值", "当日钻石充值" for _, d := range data { row := sheet.AddRow() c1, c2, c3, c4, c5, c6, c7, c8 := 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, c7.Value, c8.Value = d.Game, d.Date, ats31(d.UserId), d.Code, ats31(d.Stake), ats31(d.Award), ats31(d.GoldCharge), ats31(d.DiamondCharge) } _ = xlFile.Save(excelFileName) } func fruit() { type GameListRank struct { Date string GameId uint64 UserId uint64 Stake uint64 Award uint64 } var rows []GameListRank // 水果slot if err := mysql.ProdReadOnlyDB.Model(GameListRank{}).Where("game_id = 12").Find(&rows).Error; err != nil { panic(err) } var userIds []uint64 for _, v := range rows { userIds = append(userIds, v.UserId) } var users []model.User if err := mysql.ProdReadOnlyDB.Model(model.User{}).Where("id in ?", userIds).Find(&users).Error; err != nil { panic(err) } var uM = make(map[uint64]model.User) for i := range users { uM[users[i].Id] = users[i] } var data []H5GameData for _, row := range rows { data = append(data, H5GameData{ Game: "水果slot", Date: row.Date, UserId: row.UserId, Stake: row.Stake, Award: row.Award, Code: uM[row.UserId].Code, GoldCharge: getChargeGolds(row.UserId, row.Date), DiamondCharge: getChargeDiamonds(row.UserId, row.Date), }) } excelFileName := fmt.Sprintf("./水果slot.xlsx") xlFile := xlsx.NewFile() sheet, _ := xlFile.AddSheet("charge") row := sheet.AddRow() c1, c2, c3, c4, c5, c6, c7, c8 := 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, c7.Value, c8.Value = "游戏名字", "日期", "用户原始id", "用户ID", "下注", "奖励", "当日金币充值", "当日钻石充值" for _, d := range data { row := sheet.AddRow() c1, c2, c3, c4, c5, c6, c7, c8 := 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, c7.Value, c8.Value = d.Game, d.Date, ats31(d.UserId), d.Code, ats31(d.Stake), ats31(d.Award), ats31(d.GoldCharge), ats31(d.DiamondCharge) } _ = xlFile.Save(excelFileName) } func getChargeDiamonds(userId uint64, date string) uint64 { var res uint64 type R struct { Money uint64 } var money R if err := mysql.ProdReadOnlyDB.Table("pay_order AS p"). Where("p.status = 2 AND p.`type` = 0 AND platform >= 1 AND platform <= 6"). // type=0 就是用户给自己充值,status=2成功 Where("p.user_id = ? AND DATE(p.created_time) BETWEEN ? AND ?", userId, date, date).Select("SUM(price) as money").Scan(&money).Error; err != nil { panic(err) } res += money.Money var money2 R if err := mysql.ProdReadOnlyDB.Table("dealer_transfer_detail AS t"). Where("t.receiver_id = ? AND DATE(t.created_time) BETWEEN ? AND ?", userId, date, date).Select("SUM(t.dollar) as money"). Scan(&money2).Error; err != nil { panic(err) } res += money2.Money return res } func getChargeGolds(userId uint64, date string) uint64 { var res uint64 type R struct { Money uint64 } var money R if err := mysql.ProdReadOnlyDB.Table("pay_order AS p"). Where("p.status = 2 AND p.`type` = 0 AND platform >= 31"). // type=0 就是用户给自己充值,status=2成功 Where("p.user_id = ? AND DATE(p.created_time) BETWEEN ? AND ?", userId, date, date).Select("SUM(price) as money").Scan(&money).Error; err != nil { panic(err) } res += money.Money var money2 R if err := mysql.ProdReadOnlyDB.Table("dealer_transfer_detail_pink AS t"). Where("t.receiver_id = ? AND DATE(t.created_time) BETWEEN ? AND ?", userId, date, date).Select("SUM(t.dollar) as money"). Scan(&money2).Error; err != nil { panic(err) } res += money2.Money return res }