h5_game_yellow.go 5.92 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
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
}