109 lines
3.0 KiB
Go
109 lines
3.0 KiB
Go
package cms
|
|
|
|
import (
|
|
"fmt"
|
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
"git.rosy.net.cn/jx-callback/business/partner"
|
|
"time"
|
|
)
|
|
|
|
// CopyOnStoreSkuToOther 将一个美团门店分类和商品复制到另一个门店
|
|
func CopyOnStoreSkuToOther(ctx *jxcontext.Context, fromStoreId, toStoreId int, isAsync bool) (hint string, err error) {
|
|
var (
|
|
db = dao.GetDB()
|
|
)
|
|
|
|
// 门店api加载
|
|
fromStore, err := dao.GetStoreDetail(db, fromStoreId, model.VendorIDMTWM, "")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
toStore, err := dao.GetStoreDetail(db, fromStoreId, model.VendorIDMTWM, "")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
fromApi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, fromStore.VendorOrgCode).(*mtwmapi.API)
|
|
toApi := partner.CurAPIManager.GetAPI(model.VendorIDMTWM, toStore.VendorOrgCode).(*mtwmapi.API)
|
|
|
|
taskName := fmt.Sprintf("将平台门店[%d],分类和商品复制到[%d]", fromStoreId, toStoreId)
|
|
config := tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(false)
|
|
work := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
|
step := batchItemList[0].(int)
|
|
switch step {
|
|
case 1:
|
|
// 1.加载门店商品,删除商品.当分类下没有商品时.删除分类
|
|
errs := LoadingStoreSkuList(ctx, toApi, toStore.VendorStoreID)
|
|
if errs != nil && len(errs) > 0 {
|
|
return nil, errs[0]
|
|
}
|
|
case 2:
|
|
// 同步分类
|
|
fromCategoryList, err := fromApi.RetailCatList(fromStore.VendorStoreID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, v := range fromCategoryList {
|
|
if err := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{
|
|
CategoryCode: v.Code,
|
|
Sequence: v.Sequence,
|
|
}); err != nil {
|
|
return nil, err
|
|
}
|
|
if v.Children != nil && len(v.Children) != 0 {
|
|
//for _, c := range v.Children {
|
|
// if err := toApi.RetailCatUpdate(toStore.VendorStoreID, v.Name, &mtwmapi.Param4UpdateCat{
|
|
// CategoryCode: v.Code,
|
|
// Sequence: v.Sequence,
|
|
// }); err != nil {
|
|
// return nil, err
|
|
// }
|
|
//}
|
|
}
|
|
}
|
|
|
|
case 3:
|
|
// 同步商品
|
|
|
|
}
|
|
return
|
|
}
|
|
task := tasksch.NewParallelTask(taskName, config, ctx, work, []int{1, 2, 3})
|
|
tasksch.HandleTask(task, nil, true).Run()
|
|
if !isAsync {
|
|
_, err = task.GetResult(0)
|
|
hint = "1"
|
|
} else {
|
|
hint = task.ID
|
|
}
|
|
return hint, err
|
|
}
|
|
|
|
func LoadingStoreSkuList(ctx *jxcontext.Context, api *mtwmapi.API, poiCode string) (err []error) {
|
|
foodList, err1 := api.RetailListAll(poiCode)
|
|
if err1 != nil {
|
|
return append(err, err1)
|
|
}
|
|
|
|
i := 0
|
|
for _, v := range foodList {
|
|
err1 := api.RetailDelete(ctx.GetTrackInfo(), poiCode, v.AppFoodCode)
|
|
if err1 != nil {
|
|
err = append(err, err1)
|
|
}
|
|
if i%40 == 0 {
|
|
time.Sleep(200 * time.Millisecond)
|
|
}
|
|
i++
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func LoadStoreCategoryList() {
|
|
|
|
}
|