From 30eac6363e0694b30d47d1fb55d67b7d4be65ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 15 May 2026 13:58:10 +0800 Subject: [PATCH] 1 --- business/jxstore/cms/store_sku.go | 256 +++++++++++++++++------------- 1 file changed, 142 insertions(+), 114 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index ba6b808d4..afcb7d57a 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -6551,7 +6551,7 @@ func GetVendorStoreSkus(ctx *jxcontext.Context, storeID, vendorID int) (err erro // CopyMtToJd 复制美团到京东 func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCode string) (err error) { - type funcType func(mtID, parentID string, catInfo []*mtwmapi.RetailCategoryInfo) + //type funcType func(mtID, parentID string, catInfo []*mtwmapi.RetailCategoryInfo) var ( //mtAccessToken = "" //db = dao.GetDB() @@ -6594,46 +6594,53 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo step := batchItemList[0].(int) switch step { case 0: - //jdCatList, _ := jd.QueryCategoriesByOrgCode() + jdCatList, _ := jd.QueryCategoriesByOrgCode() catList, _ := mtapi.RetailCatList(mtStoreID) - //for _, jdc := range jdCatList { - // for _, mtc := range catList { - // if jdc.Name == mtc.Name { - // catMap[mtc.Name] = utils.Int64ToStr(jdc.Id) - // break - // } - // } - //} - - //建分类 ,账号存在分类,不在创建分类 - //jdCatList, _ := jd.QueryCategoriesByOrgCode() - //if len(jdCatList) == 0 { - //catList, _ = mtapi.RetailCatList(mtStoreID) - - for i := len(catList) - 1; i > -1; i-- { - catID, _ := jd.AddShopCategory(0, catList[i].Name, catList[i].Level, catList[i].Sequence, "") - if catID != "" { - if catList[i].Code != "" { - catMap[catList[i].Code] = catID - } else { - catMap[catList[i].Name] = catID + for _, jdc := range jdCatList { + for _, mtc := range catList { + if jdc.Name == mtc.Name { + catMap[mtc.Name] = utils.Int64ToStr(jdc.Id) + break } - } - //LoopCatChild(catList[i].Code, catID, catList[i].Children) - //美团好像只能建两级分类? - for j := len(catList[i].Children) - 1; j > -1; j-- { - catID2, _ := jd.AddShopCategory(utils.Str2Int64(catID), catList[i].Children[j].Name, catList[i].Children[j].Level, catList[i].Children[j].Sequence, "") - if catID2 != "" { - if catList[i].Children[j].Code != "" { - catMap[catList[i].Children[j].Code] = catID2 - } else { - catMap[catList[i].Children[j].Name] = catID2 + if len(mtc.Children) != 0 { + for _, mtcl := range mtc.Children { + if mtcl.Name == jdc.Name { + catMap[mtcl.Name] = utils.Int64ToStr(jdc.Id) + } } } } } - globals.SugarLogger.Debugf("--------catMapcatMap := %s", utils.Format4Output(catList, false)) + ////建分类 ,账号存在分类,不在创建分类 + ////jdCatList, _ := jd.QueryCategoriesByOrgCode() + ////if len(jdCatList) == 0 { + ////catList, _ = mtapi.RetailCatList(mtStoreID) + // + //for i := len(catList) - 1; i > -1; i-- { + // catID, _ := jd.AddShopCategory(0, catList[i].Name, catList[i].Level, catList[i].Sequence, "") + // if catID != "" { + // if catList[i].Code != "" { + // catMap[catList[i].Code] = catID + // } else { + // catMap[catList[i].Name] = catID + // } + // } + // //LoopCatChild(catList[i].Code, catID, catList[i].Children) + // //美团好像只能建两级分类? + // for j := len(catList[i].Children) - 1; j > -1; j-- { + // catID2, _ := jd.AddShopCategory(utils.Str2Int64(catID), catList[i].Children[j].Name, catList[i].Children[j].Level, catList[i].Children[j].Sequence, "") + // if catID2 != "" { + // if catList[i].Children[j].Code != "" { + // catMap[catList[i].Children[j].Code] = catID2 + // } else { + // catMap[catList[i].Children[j].Name] = catID2 + // } + // } + // } + //} + + globals.SugarLogger.Debugf("--------catMapcatMap := %s", utils.Format4Output(catMap, false)) //} case 1: //建商品 @@ -6652,93 +6659,114 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo i++ } + var searchAfterSkuId string = "" + var jdSkus = make(map[string]int, 0) + for i2 := 0; i2 < 85; i2++ { + idList, afterSkuId, err := jd.AuerySkuInfoList(int64(i), 20, searchAfterSkuId) + if err != nil { + globals.SugarLogger.Debugf("--------err:%v", err) + return + } + time.Sleep(time.Second * 1) + searchAfterSkuId = utils.Int64ToStr(afterSkuId) + for _, ifd := range idList { + jdSkus[ifd] = 1 + } + if len(idList) < 20 { + break + } + } + globals.SugarLogger.Debugf("--------jdSkus := %d", len(jdSkus)) + task2 := tasksch.NewParallelTask("美团到京东, 建商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { time.Sleep(1 * time.Second) mtSku := batchItemList[0].(*mtwmapi.AppFood) - //catMaps, _ := dao.GetMtJdCategoryMap(db, utils.Int2Str(mtSku.TagID), "") - //if len(catMaps) == 0 { - //results, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, mtSku.TagID) - // results2, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results[0].ParentID)) - // results3, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results2[0].ParentID)) - // //return retVal, fmt.Errorf("该商品美团分类还未映射到京东,商品名:[%v],美团分类:[%v] ->[%v] ->[%v]。", mtSku.Name, results3[0].Name, results2[0].Name, results[0].Name) - //} - param := &jdapi.NewAddSkuParam{ - TraceId: ctx.GetTrackInfo(), - OutSkuId: mtSku.AppFoodCode, - ShopCategories: []int64{}, // 商家分类 - CategoryId: 0, // 到家分类 - BrandId: 0, - SkuName: mtSku.Name, - SkuPrice: int64(jxutils.StandardPrice2Int(mtSku.Price)), - Weight: math.Round(float64(jxutils.IntWeight2Float(utils.Str2Int(mtSku.SkuList[0].Weight)))*1000) / 1000, - FixedStatus: 1, - IsSale: true, - Upc: mtSku.SkuList[0].Upc, - Images: mtSku.PictureList, - } - brandList, err := jd.GetSkuCategoryBySkuName(mtSku.Name) - if brandList == nil || err != nil { - param.BrandId = 35247 - } else { - param.BrandId = int64(brandList.BrandId) - param.CategoryId = int64(brandList.CategoryId) - } - - if param.OutSkuId == "" { - param.OutSkuId = fmt.Sprintf("%d_%d%d", time.Now().Unix(), param.SkuPrice, len(mtSku.Name)) - } - - if param.CategoryId == 0 { - vendorCategoryId, _ := handler.GetSkuCategoryIdByName(jdOrgCode, strings.Join(mtSku.PictureList, "|")) - param.CategoryId = utils.Str2Int64(vendorCategoryId) - //if vendorCategoryId != "" && utils.Str2Int64(vendorCategoryId) <= 25048 { - // param.CategoryID = utils.Str2Int64(vendorCategoryId) // 其他水果 - //} else if utils.Str2Int64(vendorCategoryId) > 25048 { // 只有水果,後面刪除 - // param.CategoryID = 22410 // 其他水果 + if _, ok := jdSkus[mtSku.AppFoodCode]; !ok { + //catMaps, _ := dao.GetMtJdCategoryMap(db, utils.Int2Str(mtSku.TagID), "") + //if len(catMaps) == 0 { + //results, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, mtSku.TagID) + // results2, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results[0].ParentID)) + // results3, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results2[0].ParentID)) + // //return retVal, fmt.Errorf("该商品美团分类还未映射到京东,商品名:[%v],美团分类:[%v] ->[%v] ->[%v]。", mtSku.Name, results3[0].Name, results2[0].Name, results[0].Name) //} - } - - if mtSku.SecondaryCategoryCode != "" { - param.ShopCategories = append(param.ShopCategories, utils.Str2Int64WithDefault(catMap[mtSku.SecondaryCategoryCode], 33313305)) - } else if mtSku.SecondaryCategoryName != "" { - param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.SecondaryCategoryName])) - } else if mtSku.CategoryCode != "" { - param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryCode])) - } else if mtSku.CategoryName != "" { - param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryName])) - } else { - param.ShopCategories = append(param.ShopCategories, 33313305) // 暂无分类 - } - if mtSku.PictureContents != "" { - param.ProductDesc = fmt.Sprintf(`一张图片`, mtSku.PictureContents) - } - if param.Upc == "" { - productInfo, _ := jd.GetJdUpcCodeByName(param.SkuName, "", 1, 10) - if len(productInfo) != 0 { - param.Upc = productInfo[0].UpcCode + param := &jdapi.NewAddSkuParam{ + TraceId: ctx.GetTrackInfo(), + OutSkuId: mtSku.AppFoodCode, + ShopCategories: []int64{}, // 商家分类 + CategoryId: 0, // 到家分类 + BrandId: 0, + SkuName: mtSku.Name, + SkuPrice: int64(jxutils.StandardPrice2Int(mtSku.Price)), + Weight: math.Round(float64(jxutils.IntWeight2Float(utils.Str2Int(mtSku.SkuList[0].Weight)))*1000) / 1000, + FixedStatus: 1, + IsSale: true, + Upc: mtSku.SkuList[0].Upc, + Images: mtSku.PictureList, } - } - - skuID, err := jd.NewAddSku(param) - if err != nil { - globals.SugarLogger.Debugf("---------AddSku2 := %s,%v", utils.Format4Output(param, false), err) - } - time.Sleep(1 * time.Second) - if skuID != "" { - err1 := jd.UpdateCurrentQty(ctx.GetTrackInfo(), jdStoreID, utils.Str2Int64(skuID), utils.Str2Int(mtSku.SkuList[0].Stock)) - if err1 != nil { - globals.SugarLogger.Debugf("--------err r1 := %v", err1) + brandList, err := jd.GetSkuCategoryBySkuName(mtSku.Name) + if brandList == nil || err != nil { + param.BrandId = 35247 + } else { + param.BrandId = int64(brandList.BrandId) + param.CategoryId = int64(brandList.CategoryId) } - _, err2 := jd.UpdateVendibility(ctx.GetTrackInfo(), []*jdapi.QueryStockRequest{ - &jdapi.QueryStockRequest{ - StationNo: jdStoreID, - SkuId: utils.Str2Int64(skuID), - DoSale: mtSku.IsSoldOut, - }, - }) - if err2 != nil { - globals.SugarLogger.Debugf("--------err r1 := %v", err2) + + if param.OutSkuId == "" { + param.OutSkuId = fmt.Sprintf("%d_%d%d", time.Now().Unix(), param.SkuPrice, len(mtSku.Name)) + } + + if param.CategoryId == 0 { + vendorCategoryId, _ := handler.GetSkuCategoryIdByName(jdOrgCode, strings.Join(mtSku.PictureList, "|")) + param.CategoryId = utils.Str2Int64(vendorCategoryId) + //if vendorCategoryId != "" && utils.Str2Int64(vendorCategoryId) <= 25048 { + // param.CategoryID = utils.Str2Int64(vendorCategoryId) // 其他水果 + //} else if utils.Str2Int64(vendorCategoryId) > 25048 { // 只有水果,後面刪除 + // param.CategoryID = 22410 // 其他水果 + //} + } + + if mtSku.SecondaryCategoryCode != "" { + param.ShopCategories = append(param.ShopCategories, utils.Str2Int64WithDefault(catMap[mtSku.SecondaryCategoryCode], 33313305)) + } else if mtSku.SecondaryCategoryName != "" { + param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.SecondaryCategoryName])) + } else if mtSku.CategoryCode != "" { + param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryCode])) + } else if mtSku.CategoryName != "" { + param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryName])) + } else { + param.ShopCategories = append(param.ShopCategories, 33313305) // 暂无分类 + } + if mtSku.PictureContents != "" { + param.ProductDesc = fmt.Sprintf(`一张图片`, mtSku.PictureContents) + } + if param.Upc == "" { + productInfo, _ := jd.GetJdUpcCodeByName(param.SkuName, "", 1, 10) + if len(productInfo) != 0 { + param.Upc = productInfo[0].UpcCode + } + } + + skuID, err := jd.NewAddSku(param) + if skuID == "0" || err != nil { + globals.SugarLogger.Debugf("Add sku : %s", utils.Format4Output(param, false)) + } + time.Sleep(1 * time.Second) + if skuID != "" { + err1 := jd.UpdateCurrentQty(ctx.GetTrackInfo(), jdStoreID, utils.Str2Int64(skuID), utils.Str2Int(mtSku.SkuList[0].Stock)) + if err1 != nil { + globals.SugarLogger.Debugf("--------err r1 := %v", err1) + } + _, err2 := jd.UpdateVendibility(ctx.GetTrackInfo(), []*jdapi.QueryStockRequest{ + &jdapi.QueryStockRequest{ + StationNo: jdStoreID, + SkuId: utils.Str2Int64(skuID), + DoSale: mtSku.IsSoldOut, + }, + }) + if err2 != nil { + globals.SugarLogger.Debugf("--------err r1 := %v", err2) + } } } return retVal, err