- mtwm .SyncStoreSkus
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
type SkuStoreCatInfo struct {
|
||||
@@ -85,3 +86,57 @@ func GetStoreCategories(db *DaoDB, vendorID, storeID int, level int) (cats []*St
|
||||
}
|
||||
return cats, err
|
||||
}
|
||||
|
||||
type StoreSkuSyncInfo struct {
|
||||
Price int64
|
||||
UnitPrice int64
|
||||
StoreSkuStatus int
|
||||
SkuSyncStatus int8
|
||||
model.Sku
|
||||
Prefix string
|
||||
Name string
|
||||
Unit string
|
||||
Img string
|
||||
|
||||
VendorVendorCatID int64 `orm:"column(vendor_vendor_cat_id)"`
|
||||
|
||||
CatSyncStatus int8
|
||||
VendorCatID string `orm:"column(vendor_cat_id)"`
|
||||
|
||||
SkuCatSyncStatus int8
|
||||
SkuVendorCatID string `orm:"column(sku_vendor_cat_id)"`
|
||||
}
|
||||
|
||||
func GetStoreSkus(db *DaoDB, vendorID, storeID int, skuIDs []int) (skus []*StoreSkuSyncInfo, err error) {
|
||||
sql := `
|
||||
SELECT t1.price, t1.unit_price, t1.status store_sku_status, t1.%s_id, t1.%s_sync_status sku_sync_status,
|
||||
t2.*,
|
||||
t3.prefix, t3.name, t3.unit, t3.img,
|
||||
t4.%s_category_id vendor_vendor_cat_id,
|
||||
t5.%s_sync_status cat_sync_status, t5.%s_id vendor_cat_id,
|
||||
t5sku.%s_sync_status sku_cat_sync_status, t5sku.%s_id sku_vendor_cat_id
|
||||
FROM store_sku_bind t1
|
||||
JOIN sku t2 ON t1.sku_id = t2.id
|
||||
JOIN sku_name t3 ON t2.name_id = t3.id
|
||||
JOIN sku_category t4 ON t3.category_id = t4.id
|
||||
JOIN store_sku_category_map t5 ON t4.id = t5.category_id AND t5.store_id = t1.store_id AND t5.deleted_at = ?
|
||||
LEFT JOIN store_sku_category_map t5sku ON t2.category_id = t5sku.category_id AND t5sku.store_id = t1.store_id AND t5sku.deleted_at = ?
|
||||
WHERE t1.store_id = ? AND t1.%s_sync_status <> 0
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
storeID,
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
filedPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])
|
||||
sql = fmt.Sprintf(sql, filedPrefix, filedPrefix, filedPrefix, filedPrefix, filedPrefix, filedPrefix, filedPrefix, filedPrefix)
|
||||
globals.SugarLogger.Debug(sql)
|
||||
if err = GetRows(db, &skus, sql, sqlParams...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return skus, err
|
||||
}
|
||||
|
||||
@@ -43,10 +43,13 @@ type StoreSkuBind struct {
|
||||
|
||||
ElmID int64 `orm:"column(elm_id);index"`
|
||||
EbaiID int64 `orm:"column(ebai_id);index"`
|
||||
JdID int64 `orm:"column(jd_id)"` // 无实际使用,只是为了DAO取数据语句一致
|
||||
MtwmID int64 `orm:"column(mtwm_id)"` // 这个也不是必须的,只是为了DAO取数据语句一致
|
||||
|
||||
JdSyncStatus int8
|
||||
ElmSyncStatus int8
|
||||
EbaiSyncStatus int8
|
||||
MtwmSyncStatus int8
|
||||
}
|
||||
|
||||
func (*StoreSkuBind) TableUnique() [][]string {
|
||||
|
||||
@@ -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