svip_user_charge.go 3.55 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 (
	"encoding/json"
	"fmt"
	"github.com/tealeg/xlsx"
	"io/ioutil"
	"net/http"
)

type AutoGenerated34 struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    struct {
hujiebin's avatar
hujiebin committed
15 16
		Total int                   `json:"total"`
		Data  []AutoGenerated34Data `json:"data"`
hujiebin's avatar
hujiebin committed
17 18 19
	} `json:"data"`
}

hujiebin's avatar
hujiebin committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33
type AutoGenerated34Data struct {
	UserID            int    `json:"userId"`
	Date              string `json:"date"`
	Country           string `json:"country"`
	UserCode          string `json:"userCode"`
	UserName          string `json:"userName"`
	ChargeMoney       string `json:"chargeMoney"`
	HaveFirst         int    `json:"haveFirst"`
	RegisterAt        string `json:"registerAt"`
	SvipLevel         int    `json:"svipLevel"`
	MaxDollar         int    `json:"maxDollar"`         // 历史最高单笔
	MaxDollarDuration int    `json:"maxDollarDuration"` // 时段最高单笔
}

hujiebin's avatar
hujiebin committed
34 35 36 37 38
func ats34(a interface{}) string {
	return fmt.Sprintf("%v", a)
}

func main() {
hujiebin's avatar
hujiebin committed
39 40
	//url := "https://apiv2.faceline.live/v1/stats/charge/user?lang=zh-cn&diamondType=2&beginDate=2023-10-01&endDate=2023-10-31&pageIndex=1&pageSize=10000&country=All&code=&area=1&timezone=1"
	//url := "https://apiv2.faceline.live/v1/stats/charge/user?lang=zh-cn&diamondType=1&beginDate=2022-06-01&endDate=2023-12-13&pageIndex=1&pageSize=4805&country=All&code=&area=1&timezone=0"
hujiebin's avatar
hujiebin committed
41 42 43 44 45 46 47
	var data []AutoGenerated34Data
	pageIndex := 1
	pageSize := 1000
	for {
		url := fmt.Sprintf("https://apiv2.faceline.live/v1/stats/charge/user?lang=zh-cn&diamondType=1&beginDate=2024-03-01&endDate=2024-03-31&pageIndex=%d&pageSize=%d&country=All&code=&area=2&timezone=0",
			pageIndex, pageSize)
		method := "GET"
hujiebin's avatar
hujiebin committed
48

hujiebin's avatar
hujiebin committed
49 50
		client := &http.Client{}
		req, err := http.NewRequest(method, url, nil)
hujiebin's avatar
hujiebin committed
51

hujiebin's avatar
hujiebin committed
52 53 54 55 56 57
		if err != nil {
			fmt.Println(err)
			return
		}
		req.Header.Add("nonce", "hilo")
		req.Header.Add("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjI1MSwiRXh0ZXJuYWxJZCI6IiIsImV4cCI6MTcxNDcxNjcyOH0.Mt_gpOenB25vRXDFM4u-oReTNMBYgS7ZvzQumQHOuvU")
hujiebin's avatar
hujiebin committed
58

hujiebin's avatar
hujiebin committed
59 60 61 62 63
		res, err := client.Do(req)
		if err != nil {
			fmt.Println(err)
			return
		}
hujiebin's avatar
hujiebin committed
64

hujiebin's avatar
hujiebin committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
		body, err := ioutil.ReadAll(res.Body)
		if err != nil {
			panic(err)
		}
		println(string(body))
		var response = new(AutoGenerated34)
		err = json.Unmarshal(body, &response)
		if err != nil {
			panic(err)
		}
		if len(response.Data.Data) <= 0 {
			break
		}
		data = append(data, response.Data.Data...)
		pageIndex++
hujiebin's avatar
hujiebin committed
80
	}
hujiebin's avatar
hujiebin committed
81
	excelFileName := fmt.Sprintf("./非阿语区黄钻充值20243月.xlsx")
hujiebin's avatar
hujiebin committed
82 83 84
	xlFile := xlsx.NewFile()
	sheet, _ := xlFile.AddSheet("charge")
	row := sheet.AddRow()
hujiebin's avatar
hujiebin committed
85 86
	c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 := row.AddCell(), 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, c10.Value = "日期", "国家", "用户ID", "用户昵称", "充值金额", "注册时间", "是否举办首场活动", "svip等级", "时段最高单笔", "历史最高单笔"
hujiebin's avatar
hujiebin committed
87
	for _, d := range data {
hujiebin's avatar
hujiebin committed
88
		row := sheet.AddRow()
hujiebin's avatar
hujiebin committed
89
		c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 := row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell(), row.AddCell()
hujiebin's avatar
hujiebin committed
90
		c1.Value, c2.Value, c3.Value, c4.Value, c5.Value, c6.Value = ats34(d.Date), ats34(d.Country), ats34(d.UserCode), ats34(d.UserName), ats34(d.ChargeMoney), ats34(d.RegisterAt)
hujiebin's avatar
hujiebin committed
91
		c7.Value, c8.Value, c9.Value, c10.Value = ats34(d.HaveFirst), ats34(d.SvipLevel), ats34(d.MaxDollarDuration), ats34(d.MaxDollar)
hujiebin's avatar
hujiebin committed
92 93 94
	}
	_ = xlFile.Save(excelFileName)
}