This commit is contained in:
suyl
2021-05-24 14:05:01 +08:00
parent f5673437d3
commit 5fe8987522
4 changed files with 101 additions and 5 deletions

View File

@@ -1924,12 +1924,16 @@ func UploadJdsImage(ctx *jxcontext.Context) (err error) {
// dao.UpdateEntity(db, v, "ConsigneeMobile2")
// }
//}
type funcType func(mtID, parentID string, catInfo []*mtwmapi.RetailCategoryInfo)
var (
mtStoreID = "11655829"
mtOrgCode = "589"
//mtAccessToken = ""
//jdStoreID = "12116911"
jdOrgCode = "364156"
//db = dao.GetDB()
catMap = make(map[string]string)
LoopCatChild funcType
)
jd := jd.GetAPI(jdOrgCode)
//获取token
@@ -1938,13 +1942,69 @@ func UploadJdsImage(ctx *jxcontext.Context) (err error) {
// mtAccessToken = token.AccessToken
//}
//mtapi.SetToken(mtAccessToken)
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, "")
for j := len(catList[i].Children) - 1; j > -1; j-- {
jd.AddShopCategory(utils.Str2Int64(catID), catList[i].Children[j].Name, catList[i].Children[j].Level, catList[i].Children[j].Sequence, "")
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()
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, "")
LoopCatChild(catList[i].Code, catID, catList[i].Children)
//for j := len(catList[i].Children) - 1; j > -1; j-- {
// jd.AddShopCategory(utils.Str2Int64(catID), catList[i].Children[j].Name, catList[i].Children[j].Level, catList[i].Children[j].Sequence, "")
//}
}
}
case 1:
//建商品
//skuList, _ := mtapi.RetailListAll(mtStoreID)
//task2 := tasksch.NewParallelTask("美团到京东, 建商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true).SetParallelCount(1), ctx,
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
// mtSku := batchItemList[0].(*mtwmapi.AppFood)
// catMaps, _ := dao.GetMtJdCategoryMap(db, utils.Int2Str(mtSku.TagID), "")
// param := &jdapi.OpSkuParam{
// TraceID: ctx.GetTrackInfo(),
// OutSkuID: mtSku.AppFoodCode,
// ShopCategories: []int64{},
// CategoryID: utils.Str2Int64(catMaps[0].JdID),
// 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,
// Upc: mtSku.SkuList[0].Upc,
// }
// 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]))
// }
// skuID, _ := jd.AddSku2(param)
// return retVal, err
// }, skuList)
//tasksch.HandleTask(task2, task, true).Run()
//task2.GetResult(0)
}
return retVal, err
}, []int{0, 1, 2, 3})
tasksch.HandleTask(task, nil, true).Run()
task.GetResult(0)
return err
}

View File

@@ -576,3 +576,25 @@ func GetVendorCategoryMapExt(db *DaoDB, parentID, level, vendorID int, vendorOrg
}
return vendorMaps, err
}
func GetMtJdCategoryMap(db *DaoDB, mtID, jdID string) (cats []*model.MtJdCategoryMap, err error) {
sql := `
SELECT a.*
FROM mt_jd_category_map a
WHERE 1 = 1
`
sqlParams := []interface{}{}
if mtID != "" {
sql += " AND a.mt_id = ?"
sqlParams = append(sqlParams, mtID)
}
if jdID != "" {
sql += " AND a.jd_id = ?"
sqlParams = append(sqlParams, jdID)
}
err = GetRows(db, &cats, sql, sqlParams)
if err != nil {
return nil, err
}
return cats, err
}

View File

@@ -22,3 +22,16 @@ type VendorOrgCode struct {
AppKey string `json:"appKey"`
AppSecret string `json:"appSecret"`
}
type MtJdCategoryMap struct {
ID int `orm:"column(id)" json:"id"`
MtID string `orm:"column(mt_id)" json:"mtID"`
JdID string `orm:"column(jd_id)" json:"jdID"`
}
func (*MtJdCategoryMap) TableIndex() [][]string {
return [][]string{
[]string{"MtID", "JdID"},
}
}

View File

@@ -94,6 +94,7 @@ func Init() {
orm.RegisterModel(&model.UserOrderSms{})
orm.RegisterModel(&model.FakeJdThingMap{})
orm.RegisterModel(&model.VendorOrgCode{})
orm.RegisterModel(&model.MtJdCategoryMap{})
//优惠券
orm.RegisterModel(&model.Coupons{})