定时刷新商品可售状态

This commit is contained in:
苏尹岚
2019-11-14 18:03:34 +08:00
parent 3da95b29f8
commit bcc534289a
5 changed files with 83 additions and 50 deletions

View File

@@ -3,7 +3,6 @@ package cms
import (
"errors"
"fmt"
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
@@ -657,29 +656,47 @@ func (v *VendorSync) SyncSkuNames(ctx *jxcontext.Context, nameIDs []int, isForce
func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (err error) {
var (
storeIDs []int
skuIDs []int
vendorIDs = []int{0, 1, 3}
storeIDs []int
skuIDs []int
)
vendorIDs := partner.GetPurchasePlatformVendorIDs()
db := dao.GetDB()
now := time.Now().Hour()*100 + time.Now().Minute()
storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db)
for _, v := range storeSkuList {
if (now >= v.TimeBegin1 && now <= v.TimeEnd1) || (now >= v.TimeBegin2 && now <= v.TimeEnd2) {
skuIDs = append(skuIDs, v.StoreSkuBind.SkuID)
storeIDs = append(storeIDs, v.StoreSkuBind.StoreID)
v.StoreSkuBind.Status = model.SkuStatusDontSale
setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagSaleMask)
dao.UpdateEntity(db, &v.StoreSkuBind)
} else {
v.StoreSkuBind.Status = model.SkuStatusNormal
setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagSaleMask)
dao.UpdateEntity(db, &v.StoreSkuBind)
}
storeIDs = append(storeIDs, v.StoreID)
skuIDs = append(skuIDs, v.SkuID)
setStoreSkuBindStatus(v, model.SyncFlagSaleMask)
dao.UpdateEntity(db, v)
}
if len(storeSkuList) > 0 {
v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
} else {
return errors.New("未查询到设置了可售时间的商品!")
}
v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
if err != nil {
return err
}
return nil
}
func GetTimeMixByInt(begin1, end1, begin2, end2 int) (beginAt, endAt int) {
if (begin1 > begin2 && begin1 > end2) || (begin2 > end1 && end2 > end1) {
return 0, 0
}
if begin1 > begin2 {
beginAt = begin1
if end1 > end2 {
endAt = end2
} else {
endAt = end1
}
} else {
beginAt = begin2
if end1 > end2 {
endAt = end2
} else {
endAt = end1
}
}
return beginAt, endAt
}

View File

@@ -299,6 +299,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
} else {
skus, err = dao.GetStoreSkus(db, vendorID, storeID, skuIDs)
}
if err != nil || len(skus) == 0 {
return err
}
@@ -328,8 +329,13 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
if reorderHandler != nil {
reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo)
}
now := time.Now().Hour()*100 + time.Now().Minute()
for _, sku := range skus {
if isUpdateSkuSaleStatus(sku, now) {
sku.MergedStatus = model.SkuStatusDontSale
} else {
sku.MergedStatus = model.SkuStatusNormal
}
var bareSku *partner.StoreSkuInfo
isNeedReorder := false
if isStoreSkuSyncNeedDelete(sku) {
@@ -795,3 +801,24 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st
return ""
}
func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, now int) bool {
//商品可售时间的差集与门店营业时间的交集为不可售,其余为原本状态
openTime := sku.OpenTime
closeTime := sku.CloseTime
saleBeginTime := sku.StatusSaleBegin
saleEndTime := sku.StatusSaleEnd
beginAt1, endAt1 := GetTimeMixByInt(0, saleBeginTime, openTime, closeTime)
beginAt2, endAt2 := GetTimeMixByInt(saleEndTime, 2400, openTime, closeTime)
if beginAt1 != 0 && endAt1 != 0 {
if now > beginAt1 && now < endAt1 {
return true
}
}
if beginAt2 != 0 && endAt2 != 0 {
if now > beginAt2 && now < endAt2 {
return true
}
}
return false
}

View File

@@ -47,13 +47,6 @@ var (
"22:00:00",
}
ChangeStoreSkuSaleStatusList = []string{
"0:00:00",
"1:00:00",
"2:00:00",
"3:00:00",
"4:00:00",
"5:00:00",
"6:00:00",
"7:00:00",
"8:00:00",
"9:00:00",
@@ -68,9 +61,6 @@ var (
"18:00:00",
"19:00:00",
"20:00:00",
"21:00:00",
"22:00:00",
"23:00:00",
}
openRemoteStoreTimeList = []string{
"23:30:00",
@@ -144,7 +134,7 @@ func Init() {
"04:05:06",
})
ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() {
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, false, false)
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, true, false)
}, ChangeStoreSkuSaleStatusList)
}
}