This commit is contained in:
gazebo
2019-07-10 14:30:38 +08:00
parent 3f1ba7ec54
commit 3cea125588
6 changed files with 202 additions and 124 deletions

View File

@@ -14,22 +14,18 @@ const (
PageActivityTypeSkuDirectDown = 2 // 商品直降 PageActivityTypeSkuDirectDown = 2 // 商品直降
) )
const (
maxPageSize4ActSkuList = 100
)
type PageActItem struct { type PageActItem struct {
ActivityID string `json:"activity_id"` ActivityID string `json:"activity_id"`
ActivityName string `json:"activity_name"` ActivityName string `json:"activity_name"`
ActivityType string `json:"activity_type"` ActivityType int `json:"activity_type"`
ActivityPlatform string `json:"activity_platform"` ActivityPlatform string `json:"activity_platform"`
StartTime string `json:"start_time"` StartTime int64 `json:"start_time"`
EndTime string `json:"end_time"` EndTime int64 `json:"end_time"`
User string `json:"user"` User string `json:"user"`
Status string `json:"status"` Status int `json:"status"`
StopTime string `json:"stop_time"` StopTime int64 `json:"stop_time"`
CreatorType string `json:"creator_type"` CreatorType int `json:"creator_type"`
CreateTime int `json:"create_time"` CreateTime int64 `json:"create_time"`
ChildType string `json:"child_type"` ChildType string `json:"child_type"`
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
ShopNum int `json:"shop_num,omitempty"` ShopNum int `json:"shop_num,omitempty"`
@@ -49,10 +45,10 @@ type PageActListInfo struct {
type PageActSku struct { type PageActSku struct {
ID string `json:"id"` ID string `json:"id"`
ActivityID string `json:"activity_id"` ActivityID string `json:"activity_id"`
ActivityType string `json:"activity_type"` ActivityType int `json:"activity_type"`
SkuID string `json:"sku_id"` SkuID string `json:"sku_id"`
SupplierID string `json:"supplier_id"` SupplierID int `json:"supplier_id"`
Wid string `json:"wid"` Wid int64 `json:"wid"`
ShopName string `json:"shop_name"` ShopName string `json:"shop_name"`
UpcID string `json:"upc_id"` UpcID string `json:"upc_id"`
Upc string `json:"upc"` Upc string `json:"upc"`
@@ -62,10 +58,10 @@ type PageActSku struct {
FreeSkuName string `json:"free_sku_name"` FreeSkuName string `json:"free_sku_name"`
PlatformSubsidy string `json:"platform_subsidy"` PlatformSubsidy string `json:"platform_subsidy"`
ShopSubsidy string `json:"shop_subsidy"` ShopSubsidy string `json:"shop_subsidy"`
Stock string `json:"stock"` Stock int `json:"stock"`
Status string `json:"status"` Status int `json:"status"`
CreateTime string `json:"create_time"` CreateTime int64 `json:"create_time"`
UpdateTime string `json:"update_time"` UpdateTime int64 `json:"update_time"`
RejectReason string `json:"reject_reason"` RejectReason string `json:"reject_reason"`
SupplierName string `json:"supplier_name"` SupplierName string `json:"supplier_name"`
IsRecruit string `json:"is_recruit"` IsRecruit string `json:"is_recruit"`
@@ -85,15 +81,20 @@ type PageActivityInfo struct {
Perpage int `json:"perpage"` Perpage int `json:"perpage"`
} }
func (a *API) BegetActivityList(supplierID int64, showStatus, activityType int) (actList []*PageActItem, err error) { func (a *API) BegetActivityList(showStatus, activityType int, baiduShopID, supplierID int64) (actList []*PageActItem, err error) {
pageSize := maxPageSize4ActSkuList pageSize := 20
pageNo := 1 pageNo := 1
params := map[string]interface{}{ params := map[string]interface{}{
"perpage": pageSize, "perpage": pageSize,
"supplier_id": supplierID,
"show_status": showStatus, "show_status": showStatus,
"activity_type": activityType, //不设置这个值缺省为PageActivityTypeSkuDirectDown "activity_type": activityType, //不设置这个值缺省为PageActivityTypeSkuDirectDown
} }
if baiduShopID > 0 {
params["wid"] = baiduShopID
}
if supplierID > 0 {
params[KeySupplierID] = supplierID
}
for { for {
params["curpage"] = pageNo params["curpage"] = pageNo
retVal, err2 := a.AccessStorePage("commodity/activity/begetactivitylist", params, false) 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 return nil, err
} }
func (a *API) BegetActSkuList(activityID, supplierID int64) (actSkuList []*PageActSku, err error) { func (a *API) BegetActSkuList(activityID, baiduShopID, supplierID int64) (actSkuList []*PageActSku, err error) {
pageSize := maxPageSize4ActSkuList pageSize := 100
pageNo := 1 pageNo := 1
params := map[string]interface{}{ params := map[string]interface{}{
"perpage": pageSize, "perpage": pageSize,
"supplier_id": supplierID,
"activity_id": activityID, "activity_id": activityID,
} }
if baiduShopID > 0 {
params["wid"] = baiduShopID
}
if supplierID > 0 {
params[KeySupplierID] = supplierID
}
for { for {
params["curpage"] = pageNo params["curpage"] = pageNo
retVal, err2 := a.AccessStorePage("commodity/activity/begetactskulist", params, false) retVal, err2 := a.AccessStorePage("commodity/activity/begetactskulist", params, false)

View File

@@ -7,7 +7,7 @@ import (
) )
func TestBegetActivityList(t *testing.T) { func TestBegetActivityList(t *testing.T) {
actList, err := api.BegetActivityList(2233065879, PageActivityStatusOnGoing, PageActivityTypeSkuDirectDown) actList, err := api.BegetActivityList(PageActivityStatusEnded, PageActivityTypeSkuDiscount, 0, 2233065879)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} else { } else {
@@ -17,7 +17,7 @@ func TestBegetActivityList(t *testing.T) {
} }
func TestBegetActSkuList(t *testing.T) { func TestBegetActSkuList(t *testing.T) {
actSkuList, err := api.BegetActSkuList(3000000001477429, 2233065879) actSkuList, err := api.BegetActSkuList(3000000001477429, 0, 2233065879)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} else { } else {

View File

@@ -40,6 +40,7 @@ type API struct {
client *http.Client client *http.Client
config *platformapi.APIConfig config *platformapi.APIConfig
speedLimiter *platformapi.Limiter speedLimiter *platformapi.Limiter
supplierID int64
locker sync.RWMutex locker sync.RWMutex
storeCookies map[string]string storeCookies map[string]string
@@ -58,6 +59,8 @@ func New(source, secret string, config ...*platformapi.APIConfig) *API {
config: &curConfig, config: &curConfig,
speedLimiter: platformapi.New(apiLimitConfigs, nil), //defaultAPILimitConfig), speedLimiter: platformapi.New(apiLimitConfigs, nil), //defaultAPILimitConfig),
storeCookies: make(map[string]string), storeCookies: make(map[string]string),
supplierID: -1,
} }
return api return api
} }
@@ -138,3 +141,26 @@ func (a *API) AccessAPI(cmd string, body map[string]interface{}) (retVal *Respon
}) })
return retVal, err 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
}

View File

@@ -27,9 +27,13 @@ func init() {
baseapi.Init(sugarLogger) baseapi.Init(sugarLogger)
// sandbox果园测试门店 // sandbox果园测试门店
api = New("62289", "d3ec2358d6a819ea") api = New("62289", "d3ec2358d6a819ea")
// prod
// 京西菜市
// api = New("34665", "c3db75b754ea2d89") // api = New("34665", "c3db75b754ea2d89")
// 京西果园
// api = New("35957", "10013fbb7c2ddad7")
api.SetStoreCookie("WMUSS", "4AAPQCAAB5PF0aUGcBVzoRTCEkOFhFIhx-Yk9vN2EfPHYoLlROKBEsQmAUQjhNUgRt0ADAP5x-RFklwAAdjxGO11iOj8xKXYSSDIJb2BcPghsaklNfQwGS10JOVRFfhAiYElhEXFXIzoJKyloCGdwdFE6Qk9FRxojUFN3FVEHNjJPZJu4Bt9nxQ13cwoMbjA") api.SetStoreCookie("WMUSS", "4AAPQCAAB5PF0aUGcBVzoRTCEkOFhFIhx-Yk9vN2EfPHYoLlROKBEsQmAUQjhNUgRt0ADAP5x-RFklwAAdjxGO11iOj8xKXYSSDIJb2BcPghsaklNfQwGS10JOVRFfhAiYElhEXFXIzoJKyloCGdwdFE6Qk9FRxojUFN3FVEHNjJPZJu4Bt9nxQ13cwoMbjA")
api.SetStoreCookie("WMSTOKEN", "AcAANQZAABbC04rUBZFc2UYanlocDAaP0dcfzZCeS1SHQ1qJ15ExgAA13A2dGLjdbcitBZJu4Bn6B_g6cZAAA0tyyFm8cdBaNAQAAwug8HTG0xRjwt1UZzbcAAN7ofRO") api.SetStoreCookie("WMSTOKEN", "AcAANQZAABbC04rUBZFc2UYanlocDAaP0dcfzZCeS1SHQ1qJ15ExgAA13A2dGLjdbcitBZJu4Bn6B_g6cZAAA0tyyFm8cdBaNAQAAwug8HTG0xRjwt1UZzbcAAN7ofRO")
} }

View File

@@ -77,6 +77,52 @@ type ShopInfo struct {
OrderStatusPush int `json:"order_status_push"` 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{} { func (a *API) genShopIDParams(shopID string, baiduShopID, supplierID int64) map[string]interface{} {
// if shopID == "" && baiduShopID == 0 || shopID != "" && baiduShopID != 0 { // if shopID == "" && baiduShopID == 0 || shopID != "" && baiduShopID != 0 {
// panic("shopID and baiduShopID can not all be empty or all not be empty") // 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 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) { func (a *API) ShopUpdate(params map[string]interface{}) (err error) {
_, err = a.AccessAPI("shop.update", params) _, err = a.AccessAPI("shop.update", params)
if err == nil { if err == nil {

View File

@@ -57,43 +57,37 @@ type PageShopUserInfo struct {
EleSign int `json:"eleSign"` EleSign int `json:"eleSign"`
} `json:"service_package"` } `json:"service_package"`
ShopInfo struct { ShopInfo struct {
AreaID string `json:"area_id"` AreaID string `json:"area_id"`
BaiduBusinessState string `json:"baidu_business_state"` BaiduBusinessState string `json:"baidu_business_state"`
BaiduOnlineStatus string `json:"baidu_online_status"` BaiduOnlineStatus string `json:"baidu_online_status"`
BaiduTakeoutLogo string `json:"baidu_takeout_logo"` BaiduTakeoutLogo string `json:"baidu_takeout_logo"`
CategoryID string `json:"category_id"` CategoryID string `json:"category_id"`
CategoryIds string `json:"category_ids"` CategoryIds string `json:"category_ids"`
CategoryName string `json:"category_name"` CategoryName string `json:"category_name"`
County string `json:"county"` County string `json:"county"`
CreateType string `json:"create_type"` CreateType string `json:"create_type"`
CreatedAt string `json:"created_at"` CreatedAt string `json:"created_at"`
CrmOncallType int `json:"crm_oncall_type"` CrmOncallType int `json:"crm_oncall_type"`
EffectiveAt string `json:"effective_at"` EffectiveAt string `json:"effective_at"`
EleBusinessState string `json:"ele_business_state"` EleBusinessState string `json:"ele_business_state"`
EleDeliveryParty string `json:"ele_delivery_party"` EleDeliveryParty string `json:"ele_delivery_party"`
EleID string `json:"ele_id"` EleID string `json:"ele_id"`
EleOnlineStatus string `json:"ele_online_status"` EleOnlineStatus string `json:"ele_online_status"`
EleShopLogo interface{} `json:"ele_shop_logo"` EleShopLogo interface{} `json:"ele_shop_logo"`
IsSignZhongbao string `json:"is_sign_zhongbao"` IsSignZhongbao string `json:"is_sign_zhongbao"`
OnlineStatus string `json:"online_status"` OnlineStatus string `json:"online_status"`
Phone string `json:"phone"` Phone string `json:"phone"`
ServStatus string `json:"serv_status"` ServStatus string `json:"serv_status"`
ShopTransactionOpen int `json:"shop_transaction_open"` ShopTransactionOpen int `json:"shop_transaction_open"`
SourceName string `json:"source_name"` SourceName string `json:"source_name"`
SupplierID string `json:"supplier_id"` SupplierID string `json:"supplier_id"`
TakeoutBoxPrice string `json:"takeout_box_price"` TakeoutBoxPrice string `json:"takeout_box_price"`
TakeoutDispatchTime []struct { TakeoutDispatchTime []*BussinessTimeInfo `json:"takeout_dispatch_time"`
End string `json:"end"` TakeoutOncallType string `json:"takeout_oncall_type"`
Start string `json:"start"` TakeoutOpenTime []*BussinessTimeInfo `json:"takeout_open_time"`
} `json:"takeout_dispatch_time"` TakeoutServicePhone string `json:"takeout_service_phone"`
TakeoutOncallType string `json:"takeout_oncall_type"` TakeoutShopLogo string `json:"takeout_shop_logo"`
TakeoutOpenTime []struct { TransferStatus string `json:"transfer_status"`
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"`
} `json:"shop_info"` } `json:"shop_info"`
ShopRole int `json:"shop_role"` ShopRole int `json:"shop_role"`
ShopUserID string `json:"shop_user_id"` ShopUserID string `json:"shop_user_id"`
@@ -171,30 +165,27 @@ type ActivityTagInfo struct {
} }
type PageListInnerShopInfo struct { type PageListInnerShopInfo struct {
ActivityTag []*ActivityTagInfo `json:"activity_tag"` ActivityTag []*ActivityTagInfo `json:"activity_tag"`
BrandName string `json:"brand_name"` BrandName string `json:"brand_name"`
BusinessStatus int `json:"business_status"` BusinessStatus int `json:"business_status"`
BusinessTime []struct { BusinessTime []*BussinessTimeInfo `json:"business_time"`
End string `json:"end"` CanRefund int `json:"can_refund"`
Start string `json:"start"` CashGiftComment string `json:"cash_gift_comment"`
} `json:"business_time"` DeliveryTime int `json:"delivery_time"`
CanRefund int `json:"can_refund"` DisplayRefundLabel int `json:"display_refund_label"`
CashGiftComment string `json:"cash_gift_comment"` Distance float64 `json:"distance"`
DeliveryTime int `json:"delivery_time"` EleID string `json:"ele_id"`
DisplayRefundLabel int `json:"display_refund_label"` FlashsalesStyleShop int `json:"flashsales_style_shop"`
Distance float64 `json:"distance"` HasFoodEnsurance int `json:"has_food_ensurance"`
EleID string `json:"ele_id"` HasServiceCommitment int `json:"has_service_commitment"`
FlashsalesStyleShop int `json:"flashsales_style_shop"` HitGod int `json:"hit_god"`
HasFoodEnsurance int `json:"has_food_ensurance"` IsBrand int `json:"is_brand"`
HasServiceCommitment int `json:"has_service_commitment"` IsDoubleTwelve int `json:"is_double_twelve"`
HitGod int `json:"hit_god"` IsRank int `json:"is_rank"`
IsBrand int `json:"is_brand"` IsTransfer int `json:"is_transfer"`
IsDoubleTwelve int `json:"is_double_twelve"` LogoURL string `json:"logo_url"`
IsRank int `json:"is_rank"` OverallRating float64 `json:"overall_rating"`
IsTransfer int `json:"is_transfer"` SaledMonth int `json:"saled_month"`
LogoURL string `json:"logo_url"`
OverallRating float64 `json:"overall_rating"`
SaledMonth int `json:"saled_month"`
SameBrandFolding []struct { SameBrandFolding []struct {
DeliveryTime int `json:"delivery_time"` DeliveryTime int `json:"delivery_time"`
Distance float64 `json:"distance"` Distance float64 `json:"distance"`
@@ -272,42 +263,39 @@ type PageShopInfo struct {
Tag []interface{} `json:"tag"` Tag []interface{} `json:"tag"`
Text string `json:"text"` Text string `json:"text"`
} `json:"delivery_mode"` } `json:"delivery_mode"`
Description string `json:"description"` Description string `json:"description"`
DisplayRefundLabel int `json:"display_refund_label"` DisplayRefundLabel int `json:"display_refund_label"`
Distance int `json:"distance"` Distance int `json:"distance"`
EleBusinessState int `json:"ele_business_state"` EleBusinessState int `json:"ele_business_state"`
EleID string `json:"ele_id"` EleID string `json:"ele_id"`
FirstOpenTime struct { FirstOpenTime *BussinessTimeInfo `json:"first_open_time"`
End string `json:"end"` HitGod int `json:"hit_god"`
Start string `json:"start"` ImagePath string `json:"image_path"`
} `json:"first_open_time"` IsColdChain int `json:"is_cold_chain"`
HitGod int `json:"hit_god"` IsDoubleTwelve int `json:"is_double_twelve"`
ImagePath string `json:"image_path"` IsMedicineShop int `json:"is_medicine_shop"`
IsColdChain int `json:"is_cold_chain"` IsOwnTheme int `json:"is_own_theme"`
IsDoubleTwelve int `json:"is_double_twelve"` Latitude float64 `json:"latitude"`
IsMedicineShop int `json:"is_medicine_shop"` Longitude float64 `json:"longitude"`
IsOwnTheme int `json:"is_own_theme"` MedicineQualification []interface{} `json:"medicine_qualification"`
Latitude float64 `json:"latitude"` Name string `json:"name"`
Longitude float64 `json:"longitude"` NewStyle bool `json:"new_style"`
MedicineQualification []interface{} `json:"medicine_qualification"` OTakoutCost int `json:"o_takout_cost"`
Name string `json:"name"` OTakoutPrice int `json:"o_takout_price"`
NewStyle bool `json:"new_style"` OrderLeadTime interface{} `json:"order_lead_time"`
OTakoutCost int `json:"o_takout_cost"` Phone string `json:"phone"`
OTakoutPrice int `json:"o_takout_price"` PromotionInfo string `json:"promotion_info"`
OrderLeadTime interface{} `json:"order_lead_time"` Qualification string `json:"qualification"`
Phone string `json:"phone"` RecentOrderNum int `json:"recent_order_num"`
PromotionInfo string `json:"promotion_info"` ShopID string `json:"shop_id"`
Qualification string `json:"qualification"` ShopScore float64 `json:"shop_score"`
RecentOrderNum int `json:"recent_order_num"` ShopSourceFrom int `json:"shop_source_from"`
ShopID string `json:"shop_id"` SkuCount int `json:"sku_count"`
ShopScore float64 `json:"shop_score"` TakeoutCost int `json:"takeout_cost"`
ShopSourceFrom int `json:"shop_source_from"` TakeoutInvoice int `json:"takeout_invoice"`
SkuCount int `json:"sku_count"` TakeoutInvoiceMinPrice string `json:"takeout_invoice_min_price"`
TakeoutCost int `json:"takeout_cost"` TakeoutOpenTime string `json:"takeout_open_time"`
TakeoutInvoice int `json:"takeout_invoice"` TakeoutPrice int `json:"takeout_price"`
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) { func (a *API) SetStoreCookie(key, value string) {