- 新同步逻辑调整,京东还有问题

This commit is contained in:
gazebo
2019-07-18 09:11:31 +08:00
parent b5b3d82130
commit 2c2659b0ed
10 changed files with 98 additions and 59 deletions

View File

@@ -794,7 +794,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
valid := dao.StrictMakeMapByStructObject(payload, storeMap, userName) valid := dao.StrictMakeMapByStructObject(payload, storeMap, userName)
if valid["pricePercentagePack"] != nil { if valid["pricePercentagePack"] != nil {
if pricePercentagePack := utils.Interface2String(valid["pricePercentagePack"]); pricePercentagePack != "" { if pricePercentagePack := utils.Interface2String(valid["pricePercentagePack"]); pricePercentagePack != "" {
_, err2 := dao.QueryConfigs(db, model.ConfigTypePricePack, pricePercentagePack, "") _, err2 := dao.QueryConfigs(db, pricePercentagePack, model.ConfigTypePricePack, "")
if err = err2; err != nil { if err = err2; err != nil {
return 0, err return 0, err
} }

View File

@@ -101,7 +101,7 @@ func SyncStorCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendor
return hint, err return hint, err
} }
func SyncStoreSkuNew(ctx *jxcontext.Context, vendorID, storeID int, vendorStoreID string, nameIDs, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) { func SyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, nameIDs, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
if singleStoreHandler != nil { if singleStoreHandler != nil {
if err = CreateStoreCategoryByStoreSku(ctx, vendorID, storeID, vendorStoreID, nameIDs, skuIDs); err != nil { if err = CreateStoreCategoryByStoreSku(ctx, vendorID, storeID, vendorStoreID, nameIDs, skuIDs); err != nil {
@@ -116,11 +116,11 @@ func SyncStoreSkuNew(ctx *jxcontext.Context, vendorID, storeID int, vendorStoreI
_, err = SyncStorCategories(ctx, task, vendorID, storeID, vendorStoreID, nameIDs, skuIDs, false, isContinueWhenError) _, err = SyncStorCategories(ctx, task, vendorID, storeID, vendorStoreID, nameIDs, skuIDs, false, isContinueWhenError)
} }
case 1: case 1:
err = syncStoreSkuNew(ctx, task, vendorID, storeID, nameIDs, skuIDs, isContinueWhenError) err = syncStoreSkuNew(ctx, task, false, vendorID, storeID, nameIDs, skuIDs, isContinueWhenError)
} }
return result, err return result, err
}, 2) }, 2)
tasksch.HandleTask(task, nil, true).Run() tasksch.HandleTask(task, parentTask, true).Run()
if !isAsync { if !isAsync {
_, err = task.GetResult(0) _, err = task.GetResult(0)
} else { } else {
@@ -129,19 +129,28 @@ func SyncStoreSkuNew(ctx *jxcontext.Context, vendorID, storeID int, vendorStoreI
return hint, err return hint, err
} }
func FullSyncStoreSkuNew(ctx *jxcontext.Context, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) { func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
task := tasksch.NewParallelTask("FullSyncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, task := tasksch.NewParallelTask("FullSyncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
step := batchItemList[0].(int) step := batchItemList[0].(int)
switch step { switch step {
case 0: case 0:
_, err = ClearRemoteStoreStuffAndSetNew(ctx, task, vendorID, storeID, vendorStoreID, false, isContinueWhenError) if singleStoreHandler != nil {
_, err = ClearRemoteStoreStuffAndSetNew(ctx, task, vendorID, storeID, vendorStoreID, false, isContinueWhenError)
} else {
_, err = dao.SetStoreSkuSyncStatus(dao.GetDB(), vendorID, []int{storeID}, nil, model.SyncFlagStoreSkuOnlyMask)
}
case 1: case 1:
_, err = SyncStoreSkuNew(ctx, vendorID, storeID, vendorStoreID, nil, nil, false, isContinueWhenError) if singleStoreHandler != nil {
_, err = SyncStoreSkuNew(ctx, task, vendorID, storeID, vendorStoreID, nil, nil, false, isContinueWhenError)
} else {
err = syncStoreSkuNew(ctx, task, false, vendorID, storeID, nil, nil, isContinueWhenError)
}
} }
return retVal, err return retVal, err
}, []int{0, 1}) }, []int{0, 1})
tasksch.HandleTask(task, nil, true).Run() tasksch.HandleTask(task, parentTask, true).Run()
if !isAsync { if !isAsync {
_, err = task.GetResult(0) _, err = task.GetResult(0)
} else { } else {
@@ -150,6 +159,10 @@ func FullSyncStoreSkuNew(ctx *jxcontext.Context, vendorID, storeID int, vendorSt
return hint, err return hint, err
} }
func isStoreSkuSyncNeedDelete(storeSku *dao.StoreSkuSyncInfo) bool {
return model.IsSyncStatusDelete(storeSku.StoreSkuSyncStatus) || storeSku.DeletedAt != utils.DefaultTimeValue || storeSku.BindID == 0 || storeSku.NameID == 0
}
func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSkuInfo) { func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSkuInfo) {
outSku = &partner.StoreSkuInfo{ outSku = &partner.StoreSkuInfo{
SkuID: inSku.SkuID, SkuID: inSku.SkuID,
@@ -157,10 +170,10 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
NameID: inSku.NameID, NameID: inSku.NameID,
VendorNameID: inSku.VendorNameID, VendorNameID: inSku.VendorNameID,
Status: jxutils.MergeSkuStatus(inSku.Status, inSku.StoreSkuStatus), Status: inSku.MergedStatus,
Price: inSku.VendorPrice, VendorPrice: inSku.VendorPrice,
} }
if !model.IsSyncStatusDelete(inSku.StoreSkuSyncStatus) { if !isStoreSkuSyncNeedDelete(inSku) {
outSku.Stock = model.MaxStoreSkuStockQty outSku.Stock = model.MaxStoreSkuStockQty
} }
return outSku return outSku
@@ -172,6 +185,14 @@ func calVendorPrice4StoreSku(inSku *dao.StoreSkuSyncInfo, pricePercentagePack mo
return inSku return inSku
} }
func formalizeStoreSkuList(inSkuList []*dao.StoreSkuSyncInfo) []*dao.StoreSkuSyncInfo {
for _, skuItem := range inSkuList {
skuItem.MergedStatus = jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus)
skuItem.SkuName = jxutils.ComposeSkuName(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 0)
}
return inSkuList
}
func sku2Update(vendorID int, sku *dao.StoreSkuSyncInfo, syncStatus int8) (item *dao.KVUpdateItem) { func sku2Update(vendorID int, sku *dao.StoreSkuSyncInfo, syncStatus int8) (item *dao.KVUpdateItem) {
if syncStatus&(model.SyncFlagDeletedMask|model.SyncFlagNewMask|model.SyncFlagModifiedMask) != 0 { if syncStatus&(model.SyncFlagDeletedMask|model.SyncFlagNewMask|model.SyncFlagModifiedMask) != 0 {
sku.StoreSkuSyncStatus = 0 sku.StoreSkuSyncStatus = 0
@@ -204,7 +225,7 @@ func updateStoreSku(db *dao.DaoDB, vendorID int, storeSkuList []*dao.StoreSkuSyn
return num, err return num, err
} }
func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, nameIDs, skuIDs []int, isContinueWhenError bool) (err error) { func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bool, vendorID, storeID int, nameIDs, skuIDs []int, isContinueWhenError bool) (err error) {
db := dao.GetDB() db := dao.GetDB()
storeDetail, err := dao.GetStoreDetail(db, storeID, vendorID) storeDetail, err := dao.GetStoreDetail(db, storeID, vendorID)
if err != nil { if err != nil {
@@ -212,10 +233,17 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
} }
vendorStoreID := storeDetail.VendorStoreID vendorStoreID := storeDetail.VendorStoreID
skus, err := dao.GetStoreSkus(db, vendorID, storeID, skuIDs) var skus []*dao.StoreSkuSyncInfo
if isFull {
skus, err = dao.GetFullStoreSkus(db, vendorID, storeID)
} else {
skus, err = dao.GetStoreSkus(db, vendorID, storeID, skuIDs)
}
if err != nil { if err != nil {
return err return err
} }
formalizeStoreSkuList(skus)
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler) singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler) storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
@@ -228,7 +256,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
for _, sku := range skus { for _, sku := range skus {
var bareSku *partner.StoreSkuInfo var bareSku *partner.StoreSkuInfo
if model.IsSyncStatusDelete(sku.StoreSkuSyncStatus) { if isStoreSkuSyncNeedDelete(sku) {
if !dao.IsVendorThingIDEmpty(sku.VendorSkuID) { if !dao.IsVendorThingIDEmpty(sku.VendorSkuID) {
bareSku = storeSkuSyncInfo2Bare(sku) bareSku = storeSkuSyncInfo2Bare(sku)
if singleStoreHandler == nil { if singleStoreHandler == nil {
@@ -241,11 +269,13 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
} }
} else if model.IsSyncStatusNew(sku.StoreSkuSyncStatus) { } else if model.IsSyncStatusNew(sku.StoreSkuSyncStatus) {
calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)) calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))
bareSku = storeSkuSyncInfo2Bare(sku)
if singleStoreHandler == nil { if singleStoreHandler == nil {
bareSku = storeSkuSyncInfo2Bare(sku)
stockList = append(stockList, bareSku) stockList = append(stockList, bareSku)
} else { } else {
createList = append(createList, sku) if bareSku.Status == model.SkuStatusNormal && !dao.IsVendorThingIDEmpty(sku.VendorCatID) {
createList = append(createList, sku)
}
} }
} else { } else {
if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) { if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) {
@@ -281,16 +311,16 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
} }
return skuList return skuList
} }
task := tasksch.NewParallelTask("syncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, task := tasksch.NewParallelTask("syncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
step := batchItemList[0].(int) step := batchItemList[0].(int)
globals.SugarLogger.Debugf("step:%d", step)
switch step { switch step {
case 0: case 0:
if len(deleteList) > 0 { if len(deleteList) > 0 {
_, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) { _, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) {
if err = singleStoreHandler.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { if err = singleStoreHandler.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil {
_, err = updateStoreSku(db, vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagDeletedMask) _, err = updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagDeletedMask)
} }
return nil, err return nil, err
}, ctx, task, deleteList, singleStoreHandler.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus), isContinueWhenError) }, ctx, task, deleteList, singleStoreHandler.GetStoreSkusBatchSize(partner.FuncDeleteStoreSkus), isContinueWhenError)
@@ -298,8 +328,9 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
case 1: case 1:
if len(createList) > 0 { if len(createList) > 0 {
_, err = putils.FreeBatchStoreSkuSyncInfo(func(batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, err error) { _, err = putils.FreeBatchStoreSkuSyncInfo(func(batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, err error) {
globals.SugarLogger.Debug(utils.Format4Output(batchedStoreSkuList, false))
if err = singleStoreHandler.CreateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { if err = singleStoreHandler.CreateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil {
_, err = updateStoreSku(db, vendorID, batchedStoreSkuList, model.SyncFlagNewMask) _, err = updateStoreSku(dao.GetDB(), vendorID, batchedStoreSkuList, model.SyncFlagNewMask)
} }
return nil, err return nil, err
}, ctx, task, createList, singleStoreHandler.GetStoreSkusBatchSize(partner.FuncCreateStoreSkus), isContinueWhenError) }, ctx, task, createList, singleStoreHandler.GetStoreSkusBatchSize(partner.FuncCreateStoreSkus), isContinueWhenError)
@@ -307,8 +338,8 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
case 2: case 2:
if len(updateList) > 0 { if len(updateList) > 0 {
_, err = putils.FreeBatchStoreSkuSyncInfo(func(batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, err error) { _, err = putils.FreeBatchStoreSkuSyncInfo(func(batchedStoreSkuList []*dao.StoreSkuSyncInfo) (result interface{}, err error) {
if err = singleStoreHandler.CreateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil { if err = singleStoreHandler.UpdateStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList); err == nil {
_, err = updateStoreSku(db, vendorID, batchedStoreSkuList, model.SyncFlagModifiedMask) _, err = updateStoreSku(dao.GetDB(), vendorID, batchedStoreSkuList, model.SyncFlagModifiedMask)
} }
return nil, err return nil, err
}, ctx, task, updateList, singleStoreHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkus), isContinueWhenError) }, ctx, task, updateList, singleStoreHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkus), isContinueWhenError)
@@ -317,7 +348,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
if len(stockList) > 0 { if len(stockList) > 0 {
_, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) { _, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) {
if err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, stockList); err == nil { if err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, stockList); err == nil {
_, err = updateStoreSku(db, vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagModifiedMask) // ? _, err = updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagModifiedMask) // ?
} }
return nil, err return nil, err
}, ctx, task, stockList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStock), isContinueWhenError) }, ctx, task, stockList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStock), isContinueWhenError)
@@ -325,8 +356,8 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
case 4: case 4:
if len(statusList) > 0 { if len(statusList) > 0 {
_, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) { _, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) {
if err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, statusList); err == nil { if err = storeSkuHandler.UpdateStoreSkusStatus(ctx, storeID, vendorStoreID, statusList); err == nil {
_, err = updateStoreSku(db, vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagSaleMask) _, err = updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagSaleMask)
} }
return nil, err return nil, err
}, ctx, task, statusList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStatus), isContinueWhenError) }, ctx, task, statusList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusStatus), isContinueWhenError)
@@ -334,8 +365,8 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID,
case 5: case 5:
if len(priceList) > 0 { if len(priceList) > 0 {
_, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) { _, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) {
if err = storeSkuHandler.UpdateStoreSkusStock(ctx, storeID, vendorStoreID, priceList); err == nil { if err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeID, vendorStoreID, priceList); err == nil {
_, err = updateStoreSku(db, vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagPriceMask) _, err = updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(batchedStoreSkuList), model.SyncFlagPriceMask)
} }
return nil, err return nil, err
}, ctx, task, priceList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusPrice), isContinueWhenError) }, ctx, task, priceList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusPrice), isContinueWhenError)

View File

@@ -37,9 +37,8 @@ type StoreSkuSyncInfo struct {
StoreID int `orm:"column(store_id)"` StoreID int `orm:"column(store_id)"`
SkuID int `orm:"column(sku_id)"` // 这个与Sku.ID的区别是SkuID是必然存在的 SkuID int `orm:"column(sku_id)"` // 这个与Sku.ID的区别是SkuID是必然存在的
Price int64 Price int64
UnitPrice int64 UnitPrice int64
VendorPrice int64
// 平台相关的store sku信息 // 平台相关的store sku信息
StoreSkuStatus int StoreSkuStatus int
@@ -73,6 +72,10 @@ type StoreSkuSyncInfo struct {
VendorCatID string `orm:"column(vendor_cat_id)"` VendorCatID string `orm:"column(vendor_cat_id)"`
CatPricePercentage int CatPricePercentage int
VendorPrice int64
MergedStatus int
SkuName string
} }
type MissingStoreSkuInfo struct { type MissingStoreSkuInfo struct {

View File

@@ -34,9 +34,9 @@ type StoreSkuInfo struct {
NameID int `json:"nameID,omitempty"` NameID int `json:"nameID,omitempty"`
VendorNameID string `json:"vendorNameID,omitempty"` VendorNameID string `json:"vendorNameID,omitempty"`
Stock int `json:"stock,omitempty"` Stock int `json:"stock,omitempty"`
Price int64 `json:"price,omitempty"` VendorPrice int64 `json:"price,omitempty"`
Status int `json:"status,omitempty"` Status int `json:"status,omitempty"`
} }
type SkuInfo struct { type SkuInfo struct {

View File

@@ -138,7 +138,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) { func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
skuPriceList := make([]string, len(storeSkuList)) skuPriceList := make([]string, len(storeSkuList))
for k, v := range storeSkuList { for k, v := range storeSkuList {
skuPriceList[k] = fmt.Sprintf("%s:%d", v.VendorSkuID, v.Price) skuPriceList[k] = fmt.Sprintf("%s:%d", v.VendorSkuID, v.VendorPrice)
} }
if globals.EnableEbaiStoreWrite { if globals.EnableEbaiStoreWrite {
if len(skuPriceList) > 1 { if len(skuPriceList) > 1 {
@@ -167,7 +167,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[string]interface{}) { func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[string]interface{}) {
params = map[string]interface{}{ params = map[string]interface{}{
"name": storeSku.Name, "name": utils.LimitMixedStringLen(storeSku.SkuName, ebaiapi.MaxSkuNameByteCount),
"left_num": model.MaxStoreSkuStockQty, "left_num": model.MaxStoreSkuStockQty,
"category_id": utils.Str2Int64(storeSku.VendorCatID), "category_id": utils.Str2Int64(storeSku.VendorCatID),
"predict_cat": 0, // 不使用推荐类目 "predict_cat": 0, // 不使用推荐类目
@@ -190,7 +190,7 @@ func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[s
params["market_price"] = storeSku.VendorPrice params["market_price"] = storeSku.VendorPrice
} }
if storeSku.StoreSkuSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 { if storeSku.StoreSkuSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 {
params["status"] = jxSkuStatus2Ebai(storeSku.StoreSkuStatus) params["status"] = jxSkuStatus2Ebai(storeSku.MergedStatus)
} }
// todo 饿百如果给的UPC是空要报错但如果我要删除UPC怎么弄 // todo 饿百如果给的UPC是空要报错但如果我要删除UPC怎么弄
// if storeSku.Upc != "" { // if storeSku.Upc != "" {
@@ -275,9 +275,9 @@ func vendorSku2Jx(vendorSku *ebaiapi.SkuInfo) (skuName *partner.SkuNameInfo) {
VendorSkuID: vendorSkuID, VendorSkuID: vendorSkuID,
SkuID: skuID, SkuID: skuID,
Stock: vendorSku.LeftNum, Stock: vendorSku.LeftNum,
Price: vendorSku.SalePrice, VendorPrice: vendorSku.SalePrice,
Status: ebaiSkuStatus2Jx(vendorSku.Status), Status: ebaiSkuStatus2Jx(vendorSku.Status),
}, },
SkuName: vendorSku.Name, SkuName: vendorSku.Name,
Comment: comment, Comment: comment,

View File

@@ -13,7 +13,7 @@ func TestSyncStoresSkus(t *testing.T) {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
skus[i] = i + 1 skus[i] = i + 1
} }
_, err := new(PurchaseHandler).SyncStoreSkus(jxcontext.AdminCtx, nil, testShopID, skus, false, false) _, err := CurPurchaseHandler.SyncStoreSkus(jxcontext.AdminCtx, nil, testShopID, skus, false, false)
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
@@ -22,21 +22,21 @@ func TestSyncStoresSkus(t *testing.T) {
func TestSyncOneStoreCategoriesFromRemote2Local(t *testing.T) { func TestSyncOneStoreCategoriesFromRemote2Local(t *testing.T) {
db := dao.GetDB() db := dao.GetDB()
err := new(PurchaseHandler).SyncLocalStoreCategory(db, testShopID, "autotest") err := CurPurchaseHandler.SyncLocalStoreCategory(db, testShopID, "autotest")
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
} }
func TestSyncOneStoreCategoriesFromLocal2Remote(t *testing.T) { func TestSyncOneStoreCategoriesFromLocal2Remote(t *testing.T) {
_, err := new(PurchaseHandler).SyncStoreCategory(jxcontext.AdminCtx, nil, testShopID, false) _, err := CurPurchaseHandler.SyncStoreCategory(jxcontext.AdminCtx, nil, testShopID, false)
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
} }
func TestGetAllRemoteSkus(t *testing.T) { func TestGetAllRemoteSkus(t *testing.T) {
result, err := new(PurchaseHandler).GetAllRemoteSkus(jxcontext.AdminCtx, testShopID, nil) result, err := CurPurchaseHandler.GetStoreSkusFullInfo(jxcontext.AdminCtx, nil, testShopID, testShopBaiduID, nil)
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} else { } else {
@@ -45,14 +45,14 @@ func TestGetAllRemoteSkus(t *testing.T) {
} }
func TestDeleteRemoteSkus(t *testing.T) { func TestDeleteRemoteSkus(t *testing.T) {
err := new(PurchaseHandler).DeleteRemoteSkus(jxcontext.AdminCtx, nil, testShopID, nil) err := CurPurchaseHandler.DeleteStoreAllSkus(jxcontext.AdminCtx, nil, testShopID, testShopBaiduID, true)
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }
} }
func TestDeleteRemoteCategories(t *testing.T) { func TestDeleteRemoteCategories(t *testing.T) {
err := new(PurchaseHandler).DeleteRemoteCategories(jxcontext.AdminCtx, nil, testShopID, nil) err := new(PurchaseHandler).DeleteStoreAllCategories(jxcontext.AdminCtx, nil, testShopID, testShopBaiduID, true)
if err != nil { if err != nil {
t.Fatal(err.Error()) t.Fatal(err.Error())
} }

View File

@@ -57,7 +57,7 @@ func (p *PurchaseHandler) GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTas
storeSkuMap[v.SkuID].Status = jdStoreSkuStatus2Jx(v.Vendibility) storeSkuMap[v.SkuID].Status = jdStoreSkuStatus2Jx(v.Vendibility)
} }
for _, v := range priceInfo { for _, v := range priceInfo {
storeSkuMap[v.SkuID].Price = v.Price storeSkuMap[v.SkuID].VendorPrice = v.Price
} }
} }
} }
@@ -94,14 +94,14 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) { func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
if len(storeSkuList) == 1 { if len(storeSkuList) == 1 {
if globals.EnableJdStoreWrite { if globals.EnableJdStoreWrite {
_, err = api.JdAPI.UpdateStationPrice(utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), vendorStoreID, int(storeSkuList[0].Price)) _, err = api.JdAPI.UpdateStationPrice(utils.Str2Int64WithDefault(storeSkuList[0].VendorSkuID, 0), vendorStoreID, int(storeSkuList[0].VendorPrice))
} }
} else { } else {
var skuPriceInfoList []*jdapi.SkuPriceInfo var skuPriceInfoList []*jdapi.SkuPriceInfo
for _, v := range storeSkuList { for _, v := range storeSkuList {
skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{ skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{
OutSkuId: utils.Int2Str(v.SkuID), OutSkuId: utils.Int2Str(v.SkuID),
Price: int(v.Price), Price: int(v.VendorPrice),
}) })
} }
if globals.EnableJdStoreWrite { if globals.EnableJdStoreWrite {

View File

@@ -10,6 +10,11 @@ import (
"git.rosy.net.cn/jx-callback/globals/testinit" "git.rosy.net.cn/jx-callback/globals/testinit"
) )
const (
testShopVendorID = "2523687"
testShopID = 2
)
func init() { func init() {
testinit.Init() testinit.Init()
} }

View File

@@ -117,15 +117,15 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
}, },
} }
foodData["skus"] = skus foodData["skus"] = skus
foodData["name"] = utils.LimitUTF8StringLen(storeSku.Name, 30) foodData["name"] = utils.LimitUTF8StringLen(storeSku.SkuName, mtwmapi.MaxSkuNameCharCount)
foodData["description"] = storeSku.Comment foodData["description"] = storeSku.Comment
foodData["price"] = storeSku.VendorPrice foodData["price"] = jxutils.IntPrice2Standard(storeSku.VendorPrice)
foodData["min_order_count"] = 1 foodData["min_order_count"] = 1
foodData["unit"] = storeSku.Unit foodData["unit"] = storeSku.Unit
foodData["box_num"] = 0 foodData["box_num"] = 0
foodData["box_price"] = 0.0 foodData["box_price"] = 0.0
foodData["category_name"] = storeSku.VendorCatID foodData["category_name"] = storeSku.VendorCatID
foodData["is_sold_out"] = skuStatusJX2Mtwm(storeSku.StoreSkuStatus) foodData["is_sold_out"] = skuStatusJX2Mtwm(storeSku.MergedStatus)
foodData["picture"] = storeSku.Img foodData["picture"] = storeSku.Img
if storeSku.DescImg != "" { if storeSku.DescImg != "" {
foodData["picture_contents"] = storeSku.DescImg foodData["picture_contents"] = storeSku.DescImg
@@ -205,7 +205,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
Skus: []*mtwmapi.BareStoreSkuInfo{ Skus: []*mtwmapi.BareStoreSkuInfo{
&mtwmapi.BareStoreSkuInfo{ &mtwmapi.BareStoreSkuInfo{
SkuID: storeSku.VendorSkuID, SkuID: storeSku.VendorSkuID,
Price: utils.Int64ToStr(storeSku.Price), Price: jxutils.IntPrice2StandardString(storeSku.VendorPrice),
}, },
}, },
} }
@@ -289,9 +289,9 @@ func vendorSku2Jx(appFood *mtwmapi.AppFood) (skuName *partner.SkuNameInfo) {
VendorSkuID: vendorSku.SkuID, VendorSkuID: vendorSku.SkuID,
SkuID: skuID, SkuID: skuID,
Stock: int(utils.Str2Int64WithDefault(vendorSku.Stock, partner.UnlimitedStoreSkuStock)), Stock: int(utils.Str2Int64WithDefault(vendorSku.Stock, partner.UnlimitedStoreSkuStock)),
Price: jxutils.StandardPrice2Int(utils.Str2Float64WithDefault(vendorSku.Price, 0)), VendorPrice: jxutils.StandardPrice2Int(utils.Str2Float64WithDefault(vendorSku.Price, 0)),
Status: mtwmSkuStatus2Jx(appFood.IsSoldOut), Status: mtwmSkuStatus2Jx(appFood.IsSoldOut),
}, },
SkuName: appFood.Name, SkuName: appFood.Name,
Comment: comment, Comment: comment,

View File

@@ -8,7 +8,7 @@ import (
) )
func TestSyncStoreCategory(t *testing.T) { func TestSyncStoreCategory(t *testing.T) {
hint, err := new(PurchaseHandler).SyncStoreCategory(jxcontext.AdminCtx, nil, 100077, false) hint, err := curPurchaseHandler.SyncStoreCategory(jxcontext.AdminCtx, nil, testShopID, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -16,7 +16,7 @@ func TestSyncStoreCategory(t *testing.T) {
} }
func TestSyncLocalStoreCategory(t *testing.T) { func TestSyncLocalStoreCategory(t *testing.T) {
hint, err := new(PurchaseHandler).SyncLocalStoreCategory(jxcontext.AdminCtx, nil, 100077, true, nil) hint, err := curPurchaseHandler.SyncLocalStoreCategory(jxcontext.AdminCtx, nil, testShopID, true, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -24,7 +24,7 @@ func TestSyncLocalStoreCategory(t *testing.T) {
} }
func TestSyncStoreSkus(t *testing.T) { func TestSyncStoreSkus(t *testing.T) {
hint, err := new(PurchaseHandler).SyncStoreSkus(jxcontext.AdminCtx, nil, 100077, nil, false, true) hint, err := curPurchaseHandler.SyncStoreSkus(jxcontext.AdminCtx, nil, testShopID, nil, false, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -32,14 +32,14 @@ func TestSyncStoreSkus(t *testing.T) {
} }
func TestDeleteRemoteSkus(t *testing.T) { func TestDeleteRemoteSkus(t *testing.T) {
err := new(PurchaseHandler).DeleteRemoteSkus(jxcontext.AdminCtx, nil, 100077, nil) err := curPurchaseHandler.DeleteStoreAllSkus(jxcontext.AdminCtx, nil, testShopID, testShopVendorID, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestDeleteRemoteCategories(t *testing.T) { func TestDeleteRemoteCategories(t *testing.T) {
err := new(PurchaseHandler).DeleteRemoteCategories(jxcontext.AdminCtx, nil, 100077, nil) err := curPurchaseHandler.DeleteStoreAllCategories(jxcontext.AdminCtx, nil, testShopID, testShopVendorID, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }