From d72db7588f2f3425641d4aafd80b042ff8f1c0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 14 May 2026 14:06:13 +0800 Subject: [PATCH] 1 --- business/jxstore/cms/store_sku.go | 158 ++++++++++++++++++------------ controllers/jds_callback.go | 38 +++---- 2 files changed, 110 insertions(+), 86 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 62e45d947..9aa10aa72 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -6555,75 +6555,94 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo var ( //mtAccessToken = "" //db = dao.GetDB() - catMap = make(map[string]string) - LoopCatChild funcType - handler, _ = partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IPurchasePlatformStoreSkuHandler) + catMap = make(map[string]string) + //LoopCatChild funcType + handler, _ = partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IPurchasePlatformStoreSkuHandler) ) jd := jd.GetAPI(jdOrgCode) //获取token mtapi := apimanager.CurAPIManager.GetAPI(model.VendorIDMTWM, mtOrgCode).(*mtwmapi.API) - LoopCatChild = func(mtID, parentID string, catInfo []*mtwmapi.RetailCategoryInfo) { - if len(catInfo) > 0 { - for j := len(catInfo) - 1; j > -1; j-- { - result, _ := jd.AddShopCategory(utils.Str2Int64(parentID), catInfo[j].Name, catInfo[j].Level, catInfo[j].Sequence, "") - if result != "" { - catMap[mtID] = result - } - LoopCatChild(catInfo[j].Code, result, catInfo[j].Children) - } - } - } + //LoopCatChild = func(mtID, parentID string, catInfo []*mtwmapi.RetailCategoryInfo) { + // if len(catInfo) > 0 { + // for j := len(catInfo) - 1; j > -1; j-- { + // result, _ := jd.AddShopCategory(utils.Str2Int64(parentID), catInfo[j].Name, catInfo[j].Level, catInfo[j].Sequence, "") + // if result != "" { + // catMap[mtID] = result + // } + // LoopCatChild(catInfo[j].Code, result, catInfo[j].Children) + // } + // } + //} task := tasksch.NewParallelTask("美团到京东", tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { 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 - } - } - } + //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 != "" { - // catMap[catList[i].Code] = 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 != "" { - // catMap[catList[i].Children[j].Code] = catID2 - // } - // } - // } + //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 != "" { + 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 != "" { + catMap[catList[i].Children[j].Code] = catID2 + } else { + catMap[catList[i].Children[j].Name] = catID2 + } + } + } //} case 1: //建商品 + var i = 0 skuList := make([]*mtwmapi.AppFood, 0, 0) - for i := 0; i < 9; i++ { - skuList2, _ := mtapi.RetailListAll(mtStoreID, i) - skuList = append(skuList, skuList2...) - } + //for i := 0; i < 9; i++ { + // skuList2, _ := mtapi.RetailListAll(mtStoreID, i) + // skuList = append(skuList, skuList2...) + //} //skuList, _ := mtapi.RetailList(mtStoreID, 0, 2) + + for { + foodList, err := mtapi.RetailListAll(mtStoreID, i) + if err != nil { + globals.SugarLogger.Debugf("美团商品价格和上下架状态获取平台商品异常 :%v", err) + break + } + skuList = append(skuList, foodList...) + if len(foodList) < 100 { + break + } + i++ + } + 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) + //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) @@ -6633,33 +6652,44 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo OutSkuID: mtSku.AppFoodCode, ShopCategories: []int64{}, // 商家分类 //CategoryID: utils.Str2Int64(catMaps[0].JdID), // 到家分类 - BrandID: 35247, + //BrandID: 35247, SkuName: mtSku.Name, SkuPrice: int(jxutils.StandardPrice2Int(mtSku.Price)), Weight: float64(jxutils.IntWeight2Float(utils.Str2Int(mtSku.SkuList[0].Weight))), FixedStatus: 1, - IsSale: -1, + IsSale: 1, 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)) } - vendorCategoryId, _ := handler.GetSkuCategoryIdByName(jdOrgCode, strings.Join(mtSku.PictureList, "|")) - if vendorCategoryId != "" && utils.Str2Int64(vendorCategoryId) <= 25048 { - param.CategoryID = utils.Str2Int64(vendorCategoryId) // 其他水果 - } else if utils.Str2Int64(vendorCategoryId) > 25048 { // 只有水果,後面刪除 - param.CategoryID = 22410 // 其他水果 + + 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.Str2Int64(catMap[mtSku.SecondaryCategoryCode])) - //} else if mtSku.CategoryCode != "" { - // param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryCode])) - //} else { - // param.ShopCategories = append(param.ShopCategories, 33313305) // 暂无分类 - //} - if mtSku.CategoryName != "" { + if mtSku.SecondaryCategoryCode != "" { + param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.SecondaryCategoryCode])) + } 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) // 暂无分类 @@ -6669,17 +6699,23 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo } skuID, err := jd.AddSku2(param) if err != nil { - globals.SugarLogger.Debugf("---------AddSku2 := %s,%s,%v", param.SkuName, skuID, err) + globals.SugarLogger.Debugf("---------AddSku2 := %s,%v", utils.Format4Output(param, false), err) } if skuID != "" { - jd.UpdateCurrentQty(ctx.GetTrackInfo(), jdStoreID, utils.Str2Int64(skuID), utils.Str2Int(mtSku.SkuList[0].Stock)) - jd.UpdateVendibility(ctx.GetTrackInfo(), []*jdapi.QueryStockRequest{ + 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 }, skuList) diff --git a/controllers/jds_callback.go b/controllers/jds_callback.go index 7b974faf3..1c49be193 100644 --- a/controllers/jds_callback.go +++ b/controllers/jds_callback.go @@ -3,40 +3,28 @@ package controllers import ( "bytes" "git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop" - "io/ioutil" - "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego/server/web" + "io/ioutil" + "net/http" ) type JdsController struct { web.Controller } -// Msg 这个是京东秒送平台回调 -//func (c *JdsController) Msg() { -// if c.Ctx.Input.Method() == http.MethodPost { -// ctx := c.Ctx -// ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(ctx.Input.RequestBody)) -// call, err := api.JdShopAPI.GetCallbackMsg(ctx.Request) -// if err == nil { -// jdshop.OnCallbackMsg(call) -// } -// c.Data["json"] = call -// c.ServeJSON() -// } else { -// c.Abort("404") -// } -//} - // Msg 这个是京东秒送平台回调 func (c *JdsController) Msg() { - ctx := c.Ctx - ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(ctx.Input.RequestBody)) - call, err := api.JdShopAPI.GetCallbackMsg(ctx.Request) - if err == nil { - jdshop.OnCallbackMsg(call) + if c.Ctx.Input.Method() == http.MethodPost { + ctx := c.Ctx + ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(ctx.Input.RequestBody)) + call, err := api.JdShopAPI.GetCallbackMsg(ctx.Request) + if err == nil { + jdshop.OnCallbackMsg(call) + } + c.Data["json"] = call + c.ServeJSON() + } else { + c.Abort("404") } - c.Data["json"] = call - c.ServeJSON() }