diff --git a/platformapi/jdapi/store_sku.go b/platformapi/jdapi/store_sku.go index 98a269ca..6e442688 100644 --- a/platformapi/jdapi/store_sku.go +++ b/platformapi/jdapi/store_sku.go @@ -2,6 +2,7 @@ package jdapi import ( "errors" + "fmt" "git.rosy.net.cn/baseapi/utils" ) @@ -73,6 +74,12 @@ type UpdateVendibilityResponse struct { Vendibility int `json:"vendibility"` } +type StoreSkuBatchUpdateResponse struct { + OutSkuID string `json:"outSkuId"` + Code int `json:"code"` + Msg string `json:"msg"` +} + // 传入为数组的,最多一次为50个 // 有好些功能有两个类似的函数,一个为到家ID,一个为商家ID,建议都只用商家ID的那个,因为: // 1,这类函数一般可以批量操作 @@ -129,9 +136,26 @@ 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 { + 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))) + } else if len(failedList) > 0 { // 部分失败 + err = utils.NewErrorCode(string(utils.MustMarshal(failedList)), ResponseInnerCodePartialFailed, 1) + } + } + return responseList, err +} + // 根据商家商品编码和商家门店编码批量修改现货库存接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=10812f9fc7ee4564b552f19270a7e92e -func (a *API) BatchUpdateCurrentQtys(outStationNo, stationNo string, skuStockList []*SkuStock, userPin string) ([]map[string]interface{}, error) { +func (a *API) BatchUpdateCurrentQtys(outStationNo, stationNo string, skuStockList []*SkuStock, userPin string) (responseList []*StoreSkuBatchUpdateResponse, err error) { if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") { return nil, errors.New("outStationNo and stationNo can not all be empty or have value") } @@ -146,9 +170,9 @@ func (a *API) BatchUpdateCurrentQtys(outStationNo, stationNo string, skuStockLis } result, err := a.AccessAPINoPage("stock/batchUpdateCurrentQtys", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0")) if err == nil && result != nil { - return utils.Slice2MapSlice(result.([]interface{})), nil + responseList, err = a.handleBatchOpResult(len(skuStockList), result) } - return nil, err + return responseList, err } // 根据商家商品编码和商家门店编码更新门店现货库存接口 @@ -183,7 +207,7 @@ func (a *API) UpdateVendibility(listBaseStockCenterRequest []*QueryStockRequest) // 根据商家商品编码和门店编码批量修改门店商品可售状态接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=ac6f559ebabf4b70bc423687638e07c1 -func (a *API) BatchUpdateVendibility(outStationNo, stationNo string, stockVendibilityList []*StockVendibility, userPin string) ([]map[string]interface{}, error) { +func (a *API) BatchUpdateVendibility(outStationNo, stationNo string, stockVendibilityList []*StockVendibility, userPin string) (responseList []*StoreSkuBatchUpdateResponse, err error) { if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") { return nil, errors.New("outStationNo and stationNo can not all be empty or have value") } @@ -198,9 +222,9 @@ func (a *API) BatchUpdateVendibility(outStationNo, stationNo string, stockVendib } result, err := a.AccessAPINoPage("stock/batchUpdateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0")) if err == nil && result != nil { - return utils.Slice2MapSlice(result.([]interface{})), nil + responseList, err = a.handleBatchOpResult(len(stockVendibilityList), result) } - return nil, err + return responseList, err } // 根据到家商品编码和门店编码批量查询商品库存及可售状态信息接口