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

@@ -82,15 +82,9 @@ type PageShopUserInfo struct {
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"`
Start string `json:"start"`
} `json:"takeout_dispatch_time"`
TakeoutOncallType string `json:"takeout_oncall_type"` TakeoutOncallType string `json:"takeout_oncall_type"`
TakeoutOpenTime []struct { TakeoutOpenTime []*BussinessTimeInfo `json:"takeout_open_time"`
End string `json:"end"`
Start string `json:"start"`
} `json:"takeout_open_time"`
TakeoutServicePhone string `json:"takeout_service_phone"` TakeoutServicePhone string `json:"takeout_service_phone"`
TakeoutShopLogo string `json:"takeout_shop_logo"` TakeoutShopLogo string `json:"takeout_shop_logo"`
TransferStatus string `json:"transfer_status"` TransferStatus string `json:"transfer_status"`
@@ -174,10 +168,7 @@ 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"`
Start string `json:"start"`
} `json:"business_time"`
CanRefund int `json:"can_refund"` CanRefund int `json:"can_refund"`
CashGiftComment string `json:"cash_gift_comment"` CashGiftComment string `json:"cash_gift_comment"`
DeliveryTime int `json:"delivery_time"` DeliveryTime int `json:"delivery_time"`
@@ -277,10 +268,7 @@ type PageShopInfo struct {
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"`
Start string `json:"start"`
} `json:"first_open_time"`
HitGod int `json:"hit_god"` HitGod int `json:"hit_god"`
ImagePath string `json:"image_path"` ImagePath string `json:"image_path"`
IsColdChain int `json:"is_cold_chain"` IsColdChain int `json:"is_cold_chain"`