定时刷新商品可售状态
This commit is contained in:
@@ -3,7 +3,6 @@ package cms
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"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) {
|
func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (err error) {
|
||||||
var (
|
var (
|
||||||
storeIDs []int
|
storeIDs []int
|
||||||
skuIDs []int
|
skuIDs []int
|
||||||
vendorIDs = []int{0, 1, 3}
|
|
||||||
)
|
)
|
||||||
|
vendorIDs := partner.GetPurchasePlatformVendorIDs()
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
now := time.Now().Hour()*100 + time.Now().Minute()
|
|
||||||
storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db)
|
storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db)
|
||||||
for _, v := range storeSkuList {
|
for _, v := range storeSkuList {
|
||||||
if (now >= v.TimeBegin1 && now <= v.TimeEnd1) || (now >= v.TimeBegin2 && now <= v.TimeEnd2) {
|
storeIDs = append(storeIDs, v.StoreID)
|
||||||
skuIDs = append(skuIDs, v.StoreSkuBind.SkuID)
|
skuIDs = append(skuIDs, v.SkuID)
|
||||||
storeIDs = append(storeIDs, v.StoreSkuBind.StoreID)
|
setStoreSkuBindStatus(v, model.SyncFlagSaleMask)
|
||||||
v.StoreSkuBind.Status = model.SkuStatusDontSale
|
dao.UpdateEntity(db, v)
|
||||||
setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagSaleMask)
|
}
|
||||||
dao.UpdateEntity(db, &v.StoreSkuBind)
|
if len(storeSkuList) > 0 {
|
||||||
} else {
|
v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
||||||
v.StoreSkuBind.Status = model.SkuStatusNormal
|
} else {
|
||||||
setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagSaleMask)
|
return errors.New("未查询到设置了可售时间的商品!")
|
||||||
dao.UpdateEntity(db, &v.StoreSkuBind)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -299,6 +299,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
|||||||
} else {
|
} else {
|
||||||
skus, err = dao.GetStoreSkus(db, vendorID, storeID, skuIDs)
|
skus, err = dao.GetStoreSkus(db, vendorID, storeID, skuIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil || len(skus) == 0 {
|
if err != nil || len(skus) == 0 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -328,8 +329,13 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
|||||||
if reorderHandler != nil {
|
if reorderHandler != nil {
|
||||||
reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo)
|
reorderSkuMap = make(map[string][]*dao.StoreSkuSyncInfo)
|
||||||
}
|
}
|
||||||
|
now := time.Now().Hour()*100 + time.Now().Minute()
|
||||||
for _, sku := range skus {
|
for _, sku := range skus {
|
||||||
|
if isUpdateSkuSaleStatus(sku, now) {
|
||||||
|
sku.MergedStatus = model.SkuStatusDontSale
|
||||||
|
} else {
|
||||||
|
sku.MergedStatus = model.SkuStatusNormal
|
||||||
|
}
|
||||||
var bareSku *partner.StoreSkuInfo
|
var bareSku *partner.StoreSkuInfo
|
||||||
isNeedReorder := false
|
isNeedReorder := false
|
||||||
if isStoreSkuSyncNeedDelete(sku) {
|
if isStoreSkuSyncNeedDelete(sku) {
|
||||||
@@ -795,3 +801,24 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st
|
|||||||
|
|
||||||
return ""
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,13 +47,6 @@ var (
|
|||||||
"22:00:00",
|
"22:00:00",
|
||||||
}
|
}
|
||||||
ChangeStoreSkuSaleStatusList = []string{
|
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",
|
"7:00:00",
|
||||||
"8:00:00",
|
"8:00:00",
|
||||||
"9:00:00",
|
"9:00:00",
|
||||||
@@ -68,9 +61,6 @@ var (
|
|||||||
"18:00:00",
|
"18:00:00",
|
||||||
"19:00:00",
|
"19:00:00",
|
||||||
"20:00:00",
|
"20:00:00",
|
||||||
"21:00:00",
|
|
||||||
"22:00:00",
|
|
||||||
"23:00:00",
|
|
||||||
}
|
}
|
||||||
openRemoteStoreTimeList = []string{
|
openRemoteStoreTimeList = []string{
|
||||||
"23:30:00",
|
"23:30:00",
|
||||||
@@ -144,7 +134,7 @@ func Init() {
|
|||||||
"04:05:06",
|
"04:05:06",
|
||||||
})
|
})
|
||||||
ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() {
|
ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() {
|
||||||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, false, false)
|
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, true, false)
|
||||||
}, ChangeStoreSkuSaleStatusList)
|
}, ChangeStoreSkuSaleStatusList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,9 +79,13 @@ type StoreSkuSyncInfo struct {
|
|||||||
StoreCatSyncStatus int8
|
StoreCatSyncStatus int8
|
||||||
VendorCatID string `orm:"column(vendor_cat_id)"`
|
VendorCatID string `orm:"column(vendor_cat_id)"`
|
||||||
|
|
||||||
VendorPrice int64
|
VendorPrice int64
|
||||||
MergedStatus int
|
MergedStatus int
|
||||||
SkuName string
|
SkuName string
|
||||||
|
StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围
|
||||||
|
StatusSaleEnd int `json:"statusSaleEnd"`
|
||||||
|
OpenTime int //门店营业时间
|
||||||
|
CloseTime int
|
||||||
}
|
}
|
||||||
|
|
||||||
type MissingStoreSkuInfo struct {
|
type MissingStoreSkuInfo struct {
|
||||||
@@ -107,14 +111,6 @@ type StoreSkuNameInfo struct {
|
|||||||
UnitPrice int64
|
UnitPrice int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type StoreSkuBindWithSaleTime struct {
|
|
||||||
StoreSkuBind model.StoreSkuBind
|
|
||||||
TimeBegin1 int
|
|
||||||
TimeEnd1 int
|
|
||||||
TimeBegin2 int
|
|
||||||
TimeEnd2 int
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑
|
// todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑
|
||||||
// 单门店模式厂商适用
|
// 单门店模式厂商适用
|
||||||
// 从store_sku_bind中,得到所有依赖的商家分类信息
|
// 从store_sku_bind中,得到所有依赖的商家分类信息
|
||||||
@@ -224,7 +220,9 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo
|
|||||||
fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])
|
fieldPrefix := ConvertDBFieldPrefix(model.VendorNames[vendorID])
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.id bind_id, t1.sku_id, t1.price, t1.unit_price, t1.status store_sku_status, %s.%s_id vendor_sku_id,
|
SELECT t1.id bind_id, t1.sku_id, t1.price, t1.unit_price, t1.status store_sku_status, %s.%s_id vendor_sku_id,
|
||||||
t1.%s_sync_status store_sku_sync_status, t1.store_id, t1.deleted_at bind_deleted_at,
|
t1.%s_sync_status store_sku_sync_status, t1.store_id, t1.deleted_at bind_deleted_at,t1.status_sale_begin,t1.status_sale_end,
|
||||||
|
IF(t6.open_time2 <> 0 AND t6.close_time2 <>0,IF(t6.open_time1 < t6.open_time2,t6.open_time1,t6.open_time2),t6.open_time1) open_time,
|
||||||
|
IF(t6.open_time2 <> 0 AND t6.close_time2 <>0,IF(t6.close_time1 > t6.close_time2,t6.close_time1,t6.close_time2),t6.close_time1) close_time,
|
||||||
t2.*,
|
t2.*,
|
||||||
t3.id name_id, t3.prefix, t3.name, t3.unit, t3.upc,
|
t3.id name_id, t3.prefix, t3.name, t3.unit, t3.upc,
|
||||||
IF(t11.%s <> '', t11.%s, t3.img) img,
|
IF(t11.%s <> '', t11.%s, t3.img) img,
|
||||||
@@ -257,6 +255,7 @@ func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, mustDirty boo
|
|||||||
LEFT JOIN data_resource t11 ON t11.main_url = t3.img
|
LEFT JOIN data_resource t11 ON t11.main_url = t3.img
|
||||||
LEFT JOIN data_resource t12 ON t12.main_url = t3.img2
|
LEFT JOIN data_resource t12 ON t12.main_url = t3.img2
|
||||||
LEFT JOIN data_resource t13 ON t13.main_url = t3.desc_img
|
LEFT JOIN data_resource t13 ON t13.main_url = t3.desc_img
|
||||||
|
LEFT JOIN store t6 ON t6.id = t1.store_id
|
||||||
`
|
`
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
utils.DefaultTimeValue,
|
utils.DefaultTimeValue,
|
||||||
@@ -593,20 +592,17 @@ func (s *StoreSkuSyncInfo) GetSeq() int {
|
|||||||
return int(s.VendorPrice)
|
return int(s.VendorPrice)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*StoreSkuBindWithSaleTime, err error) {
|
func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*model.StoreSkuBind, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.*,
|
SELECT t1.*
|
||||||
IF(t2.open_time1 <= t1.status_sale_begin,t2.open_time1,0) time_begin1,
|
|
||||||
IF(t2.open_time1 <= t1.status_sale_begin,t1.status_sale_begin,0) time_end1,
|
|
||||||
IF(t2.close_time1 >= t1.status_sale_end,t1.status_sale_end,0) time_begin2,
|
|
||||||
IF(t2.close_time1 >= t1.status_sale_end,t2.close_time1,0) time_end2
|
|
||||||
FROM store_sku_bind t1
|
FROM store_sku_bind t1
|
||||||
JOIN store t2 ON t1.store_id = t2.id
|
|
||||||
WHERE t1.status_sale_begin <> 0 AND t1.status_sale_end <> 0
|
WHERE t1.status_sale_begin <> 0 AND t1.status_sale_end <> 0
|
||||||
AND t1.status != ?
|
AND t1.status = ?
|
||||||
|
AND t1.deleted_at = ?
|
||||||
`
|
`
|
||||||
sqlParams := []interface{}{
|
sqlParams := []interface{}{
|
||||||
model.SkuStatusDeleted,
|
model.SkuStatusNormal,
|
||||||
|
utils.DefaultTimeValue,
|
||||||
}
|
}
|
||||||
err = GetRows(db, &storeSkuBindList, sql, sqlParams...)
|
err = GetRows(db, &storeSkuBindList, sql, sqlParams...)
|
||||||
return storeSkuBindList, err
|
return storeSkuBindList, err
|
||||||
|
|||||||
@@ -112,6 +112,9 @@ type StoreSkuBind struct {
|
|||||||
// WscPrice int `json:"wscPrice"`
|
// WscPrice int `json:"wscPrice"`
|
||||||
|
|
||||||
AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
|
AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
|
||||||
|
|
||||||
|
StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围
|
||||||
|
StatusSaleEnd int `json:"statusSaleEnd"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*StoreSkuBind) TableUnique() [][]string {
|
func (*StoreSkuBind) TableUnique() [][]string {
|
||||||
|
|||||||
Reference in New Issue
Block a user