sync_fruit_rank.go 1.69 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
package main

import (
	"git.hilo.cn/hilo-common/script/mysql"
	"time"
)

type FruitDayRank struct {
	Period string
	UserId uint64
	Stake  int64
	Award  int64
}

hujiebin's avatar
hujiebin committed
15 16 17 18 19 20 21
type FruitDayRankKsa struct {
	Period string
	UserId uint64
	Stake  int64
	Award  int64
}

hujiebin's avatar
hujiebin committed
22 23 24 25 26 27 28 29 30 31 32 33
type FruitMachineStake struct {
	Date   string
	UserId uint64
	Stake  int64
}

type FruitMachineAward struct {
	Date   string
	UserId uint64
	Award  int64
}

hujiebin's avatar
hujiebin committed
34 35
var Cstzone = time.FixedZone("CST", 3*3600) // 东三

hujiebin's avatar
hujiebin committed
36
func main() {
hujiebin's avatar
hujiebin committed
37
	start := time.Date(2023, time.January, 2, 0, 0, 0, 0, Cstzone)
hujiebin's avatar
hujiebin committed
38 39
	for start.Before(time.Now()) {
		var rows []FruitMachineStake
hujiebin's avatar
hujiebin committed
40 41
		if err := mysql.ProdReadOnlyDB.Table("fruit_machine_stake FORCE INDEX(created_time)").Where("DATE(`created_time`) = ?", start.Format("2006-01-02")).
			Select("`date`,user_id,SUM(stake) stake").Group("DATE(`created_time`),user_id").Find(&rows).Error; err != nil {
hujiebin's avatar
hujiebin committed
42 43 44
			panic(err)
		}
		for _, row := range rows {
hujiebin's avatar
hujiebin committed
45 46
			if err := mysql.ProdWriteDB.Create(FruitDayRankKsa{
				Period: start.Format("2006-01-02"),
hujiebin's avatar
hujiebin committed
47 48 49 50 51 52 53 54
				UserId: row.UserId,
				Stake:  row.Stake,
				Award:  0,
			}).Error; err != nil {
				panic(err)
			}
		}
		var rows2 []FruitMachineAward
hujiebin's avatar
hujiebin committed
55 56
		if err := mysql.ProdReadOnlyDB.Table("fruit_machine_player FORCE INDEX(created_time)").Where("DATE(`created_time`) = ?", start.Format("2006-01-02")).
			Select("`date`,user_id,SUM(award) award").Group("DATE(`created_time`),user_id").Find(&rows2).Error; err != nil {
hujiebin's avatar
hujiebin committed
57 58 59
			panic(err)
		}
		for _, row := range rows2 {
hujiebin's avatar
hujiebin committed
60
			if err := mysql.ProdWriteDB.Table("fruit_day_rank_ksa").Where("period = ? AND user_id = ?", start.Format("2006-01-02"), row.UserId).
hujiebin's avatar
hujiebin committed
61 62 63 64 65
				Update("award", row.Award).Error; err != nil {
				panic(err)
			}
		}
		start = start.AddDate(0, 0, 1)
hujiebin's avatar
hujiebin committed
66
		//break
hujiebin's avatar
hujiebin committed
67 68
	}
}