- mtwm .SyncStoreSkus
This commit is contained in:
@@ -140,3 +140,10 @@ func bizStatusJX2Mtwm(status int) (openLevel, online int) {
|
||||
}
|
||||
return mtwmapi.PoiOpenLevelNormal, mtwmapi.PoiOnline
|
||||
}
|
||||
|
||||
func skuStatusJX2Mtwm(status int) int {
|
||||
if status == 1 {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mtwm
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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"
|
||||
@@ -11,6 +12,10 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
defVendorCatID = 200000380
|
||||
)
|
||||
|
||||
func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error) {
|
||||
userName := ctx.GetUserName()
|
||||
strStoreID := utils.Int2Str(storeID)
|
||||
@@ -183,7 +188,57 @@ func (p *PurchaseHandler) ReadStoreSku(storeID, skuID int) (skuNameExt *model.Sk
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
return hint, err
|
||||
db := dao.GetDB()
|
||||
skus, err := dao.GetStoreSkus(db, model.VendorIDMTWM, storeID, skuIDs)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(skus, false))
|
||||
strStoreID := utils.Int2Str(storeID)
|
||||
rootTask := tasksch.NewParallelTask("mtwm SyncStoreSkus", tasksch.NewParallelConfig().SetBatchSize(200), ctx.GetUserName(), func(rootTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
foodDataList := make([]map[string]interface{}, len(batchItemList))
|
||||
for k, v := range batchItemList {
|
||||
skuItem := v.(*dao.StoreSkuSyncInfo)
|
||||
foodDataList[k] = make(map[string]interface{})
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(skuItem, false))
|
||||
foodDataList[k][mtwmapi.KeyAppFoodCode] = utils.Int2Str(skuItem.ID)
|
||||
foodDataList[k]["name"] = skuItem.Name
|
||||
foodDataList[k]["description"] = skuItem.Comment
|
||||
foodDataList[k]["price"] = jxutils.IntPrice2Standard(skuItem.Price)
|
||||
foodDataList[k]["min_order_count"] = 1
|
||||
foodDataList[k]["unit"] = skuItem.Unit
|
||||
foodDataList[k]["box_num"] = 0
|
||||
foodDataList[k]["box_price"] = 0
|
||||
foodDataList[k]["category_name"] = skuItem.VendorCatID
|
||||
foodDataList[k]["is_sold_out"] = skuStatusJX2Mtwm(jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus))
|
||||
foodDataList[k]["picture"] = skuItem.Img
|
||||
if skuItem.VendorVendorCatID != 0 {
|
||||
foodDataList[k]["tag_id"] = utils.Int64ToStr(skuItem.VendorVendorCatID)
|
||||
} else {
|
||||
foodDataList[k]["tag_id"] = utils.Int64ToStr(defVendorCatID)
|
||||
}
|
||||
foodDataList[k]["skus"] = []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"sku_id": foodDataList[k][mtwmapi.KeyAppFoodCode],
|
||||
"spec": "大",
|
||||
"weight": skuItem.Weight,
|
||||
"price": foodDataList[k]["price"],
|
||||
"stock": "*",
|
||||
},
|
||||
}
|
||||
// if err = api.MtwmAPI.RetailInitData(strStoreID, utils.Int2Str(skuItem.ID), foodDataList[k]); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
}
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(foodDataList, false))
|
||||
err = api.MtwmAPI.RetailBatchInitData(strStoreID, foodDataList)
|
||||
return nil, err
|
||||
}, skus)
|
||||
if parentTask != nil {
|
||||
parentTask.AddChild(rootTask)
|
||||
}
|
||||
rootTask.Run()
|
||||
if !isAsync {
|
||||
_, err = rootTask.GetResult(0)
|
||||
}
|
||||
return rootTask.ID, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error) {
|
||||
|
||||
@@ -3,25 +3,32 @@ package mtwm
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
// _ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
)
|
||||
|
||||
func TestSyncStoreCategory(t *testing.T) {
|
||||
store, err := new(PurchaseHandler).SyncStoreCategory(jxcontext.AdminCtx, nil, 100077, false)
|
||||
hint, err := new(PurchaseHandler).SyncStoreCategory(jxcontext.AdminCtx, nil, 100077, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(store, false))
|
||||
t.Log(hint)
|
||||
}
|
||||
|
||||
func TestSyncLocalStoreCategory(t *testing.T) {
|
||||
store, err := new(PurchaseHandler).SyncLocalStoreCategory(jxcontext.AdminCtx, nil, 100077, true, false)
|
||||
hint, err := new(PurchaseHandler).SyncLocalStoreCategory(jxcontext.AdminCtx, nil, 100077, true, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(store, false))
|
||||
t.Log(hint)
|
||||
}
|
||||
|
||||
func TestSyncStoreSkus(t *testing.T) {
|
||||
hint, err := new(PurchaseHandler).SyncStoreSkus(jxcontext.AdminCtx, nil, 100077, nil, false, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(hint)
|
||||
}
|
||||
|
||||
func TestDeleteRemoteSkus(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user