diff --git a/platformapi/ebaiapi/activity_page.go b/platformapi/ebaiapi/activity_page.go index 48f5f3cc..91b8b3e3 100644 --- a/platformapi/ebaiapi/activity_page.go +++ b/platformapi/ebaiapi/activity_page.go @@ -14,22 +14,18 @@ const ( PageActivityTypeSkuDirectDown = 2 // 商品直降 ) -const ( - maxPageSize4ActSkuList = 100 -) - type PageActItem struct { ActivityID string `json:"activity_id"` ActivityName string `json:"activity_name"` - ActivityType string `json:"activity_type"` + ActivityType int `json:"activity_type"` ActivityPlatform string `json:"activity_platform"` - StartTime string `json:"start_time"` - EndTime string `json:"end_time"` + StartTime int64 `json:"start_time"` + EndTime int64 `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"` + Status int `json:"status"` + StopTime int64 `json:"stop_time"` + CreatorType int `json:"creator_type"` + CreateTime int64 `json:"create_time"` ChildType string `json:"child_type"` CreatedAt string `json:"created_at"` ShopNum int `json:"shop_num,omitempty"` @@ -49,10 +45,10 @@ type PageActListInfo struct { type PageActSku struct { ID string `json:"id"` ActivityID string `json:"activity_id"` - ActivityType string `json:"activity_type"` + ActivityType int `json:"activity_type"` SkuID string `json:"sku_id"` - SupplierID string `json:"supplier_id"` - Wid string `json:"wid"` + SupplierID int `json:"supplier_id"` + Wid int64 `json:"wid"` ShopName string `json:"shop_name"` UpcID string `json:"upc_id"` Upc string `json:"upc"` @@ -62,10 +58,10 @@ type PageActSku struct { 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"` + Stock int `json:"stock"` + Status int `json:"status"` + CreateTime int64 `json:"create_time"` + UpdateTime int64 `json:"update_time"` RejectReason string `json:"reject_reason"` SupplierName string `json:"supplier_name"` IsRecruit string `json:"is_recruit"` @@ -85,15 +81,20 @@ type PageActivityInfo struct { Perpage int `json:"perpage"` } -func (a *API) BegetActivityList(supplierID int64, showStatus, activityType int) (actList []*PageActItem, err error) { - pageSize := maxPageSize4ActSkuList +func (a *API) BegetActivityList(showStatus, activityType int, baiduShopID, supplierID int64) (actList []*PageActItem, err error) { + pageSize := 20 pageNo := 1 params := map[string]interface{}{ "perpage": pageSize, - "supplier_id": supplierID, "show_status": showStatus, "activity_type": activityType, //不设置这个值,缺省为:PageActivityTypeSkuDirectDown } + if baiduShopID > 0 { + params["wid"] = baiduShopID + } + if supplierID > 0 { + params[KeySupplierID] = supplierID + } for { params["curpage"] = pageNo retVal, err2 := a.AccessStorePage("commodity/activity/begetactivitylist", params, false) @@ -116,14 +117,19 @@ func (a *API) BegetActivityList(supplierID int64, showStatus, activityType int) return nil, err } -func (a *API) BegetActSkuList(activityID, supplierID int64) (actSkuList []*PageActSku, err error) { - pageSize := maxPageSize4ActSkuList +func (a *API) BegetActSkuList(activityID, baiduShopID, supplierID int64) (actSkuList []*PageActSku, err error) { + pageSize := 100 pageNo := 1 params := map[string]interface{}{ "perpage": pageSize, - "supplier_id": supplierID, "activity_id": activityID, } + if baiduShopID > 0 { + params["wid"] = baiduShopID + } + if supplierID > 0 { + params[KeySupplierID] = supplierID + } for { params["curpage"] = pageNo retVal, err2 := a.AccessStorePage("commodity/activity/begetactskulist", params, false) diff --git a/platformapi/ebaiapi/activity_page_test.go b/platformapi/ebaiapi/activity_page_test.go index fdd55993..fc1ecbdd 100644 --- a/platformapi/ebaiapi/activity_page_test.go +++ b/platformapi/ebaiapi/activity_page_test.go @@ -7,7 +7,7 @@ import ( ) func TestBegetActivityList(t *testing.T) { - actList, err := api.BegetActivityList(2233065879, PageActivityStatusOnGoing, PageActivityTypeSkuDirectDown) + actList, err := api.BegetActivityList(PageActivityStatusEnded, PageActivityTypeSkuDiscount, 0, 2233065879) if err != nil { t.Fatal(err) } else { @@ -17,7 +17,7 @@ func TestBegetActivityList(t *testing.T) { } func TestBegetActSkuList(t *testing.T) { - actSkuList, err := api.BegetActSkuList(3000000001477429, 2233065879) + actSkuList, err := api.BegetActSkuList(3000000001477429, 0, 2233065879) if err != nil { t.Fatal(err) } else { diff --git a/platformapi/ebaiapi/ebaiapi.go b/platformapi/ebaiapi/ebaiapi.go index 0535909a..139aa5fd 100644 --- a/platformapi/ebaiapi/ebaiapi.go +++ b/platformapi/ebaiapi/ebaiapi.go @@ -40,6 +40,7 @@ type API struct { client *http.Client config *platformapi.APIConfig speedLimiter *platformapi.Limiter + supplierID int64 locker sync.RWMutex storeCookies map[string]string @@ -58,6 +59,8 @@ func New(source, secret string, config ...*platformapi.APIConfig) *API { config: &curConfig, speedLimiter: platformapi.New(apiLimitConfigs, nil), //defaultAPILimitConfig), storeCookies: make(map[string]string), + + supplierID: -1, } return api } @@ -138,3 +141,26 @@ func (a *API) AccessAPI(cmd string, body map[string]interface{}) (retVal *Respon }) return retVal, err } + +func (a *API) GetSupplierID() (supplierID int64) { + a.locker.RLock() + supplierID = a.supplierID + a.locker.RUnlock() + if supplierID < 0 { + a.locker.Lock() + defer a.locker.Unlock() + + a.supplierID = 0 + if shopList, err := a.ShopList(SysStatusAll); err == nil { + for _, shop := range shopList { + if shopDetail, err := a.ShopGet2("", shop.BaiduShopID); err != nil { + break + } else if shopDetail.SupplierID > 0 { + a.supplierID = shopDetail.SupplierID + break + } + } + } + } + return a.supplierID +} diff --git a/platformapi/ebaiapi/ebaiapi_test.go b/platformapi/ebaiapi/ebaiapi_test.go index f94f4331..e441d6cf 100644 --- a/platformapi/ebaiapi/ebaiapi_test.go +++ b/platformapi/ebaiapi/ebaiapi_test.go @@ -27,9 +27,13 @@ func init() { baseapi.Init(sugarLogger) // sandbox,果园测试门店 api = New("62289", "d3ec2358d6a819ea") - // prod + + // 京西菜市 // api = New("34665", "c3db75b754ea2d89") + // 京西果园 + // api = New("35957", "10013fbb7c2ddad7") + api.SetStoreCookie("WMUSS", "4AAPQCAAB5PF0aUGcBVzoRTCEkOFhFIhx-Yk9vN2EfPHYoLlROKBEsQmAUQjhNUgRt0ADAP5x-RFklwAAdjxGO11iOj8xKXYSSDIJb2BcPghsaklNfQwGS10JOVRFfhAiYElhEXFXIzoJKyloCGdwdFE6Qk9FRxojUFN3FVEHNjJPZJu4Bt9nxQ13cwoMbjA") api.SetStoreCookie("WMSTOKEN", "AcAANQZAABbC04rUBZFc2UYanlocDAaP0dcfzZCeS1SHQ1qJ15ExgAA13A2dGLjdbcitBZJu4Bn6B_g6cZAAA0tyyFm8cdBaNAQAAwug8HTG0xRjwt1UZzbcAAN7ofRO") } diff --git a/platformapi/ebaiapi/shop.go b/platformapi/ebaiapi/shop.go index 8bd38e27..96bff74e 100644 --- a/platformapi/ebaiapi/shop.go +++ b/platformapi/ebaiapi/shop.go @@ -77,6 +77,52 @@ type ShopInfo struct { OrderStatusPush int `json:"order_status_push"` } +type BussinessTimeInfo struct { + End string `json:"end"` + Start string `json:"start"` +} + +type ShopDetail struct { + Address string `json:"address"` + BaiduShopID int64 `json:"baidu_shop_id"` + BookAheadTime int `json:"book_ahead_time"` + Brand string `json:"brand"` + BusinessFormID string `json:"business_form_id"` + BusinessTime []*BussinessTimeInfo `json:"business_time"` + Category1 string `json:"category1"` + Category2 string `json:"category2"` + Category3 string `json:"category3"` + Categorys []struct { + Category1 string `json:"category1"` + Category2 string `json:"category2"` + } `json:"categorys"` + City string `json:"city"` + CoordType string `json:"coord_type"` + County string `json:"county"` + DeliveryParty int `json:"delivery_party"` + DeliveryRegion []interface{} `json:"delivery_region"` + DeliveryType string `json:"delivery_type"` + InvoiceSupport string `json:"invoice_support"` + IvrPhone string `json:"ivr_phone"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + MinOrderPrice string `json:"min_order_price"` + Name string `json:"name"` + OrderPush int `json:"order_push"` + OrderStatusPush int `json:"order_status_push"` + PackageBoxPrice int `json:"package_box_price"` + Phone string `json:"phone"` + PickTime string `json:"pick_time"` + Province string `json:"province"` + ServicePhone string `json:"service_phone"` + ServicePhones []string `json:"service_phones"` + ShopID string `json:"shop_id"` + ShopLogo string `json:"shop_logo"` + Status string `json:"status"` + SupplierID int64 `json:"supplier_id"` + SupplierName string `json:"supplier_name"` +} + func (a *API) genShopIDParams(shopID string, baiduShopID, supplierID int64) map[string]interface{} { // if shopID == "" && baiduShopID == 0 || shopID != "" && baiduShopID != 0 { // panic("shopID and baiduShopID can not all be empty or all not be empty") @@ -139,6 +185,14 @@ func (a *API) ShopGet(shopID string, baiduShopID int64) (shop map[string]interfa return nil, err } +func (a *API) ShopGet2(shopID string, baiduShopID int64) (shopDetail *ShopDetail, err error) { + result, err := a.ShopGet(shopID, baiduShopID) + if err == nil { + err = utils.Map2StructByJson(result, &shopDetail, true) + } + return shopDetail, err +} + func (a *API) ShopUpdate(params map[string]interface{}) (err error) { _, err = a.AccessAPI("shop.update", params) if err == nil { diff --git a/platformapi/ebaiapi/store_page.go b/platformapi/ebaiapi/store_page.go index 40d1e0c0..788a1775 100644 --- a/platformapi/ebaiapi/store_page.go +++ b/platformapi/ebaiapi/store_page.go @@ -57,43 +57,37 @@ type PageShopUserInfo struct { EleSign int `json:"eleSign"` } `json:"service_package"` ShopInfo struct { - AreaID string `json:"area_id"` - BaiduBusinessState string `json:"baidu_business_state"` - BaiduOnlineStatus string `json:"baidu_online_status"` - BaiduTakeoutLogo string `json:"baidu_takeout_logo"` - CategoryID string `json:"category_id"` - CategoryIds string `json:"category_ids"` - CategoryName string `json:"category_name"` - County string `json:"county"` - CreateType string `json:"create_type"` - CreatedAt string `json:"created_at"` - CrmOncallType int `json:"crm_oncall_type"` - EffectiveAt string `json:"effective_at"` - EleBusinessState string `json:"ele_business_state"` - EleDeliveryParty string `json:"ele_delivery_party"` - EleID string `json:"ele_id"` - EleOnlineStatus string `json:"ele_online_status"` - EleShopLogo interface{} `json:"ele_shop_logo"` - IsSignZhongbao string `json:"is_sign_zhongbao"` - OnlineStatus string `json:"online_status"` - Phone string `json:"phone"` - ServStatus string `json:"serv_status"` - ShopTransactionOpen int `json:"shop_transaction_open"` - SourceName string `json:"source_name"` - SupplierID string `json:"supplier_id"` - TakeoutBoxPrice string `json:"takeout_box_price"` - TakeoutDispatchTime []struct { - End string `json:"end"` - Start string `json:"start"` - } `json:"takeout_dispatch_time"` - TakeoutOncallType string `json:"takeout_oncall_type"` - TakeoutOpenTime []struct { - End string `json:"end"` - Start string `json:"start"` - } `json:"takeout_open_time"` - TakeoutServicePhone string `json:"takeout_service_phone"` - TakeoutShopLogo string `json:"takeout_shop_logo"` - TransferStatus string `json:"transfer_status"` + AreaID string `json:"area_id"` + BaiduBusinessState string `json:"baidu_business_state"` + BaiduOnlineStatus string `json:"baidu_online_status"` + BaiduTakeoutLogo string `json:"baidu_takeout_logo"` + CategoryID string `json:"category_id"` + CategoryIds string `json:"category_ids"` + CategoryName string `json:"category_name"` + County string `json:"county"` + CreateType string `json:"create_type"` + CreatedAt string `json:"created_at"` + CrmOncallType int `json:"crm_oncall_type"` + EffectiveAt string `json:"effective_at"` + EleBusinessState string `json:"ele_business_state"` + EleDeliveryParty string `json:"ele_delivery_party"` + EleID string `json:"ele_id"` + EleOnlineStatus string `json:"ele_online_status"` + EleShopLogo interface{} `json:"ele_shop_logo"` + IsSignZhongbao string `json:"is_sign_zhongbao"` + OnlineStatus string `json:"online_status"` + Phone string `json:"phone"` + ServStatus string `json:"serv_status"` + ShopTransactionOpen int `json:"shop_transaction_open"` + SourceName string `json:"source_name"` + SupplierID string `json:"supplier_id"` + TakeoutBoxPrice string `json:"takeout_box_price"` + TakeoutDispatchTime []*BussinessTimeInfo `json:"takeout_dispatch_time"` + TakeoutOncallType string `json:"takeout_oncall_type"` + TakeoutOpenTime []*BussinessTimeInfo `json:"takeout_open_time"` + TakeoutServicePhone string `json:"takeout_service_phone"` + TakeoutShopLogo string `json:"takeout_shop_logo"` + TransferStatus string `json:"transfer_status"` } `json:"shop_info"` ShopRole int `json:"shop_role"` ShopUserID string `json:"shop_user_id"` @@ -171,30 +165,27 @@ type ActivityTagInfo struct { } type PageListInnerShopInfo struct { - ActivityTag []*ActivityTagInfo `json:"activity_tag"` - BrandName string `json:"brand_name"` - BusinessStatus int `json:"business_status"` - BusinessTime []struct { - End string `json:"end"` - Start string `json:"start"` - } `json:"business_time"` - CanRefund int `json:"can_refund"` - CashGiftComment string `json:"cash_gift_comment"` - DeliveryTime int `json:"delivery_time"` - DisplayRefundLabel int `json:"display_refund_label"` - Distance float64 `json:"distance"` - EleID string `json:"ele_id"` - FlashsalesStyleShop int `json:"flashsales_style_shop"` - HasFoodEnsurance int `json:"has_food_ensurance"` - HasServiceCommitment int `json:"has_service_commitment"` - HitGod int `json:"hit_god"` - IsBrand int `json:"is_brand"` - IsDoubleTwelve int `json:"is_double_twelve"` - IsRank int `json:"is_rank"` - IsTransfer int `json:"is_transfer"` - LogoURL string `json:"logo_url"` - OverallRating float64 `json:"overall_rating"` - SaledMonth int `json:"saled_month"` + ActivityTag []*ActivityTagInfo `json:"activity_tag"` + BrandName string `json:"brand_name"` + BusinessStatus int `json:"business_status"` + BusinessTime []*BussinessTimeInfo `json:"business_time"` + CanRefund int `json:"can_refund"` + CashGiftComment string `json:"cash_gift_comment"` + DeliveryTime int `json:"delivery_time"` + DisplayRefundLabel int `json:"display_refund_label"` + Distance float64 `json:"distance"` + EleID string `json:"ele_id"` + FlashsalesStyleShop int `json:"flashsales_style_shop"` + HasFoodEnsurance int `json:"has_food_ensurance"` + HasServiceCommitment int `json:"has_service_commitment"` + HitGod int `json:"hit_god"` + IsBrand int `json:"is_brand"` + IsDoubleTwelve int `json:"is_double_twelve"` + IsRank int `json:"is_rank"` + IsTransfer int `json:"is_transfer"` + LogoURL string `json:"logo_url"` + OverallRating float64 `json:"overall_rating"` + SaledMonth int `json:"saled_month"` SameBrandFolding []struct { DeliveryTime int `json:"delivery_time"` Distance float64 `json:"distance"` @@ -272,42 +263,39 @@ type PageShopInfo struct { Tag []interface{} `json:"tag"` Text string `json:"text"` } `json:"delivery_mode"` - Description string `json:"description"` - DisplayRefundLabel int `json:"display_refund_label"` - Distance int `json:"distance"` - EleBusinessState int `json:"ele_business_state"` - EleID string `json:"ele_id"` - FirstOpenTime struct { - End string `json:"end"` - Start string `json:"start"` - } `json:"first_open_time"` - HitGod int `json:"hit_god"` - ImagePath string `json:"image_path"` - IsColdChain int `json:"is_cold_chain"` - IsDoubleTwelve int `json:"is_double_twelve"` - IsMedicineShop int `json:"is_medicine_shop"` - IsOwnTheme int `json:"is_own_theme"` - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - MedicineQualification []interface{} `json:"medicine_qualification"` - Name string `json:"name"` - NewStyle bool `json:"new_style"` - OTakoutCost int `json:"o_takout_cost"` - OTakoutPrice int `json:"o_takout_price"` - OrderLeadTime interface{} `json:"order_lead_time"` - Phone string `json:"phone"` - PromotionInfo string `json:"promotion_info"` - Qualification string `json:"qualification"` - RecentOrderNum int `json:"recent_order_num"` - ShopID string `json:"shop_id"` - ShopScore float64 `json:"shop_score"` - ShopSourceFrom int `json:"shop_source_from"` - SkuCount int `json:"sku_count"` - TakeoutCost int `json:"takeout_cost"` - TakeoutInvoice int `json:"takeout_invoice"` - TakeoutInvoiceMinPrice string `json:"takeout_invoice_min_price"` - TakeoutOpenTime string `json:"takeout_open_time"` - TakeoutPrice int `json:"takeout_price"` + Description string `json:"description"` + DisplayRefundLabel int `json:"display_refund_label"` + Distance int `json:"distance"` + EleBusinessState int `json:"ele_business_state"` + EleID string `json:"ele_id"` + FirstOpenTime *BussinessTimeInfo `json:"first_open_time"` + HitGod int `json:"hit_god"` + ImagePath string `json:"image_path"` + IsColdChain int `json:"is_cold_chain"` + IsDoubleTwelve int `json:"is_double_twelve"` + IsMedicineShop int `json:"is_medicine_shop"` + IsOwnTheme int `json:"is_own_theme"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + MedicineQualification []interface{} `json:"medicine_qualification"` + Name string `json:"name"` + NewStyle bool `json:"new_style"` + OTakoutCost int `json:"o_takout_cost"` + OTakoutPrice int `json:"o_takout_price"` + OrderLeadTime interface{} `json:"order_lead_time"` + Phone string `json:"phone"` + PromotionInfo string `json:"promotion_info"` + Qualification string `json:"qualification"` + RecentOrderNum int `json:"recent_order_num"` + ShopID string `json:"shop_id"` + ShopScore float64 `json:"shop_score"` + ShopSourceFrom int `json:"shop_source_from"` + SkuCount int `json:"sku_count"` + TakeoutCost int `json:"takeout_cost"` + TakeoutInvoice int `json:"takeout_invoice"` + TakeoutInvoiceMinPrice string `json:"takeout_invoice_min_price"` + TakeoutOpenTime string `json:"takeout_open_time"` + TakeoutPrice int `json:"takeout_price"` } func (a *API) SetStoreCookie(key, value string) {