同步错误返回

This commit is contained in:
苏尹岚
2019-12-04 17:34:45 +08:00
parent 16a14e8b4d
commit 6d677bab43
6 changed files with 61 additions and 28 deletions

View File

@@ -120,7 +120,7 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, v
if globals.EnableEbaiStoreWrite {
_, err = api.EbaiAPI.SkuUpdate(ctx.GetTrackInfo(), strStoreID, utils.Str2Int64(storeSku.VendorSkuID), params)
if err != nil {
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "更新商品基础信息")
}
utils.CallFuncAsync(func() {
api.EbaiAPI.SkuShopCategoryMap(strStoreID, utils.Str2Int64(storeSku.VendorSkuID), "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku))
@@ -141,7 +141,7 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
api.EbaiAPI.SkuShopCategoryMap(strStoreID, vendorSkuID, "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku))
})
} else {
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "创建商品")
}
} else {
vendorSkuID = jxutils.GenFakeID()
@@ -164,7 +164,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v
opResult, err2 := api.EbaiAPI.SkuDelete(ctx.GetTrackInfo(), utils.Int2Str(storeID), partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDIntList(), nil)
if err = err2; err2 != nil && opResult != nil {
// if len(storeSkuList) > len(opResult.FailedList) {
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult)
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "删除商品")
// successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult))
// }
}
@@ -181,7 +181,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
opResult, err = api.EbaiAPI.SkuOnline(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs, nil, nil)
} else if len(vendorSkuIDs) == 1 {
err = api.EbaiAPI.SkuOnlineOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs[0], "", "")
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "更新商品状态")
return failedList, err
}
} else {
@@ -189,12 +189,12 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
opResult, err = api.EbaiAPI.SkuOffline(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs, nil, nil)
} else if len(vendorSkuIDs) == 1 {
err = api.EbaiAPI.SkuOfflineOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), vendorSkuIDs[0], "", "")
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "更新商品状态")
return failedList, err
}
}
if err != nil && opResult != nil {
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult)
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品状态")
// failedList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult))
}
}
@@ -219,12 +219,12 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
if len(storeSkuList) > 1 {
opResult, err2 := api.EbaiAPI.SkuPriceUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID)
if err = err2; err != nil && opResult != nil {
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult)
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品价格")
}
} else if len(storeSkuList) == 1 {
opResult2, err := api.EbaiAPI.SkuPriceUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0])
if err != nil && opResult2 != nil {
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult2)
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult2, storeID, model.VendorIDEBAI, "更新商品价格")
}
}
}
@@ -236,12 +236,12 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
if len(storeSkuList) > 1 {
opResult, err2 := api.EbaiAPI.SkuStockUpdateBatch(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList), ebaiapi.SkuIDTypeSkuID)
if err = err2; err != nil && opResult != nil {
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult)
failedList = putils.SelectStoreSkuListByOpResult(storeSkuList, opResult, storeID, model.VendorIDEBAI, "更新商品库存")
// successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getFailedVendorSkuIDsFromOpResult(opResult))
}
} else if len(storeSkuList) == 1 {
err = api.EbaiAPI.SkuStockUpdateOne(ctx.GetTrackInfo(), utils.Int2Str(storeID), StoreSkuInfoList2Ebai(storeSkuList)[0])
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDEBAI, "更新商品库存")
}
}
return failedList, err

View File

@@ -122,7 +122,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
if globals.EnableJdStoreWrite {
responseList, err2 := getAPI("").BatchUpdateVendibility(ctx.GetTrackInfo(), "", vendorStoreID, skuVendibilityList, ctx.GetUserName())
if err = err2; isErrPartialFailed(err) {
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList)
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品状态")
// successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false)))
}
}
@@ -133,7 +133,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
if len(storeSkuList) == 1 {
if globals.EnableJdStoreWrite {
_, err = getAPI("").UpdateStationPrice(ctx.GetTrackInfo(), utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), vendorStoreID, int(storeSkuList[0].VendorPrice))
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDJD, "更新商品价格")
}
} else {
var skuPriceInfoList []*jdapi.SkuPriceInfo
@@ -146,7 +146,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
if globals.EnableJdStoreWrite {
responseList, err2 := getAPI("").UpdateVendorStationPrice(ctx.GetTrackInfo(), "", vendorStoreID, skuPriceInfoList)
if err = err2; isErrPartialFailed(err) {
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList)
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品价格")
}
}
}
@@ -157,7 +157,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
if len(storeSkuList) == 1 {
if globals.EnableJdStoreWrite {
err = getAPI("").UpdateCurrentQty(ctx.GetTrackInfo(), vendorStoreID, utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), storeSkuList[0].Stock)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDJD, "更新商品库存")
}
} else {
var skuStockList []*jdapi.SkuStock
@@ -170,7 +170,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
if globals.EnableJdStoreWrite {
responseList, err2 := getAPI("").BatchUpdateCurrentQtys(ctx.GetTrackInfo(), "", vendorStoreID, skuStockList, ctx.GetUserName())
if err = err2; isErrPartialFailed(err) {
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList)
failedList = putils.SelectStoreSkuListByResponseList(storeSkuList, responseList, storeID, model.VendorIDJD, "更新商品库存")
// successList = putils.UnselectStoreSkuListBySkuIDs(storeSkuList, utils.StringSlice2Int(getStrOutSkuIDs(responseList, false)))
}
}

View File

@@ -234,7 +234,13 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
// 对于多门店平台来说storeSkuList中只有SkuID与VendorSkuID有意义
func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo, isCreate bool) (failedList []*partner.StoreSkuInfoWithErr, err error) {
var syncType string
foodDataList := make([]map[string]interface{}, len(storeSkuList))
if isCreate {
syncType = "创建商品"
} else {
syncType = "更新商品"
}
for i, storeSku := range storeSkuList {
isNeedUpdatePrice := isCreate //storeSku.StoreSkuSyncStatus&( model.SyncFlagPriceMask| model.SyncFlagNewMask) != 0
foodData := make(map[string]interface{})
@@ -294,12 +300,12 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
if len(foodDataList) == 1 {
foodDataList[0]["skus"] = string(utils.MustMarshal(foodDataList[0]["skus"]))
err = api.MtwmAPI.RetailInitData(ctx.GetTrackInfo(), vendorStoreID, utils.Int2Str(storeSkuList[0].SkuID), foodDataList[0])
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDMTWM, syncType)
} else if len(foodDataList) > 0 {
failedFoodList, err2 := api.MtwmAPI.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList)
if err = err2; err == nil {
if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil {
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList)
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, syncType)
// successList = putils.UnselectStoreSkuSyncListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList))
}
}
@@ -325,7 +331,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v
if globals.EnableMtwmStoreWrite {
if len(storeSkuList) == 1 {
err = api.MtwmAPI.RetailDelete(ctx.GetTrackInfo(), vendorStoreID, storeSkuList[0].VendorSkuID)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err)
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorIDMTWM, "删除商品")
} else {
// todo 部分失败
err = api.MtwmAPI.RetailCatSkuBatchDelete2(ctx.GetTrackInfo(), vendorStoreID, nil, nil, nil, nil, partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDList())
@@ -333,7 +339,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v
if errExt, ok := err.(*utils.ErrorWithCode); ok {
myMap := make(map[string][]*mtwmapi.AppFoodResult)
json.Unmarshal([]byte(errExt.ErrMsg()), &myMap)
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, myMap["retail_error_list"])
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, myMap["retail_error_list"], storeID, model.VendorIDMTWM, "批量删除商品")
}
}
}
@@ -374,7 +380,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
failedFoodList, err2 := api.MtwmAPI.RetailSellStatus(ctx.GetTrackInfo(), vendorStoreID, skuList, mtwmStatus)
if err = err2; err == nil {
if len(failedFoodList) > 0 {
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList)
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品状态")
// successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList))
}
}
@@ -388,7 +394,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
failedFoodList, err2 := api.MtwmAPI.RetailSkuPrice(ctx.GetTrackInfo(), vendorStoreID, priceList)
if err = err2; err == nil {
if len(failedFoodList) > 0 {
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList)
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品价格")
}
}
}
@@ -401,7 +407,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
failedFoodList, err2 := api.MtwmAPI.RetailSkuStock(ctx.GetTrackInfo(), vendorStoreID, stockList)
if err = err2; err == nil {
if len(failedFoodList) > 0 {
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList)
failedList = putils.SelectStoreSkuListByFoodList(storeSkuList, failedFoodList, storeID, model.VendorIDMTWM, "更新商品库存")
}
// if err = putils.GenPartialFailedErr(failedFoodList, len(failedFoodList)); err != nil {
// successList = putils.UnselectStoreSkuListByVendorSkuIDs(storeSkuList, getAppFoodCodeList(failedFoodList))