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

@@ -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
}