- 清理三个平台的门店商品批处理操作,部分失败返回失败条目
This commit is contained in:
@@ -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