fruit_fix.go 1.54 KB
Newer Older
hujiebin's avatar
hujiebin 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 57 58 59 60 61 62 63 64 65 66
package main

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

var userIds = []uint64{3117191}

type FruitMachine struct {
	Date    string
	Round   int64
	FruitId int
}

type FruitMachineStake2 struct {
	Stake int64
}

func main() {
	var Plus = make(map[int]int64) // fruitId->plush
	Plus[1] = 5
	Plus[2] = 5
	Plus[3] = 5
	Plus[4] = 5
	Plus[5] = 10
	Plus[6] = 15
	Plus[7] = 25
	Plus[8] = 45
	var data = make(map[uint64]int64)
	for round := 194; round <= 216; round++ {
		var fm = new(FruitMachine)
		if err := mysql.ProdReadOnlyDB.Model(FruitMachine{}).Where("`date` = '2023-08-09'").Where("round = ?", round).First(fm).Error; err != nil {
			panic(err)
		}
		for _, userId := range userIds {
			var fs = new(FruitMachineStake2)
			if err := mysql.ProdReadOnlyDB.Table("fruit_machine_stake").
				Where("`date` = '2023-08-09'").
				Where("round = ?", round).
				Where("fruit_id = ?", fm.FruitId).
				Where("user_id = ?", userId).First(&fs).Error; err != nil {
				if err != gorm.ErrRecordNotFound {
					panic(err)
				}
				continue
			}
			data[userId] += fs.Stake * Plus[fm.FruitId]
		}
	}
	excelFileName := fmt.Sprintf("./水果机.xlsx")
	xlFile := xlsx.NewFile()
	sheet, _ := xlFile.AddSheet("charge")
	row := sheet.AddRow()
	c1, c2 := row.AddCell(), row.AddCell()
	c1.Value, c2.Value = "userId", "should"
	for userId, award := range data {
		row := sheet.AddRow()
		c1, c2 := row.AddCell(), row.AddCell()
		c1.Value, c2.Value = fmt.Sprintf("%d", userId), fmt.Sprintf("%d", award)
	}
	_ = xlFile.Save(excelFileName)

}