diff --git a/platformapi/ebaiapi/order_test.go b/platformapi/ebaiapi/order_test.go index 7fff85b5..d4b0e8ce 100644 --- a/platformapi/ebaiapi/order_test.go +++ b/platformapi/ebaiapi/order_test.go @@ -16,7 +16,7 @@ func TestOrderGet(t *testing.T) { } func TestOrderGet2(t *testing.T) { - result, err := api.OrderGet2("1576493808229489038") + result, err := api.OrderGet2("1577252398158729707") if err != nil { t.Fatal(err) } else { @@ -42,7 +42,7 @@ func TestOrderList(t *testing.T) { } func TestOrderListAll(t *testing.T) { - result, err := api.OrderListAll("", 32267089397, 1563379200, 1563465599, 0) + result, err := api.OrderListAll("", 32267184047, utils.Str2Time("2019-12-25").Unix(), utils.Str2Time("2019-12-26").Unix(), 0) if err != nil { t.Fatal(err) } else { @@ -145,3 +145,10 @@ func TestOrderPartRefund(t *testing.T) { t.Fatal(err) } } + +func TestOrderCancel(t *testing.T) { + err := api.OrderCancel("2122788271803194389", CancelTypeCustom, "admin") + if err != nil { + t.Fatal(err) + } +} diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index ed51e200..0e60a104 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -32,6 +32,9 @@ const ( var ( shopSkuBatchFailedSkuReg = regexp.MustCompile(`请核查以下sku:(\{.*\})`) + + skuExistMsgList = []string{"商品已存在", "shop sku exist", "已被使用,请更换"} + skuNotExistMsgList = []string{"sku_id与shop_id不匹配", "SKU不存在或者已经被删除", "商品不存在"} ) type CategoryInfo struct { @@ -551,11 +554,19 @@ func IsErrCategoryNotExist(err error) (isNotExist bool) { } func IsErrSkuExist(err error) (isExist bool) { - return utils.IsErrMatch(err, "1", []string{"商品已存在", "shop sku exist", "已被使用,请更换"}) + return utils.IsErrMatch(err, "1", skuExistMsgList) } func IsErrSkuNotExist(err error) (isExist bool) { - return utils.IsErrMatch(err, "1", []string{"sku_id与shop_id不匹配", "SKU不存在或者已经被删除", "商品不存在"}) + return utils.IsErrMatch(err, "1", skuNotExistMsgList) +} + +func IsMsgSkuExist(msg string) bool { + return utils.IsErrMsgMatch(msg, skuExistMsgList) +} + +func IsMsgSkuNotExist(msg string) bool { + return utils.IsErrMsgMatch(msg, skuNotExistMsgList) } func (a *API) GetEbaiSkuIDFromCustomID(shopID, customSkuID string) (ebaiSkuID int64) { diff --git a/utils/errorwithcode.go b/utils/errorwithcode.go index b42da06f..27f26d77 100644 --- a/utils/errorwithcode.go +++ b/utils/errorwithcode.go @@ -71,19 +71,24 @@ func IsErrMatch(err error, strCode string, strList []string) (isMatch bool) { if err != nil { if codeErr, ok := err.(*ErrorWithCode); ok { if strCode == "" || codeErr.Code() == strCode { - isMatch = len(strList) == 0 - for _, v := range strList { - if strings.Index(codeErr.ErrMsg(), v) >= 0 { - isMatch = true - break - } - } + isMatch = IsErrMsgMatch(codeErr.ErrMsg(), strList) } } } return isMatch } +func IsErrMsgMatch(errMsg string, strList []string) (isMatch bool) { + isMatch = len(strList) == 0 + for _, v := range strList { + if strings.Index(errMsg, v) >= 0 { + isMatch = true + break + } + } + return isMatch +} + func GetErrMsg(err error) (errMsg string) { if errExt, ok := err.(*ErrorWithCode); ok { errMsg = errExt.ErrMsg()