This commit is contained in:
邹宗楠
2023-09-22 15:09:11 +08:00
parent 56808546cd
commit 0ffe12bb75

View File

@@ -13,7 +13,6 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
"git.rosy.net.cn/jx-callback/business/partner/putils"
)
@@ -78,18 +77,26 @@ func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromVendorStoreId, toStoreId
//}
case 3:
// 同步商品
fromFoodList, err1 := fromApi.RetailListAll(utils.Int2Str(fromVendorStoreId))
if len(fromFoodList) == 0 || fromFoodList == nil {
return nil, fmt.Errorf("fromFoodList 为空")
}
globals.SugarLogger.Debugf("RetailListAll : %s", utils.Format4Output(len(fromFoodList), false))
if err1 != nil {
globals.SugarLogger.Debugf("RetailListAll : %s", utils.Format4Output(err, false))
}
if err := BatchInitData(ctx, fromFoodList, toApi, toStore.VendorStoreID); err != nil {
globals.SugarLogger.Debugf("BatchInitData : %s", utils.Format4Output(err, false))
i := 0
for {
// 同步商品
fromFoodList, err1 := fromApi.RetailListAll(utils.Int2Str(fromVendorStoreId), i)
if len(fromFoodList) == 0 || fromFoodList == nil {
return nil, fmt.Errorf("fromFoodList 为空")
}
globals.SugarLogger.Debugf("RetailListAll : %s", utils.Format4Output(len(fromFoodList), false))
if err1 != nil {
globals.SugarLogger.Debugf("RetailListAll : %s", utils.Format4Output(err, false))
}
if err := BatchInitData(ctx, fromFoodList, toApi, toStore.VendorStoreID); err != nil {
globals.SugarLogger.Debugf("BatchInitData : %s", utils.Format4Output(err, false))
}
if len(fromFoodList) < 200 {
break
}
i++
}
}
return
}
@@ -105,7 +112,7 @@ func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromVendorStoreId, toStoreId
}
func LoadingStoreSkuList(ctx *jxcontext.Context, api *mtwmapi.API, poiCode string) (err []error) {
foodList, err1 := api.RetailListAll(poiCode)
foodList, err1 := api.RetailListAll(poiCode, 0)
if err1 != nil {
return append(err, err1)
}
@@ -156,7 +163,7 @@ type Skus struct {
// BatchInitData 批量创建商品
func BatchInitData(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi *mtwmapi.API, vendorStoreID string) error {
globals.SugarLogger.Debugf("===========[] %s", utils.Format4Output(fromSku[0], false))
globals.SugarLogger.Debugf("===========[] %d", len(fromSku))
foodDataList := make([]map[string]interface{}, len(fromSku))
for i, storeSku := range fromSku {
foodData := make(map[string]interface{})
@@ -178,10 +185,10 @@ func BatchInitData(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi *mt
foodData["min_order_count"] = storeSku.MinOrderCount
foodData["unit"] = storeSku.Unit
//todo 增加商品必填属性
attr := mtwm.SwitchAttr(toApi, vendorStoreID, int64(storeSku.TagID), 0, storeSku.Name)
if attr != "" {
foodData["common_attr_value"] = attr
}
//attr := mtwm.SwitchAttr(toApi, vendorStoreID, int64(storeSku.TagID), 0, storeSku.Name)
//if attr != "" {
foodData["common_attr_value"] = storeSku.CommonAttrValue
//}
if storeSku.SecondaryCategoryCode != "" {
foodData["category_code"] = storeSku.SecondaryCategoryCode
} else {
@@ -257,7 +264,7 @@ func BatchInitData(ctx *jxcontext.Context, fromSku []*mtwmapi.AppFood, toApi *mt
if len(foodDataList)%5 != 0 {
count += 1
}
globals.SugarLogger.Debugf("===========[count] %d", count)
for i := 0; i < count; i++ {
if i == count-1 {
failedFoodList, err2 := toApi.RetailBatchInitData(ctx.GetTrackInfo(), vendorStoreID, foodDataList[i*5:])