1
This commit is contained in:
@@ -212,7 +212,7 @@ func CopyMtToMT(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail, isA
|
||||
//}
|
||||
case 2:
|
||||
i := offSet
|
||||
errList := make([]string, 0, 0)
|
||||
errList := make([]*mtwmapi.AppFoodResult, 0, 0)
|
||||
for {
|
||||
// 同步商品
|
||||
fromFoodList, err1 := fromApi.RetailListAll(fromStore.VendorStoreID, i)
|
||||
@@ -220,18 +220,20 @@ func CopyMtToMT(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail, isA
|
||||
return nil, fmt.Errorf("fromFoodList 为空 %s ,i:= %d", utils.Format4Output(err1, false), i)
|
||||
}
|
||||
|
||||
if err = BatchInitSkuMT2MT(ctx, fromFoodList, toApi, toStore.VendorStoreID, i); err != nil {
|
||||
errs := utils.Format4Output(err, false)
|
||||
errList = append(errList, errs)
|
||||
errDataList, err := BatchInitSkuMT2MT(ctx, fromFoodList, toApi, toStore.VendorStoreID, i)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("BatchInitData : %v", err)
|
||||
}
|
||||
if len(errDataList) > model.NO {
|
||||
errList = append(errList, errDataList...)
|
||||
}
|
||||
globals.SugarLogger.Debugf("==============i: %d len: %d", i, len(fromFoodList))
|
||||
if len(fromFoodList) < 100 {
|
||||
globals.SugarLogger.Debugf("BatchInitData : %s", utils.Format4Output(errList, false))
|
||||
return nil, nil
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
globals.SugarLogger.Debugf("errListData := %s", utils.Format4Output(errList, false))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -247,7 +249,7 @@ func CopyMtToMT(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail, isA
|
||||
}
|
||||
|
||||
// BatchInitSkuMT2MT 批量创建商品
|
||||
func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi *mtwmapi.API, vendorStoreID string, offset int) error {
|
||||
func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi *mtwmapi.API, vendorStoreID string, offset int) (errList []*mtwmapi.AppFoodResult, err error) {
|
||||
foodDataList := make([]map[string]interface{}, len(fromSku))
|
||||
for k, storeSku := range fromSku {
|
||||
foodData := make(map[string]interface{})
|
||||
@@ -258,6 +260,7 @@ func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi
|
||||
}
|
||||
|
||||
skus := make([]interface{}, 0)
|
||||
upc := ""
|
||||
for _, v := range storeSku.SkuList {
|
||||
if v.SkuId == "" {
|
||||
v.SkuId = storeSku.AppFoodCode
|
||||
@@ -270,6 +273,9 @@ func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi
|
||||
if v.BoxPrice == "" {
|
||||
delete(mapSkuList, "box_price")
|
||||
}
|
||||
if v.Upc != "" {
|
||||
upc = v.Upc
|
||||
}
|
||||
mapSkuList["available_times"] = string(salesCycle)
|
||||
skus = append(skus, mapSkuList)
|
||||
}
|
||||
@@ -301,7 +307,10 @@ func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi
|
||||
foodData["sequence"] = storeSku.Sequence
|
||||
foodData["tag_id"] = storeSku.TagID
|
||||
foodData["upc"] = storeSku.UpcCode
|
||||
if storeSku.UpcCode == "" {
|
||||
if foodData["upc"].(string) == "" {
|
||||
foodData["upc"] = upc
|
||||
}
|
||||
if foodData["upc"].(string) == "" {
|
||||
foodData["upc"] = "no_upc"
|
||||
}
|
||||
|
||||
@@ -312,21 +321,20 @@ func BatchInitSkuMT2MT(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi
|
||||
if len(foodDataList)%10 != 0 {
|
||||
count += 1
|
||||
}
|
||||
globals.SugarLogger.Debugf("=====data := %s", utils.Format4Output(foodDataList, false))
|
||||
for i := 0; i < count; i++ {
|
||||
if i == count-1 {
|
||||
failedFoodList, _ := toApi.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList[i*10:])
|
||||
if len(failedFoodList) != 0 {
|
||||
globals.SugarLogger.Debugf("RetailBatchInitData2 failedFoodList :%s", utils.Format4Output(failedFoodList, false))
|
||||
errList = append(errList, failedFoodList...)
|
||||
}
|
||||
} else {
|
||||
failedFoodList, _ := toApi.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList[i*10:(i+1)*10])
|
||||
if len(failedFoodList) != 0 {
|
||||
globals.SugarLogger.Debugf("RetailBatchInitData4 failedFoodList :%s", utils.Format4Output(failedFoodList, false))
|
||||
errList = append(errList, failedFoodList...)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
return errList, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user