package bbxt import ( "ai_scheduler/internal/pkg" "ai_scheduler/internal/pkg/l_request" "encoding/json" "fmt" "net/http" "net/url" "strings" ) type StatisOursProductLossSumReq struct { ResellerId int `json:"reseller_id,omitempty"` Ct []string `json:"ct,omitempty"` } type StatisOursProductLossSumRes struct { List []*StatisOursProductLossSumResponse `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` } type StatisOursProductLossSumResponse struct { OursProductId int32 `json:"oursProductId,omitempty"` OursProductName string `json:"oursProductName,omitempty"` ResellerName string `json:"resellerName,omitempty"` ResellerId int32 `json:"resellerId,omitempty"` Loss float64 `json:"loss,omitempty"` } const Base = "https://reportapi.1688sup.com/api" // StatisOursProductLossSumApi 负利润分析 func StatisOursProductLossSumApi(param *StatisOursProductLossSumReq) (*StatisOursProductLossSumRes, error) { url := "/dataanalytics/statisOursProductLossSum" var res StatisOursProductLossSumRes if err := request(url, param, &res); err != nil { return nil, err } return &res, nil } type GetProfitRankingSumRequest struct { Ct []string `protobuf:"bytes,1,rep,name=ct,proto3" json:"ct,omitempty"` Page int32 `protobuf:"varint,3,opt,name=page,proto3" json:"page,omitempty"` Limit int32 `protobuf:"varint,4,opt,name=limit,proto3" json:"limit,omitempty"` ResellerIds []int32 `protobuf:"varint,5,rep,packed,name=reseller_ids,json=resellerIds,proto3" json:"reseller_ids,omitempty"` } type GetProfitRankingSumResponse struct { List []*ProfitRankingSumResponse `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` DataCount int32 `protobuf:"varint,2,opt,name=data_count,json=dataCount,proto3" json:"data_count,omitempty"` } type ProfitRankingSumResponse struct { // 分销商ID ResellerId string `protobuf:"bytes,1,opt,name=reseller_id,json=resellerId,proto3" json:"ResellerId,omitempty"` // 分销商名称 ResellerName string `protobuf:"bytes,2,opt,name=reseller_name,json=resellerName,proto3" json:"ResellerName,omitempty"` // 当前利润 CurrentProfit float64 `protobuf:"fixed64,3,opt,name=current_profit,json=currentProfit,proto3" json:"CurrentProfit,omitempty"` // 昨日同比利润 HistoryOneProfit float64 `protobuf:"fixed64,4,opt,name=history_one_profit,json=historyOneProfit,proto3" json:"HistoryOneProfit,omitempty"` // 上周同比利润 HistoryTwoProfit float64 `protobuf:"fixed64,5,opt,name=history_two_profit,json=historyTwoProfit,proto3" json:"HistoryTwoProfit,omitempty"` // 昨日同比利润差值 HistoryOneDiff float64 `protobuf:"fixed64,6,opt,name=history_one_diff,json=historyOneDiff,proto3" json:"HistoryOneDiff,omitempty"` // 上周同比利润差值 HistoryTwoDiff float64 `protobuf:"fixed64,7,opt,name=history_two_diff,json=historyTwoDiff,proto3" json:"HistoryTwoDiff,omitempty"` } // GetProfitRankingSumApi 利润同比分销商排行榜 func GetProfitRankingSumApi(param *GetProfitRankingSumRequest) (*GetProfitRankingSumResponse, error) { url := "/dataanalytics/profitRankingSum" var res GetProfitRankingSumResponse if err := request(url, param, &res); err != nil { return nil, err } return &res, nil } type GetStatisOfficialProductSumRequest struct { Ct []string `protobuf:"bytes,1,rep,name=ct,proto3" json:"ct,omitempty"` DownwardValue int32 `protobuf:"varint,4,opt,name=downward_value,json=downwardValue,proto3" json:"downward_value,omitempty"` Page int32 `protobuf:"varint,5,opt,name=page,proto3" json:"page,omitempty"` Limit int32 `protobuf:"varint,6,opt,name=limit,proto3" json:"limit,omitempty"` OfficialProductId []int32 `protobuf:"varint,7,rep,packed,name=official_product_id,json=officialProductId,proto3" json:"official_product_id,omitempty"` } type GetStatisOfficialProductSumResponse struct { OfficialProductSum []*GetStatisOfficialProductSum `protobuf:"bytes,1,rep,name=official_product_sum,json=officialProductSum,proto3" json:"official_product_sum,omitempty"` DataCount int32 `protobuf:"varint,2,opt,name=data_count,json=dataCount,proto3" json:"data_count,omitempty"` } type GetStatisOfficialProductSum struct { OfficialProductId int32 `protobuf:"varint,1,opt,name=official_product_id,json=officialProductId,proto3" json:"official_product_id,omitempty"` OfficialProductName string `protobuf:"bytes,2,opt,name=official_product_name,json=officialProductName,proto3" json:"official_product_name,omitempty"` CurrentNum int32 `protobuf:"varint,3,opt,name=current_num,json=currentNum,proto3" json:"current_num,omitempty"` HistoryOneNum int32 `protobuf:"varint,4,opt,name=history_one_num,json=historyOneNum,proto3" json:"history_one_num,omitempty"` HistoryTwoNum int32 `protobuf:"varint,5,opt,name=history_two_num,json=historyTwoNum,proto3" json:"history_two_num,omitempty"` HistoryOneDiff int32 `protobuf:"varint,6,opt,name=history_one_diff,json=historyOneDiff,proto3" json:"history_one_diff,omitempty"` HistoryTwoDiff int32 `protobuf:"varint,7,opt,name=history_two_diff,json=historyTwoDiff,proto3" json:"history_two_diff,omitempty"` } // GetStatisOfficialProductSumApi 销量同比分析 func GetStatisOfficialProductSumApi(param *GetStatisOfficialProductSumRequest) (*GetStatisOfficialProductSumResponse, error) { url := "/dataanalytics/statisOfficialProduct" var res GetStatisOfficialProductSumResponse if err := request(url, param, &res); err != nil { return nil, err } return &res, nil } type GetStatisOfficialProductSumDeclineResponse struct { OfficialProductSumDecline []*GetStatisOfficialProductSumDecline `protobuf:"bytes,1,rep,name=official_product_sum_decline,json=officialProductSumDecline,proto3" json:"official_product_sum_decline,omitempty"` DataCount int32 `protobuf:"varint,2,opt,name=data_count,json=dataCount,proto3" json:"data_count,omitempty"` } type GetStatisOfficialProductSumDecline struct { ResellerId int32 `protobuf:"varint,1,opt,name=reseller_id,json=resellerId,proto3" json:"reseller_id,omitempty"` OfficialProductId int32 `protobuf:"varint,2,opt,name=official_product_id,json=officialProductId,proto3" json:"official_product_id,omitempty"` OfficialProductName string `protobuf:"bytes,3,opt,name=official_product_name,json=officialProductName,proto3" json:"official_product_name,omitempty"` ResellerName string `protobuf:"bytes,4,opt,name=reseller_name,json=resellerName,proto3" json:"reseller_name,omitempty"` CurrentNum int32 `protobuf:"varint,5,opt,name=current_num,json=currentNum,proto3" json:"current_num,omitempty"` HistoryOneNum int32 `protobuf:"varint,6,opt,name=history_one_num,json=historyOneNum,proto3" json:"history_one_num,omitempty"` HistoryTwoNum int32 `protobuf:"varint,7,opt,name=history_two_num,json=historyTwoNum,proto3" json:"history_two_num,omitempty"` HistoryOneDiff int32 `protobuf:"varint,8,opt,name=history_one_diff,json=historyOneDiff,proto3" json:"history_one_diff,omitempty"` HistoryTwoDiff int32 `protobuf:"varint,9,opt,name=history_two_diff,json=historyTwoDiff,proto3" json:"history_two_diff,omitempty"` } // GetStatisOfficialProductSumDeclineApi 销量同比分析 func GetStatisOfficialProductSumDeclineApi(param *GetStatisOfficialProductSumRequest) (*GetStatisOfficialProductSumDeclineResponse, error) { url := "/dataanalytics/statisOfficialProductDecline" var res GetStatisOfficialProductSumDeclineResponse if err := request(url, param, &res); err != nil { return nil, err } return &res, nil } type resCode struct { Code int `json:"code"` Data json.RawMessage `json:"data"` Error string `json:"error"` } type GetStatisFilterOfficialProductRequest struct { OfficialProductId int32 `protobuf:"varint,1,opt,name=official_product_id,json=officialProductId,proto3" json:"official_product_id,omitempty"` } type GetStatisFilterOfficialProductResponse struct { List []*StatisFilterOfficialProductResponse `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` } type StatisFilterOfficialProductResponse struct { OfficialProductId int32 `protobuf:"varint,1,opt,name=official_product_id,json=officialProductId,proto3" json:"OfficialProductId,omitempty"` OfficialProductName string `protobuf:"bytes,2,opt,name=official_product_name,json=officialProductName,proto3" json:"OfficialProductName,omitempty"` } // GetStatisFilterOfficialProductApi 官方商品列表 func GetStatisFilterOfficialProductApi(param *GetStatisFilterOfficialProductRequest) (*GetStatisFilterOfficialProductResponse, error) { url := "/dataanalytics/statisFilterOfficialProduct" var res GetStatisFilterOfficialProductResponse if err := request(url, param, &res); err != nil { return nil, err } return &res, nil } func request(url string, reqData interface{}, resData interface{}) error { reqParam, err := pkg.StructToQuery(reqData) if err != nil { return err } req := &l_request.Request{ Url: Base + url + "?" + customEncode(reqParam), Method: http.MethodGet, } res, err := req.Send() if res.StatusCode != http.StatusOK { return fmt.Errorf("request failed, status code: %d,resion: %s", res.StatusCode, res.Reason) } var code resCode if err = json.Unmarshal(res.Content, &code); err != nil { return fmt.Errorf("返回结构异常:%s", string(res.Content)) } if code.Code != 200 { return fmt.Errorf("返回状态异常:%s", string(code.Error)) } if err = json.Unmarshal(code.Data, resData); err != nil { return fmt.Errorf("返回数据异常:%s", string(res.Content)) } return nil } func customEncode(params url.Values) string { encoded := params.Encode() // 解码我们想要保留的字符 encoded = strings.ReplaceAll(encoded, "%5B", "[") // 恢复 [ encoded = strings.ReplaceAll(encoded, "%5D", "]") // 恢复 ] encoded = strings.ReplaceAll(encoded, "%2B", "+") // 恢复 + return encoded }