diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index ddb2751d..88763313 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -1,6 +1,9 @@ package ebaiapi import ( + "regexp" + "strings" + "git.rosy.net.cn/baseapi/utils" ) @@ -32,6 +35,10 @@ type PageDataInfo struct { List []map[string]interface{} } +var ( + skuExistReg = regexp.MustCompile(`sku_id:(\d+)`) +) + // category相关的函数,shop_custom_id可重 func (a *API) ShopCategoryCreate(shopID string, parentID int64, name string, rank int) (catID int64, err error) { @@ -133,6 +140,16 @@ func (a *API) SkuCreate(shopID string, customSkuID int, params map[string]interf return 0, err } +func GetEbaiSkuIDFromError(err error) int64 { + if err2, ok := err.(*utils.ErrorWithCode); ok && err2.IntCode() == 1 && strings.Index(err2.ErrMsg(), "shop sku exist") >= 0 { + searchResult := skuExistReg.FindStringSubmatch(err2.ErrMsg()) + if searchResult != nil && len(searchResult[1]) > 0 { + return utils.Str2Int64(searchResult[1]) + } + } + return 0 +} + func (a *API) SkuUpdate(shopID string, ebaiSkuID int64, params map[string]interface{}) (skuID int64, err error) { defParams := map[string]interface{}{ KeyShopID: shopID,