- 添加IStoreSkuSorter接口,但当前无实际平台支持
This commit is contained in:
@@ -3,6 +3,7 @@ package cms
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -189,6 +190,7 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
|
||||
|
||||
Status: inSku.MergedStatus,
|
||||
VendorPrice: inSku.VendorPrice,
|
||||
Seq: inSku.Seq,
|
||||
}
|
||||
if !isStoreSkuSyncNeedDelete(inSku) {
|
||||
outSku.Stock = model.MaxStoreSkuStockQty
|
||||
@@ -197,10 +199,12 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
|
||||
}
|
||||
|
||||
func calVendorPrice4StoreSku(inSku *dao.StoreSkuSyncInfo, pricePercentagePack model.PricePercentagePack, pricePercentage int) (outSku *dao.StoreSkuSyncInfo) {
|
||||
pricePercentage = jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage)
|
||||
inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage, 0))
|
||||
if inSku.VendorPrice <= 0 {
|
||||
inSku.VendorPrice = 1 // 最少1分钱
|
||||
if inSku.VendorPrice <= 0 { // 避免重新计算
|
||||
pricePercentage = jxutils.GetPricePercentage(pricePercentagePack, int(inSku.Price), pricePercentage)
|
||||
inSku.VendorPrice = int64(jxutils.CaculateSkuVendorPrice(int(inSku.Price), pricePercentage, 0))
|
||||
if inSku.VendorPrice <= 0 {
|
||||
inSku.VendorPrice = 1 // 最少1分钱
|
||||
}
|
||||
}
|
||||
return inSku
|
||||
}
|
||||
@@ -292,16 +296,22 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
|
||||
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
reorderHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IStoreSkuSorter)
|
||||
|
||||
var (
|
||||
createList, updateList []*dao.StoreSkuSyncInfo
|
||||
deleteList, stockList, onlineList, offlineList, priceList []*partner.StoreSkuInfo
|
||||
updateItems []*dao.KVUpdateItem
|
||||
reorderSkuMap map[string][]*dao.StoreSkuSyncInfo
|
||||
)
|
||||
skuMap := make(map[*partner.StoreSkuInfo]*dao.StoreSkuSyncInfo)
|
||||
if reorderHandler != nil {
|
||||
reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo)
|
||||
}
|
||||
|
||||
for _, sku := range skus {
|
||||
var bareSku *partner.StoreSkuInfo
|
||||
isNeedReorder := false
|
||||
if isStoreSkuSyncNeedDelete(sku) {
|
||||
if !dao.IsVendorThingIDEmpty(sku.VendorSkuID) {
|
||||
bareSku = storeSkuSyncInfo2Bare(sku)
|
||||
@@ -330,6 +340,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
createList = append(createList, sku)
|
||||
}
|
||||
}
|
||||
isNeedReorder = true
|
||||
} else {
|
||||
if dao.IsVendorThingIDEmpty(sku.VendorSkuID) {
|
||||
err = fmt.Errorf("门店:%d,修改没有创建的商品:%d", storeID, sku.SkuID)
|
||||
@@ -340,7 +351,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
} else {
|
||||
isAdded2Update := false
|
||||
// 修改商品信息时不改价(以免活动引起的失败),而用单独的改价来改
|
||||
if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) && singleStoreHandler != nil {
|
||||
if (model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) || (model.IsSyncStatusSec(sku.StoreSkuSyncStatus) && reorderHandler == nil)) && singleStoreHandler != nil {
|
||||
isAdded2Update = true
|
||||
updateList = append(updateList, calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
|
||||
}
|
||||
@@ -367,8 +378,12 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
}
|
||||
}
|
||||
}
|
||||
isNeedReorder = model.IsSyncStatusSec(sku.StoreSkuSyncStatus)
|
||||
}
|
||||
}
|
||||
if isNeedReorder && reorderHandler != nil && sku.VendorCatID != "" {
|
||||
reorderSkuMap[sku.VendorCatID] = append(reorderSkuMap[sku.VendorCatID], sku)
|
||||
}
|
||||
if bareSku != nil {
|
||||
skuMap[bareSku] = sku
|
||||
}
|
||||
@@ -500,9 +515,32 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
return nil, len(successList), err
|
||||
}, ctx, task, priceList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusPrice), isContinueWhenError)
|
||||
}
|
||||
case 7:
|
||||
if len(reorderSkuMap) > 0 {
|
||||
var vendorCatIDs []string
|
||||
for vendorCatID := range reorderSkuMap {
|
||||
vendorCatIDs = append(vendorCatIDs, vendorCatID)
|
||||
}
|
||||
reorderTask := tasksch.NewParallelTask("门店商品排序", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorCatID := batchItemList[0].(string)
|
||||
skuList := reorderSkuMap[vendorCatID]
|
||||
var bareList []*partner.StoreSkuInfo
|
||||
for _, v := range skuList {
|
||||
bareList = append(bareList, storeSkuSyncInfo2Bare(calVendorPrice4StoreSku(v, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage))))
|
||||
}
|
||||
sort.Sort(partner.BareStoreSkuInfoList(bareList))
|
||||
if err = reorderHandler.ReorderStoreSkus(ctx, storeID, vendorStoreID, vendorCatID, bareList); err == nil {
|
||||
updateStoreSku(dao.GetDB(), vendorID, skuList, model.SyncFlagSeqMask)
|
||||
}
|
||||
return retVal, err
|
||||
}, vendorCatIDs)
|
||||
tasksch.HandleTask(reorderTask, task, true).Run()
|
||||
_, err = reorderTask.GetResult(0)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1, 2, 3, 4, 5, 6})
|
||||
}, []int{0, 1, 2, 3, 4, 5, 6, 7})
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user