game_race_1m.go 1.6 KB
Newer Older
iamhujiebin's avatar
iamhujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
package main

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

type GameRacePlayer struct {
	Date   string
	Round  int
	Award  int64
	Stake  int64
	Code   string
	UserId uint64
}

func main() {
	var rows []GameRacePlayer
	if err := mysql.ProdReadOnlyDB.Table("game_race_player").Select("`date`,round,user_id,award,u.code").
		Joins("JOIN user u ON u.id = user_id").Where("award >= 1000000 AND `date` = '2023-11-06'").Find(&rows).Error; err != nil {
		panic(err)
	}
	for i, v := range rows {
		var user model.User
		if err := mysql.ProdReadOnlyDB.Table("user").Where("id = ?", v.UserId).First(&user).Error; err != nil {
			panic(err)
		}
		rows[i].Code = user.Code
		var stake int64
		if err := mysql.ProdReadOnlyDB.Table("game_race_stake").Select("SUM(stake)").
			Where("`date` = ? AND round = ? AND user_id = ?", v.Date, v.Round, v.UserId).Scan(&stake).Error; err != nil {
			panic(err)
		}
		rows[i].Stake = stake
	}
	excelFileName := fmt.Sprintf("./赛车1M.xlsx")
	xlFile := xlsx.NewFile()
	sheet, _ := xlFile.AddSheet("race")
	row := sheet.AddRow()
	c1, c2, c3, c4 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
	c1.Value, c2.Value, c3.Value, c4.Value = "用户ID", "轮次", "投注", "中奖"
	for _, d := range rows {
		row := sheet.AddRow()
		c1, c2, c3, c4 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
		c1.Value, c2.Value, c3.Value, c4.Value =
			ats37(d.Code), ats37(d.Round), ats37(d.Stake), ats37(d.Award)
	}
	_ = xlFile.Save(excelFileName)

}

func ats37(d interface{}) string {
	return fmt.Sprintf("%v", d)
}