- 清理三个平台的门店商品批处理操作,部分失败返回失败条目
This commit is contained in:
@@ -207,28 +207,23 @@ func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal
|
||||
}
|
||||
|
||||
func genNoPageResultParser(codeKey, msgKey, resultKey, okCode string) func(data map[string]interface{}) (interface{}, error) {
|
||||
return func(data map[string]interface{}) (interface{}, error) {
|
||||
return func(data map[string]interface{}) (innerData interface{}, err error) {
|
||||
rawInnerCode, ok := data[codeKey]
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("genNoPageResultParser codeKey %s can not be found in result:%v", codeKey, data))
|
||||
}
|
||||
innerCode := forceInnerCode2Str(rawInnerCode)
|
||||
errMsg := formatErrorMsg(data[msgKey])
|
||||
if innerCode == okCode && errMsg != "调用订单中心修改承运商接口失败!" { // todo 京东的order/modifySellerDelivery在失败时也返回成功code,临时处理一下
|
||||
if resultKey != "" {
|
||||
if innerData, ok := data[resultKey]; ok {
|
||||
return innerData, nil
|
||||
}
|
||||
baseapi.SugarLogger.Warnf("genNoPageResultParser resultKey %s can not be found in result:%v", resultKey, utils.Format4Output(data, false))
|
||||
return nil, nil // 容错
|
||||
// panic(fmt.Sprintf("genNoPageResultParser resultKey %s can not be found in result:%v", resultKey, data))
|
||||
if resultKey != "" {
|
||||
innerData, _ = data[resultKey]
|
||||
}
|
||||
if innerCode != okCode {
|
||||
errMsg := formatErrorMsg(data[msgKey])
|
||||
if innerCode == ResponseInnerCodePartialFailed {
|
||||
errMsg += ", " + utils.Format4Output(innerData, true)
|
||||
}
|
||||
return nil, nil
|
||||
err = utils.NewErrorCode(errMsg, innerCode, 1)
|
||||
}
|
||||
if innerCode == ResponseInnerCodePartialFailed {
|
||||
errMsg += ", " + utils.Format4Output(data[resultKey], true)
|
||||
}
|
||||
return nil, utils.NewErrorCode(errMsg, innerCode, 1)
|
||||
return innerData, err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -187,3 +187,12 @@ func TestUpdateSpu(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateSku(t *testing.T) {
|
||||
_, err := api.UpdateSku("27379", map[string]interface{}{
|
||||
"upc": "ttld20190712",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package jdapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
@@ -63,22 +62,23 @@ type QueryStockResponse struct {
|
||||
}
|
||||
|
||||
type UpdateVendibilityResponse struct {
|
||||
Code int `json:"code"`
|
||||
CurrentQty int `json:"currentQty"`
|
||||
LockQty int `json:"lockQty"`
|
||||
Msg string `json:"msg"`
|
||||
OrderQty int `json:"orderQty"`
|
||||
OutSkuID string `json:"outSkuId"`
|
||||
SkuID int64 `json:"skuId"`
|
||||
UsableQty int `json:"usableQty"`
|
||||
Vendibility int `json:"vendibility"`
|
||||
}
|
||||
|
||||
type StoreSkuBatchUpdateResponse struct {
|
||||
OutSkuID string `json:"outSkuId"`
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
|
||||
SkuID int64 `json:"skuId"`
|
||||
CurrentQty int `json:"currentQty"`
|
||||
LockQty int `json:"lockQty"`
|
||||
OrderQty int `json:"orderQty"`
|
||||
UsableQty int `json:"usableQty"`
|
||||
Vendibility int `json:"vendibility"`
|
||||
}
|
||||
|
||||
type StoreSkuBatchUpdateResponse struct {
|
||||
OutSkuID string `json:"outSkuId" json2:"outSkuId"`
|
||||
Code int `json:"code" json2:"errorCode"`
|
||||
Msg string `json:"msg" json2:"errorMessage"`
|
||||
|
||||
// UpdateVendibility会返回以下字段
|
||||
SkuID int64 `json:"skuId"`
|
||||
StationNo string `json:"stationNo"`
|
||||
@@ -97,10 +97,7 @@ type StoreSkuBatchUpdateResponse struct {
|
||||
|
||||
// 根据商家商品编码和商家门店编码批量修改门店价格接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=205&apiid=fcbf346648a54d03b92dec8fa62ea643
|
||||
func (a *API) UpdateVendorStationPrice(outStationNo, stationNo string, skuPriceInfoList []*SkuPriceInfo) ([]map[string]interface{}, error) {
|
||||
if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") {
|
||||
return nil, errors.New("outStationNo and stationNo can not all be empty or have value")
|
||||
}
|
||||
func (a *API) UpdateVendorStationPrice(outStationNo, stationNo string, skuPriceInfoList []*SkuPriceInfo) (responseList []*StoreSkuBatchUpdateResponse, err error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"skuPriceInfoList": skuPriceInfoList,
|
||||
}
|
||||
@@ -109,11 +106,14 @@ func (a *API) UpdateVendorStationPrice(outStationNo, stationNo string, skuPriceI
|
||||
} else {
|
||||
jdParams["stationNo"] = stationNo
|
||||
}
|
||||
result, err := a.AccessAPINoPage("venderprice/updateStationPrice", jdParams, nil, nil, nil)
|
||||
if err == nil && result != nil {
|
||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||||
result, err := a.AccessAPINoPage("venderprice/updateStationPrice", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "0"))
|
||||
if result != nil {
|
||||
var err2 error
|
||||
if responseList, err2 = a.handleBatchOpResult(len(skuPriceInfoList), result, "json2"); err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
return responseList, err
|
||||
}
|
||||
|
||||
// 根据到家商品编码和到家门店编码修改门店价格接口
|
||||
@@ -146,16 +146,16 @@ func (a *API) GetStationInfoList(stationNo string, skuIds []int64) (priceInfo []
|
||||
return priceInfo, err
|
||||
}
|
||||
|
||||
func (a *API) handleBatchOpResult(batchCount int, result interface{}) (responseList []*StoreSkuBatchUpdateResponse, err error) {
|
||||
if err = utils.Map2StructByJson(result, &responseList, true); err == nil {
|
||||
func (a *API) handleBatchOpResult(batchCount int, result interface{}, tagName string) (responseList []*StoreSkuBatchUpdateResponse, err error) {
|
||||
if err = utils.Map2Struct(result, &responseList, true, tagName); err == nil {
|
||||
var failedList []*StoreSkuBatchUpdateResponse
|
||||
for _, v := range responseList {
|
||||
if v.Code != 0 {
|
||||
failedList = append(failedList, v)
|
||||
}
|
||||
}
|
||||
if batchCount == len(failedList) {
|
||||
err = fmt.Errorf(string(utils.MustMarshal(failedList)))
|
||||
if len(failedList) >= batchCount {
|
||||
err = utils.NewErrorCode(string(utils.MustMarshal(failedList)), ResponseCodeAccessFailed, 1) // 此错误基本用不到
|
||||
} else if len(failedList) > 0 { // 部分失败
|
||||
err = utils.NewErrorCode(string(utils.MustMarshal(failedList)), ResponseInnerCodePartialFailed, 1)
|
||||
}
|
||||
@@ -179,8 +179,11 @@ func (a *API) BatchUpdateCurrentQtys(outStationNo, stationNo string, skuStockLis
|
||||
jdParams["stationNo"] = stationNo
|
||||
}
|
||||
result, err := a.AccessAPINoPage("stock/batchUpdateCurrentQtys", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
|
||||
if err == nil && result != nil {
|
||||
responseList, err = a.handleBatchOpResult(len(skuStockList), result)
|
||||
if result != nil {
|
||||
var err2 error
|
||||
if responseList, err2 = a.handleBatchOpResult(len(skuStockList), result, ""); err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
return responseList, err
|
||||
}
|
||||
@@ -220,16 +223,19 @@ func (a *API) UpdateCurrentQty(stationNo string, skuID int64, currentQty int) er
|
||||
|
||||
// 根据到家商品编码和到家门店编码批量修改门店商品可售状态接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=b783a508e2cf4aca94681e4eed9af5bc
|
||||
// 尽量不用这个接口,用下面那个
|
||||
// 尽量不用这个接口,用下面那个,原因是这个不支持设置操作人,BatchUpdateVendibility可以
|
||||
func (a *API) UpdateVendibility(listBaseStockCenterRequest []*QueryStockRequest) (responseList []*StoreSkuBatchUpdateResponse, err error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"listBaseStockCenterRequest": listBaseStockCenterRequest,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("stock/updateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
|
||||
if err == nil && result != nil {
|
||||
responseList, err = a.handleBatchOpResult(len(listBaseStockCenterRequest), result)
|
||||
if result != nil {
|
||||
var err2 error
|
||||
if responseList, err2 = a.handleBatchOpResult(len(listBaseStockCenterRequest), result, ""); err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
return responseList, err
|
||||
}
|
||||
|
||||
// 根据商家商品编码和门店编码批量修改门店商品可售状态接口
|
||||
@@ -248,8 +254,11 @@ func (a *API) BatchUpdateVendibility(outStationNo, stationNo string, stockVendib
|
||||
jdParams["stationNo"] = stationNo
|
||||
}
|
||||
result, err := a.AccessAPINoPage("stock/batchUpdateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
|
||||
if err == nil && result != nil {
|
||||
responseList, err = a.handleBatchOpResult(len(stockVendibilityList), result)
|
||||
if result != nil {
|
||||
var err2 error
|
||||
if responseList, err2 = a.handleBatchOpResult(len(stockVendibilityList), result, ""); err2 != nil && err == nil {
|
||||
err = err2
|
||||
}
|
||||
}
|
||||
return responseList, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user