race_day_award.go 3.4 KB
Newer Older
JiebinHu's avatar
JiebinHu 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
package main

import (
	"encoding/json"
	"fmt"
	"git.hilo.cn/hilo-common/script/mysql"
	"github.com/tealeg/xlsx"
	"io/ioutil"
	"net/http"
)

type RaceDayAward struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    struct {
		Total int `json:"total"`
		Data  []struct {
			Rank        int     `json:"rank"`
			UserCode    string  `json:"userCode"`
			Country     string  `json:"country"`
			Stake       int     `json:"stake"`
			Award       int     `json:"award"`
			ProfitLoss  int     `json:"profitLoss"`
			ChargeMoney float64 `json:"chargeMoney"`
		} `json:"data"`
	} `json:"data"`
}

type ResCountry3 struct {
	Name string
	Area int
}

func (ResCountry3) TableName() string {
	return "res_country"
}

type UserSvip3 struct {
	Code  string
	Level int
}

func ats33(a interface{}) string {
	return fmt.Sprintf("%v", a)
}

func main() {
hujiebin's avatar
hujiebin committed
48
	url := "https://apiv2.faceline.live/v1/race/rank/award?lang=zh-cn&pageIndex=1&pageSize=50000&beginDate=2023-08-20&endDate=2023-08-20&userCode=&timezone=1"
JiebinHu's avatar
JiebinHu committed
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
	method := "GET"

	client := &http.Client{}
	req, err := http.NewRequest(method, url, nil)

	if err != nil {
		fmt.Println(err)
		return
	}
	req.Header.Add("nonce", "hilo")
	req.Header.Add("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjI1MSwiRXh0ZXJuYWxJZCI6IiIsImV4cCI6MTY5MzIwNjcxOH0.V-5CfVUGbQDtn04vy85rjb2TtrfntZCuv209tUKFcgU")

	res, err := client.Do(req)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer res.Body.Close()

	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	var response = new(RaceDayAward)
	err = json.Unmarshal(body, &response)
	if err != nil {
		panic(err)
	}
	var countryArea = make(map[string]string)
	// get from db
	var countries []ResCountry3
	if err := mysql.ProdReadOnlyDB.Model(ResCountry3{}).Find(&countries).Error; err != nil {
		panic(err)
	}
	for _, v := range countries {
		area := "阿语"
		if v.Area == 2 {
			area = "非阿语"
		}
		countryArea[v.Name] = area
	}
	var svipMap = make(map[string]int)
	var codes []string
	for _, v := range response.Data.Data {
		codes = append(codes, v.UserCode)
	}
	var svips []UserSvip3
	if err := mysql.ProdReadOnlyDB.Table("user_svip s").Joins("INNER JOIN user u ON u.id = s.user_id").Select("u.code,s.level").Where("u.code in ?", codes).Find(&svips).Error; err != nil {
		panic(err)
	}
	for _, v := range svips {
		svipMap[v.Code] = v.Level
	}
hujiebin's avatar
hujiebin committed
102
	excelFileName := fmt.Sprintf("./0820赛车中奖榜.xlsx")
JiebinHu's avatar
JiebinHu committed
103 104 105 106 107 108 109 110 111 112 113 114 115
	xlFile := xlsx.NewFile()
	sheet, _ := xlFile.AddSheet("charge")
	row := sheet.AddRow()
	c1, c2, c3, c4, c5, c6, c7, c8, c9 := row.AddCell(), 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, c9.Value = "排名", "用户ID", "区域", "国家", "SVIP等级", "投注钻石数", "中奖钻石数", "盈亏(中奖-投注)", "充值金额$"
	for _, d := range response.Data.Data {
		row := sheet.AddRow()
		c1, c2, c3, c4, c5, c6, c7, c8, c9 := row.AddCell(), 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, c9.Value =
			ats33(d.Rank), ats33(d.UserCode), countryArea[d.Country], ats33(d.Country), ats33(svipMap[d.UserCode]), ats33(d.Stake), ats33(d.Award), ats33(d.ProfitLoss), ats33(d.ChargeMoney)
	}
	_ = xlFile.Save(excelFileName)
}