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