promotion_data.go 3.91 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
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"`
}

hujiebin's avatar
1  
hujiebin committed
37
func ats38(a interface{}) string {
hujiebin's avatar
hujiebin committed
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
	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-10-01&endTime=2023-10-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.eyJVc2VySWQiOjI1MSwiRXh0ZXJuYWxJZCI6IiIsImV4cCI6MTcwMjU0NjkzMX0.-3OB6g_T9sX4XZIh3BaDlG7uSpYkRAcOh6PobBFyOKA")

		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("./推广员数据10月.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 =
hujiebin's avatar
1  
hujiebin committed
98 99
			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)
hujiebin's avatar
hujiebin committed
100 101 102
	}
	_ = xlFile.Save(excelFileName)
}