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