aa
This commit is contained in:
@@ -5635,3 +5635,102 @@ func GetVendorStoreSkus(ctx *jxcontext.Context, storeID, vendorID int) (err erro
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func CopyMtToJd(ctx *jxcontext.Context, mtStoreID, mtOrgCode, jdStoreID, jdOrgCode string) (err error) {
|
||||
type funcType func(mtID, parentID string, catInfo []*mtwmapi.RetailCategoryInfo)
|
||||
var (
|
||||
//mtAccessToken = ""
|
||||
db = dao.GetDB()
|
||||
catMap = make(map[string]string)
|
||||
LoopCatChild funcType
|
||||
)
|
||||
mtStoreID = "11655829"
|
||||
mtOrgCode = "589"
|
||||
jdStoreID = "12116911"
|
||||
jdOrgCode = "364156"
|
||||
jd := jd.GetAPI(jdOrgCode)
|
||||
//获取token
|
||||
mtapi := apimanager.CurAPIManager.GetAPI(model.VendorIDMTWM, mtOrgCode).(*mtwmapi.API)
|
||||
//if token, err := mtapi.GetAccessToken2(mtStoreID); err == nil && token != nil {
|
||||
// mtAccessToken = token.AccessToken
|
||||
//}
|
||||
//mtapi.SetToken(mtAccessToken)
|
||||
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)
|
||||
skuList, _ := mtapi.RetailList(mtStoreID, 0, 2)
|
||||
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,
|
||||
Images: mtSku.PictureList,
|
||||
}
|
||||
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]))
|
||||
}
|
||||
param.ProductDesc = fmt.Sprintf(`<img src="%s" alt="一张图片" />`, mtSku.PictureContents)
|
||||
skuID, _ := jd.AddSku2(param)
|
||||
if skuID != "" {
|
||||
jd.UpdateCurrentQty(ctx.GetTrackInfo(), jdStoreID, utils.Str2Int64(skuID), utils.Str2Int(mtSku.SkuList[0].Stock))
|
||||
jd.UpdateVendibility(ctx.GetTrackInfo(), []*jdapi.QueryStockRequest{
|
||||
&jdapi.QueryStockRequest{
|
||||
StationNo: jdStoreID,
|
||||
SkuId: utils.Str2Int64(skuID),
|
||||
DoSale: mtSku.IsSoldOut,
|
||||
},
|
||||
})
|
||||
}
|
||||
return retVal, err
|
||||
}, skuList)
|
||||
tasksch.HandleTask(task2, task, true).Run()
|
||||
task2.GetResult(0)
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
task.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/jx-callback/globals/api/apimanager"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -1924,87 +1923,6 @@ 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
|
||||
mtapi := apimanager.CurAPIManager.GetAPI(model.VendorIDMTWM, mtOrgCode).(*mtwmapi.API)
|
||||
//if token, err := mtapi.GetAccessToken2(mtStoreID); err == nil && token != nil {
|
||||
// mtAccessToken = token.AccessToken
|
||||
//}
|
||||
//mtapi.SetToken(mtAccessToken)
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -961,3 +961,20 @@ func (c *StoreSkuController) GetStoresSkusForStore() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 复制美团到京东
|
||||
// @Description 复制美团到京东
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mtStoreID formData string true "美团门店ID"
|
||||
// @Param mtOrgCode formData string true "美团账号"
|
||||
// @Param jdStoreID formData string true "京东门店ID"
|
||||
// @Param jdOrgCode formData string true "京东账号"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /CopyMtToJd [post]
|
||||
func (c *StoreSkuController) CopyMtToJd() {
|
||||
c.callCopyMtToJd(func(params *tStoreSkuCopyMtToJdParams) (retVal interface{}, errCode string, err error) {
|
||||
err = cms.CopyMtToJd(params.Ctx, params.MtStoreID, params.MtOrgCode, params.JdStoreID, params.JdOrgCode)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2691,6 +2691,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||
web.ControllerComments{
|
||||
Method: "CopyMtToJd",
|
||||
Router: `/CopyMtToJd`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||
web.ControllerComments{
|
||||
Method: "GetStoresSkusSaleInfo",
|
||||
|
||||
Reference in New Issue
Block a user