From 41eae8574206e7e411c0bb93f7508f7715c76c5e Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 9 Jan 2020 09:27:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E4=BF=AE=E6=94=B9=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E5=90=8D=E5=BF=BD=E7=95=A5=E6=B2=A1=E6=9C=89=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E4=BF=AE=E6=94=B9=E9=94=99=EF=BC=88=E5=8D=B3=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E4=B8=8E=E8=A6=81=E4=BF=AE=E6=94=B9=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E6=A0=B7=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdapi/sku.go | 7 ++++++ platformapi/jdapi/sku_test.go | 42 ++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/platformapi/jdapi/sku.go b/platformapi/jdapi/sku.go index bd150b8b..297c5fcc 100644 --- a/platformapi/jdapi/sku.go +++ b/platformapi/jdapi/sku.go @@ -340,9 +340,16 @@ func (a *API) UpdateShopCategory(id int64, shopCategoryName string) error { KeyShopCategoryName: shopCategoryName, } _, err := a.AccessAPINoPage("pms/updateShopCategory", params, nil, nil, nullResultParser) + if IsErrIgnorable(err) { + err = nil + } return err } +func IsErrIgnorable(err error) bool { + return err == nil || utils.IsErrMatch(err, "-3", []string{"店内分类名称未修改,无需操作"}) +} + // 修改商家店内分类顺序接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=2a8267602e814be9828f0c7ce307b872 func (a *API) ChangeShopCategoryOrder(pid int64, childIds []int64) error { diff --git a/platformapi/jdapi/sku_test.go b/platformapi/jdapi/sku_test.go index ea73605d..08467a1d 100644 --- a/platformapi/jdapi/sku_test.go +++ b/platformapi/jdapi/sku_test.go @@ -60,19 +60,32 @@ func TestBatchUpdateOutSkuId(t *testing.T) { } func TestQuerySkuInfos(t *testing.T) { - pageSize := 20 - result, totalCount, err := api.QuerySkuInfos(&QuerySkuParam{ - IsFilterDel: IsFilterDelTrue, - }) - t.Log(utils.Format4Output(result, false)) - t.Log(totalCount) - if err != nil { - t.Fatal(err) + pageSize := MaxSkuIDsCount4QueryListBySkuIds + pageNo := 1 + var skuList []*SkuMain + for { + result, totalCount, err := api.QuerySkuInfos(&QuerySkuParam{ + PageSize: pageSize, + PageNo: pageNo, + IsFilterDel: IsFilterDelTrue, + }) + if err != nil { + t.Fatal(err) + } + skuList = append(skuList, result...) + if len(skuList) >= totalCount { + break + } + pageNo++ } - if len(result) != pageSize || totalCount == 0 { - baseapi.SugarLogger.Debug(utils.Format4Output(result, false)) - t.Fatalf("QuerySkuInfos result size is not same as requested:%d", pageSize) + var abnormalSkuList []*SkuMain + for _, v := range skuList { + if len(v.ShopCategories) == 0 { + abnormalSkuList = append(abnormalSkuList, v) + } } + t.Log(utils.Format4Output(abnormalSkuList, false)) + t.Log(len(abnormalSkuList)) } func TestQueryListBySkuIds(t *testing.T) { @@ -240,3 +253,10 @@ func TestUpdateSku(t *testing.T) { t.Fatal(err) } } + +func TestUpdateShopCategory(t *testing.T) { + err := api.UpdateShopCategory(4760208, "中秋必抢🍳") + if err != nil { + t.Fatal(err) + } +}