This commit is contained in:
邹宗楠
2026-05-14 14:06:13 +08:00
parent 8ea9f38a99
commit d72db7588f
2 changed files with 110 additions and 86 deletions

View File

@@ -6555,75 +6555,94 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo
var ( var (
//mtAccessToken = "" //mtAccessToken = ""
//db = dao.GetDB() //db = dao.GetDB()
catMap = make(map[string]string) catMap = make(map[string]string)
LoopCatChild funcType //LoopCatChild funcType
handler, _ = partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IPurchasePlatformStoreSkuHandler) handler, _ = partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IPurchasePlatformStoreSkuHandler)
) )
jd := jd.GetAPI(jdOrgCode) jd := jd.GetAPI(jdOrgCode)
//获取token //获取token
mtapi := apimanager.CurAPIManager.GetAPI(model.VendorIDMTWM, mtOrgCode).(*mtwmapi.API) mtapi := apimanager.CurAPIManager.GetAPI(model.VendorIDMTWM, mtOrgCode).(*mtwmapi.API)
LoopCatChild = func(mtID, parentID string, catInfo []*mtwmapi.RetailCategoryInfo) { //LoopCatChild = func(mtID, parentID string, catInfo []*mtwmapi.RetailCategoryInfo) {
if len(catInfo) > 0 { // if len(catInfo) > 0 {
for j := len(catInfo) - 1; j > -1; j-- { // for j := len(catInfo) - 1; j > -1; j-- {
result, _ := jd.AddShopCategory(utils.Str2Int64(parentID), catInfo[j].Name, catInfo[j].Level, catInfo[j].Sequence, "") // result, _ := jd.AddShopCategory(utils.Str2Int64(parentID), catInfo[j].Name, catInfo[j].Level, catInfo[j].Sequence, "")
if result != "" { // if result != "" {
catMap[mtID] = result // catMap[mtID] = result
} // }
LoopCatChild(catInfo[j].Code, result, catInfo[j].Children) // LoopCatChild(catInfo[j].Code, result, catInfo[j].Children)
} // }
} // }
} //}
task := tasksch.NewParallelTask("美团到京东", tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx, task := tasksch.NewParallelTask("美团到京东", tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
step := batchItemList[0].(int) step := batchItemList[0].(int)
switch step { switch step {
case 0: case 0:
jdCatList, _ := jd.QueryCategoriesByOrgCode() //jdCatList, _ := jd.QueryCategoriesByOrgCode()
catList, _ := mtapi.RetailCatList(mtStoreID) catList, _ := mtapi.RetailCatList(mtStoreID)
for _, jdc := range jdCatList { //for _, jdc := range jdCatList {
for _, mtc := range catList { // for _, mtc := range catList {
if jdc.Name == mtc.Name { // if jdc.Name == mtc.Name {
catMap[mtc.Name] = utils.Int64ToStr(jdc.Id) // catMap[mtc.Name] = utils.Int64ToStr(jdc.Id)
break // break
} // }
} // }
} //}
//建分类 ,账号存在分类,不在创建分类 //建分类 ,账号存在分类,不在创建分类
//jdCatList, _ := jd.QueryCategoriesByOrgCode() //jdCatList, _ := jd.QueryCategoriesByOrgCode()
//if len(jdCatList) == 0 { //if len(jdCatList) == 0 {
// catList, _ := mtapi.RetailCatList(mtStoreID) //catList, _ = mtapi.RetailCatList(mtStoreID)
// for i := len(catList) - 1; i > -1; i-- { for i := len(catList) - 1; i > -1; i-- {
// catID, _ := jd.AddShopCategory(0, catList[i].Name, catList[i].Level, catList[i].Sequence, "") catID, _ := jd.AddShopCategory(0, catList[i].Name, catList[i].Level, catList[i].Sequence, "")
// if catID != "" { if catID != "" {
// catMap[catList[i].Code] = catID catMap[catList[i].Code] = catID
// } } else {
// LoopCatChild(catList[i].Code, catID, catList[i].Children) catMap[catList[i].Name] = catID
// //美团好像只能建两级分类? }
// for j := len(catList[i].Children) - 1; j > -1; j-- { //LoopCatChild(catList[i].Code, catID, catList[i].Children)
// catID2, _ := jd.AddShopCategory(utils.Str2Int64(catID), catList[i].Children[j].Name, catList[i].Children[j].Level, catList[i].Children[j].Sequence, "") //美团好像只能建两级分类?
// if catID2 != "" { for j := len(catList[i].Children) - 1; j > -1; j-- {
// catMap[catList[i].Children[j].Code] = catID2 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: case 1:
//建商品 //建商品
var i = 0
skuList := make([]*mtwmapi.AppFood, 0, 0) skuList := make([]*mtwmapi.AppFood, 0, 0)
for i := 0; i < 9; i++ { //for i := 0; i < 9; i++ {
skuList2, _ := mtapi.RetailListAll(mtStoreID, i) // skuList2, _ := mtapi.RetailListAll(mtStoreID, i)
skuList = append(skuList, skuList2...) // skuList = append(skuList, skuList2...)
} //}
//skuList, _ := mtapi.RetailList(mtStoreID, 0, 2) //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, task2 := tasksch.NewParallelTask("美团到京东, 建商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
mtSku := batchItemList[0].(*mtwmapi.AppFood) mtSku := batchItemList[0].(*mtwmapi.AppFood)
//catMaps, _ := dao.GetMtJdCategoryMap(db, utils.Int2Str(mtSku.TagID), "") //catMaps, _ := dao.GetMtJdCategoryMap(db, utils.Int2Str(mtSku.TagID), "")
//if len(catMaps) == 0 { //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)) // results2, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results[0].ParentID))
// results3, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results2[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) // //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, OutSkuID: mtSku.AppFoodCode,
ShopCategories: []int64{}, // 商家分类 ShopCategories: []int64{}, // 商家分类
//CategoryID: utils.Str2Int64(catMaps[0].JdID), // 到家分类 //CategoryID: utils.Str2Int64(catMaps[0].JdID), // 到家分类
BrandID: 35247, //BrandID: 35247,
SkuName: mtSku.Name, SkuName: mtSku.Name,
SkuPrice: int(jxutils.StandardPrice2Int(mtSku.Price)), SkuPrice: int(jxutils.StandardPrice2Int(mtSku.Price)),
Weight: float64(jxutils.IntWeight2Float(utils.Str2Int(mtSku.SkuList[0].Weight))), Weight: float64(jxutils.IntWeight2Float(utils.Str2Int(mtSku.SkuList[0].Weight))),
FixedStatus: 1, FixedStatus: 1,
IsSale: -1, IsSale: 1,
Upc: mtSku.SkuList[0].Upc, Upc: mtSku.SkuList[0].Upc,
Images: mtSku.PictureList, 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 == "" { if param.OutSkuID == "" {
param.OutSkuID = fmt.Sprintf("%d_%d%d", time.Now().Unix(), param.SkuPrice, len(mtSku.Name)) 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 { if param.CategoryID == 0 {
param.CategoryID = utils.Str2Int64(vendorCategoryId) // 其他水果 vendorCategoryId, _ := handler.GetSkuCategoryIdByName(jdOrgCode, strings.Join(mtSku.PictureList, "|"))
} else if utils.Str2Int64(vendorCategoryId) > 25048 { // 只有水果,後面刪除 param.CategoryID = utils.Str2Int64(vendorCategoryId)
param.CategoryID = 22410 // 其他水果 //if vendorCategoryId != "" && utils.Str2Int64(vendorCategoryId) <= 25048 {
// param.CategoryID = utils.Str2Int64(vendorCategoryId) // 其他水果
//} else if utils.Str2Int64(vendorCategoryId) > 25048 { // 只有水果,後面刪除
// param.CategoryID = 22410 // 其他水果
//}
} }
//if mtSku.SecondaryCategoryCode != "" { if mtSku.SecondaryCategoryCode != "" {
// param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.SecondaryCategoryCode])) param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.SecondaryCategoryCode]))
//} else if mtSku.CategoryCode != "" { } else if mtSku.SecondaryCategoryName != "" {
// param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryCode])) param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.SecondaryCategoryName]))
//} else { } else if mtSku.CategoryCode != "" {
// param.ShopCategories = append(param.ShopCategories, 33313305) // 暂无分类 param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryCode]))
//} } else if mtSku.CategoryName != "" {
if mtSku.CategoryName != "" {
param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryName])) param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryName]))
} else { } else {
param.ShopCategories = append(param.ShopCategories, 33313305) // 暂无分类 param.ShopCategories = append(param.ShopCategories, 33313305) // 暂无分类
@@ -6669,17 +6699,23 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo
} }
skuID, err := jd.AddSku2(param) skuID, err := jd.AddSku2(param)
if err != nil { 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 != "" { if skuID != "" {
jd.UpdateCurrentQty(ctx.GetTrackInfo(), jdStoreID, utils.Str2Int64(skuID), utils.Str2Int(mtSku.SkuList[0].Stock)) err1 := jd.UpdateCurrentQty(ctx.GetTrackInfo(), jdStoreID, utils.Str2Int64(skuID), utils.Str2Int(mtSku.SkuList[0].Stock))
jd.UpdateVendibility(ctx.GetTrackInfo(), []*jdapi.QueryStockRequest{ if err1 != nil {
globals.SugarLogger.Debugf("--------err r1 := %v", err1)
}
_, err2 := jd.UpdateVendibility(ctx.GetTrackInfo(), []*jdapi.QueryStockRequest{
&jdapi.QueryStockRequest{ &jdapi.QueryStockRequest{
StationNo: jdStoreID, StationNo: jdStoreID,
SkuId: utils.Str2Int64(skuID), SkuId: utils.Str2Int64(skuID),
DoSale: mtSku.IsSoldOut, DoSale: mtSku.IsSoldOut,
}, },
}) })
if err2 != nil {
globals.SugarLogger.Debugf("--------err r1 := %v", err2)
}
} }
return retVal, err return retVal, err
}, skuList) }, skuList)

View File

@@ -3,40 +3,28 @@ package controllers
import ( import (
"bytes" "bytes"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop" "git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop"
"io/ioutil"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego/server/web" "github.com/astaxie/beego/server/web"
"io/ioutil"
"net/http"
) )
type JdsController struct { type JdsController struct {
web.Controller 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 这个是京东秒送平台回调 // Msg 这个是京东秒送平台回调
func (c *JdsController) Msg() { func (c *JdsController) Msg() {
ctx := c.Ctx if c.Ctx.Input.Method() == http.MethodPost {
ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(ctx.Input.RequestBody)) ctx := c.Ctx
call, err := api.JdShopAPI.GetCallbackMsg(ctx.Request) ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(ctx.Input.RequestBody))
if err == nil { call, err := api.JdShopAPI.GetCallbackMsg(ctx.Request)
jdshop.OnCallbackMsg(call) if err == nil {
jdshop.OnCallbackMsg(call)
}
c.Data["json"] = call
c.ServeJSON()
} else {
c.Abort("404")
} }
c.Data["json"] = call
c.ServeJSON()
} }