From 68f2de0bf4053176caf658b04cec4e4873acf146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 26 Nov 2020 08:59:56 +0800 Subject: [PATCH] aa --- platformapi/jdshopapi/store_page.go | 85 ++++++++++++++++++++++++ platformapi/jdshopapi/store_page_test.go | 32 +++++++++ 2 files changed, 117 insertions(+) diff --git a/platformapi/jdshopapi/store_page.go b/platformapi/jdshopapi/store_page.go index 33b655fb..06abb294 100644 --- a/platformapi/jdshopapi/store_page.go +++ b/platformapi/jdshopapi/store_page.go @@ -108,6 +108,41 @@ func (a *API) AccessStorePage2(fullURL string, bizParams map[string]interface{}, return retVal, err } +func (a *API) AccessStorePage4(fullURL, param string, isPost bool) (retVal map[string]interface{}, err error) { + if a.GetCookieCount() == 0 { + return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法") + } + err = platformapi.AccessPlatformAPIWithRetry(a.client, + func() *http.Request { + var request *http.Request + if isPost { + request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(param)) + request.Header.Set("Content-Type", "application/json;charset=UTF-8") + } + a.FillRequestCookies(request) + return request + }, + a.config, + func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) { + if jsonResult1 == nil { + return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil") + } + if strings.Contains(bodyStr, "登录") || strings.Contains(bodyStr, "访问的内容") { + return platformapi.ErrLevelRecoverableErr, fmt.Errorf("cookie可能过期了!") + } + if err == nil { + if jsonResult1["error_response"] != nil { + errLevel = platformapi.ErrLevelGeneralFail + err = utils.NewErrorCode(jsonResult1["error_response"].(map[string]interface{})["zh_desc"].(string), jsonResult1["error_response"].(map[string]interface{})["code"].(string)) + baseapi.SugarLogger.Debugf("jdeclp AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true)) + } + retVal = jsonResult1 + } + return errLevel, err + }) + return retVal, err +} + func RandStringBytes(n int) string { b := make([]byte, n) for i := range b { @@ -993,3 +1028,53 @@ func (a *API) WareDoUpdate(op string, updateWareIds string) (err error) { }, true) return err } + +//门店商品上下架 +func (a *API) StoreWareDoUpdate(status int, skuId int64, vendorStoreID string) (err error) { + params := map[string]interface{}{ + "skuId": skuId, + "storeId": vendorStoreID, + } + data, _ := json.Marshal(params) + _, err = a.AccessStorePage4("https://ware.shop.jd.com/rest/storeProduct/updateStatus/"+utils.Int2Str(status), "["+string(data)+"]", true) + return err +} + +//门店商品改价 +func (a *API) StoreUpdatePrice(price int, skuId int64, vendorStoreID string) (err error) { + _, err = a.AccessStorePage2("https://ware.shop.jd.com/rest/storeProduct/updateStoreFeature", map[string]interface{}{ + "skuId": skuId, + "storeId": vendorStoreID, + "features": map[string]interface{}{ + "store_sku_price": price, + }, + }, true) + return err +} + +//门店商品改库存 +func (a *API) StoreUpdateStock(stockNum int, skuId int64, vendorStoreID string) (err error) { + params := map[string]interface{}{ + "skuId": skuId, + "storeId": vendorStoreID, + "stockNum": stockNum, + } + data, _ := json.Marshal(params) + _, err = a.AccessStorePage4("https://ware.shop.jd.com/rest/storeProduct/updateStoreStock", "["+string(data)+"]", true) + return err +} + +//门店关注商品 +func (a *API) StoreSkuBindStore(allStore bool, skuId int64, vendorStoreID string) (err error) { + var storeIDs []string + if vendorStoreID != "" { + storeIDs = append(storeIDs, vendorStoreID) + } + params := map[string]interface{}{ + "skuIds": []string{utils.Int64ToStr(skuId)}, + "storeIds": storeIDs, + "allStore": allStore, + } + _, err = a.AccessStorePage2("https://ware.shop.jd.com/rest/storeProduct/skuBindStore", params, true) + return err +} diff --git a/platformapi/jdshopapi/store_page_test.go b/platformapi/jdshopapi/store_page_test.go index f265feae..5c851747 100644 --- a/platformapi/jdshopapi/store_page_test.go +++ b/platformapi/jdshopapi/store_page_test.go @@ -273,3 +273,35 @@ func TestWareDoUpdate(t *testing.T) { } // t.Log(utils.Format4Output(result, false)) } + +func TestStoreWareDoUpdate(t *testing.T) { + err := api.StoreWareDoUpdate(1, 10024685331653, "1000063128") + if err != nil { + t.Fatal(err) + } + // t.Log(utils.Format4Output(result, false)) +} + +func TestStoreUpdatePrice(t *testing.T) { + err := api.StoreUpdatePrice(80, 10024685331653, "1000063128") + if err != nil { + t.Fatal(err) + } + // t.Log(utils.Format4Output(result, false)) +} + +func TestStoreUpdateStock(t *testing.T) { + err := api.StoreUpdateStock(80, 10024685331653, "1000063128") + if err != nil { + t.Fatal(err) + } + // t.Log(utils.Format4Output(result, false)) +} + +func TestStoreSkuBindStore(t *testing.T) { + err := api.StoreSkuBindStore(false, 10024685331653, "1000063128") + if err != nil { + t.Fatal(err) + } + // t.Log(utils.Format4Output(result, false)) +}