From 58bc3ba38a51415d597ce555e604d4af6be4a4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 26 Jan 2024 16:25:29 +0800 Subject: [PATCH] 1 --- business/jxstore/cms/system_store_sku.go | 48 ++++++++++++++---------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/business/jxstore/cms/system_store_sku.go b/business/jxstore/cms/system_store_sku.go index 6e7c39fbc..08e2a0c23 100644 --- a/business/jxstore/cms/system_store_sku.go +++ b/business/jxstore/cms/system_store_sku.go @@ -45,6 +45,7 @@ func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromStoreId, toStoreId string // CopyEBaiToEBai 饿了么商品复制到饿了么 func CopyEBaiToEBai(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail, isAsync bool) (hint string, err error) { + VendorCategoryIDMap := make(map[int64]int64, 0) api := api.EbaiAPI taskName := fmt.Sprintf("将饿了么平台门店[%s],分类和商品复制到[%s]", fromStore.VendorStoreID, toStore.VendorStoreID) config := tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(false) @@ -60,21 +61,29 @@ func CopyEBaiToEBai(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail, //} case 2: // 同步分类 - //fromCategoryList, err := api.ShopCategoryGet(utils.Int2Str(fromStore.ID)) - //for _, v := range fromCategoryList { - // parentID, categoryErr := api.ShopCategoryCreate(utils.Int2Str(toStore.ID), 0, v.Name, v.Rank) - // if categoryErr != nil { - // globals.SugarLogger.Debugf("err := RetailCatUpdate : %v", categoryErr) - // continue - // } - // if v.Children != nil && len(v.Children) != 0 { - // for _, c := range v.Children { - // if _, err = api.ShopCategoryCreate(utils.Int2Str(toStore.ID), parentID, c.Name, c.Rank); err != nil { - // globals.SugarLogger.Debugf("err := RetailCatUpdate Children : %v", err) - // } - // } - // } - //} + fromCategoryList, err := api.ShopCategoryGet(utils.Int2Str(fromStore.ID)) + if err != nil { + return nil, err + } + for _, v := range fromCategoryList { + parentID, categoryErr := api.ShopCategoryCreate(utils.Int2Str(toStore.ID), 0, v.Name, v.Rank) + if categoryErr != nil { + globals.SugarLogger.Debugf("err := RetailCatUpdate : %v", categoryErr) + continue + } + VendorCategoryIDMap[v.CategoryID] = parentID + if v.Children != nil && len(v.Children) != 0 { + for _, c := range v.Children { + childrenCateId, err := api.ShopCategoryCreate(utils.Int2Str(toStore.ID), parentID, c.Name, c.Rank) + if err != nil { + globals.SugarLogger.Debugf("err := RetailCatUpdate Children : %v", err) + continue + } + VendorCategoryIDMap[v.CategoryID] = childrenCateId + } + } + } + globals.SugarLogger.Debugf("======VendorCategoryIDMap := %s", utils.Format4Output(VendorCategoryIDMap, false)) case 3: i := 0 for { @@ -84,8 +93,7 @@ func CopyEBaiToEBai(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail, return nil, fmt.Errorf("fromFoodList 为空 %s ,i:= %d", utils.Format4Output(err1, false), i) } - globals.SugarLogger.Debugf("===========%s", api.GetSource()) - if err = BatchInitSkuEBai2EBai(ctx, fromFoodList.List, api, toStore.VendorStoreID); err != nil { + if err = BatchInitSkuEBai2EBai(ctx, fromFoodList.List, api, utils.Int2Str(toStore.ID), VendorCategoryIDMap); err != nil { globals.SugarLogger.Debugf("BatchInitData : %s", utils.Format4Output(err, false)) } i = fromFoodList.SkuIdOffset @@ -106,7 +114,7 @@ func CopyEBaiToEBai(ctx *jxcontext.Context, fromStore, toStore *dao.StoreDetail, } // BatchInitSkuEBai2EBai 批量创建商品 -func BatchInitSkuEBai2EBai(ctx *jxcontext.Context, fromSku []*ebaiapi.SkuInfo, toApi *ebaiapi.API, storeID string) error { +func BatchInitSkuEBai2EBai(ctx *jxcontext.Context, fromSku []*ebaiapi.SkuInfo, toApi *ebaiapi.API, storeID string, VendorCategoryIDMap map[int64]int64) error { for _, storeSku := range fromSku { params := map[string]interface{}{ "left_num": model.MaxStoreSkuStockQty, @@ -116,8 +124,8 @@ func BatchInitSkuEBai2EBai(ctx *jxcontext.Context, fromSku []*ebaiapi.SkuInfo, t } params["upc"] = storeSku.Upc params["name"] = storeSku.Name - params["cat3_id"] = storeSku.CateId2 - params["category_id"] = storeSku.CateId + params["cat3_id"] = VendorCategoryIDMap[int64(storeSku.CateId2)] + params["category_id"] = VendorCategoryIDMap[int64(storeSku.CateId)] params["rtf"] = storeSku.Rtf params["process_type"] = storeSku.ProcessType params["process_detail"] = storeSku.ProcessDetail