1
This commit is contained in:
@@ -6551,7 +6551,7 @@ func GetVendorStoreSkus(ctx *jxcontext.Context, storeID, vendorID int) (err erro
|
|||||||
|
|
||||||
// CopyMtToJd 复制美团到京东
|
// CopyMtToJd 复制美团到京东
|
||||||
func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCode string) (err error) {
|
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 (
|
var (
|
||||||
//mtAccessToken = ""
|
//mtAccessToken = ""
|
||||||
//db = dao.GetDB()
|
//db = dao.GetDB()
|
||||||
@@ -6594,46 +6594,53 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo
|
|||||||
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()
|
|
||||||
//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
|
|
||||||
}
|
}
|
||||||
}
|
if len(mtc.Children) != 0 {
|
||||||
//LoopCatChild(catList[i].Code, catID, catList[i].Children)
|
for _, mtcl := range mtc.Children {
|
||||||
//美团好像只能建两级分类?
|
if mtcl.Name == jdc.Name {
|
||||||
for j := len(catList[i].Children) - 1; j > -1; j-- {
|
catMap[mtcl.Name] = utils.Int64ToStr(jdc.Id)
|
||||||
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(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:
|
case 1:
|
||||||
//建商品
|
//建商品
|
||||||
@@ -6652,93 +6659,114 @@ func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCo
|
|||||||
i++
|
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,
|
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), "")
|
if _, ok := jdSkus[mtSku.AppFoodCode]; !ok {
|
||||||
//if len(catMaps) == 0 {
|
//catMaps, _ := dao.GetMtJdCategoryMap(db, utils.Int2Str(mtSku.TagID), "")
|
||||||
//results, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, mtSku.TagID)
|
//if len(catMaps) == 0 {
|
||||||
// results2, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results[0].ParentID))
|
//results, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, mtSku.TagID)
|
||||||
// results3, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results2[0].ParentID))
|
// results2, _ := dao.GetVendorCategoriesWithMap(db, model.VendorIDMTWM, utils.Str2Int(results[0].ParentID))
|
||||||
// //return retVal, fmt.Errorf("该商品美团分类还未映射到京东,商品名:[%v],美团分类:[%v] ->[%v] ->[%v]。", mtSku.Name, results3[0].Name, results2[0].Name, results[0].Name)
|
// 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 // 其他水果
|
|
||||||
//}
|
//}
|
||||||
}
|
param := &jdapi.NewAddSkuParam{
|
||||||
|
TraceId: ctx.GetTrackInfo(),
|
||||||
if mtSku.SecondaryCategoryCode != "" {
|
OutSkuId: mtSku.AppFoodCode,
|
||||||
param.ShopCategories = append(param.ShopCategories, utils.Str2Int64WithDefault(catMap[mtSku.SecondaryCategoryCode], 33313305))
|
ShopCategories: []int64{}, // 商家分类
|
||||||
} else if mtSku.SecondaryCategoryName != "" {
|
CategoryId: 0, // 到家分类
|
||||||
param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.SecondaryCategoryName]))
|
BrandId: 0,
|
||||||
} else if mtSku.CategoryCode != "" {
|
SkuName: mtSku.Name,
|
||||||
param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryCode]))
|
SkuPrice: int64(jxutils.StandardPrice2Int(mtSku.Price)),
|
||||||
} else if mtSku.CategoryName != "" {
|
Weight: math.Round(float64(jxutils.IntWeight2Float(utils.Str2Int(mtSku.SkuList[0].Weight)))*1000) / 1000,
|
||||||
param.ShopCategories = append(param.ShopCategories, utils.Str2Int64(catMap[mtSku.CategoryName]))
|
FixedStatus: 1,
|
||||||
} else {
|
IsSale: true,
|
||||||
param.ShopCategories = append(param.ShopCategories, 33313305) // 暂无分类
|
Upc: mtSku.SkuList[0].Upc,
|
||||||
}
|
Images: mtSku.PictureList,
|
||||||
if mtSku.PictureContents != "" {
|
|
||||||
param.ProductDesc = fmt.Sprintf(`<img src="%s" alt="一张图片" />`, mtSku.PictureContents)
|
|
||||||
}
|
|
||||||
if param.Upc == "" {
|
|
||||||
productInfo, _ := jd.GetJdUpcCodeByName(param.SkuName, "", 1, 10)
|
|
||||||
if len(productInfo) != 0 {
|
|
||||||
param.Upc = productInfo[0].UpcCode
|
|
||||||
}
|
}
|
||||||
}
|
brandList, err := jd.GetSkuCategoryBySkuName(mtSku.Name)
|
||||||
|
if brandList == nil || err != nil {
|
||||||
skuID, err := jd.NewAddSku(param)
|
param.BrandId = 35247
|
||||||
if err != nil {
|
} else {
|
||||||
globals.SugarLogger.Debugf("---------AddSku2 := %s,%v", utils.Format4Output(param, false), err)
|
param.BrandId = int64(brandList.BrandId)
|
||||||
}
|
param.CategoryId = int64(brandList.CategoryId)
|
||||||
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{
|
if param.OutSkuId == "" {
|
||||||
StationNo: jdStoreID,
|
param.OutSkuId = fmt.Sprintf("%d_%d%d", time.Now().Unix(), param.SkuPrice, len(mtSku.Name))
|
||||||
SkuId: utils.Str2Int64(skuID),
|
}
|
||||||
DoSale: mtSku.IsSoldOut,
|
|
||||||
},
|
if param.CategoryId == 0 {
|
||||||
})
|
vendorCategoryId, _ := handler.GetSkuCategoryIdByName(jdOrgCode, strings.Join(mtSku.PictureList, "|"))
|
||||||
if err2 != nil {
|
param.CategoryId = utils.Str2Int64(vendorCategoryId)
|
||||||
globals.SugarLogger.Debugf("--------err r1 := %v", err2)
|
//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(`<img src="%s" alt="一张图片" />`, 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
|
return retVal, err
|
||||||
|
|||||||
Reference in New Issue
Block a user