package main import ( "encoding/json" "fmt" "github.com/tealeg/xlsx" "io/ioutil" "net/http" ) type PromotionData struct { ID int `json:"id"` AgentCode string `json:"agentCode"` // 推广员id Name string `json:"name"` // 团队名称 InviteeCode string `json:"inviteeCode"` // 被邀请人id Platform string `json:"platform"` // 来自平台 PlatformId string `json:"platformId"` // 平台ID Reason string `json:"reason"` // 邀请原因 GroupCode string `json:"groupCode"` // 群组ID GroupMemberNum uint `json:"groupMemberNum"` // 群组人数 GroupTotalConsume uint64 `json:"groupTotalConsume"` // 群组奖杯 InviteDate string `json:"inviteDate"` // 邀请日期 MonthPaySum float64 `json:"monthPaySum"` // 30天内充值 $ TwoMonthPaySum float64 `json:"twoMonthPaySum"` // 60天内充值 $ MonthDealPaySum float64 `json:"monthDealPaySum"` // 30天内代理充值 $ } type PromotionDataResp struct { Code int `json:"code"` Message string `json:"message"` Data struct { Total int `json:"total"` Items []PromotionData `json:"items"` } `json:"data"` } func ats38(a interface{}) string { return fmt.Sprintf("%v", a) } func main() { var data []PromotionData pageIndex := 1 pageSize := 1000 for { url := fmt.Sprintf("https://apiv2.faceline.live/v1/mgr/promotion/invite/data?lang=zh-cn&pageIndex=%d&pageSize=%d&startTime=2023-12-01&endTime=2024-03-31&teamName=&agentCode=&inviteeCode=&platform=All", pageIndex, pageSize) 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.eyJVc2VySWQiOjI1MSwiRXh0ZXJuYWxJZCI6IiIsImV4cCI6MTcxNDcxNjcyOH0.Mt_gpOenB25vRXDFM4u-oReTNMBYgS7ZvzQumQHOuvU") res, err := client.Do(req) if err != nil { fmt.Println(err) return } body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } _ = res.Body.Close() var resp PromotionDataResp err = json.Unmarshal(body, &resp) if err != nil { panic(err) } if len(resp.Data.Items) <= 0 { break } data = append(data, resp.Data.Items...) pageIndex++ } excelFileName := fmt.Sprintf("./推广员数据12月1日-3月31日.xlsx") xlFile := xlsx.NewFile() sheet, err := xlFile.AddSheet("promotion") if err != nil { panic(err) } row := sheet.AddRow() c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13 := row.AddCell(), row.AddCell(), row.AddCell(), 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, c11.Value, c12.Value, c13.Value = "推广员id", "团队名称", "被邀请人id", "来自平台", "平台ID", "邀请原因", "群组ID", "群组人数", "群组奖杯", "邀请日期", "30天内充值 $", "60天内充值 $", "30天内代理充值 $" for _, d := range data { row := sheet.AddRow() c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13 := row.AddCell(), row.AddCell(), row.AddCell(), 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, c11.Value, c12.Value, c13.Value = ats38(d.AgentCode), ats38(d.Name), ats38(d.InviteeCode), ats38(d.Platform), ats38(d.PlatformId), ats38(d.Reason), ats38(d.GroupCode), ats38(d.GroupMemberNum), ats38(d.GroupTotalConsume), ats38(d.InviteDate), ats38(d.MonthPaySum), ats38(d.TwoMonthPaySum), ats38(d.MonthDealPaySum) } _ = xlFile.Save(excelFileName) }