svip_user_charge.go 3.31 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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 {
		Total int `json:"total"`
		Data  []struct {
hujiebin's avatar
hujiebin committed
17 18 19 20 21 22 23 24 25 26 27
			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
28 29 30 31 32 33 34 35 36
		} `json:"data"`
	} `json:"data"`
}

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

func main() {
hujiebin's avatar
hujiebin committed
37 38 39
	//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"
	url := "https://apiv2.faceline.live/v1/stats/charge/user?lang=zh-cn&diamondType=1&beginDate=2023-12-01&endDate=2023-12-31&pageIndex=2&pageSize=2500&country=All&code=&area=2&timezone=0"
hujiebin's avatar
hujiebin committed
40 41 42 43 44 45 46 47 48 49
	method := "GET"

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

	if err != nil {
		fmt.Println(err)
		return
	}
	req.Header.Add("nonce", "hilo")
hujiebin's avatar
hujiebin committed
50
	req.Header.Add("token", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOjI1MSwiRXh0ZXJuYWxJZCI6IiIsImV4cCI6MTcwNTIxODE0MH0.Xb7DU89AUYBahJfV4MDcr-pBbsLJcf1VM0WgnCNb-ig")
hujiebin's avatar
hujiebin committed
51 52 53 54 55 56 57 58 59 60 61 62

	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)
	}
hujiebin's avatar
hujiebin committed
63
	println(string(body))
hujiebin's avatar
hujiebin committed
64 65 66 67 68
	var response = new(AutoGenerated34)
	err = json.Unmarshal(body, &response)
	if err != nil {
		panic(err)
	}
hujiebin's avatar
hujiebin committed
69
	excelFileName := fmt.Sprintf("./非阿语区黄钻充值202312月2.xlsx")
hujiebin's avatar
hujiebin committed
70 71 72
	xlFile := xlsx.NewFile()
	sheet, _ := xlFile.AddSheet("charge")
	row := sheet.AddRow()
hujiebin's avatar
hujiebin committed
73 74
	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
75 76
	for _, d := range response.Data.Data {
		row := sheet.AddRow()
hujiebin's avatar
hujiebin committed
77
		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
78
		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
79
		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
80 81 82
	}
	_ = xlFile.Save(excelFileName)
}