- ebai.activity_page
This commit is contained in:
147
platformapi/ebaiapi/activity_page.go
Normal file
147
platformapi/ebaiapi/activity_page.go
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
package ebaiapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PageActivityStatusWaiting = 3 // 待生效
|
||||||
|
PageActivityStatusOnGoing = 4 // 进行中
|
||||||
|
PageActivityStatusEnded = 5 // 已结束
|
||||||
|
|
||||||
|
PageActivityTypeSkuDiscount = 64 // 商品折扣
|
||||||
|
PageActivityTypeSkuSpecialPrice = 32 // 商品特价
|
||||||
|
PageActivityTypeSkuDirectDown = 2 // 商品直降
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
maxPageSize4ActSkuList = 100
|
||||||
|
)
|
||||||
|
|
||||||
|
type PageActItem struct {
|
||||||
|
ActivityID string `json:"activity_id"`
|
||||||
|
ActivityName string `json:"activity_name"`
|
||||||
|
ActivityType string `json:"activity_type"`
|
||||||
|
ActivityPlatform string `json:"activity_platform"`
|
||||||
|
StartTime string `json:"start_time"`
|
||||||
|
EndTime string `json:"end_time"`
|
||||||
|
User string `json:"user"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
StopTime string `json:"stop_time"`
|
||||||
|
CreatorType string `json:"creator_type"`
|
||||||
|
CreateTime int `json:"create_time"`
|
||||||
|
ChildType string `json:"child_type"`
|
||||||
|
CreatedAt string `json:"created_at"`
|
||||||
|
ShopNum int `json:"shop_num,omitempty"`
|
||||||
|
IsCanDelete int `json:"is_can_delete"`
|
||||||
|
IsRisk int `json:"is_risk"`
|
||||||
|
StopShopCount int `json:"stop_shop_count"`
|
||||||
|
SkuImportStatus int `json:"sku_import_status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageActListInfo struct {
|
||||||
|
Total int `json:"total"`
|
||||||
|
Curpage int `json:"curpage"`
|
||||||
|
Perpage int `json:"perpage"`
|
||||||
|
ActivityList []*PageActItem `json:"activity_list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageActSku struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
ActivityID string `json:"activity_id"`
|
||||||
|
ActivityType string `json:"activity_type"`
|
||||||
|
SkuID string `json:"sku_id"`
|
||||||
|
SupplierID string `json:"supplier_id"`
|
||||||
|
Wid string `json:"wid"`
|
||||||
|
ShopName string `json:"shop_name"`
|
||||||
|
UpcID string `json:"upc_id"`
|
||||||
|
Upc string `json:"upc"`
|
||||||
|
UpcName string `json:"upc_name"`
|
||||||
|
OriginalPrice float64 `json:"original_price"`
|
||||||
|
PromotionPrice float64 `json:"promotion_price"`
|
||||||
|
FreeSkuName string `json:"free_sku_name"`
|
||||||
|
PlatformSubsidy string `json:"platform_subsidy"`
|
||||||
|
ShopSubsidy string `json:"shop_subsidy"`
|
||||||
|
Stock string `json:"stock"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
CreateTime string `json:"create_time"`
|
||||||
|
UpdateTime string `json:"update_time"`
|
||||||
|
RejectReason string `json:"reject_reason"`
|
||||||
|
SupplierName string `json:"supplier_name"`
|
||||||
|
IsRecruit string `json:"is_recruit"`
|
||||||
|
Cat1ID string `json:"cat1_id"`
|
||||||
|
Cat2ID string `json:"cat2_id"`
|
||||||
|
Cat3ID string `json:"cat3_id"`
|
||||||
|
WeightFlag string `json:"weight_flag"`
|
||||||
|
RealStock int `json:"real_stock"`
|
||||||
|
Photos string `json:"photos"`
|
||||||
|
ActivityTotal int `json:"activity_total"`
|
||||||
|
}
|
||||||
|
type PageActivityInfo struct {
|
||||||
|
Total int `json:"total"`
|
||||||
|
List []*PageActSku `json:"list"`
|
||||||
|
IsCanDelete int `json:"is_can_delete"`
|
||||||
|
Curpage int `json:"curpage"`
|
||||||
|
Perpage int `json:"perpage"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) BegetActivityList(supplierID int64, showStatus, activityType int) (actList []*PageActItem, err error) {
|
||||||
|
pageSize := maxPageSize4ActSkuList
|
||||||
|
pageNo := 1
|
||||||
|
urlTemplate := "commodity/activity/begetactivitylist?perpage=%d&supplier_id=%d&show_status=%d&activity_type=%d"
|
||||||
|
params := []interface{}{
|
||||||
|
pageSize,
|
||||||
|
supplierID,
|
||||||
|
showStatus,
|
||||||
|
activityType,
|
||||||
|
}
|
||||||
|
fixedURL := fmt.Sprintf(urlTemplate, params...)
|
||||||
|
for {
|
||||||
|
retVal, err2 := a.AccessStorePage(fixedURL+"&curpage="+utils.Int2Str(pageNo), nil)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
var listInfo *PageActListInfo
|
||||||
|
if err = utils.Map2StructByJson(retVal, &listInfo, false); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
actList = append(actList, listInfo.ActivityList...)
|
||||||
|
if len(actList) >= listInfo.Total {
|
||||||
|
return actList, nil
|
||||||
|
}
|
||||||
|
pageNo++
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) BegetActSkuList(activityID, supplierID int64) (actSkuList []*PageActSku, err error) {
|
||||||
|
pageSize := maxPageSize4ActSkuList
|
||||||
|
pageNo := 1
|
||||||
|
urlTemplate := "commodity/activity/begetactskulist?activity_id=%d&perpage=%d&supplier_id=%d"
|
||||||
|
params := []interface{}{
|
||||||
|
activityID,
|
||||||
|
pageSize,
|
||||||
|
supplierID,
|
||||||
|
}
|
||||||
|
fixedURL := fmt.Sprintf(urlTemplate, params...)
|
||||||
|
for {
|
||||||
|
retVal, err2 := a.AccessStorePage(fixedURL+"&curpage="+utils.Int2Str(pageNo), nil)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
var pageActivityInfo *PageActivityInfo
|
||||||
|
if err = utils.Map2StructByJson(retVal, &pageActivityInfo, false); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
actSkuList = append(actSkuList, pageActivityInfo.List...)
|
||||||
|
if len(actSkuList) >= pageActivityInfo.Total {
|
||||||
|
return actSkuList, nil
|
||||||
|
}
|
||||||
|
pageNo++
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
27
platformapi/ebaiapi/activity_page_test.go
Normal file
27
platformapi/ebaiapi/activity_page_test.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package ebaiapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBegetActivityList(t *testing.T) {
|
||||||
|
actList, err := api.BegetActivityList(2233065879, PageActivityStatusOnGoing, PageActivityTypeSkuDirectDown)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else {
|
||||||
|
t.Log(utils.Format4Output(actList, false))
|
||||||
|
t.Log(len(actList))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBegetActSkuList(t *testing.T) {
|
||||||
|
actSkuList, err := api.BegetActSkuList(3000000001477429, 2233065879)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else {
|
||||||
|
t.Log(utils.Format4Output(actSkuList, false))
|
||||||
|
t.Log(len(actSkuList))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user