门店商品直接活动

This commit is contained in:
gazebo
2020-01-17 09:42:19 +08:00
parent 983e4b4218
commit b849f2c195
7 changed files with 102 additions and 26 deletions

View File

@@ -608,7 +608,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
if len(priceList) > 0 {
_, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
if isNeedHandleAct(causeFlag) {
cancelStoreSkuActs(ctx, task, vendorID, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList)
cancelStoreSkuActs(ctx, task, vendorID, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList, true)
}
var failedList []*partner.StoreSkuInfoWithErr
failedList, err = storeSkuHandler.UpdateStoreSkusPrice(ctx, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList)
@@ -620,7 +620,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
updateStoreSku(dao.GetDB(), vendorID, bareSku2Sync(successList), model.SyncFlagPriceMask)
}
if isNeedHandleAct(causeFlag) {
createStoreSkuActs(ctx, task, vendorID, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList)
createStoreSkuActs(ctx, task, vendorID, storeDetail.VendorOrgCode, storeID, vendorStoreID, batchedStoreSkuList, true)
}
return nil, len(successList), err
}, ctx, task, priceList, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncUpdateStoreSkusPrice), isContinueWhenError2)
@@ -934,13 +934,14 @@ func MergeSkuSaleStatusWithStoreOpTime(sku *dao.StoreSkuSyncInfo, storeDetail *d
}
func GetVendorSkuIDList(l []*partner.StoreSkuInfoWithErr) (vendorSkuIDs []string) {
vendorSkuIDs2 := make([]string, len(l))
if len(l) > 0 {
for k, v := range l {
vendorSkuIDs2[k] = v.StoreSkuInfo.VendorSkuID
for _, v := range l {
if v.StoreSkuInfo != nil {
vendorSkuIDs = append(vendorSkuIDs, v.StoreSkuInfo.VendorSkuID)
}
}
}
return vendorSkuIDs2
return vendorSkuIDs
}
func skuAct2Update(storeSkuAct *model.StoreSkuAct, isCreateAct bool) (item *dao.KVUpdateItem) {
@@ -1005,7 +1006,7 @@ func parseStoreSkuActList(isCreateAct bool, storeSkuList []*partner.StoreSkuInfo
return outStoreSkuList, storeSkuActMap
}
func createStoreSkuActs(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
func createStoreSkuActs(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, isChangePrice bool) (err error) {
globals.SugarLogger.Debugf("createStoreSkuActs vendorID:%d, storeID:%d, storeSkuList:%s", vendorID, storeID, utils.Format4Output(storeSkuList, true))
skuIDs := putils.StoreSkuList2IDs(storeSkuList)
db := dao.GetDB()
@@ -1013,6 +1014,9 @@ func createStoreSkuActs(ctx *jxcontext.Context, parentTask tasksch.ITask, vendor
if err == nil {
storeSkuList2, storeSkuActMap := parseStoreSkuActList(true, storeSkuList, storeSkuActList)
if len(storeSkuList2) > 0 {
if isChangePrice {
time.Sleep(1 * time.Second) // 改价后马上建活动可能失败
}
storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
_, err = putils.FreeBatchStoreSkuInfo(fmt.Sprintf("创建门店%d直降活动", storeID), func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
var failedList []*partner.StoreSkuInfoWithErr
@@ -1020,7 +1024,7 @@ func createStoreSkuActs(ctx *jxcontext.Context, parentTask tasksch.ITask, vendor
if len(failedList) > 0 {
task.AddFailedList(failedList)
}
successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList))
successList := putils.UnselectStoreSkuListBySkuIDs(batchedStoreSkuList, putils.StoreSkuInfoWithErrList2SkuIDs(failedList))
if len(successList) > 0 {
updateStoreSkuAct(dao.GetDB(), vendorID, bareSku2StoreSkuAct(storeSkuActMap, successList), true)
}
@@ -1031,7 +1035,7 @@ func createStoreSkuActs(ctx *jxcontext.Context, parentTask tasksch.ITask, vendor
return err
}
func cancelStoreSkuActs(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
func cancelStoreSkuActs(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, isChangePrice bool) (err error) {
globals.SugarLogger.Debugf("cancelStoreSkuActs vendorID:%d, storeID:%d, storeSkuList:%s", vendorID, storeID, utils.Format4Output(storeSkuList, true))
skuIDs := putils.StoreSkuList2IDs(storeSkuList)
db := dao.GetDB()
@@ -1046,12 +1050,15 @@ func cancelStoreSkuActs(ctx *jxcontext.Context, parentTask tasksch.ITask, vendor
if len(failedList) > 0 {
task.AddFailedList(failedList)
}
successList := putils.UnselectStoreSkuListByVendorSkuIDs(batchedStoreSkuList, GetVendorSkuIDList(failedList))
successList := putils.UnselectStoreSkuListBySkuIDs(batchedStoreSkuList, putils.StoreSkuInfoWithErrList2SkuIDs(failedList))
if len(successList) > 0 {
updateStoreSkuAct(dao.GetDB(), vendorID, bareSku2StoreSkuAct(storeSkuActMap, successList), false)
}
return nil, len(successList), err
}, ctx, parentTask, storeSkuList2, storeSkuHandler.GetStoreSkusBatchSize(partner.FuncCancelActs), true)
if isChangePrice && vendorID == model.VendorIDJD {
time.Sleep(1 * time.Second) // 取消活动后马上改价可能失败
}
}
}
return err