定时刷新商品可售状态
This commit is contained in:
@@ -777,6 +777,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
||||
dao.Commit(db)
|
||||
}
|
||||
notifyStoreOperatorChanged(store, valid["operatorPhone"])
|
||||
if (valid["openTime1"] != 0 && valid["closeTime1"] != 0) && (valid["openTime2"] != 0) && (valid["closeTime2"] != 0) {
|
||||
err = CurVendorSync.ChangeStoreSkuSaleStatus(ctx, true, false, storeID)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("UpdateStore track:%s, store:%s", ctx.GetTrackInfo(), utils.Format4Output(store, true))
|
||||
|
||||
@@ -122,8 +122,8 @@ type StoreSkuBindInfo struct {
|
||||
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
||||
IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售
|
||||
SubStoreID int `json:"subStoreID,omitempty"`
|
||||
StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围
|
||||
StatusSaleEnd int `json:"statusSaleEnd"`
|
||||
StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围
|
||||
StatusSaleEnd int16 `json:"statusSaleEnd"`
|
||||
Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"`
|
||||
}
|
||||
|
||||
@@ -1079,8 +1079,17 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
updateFieldMap["JxPrice"] = 1
|
||||
}
|
||||
if skuBindInfo.StatusSaleBegin != 0 && skuBindInfo.StatusSaleEnd != 0 {
|
||||
updateFieldMap["StatusSaleBegin"] = skuBindInfo.StatusSaleBegin
|
||||
updateFieldMap["StatusSaleEnd"] = skuBindInfo.StatusSaleEnd
|
||||
if skuBindInfo.StatusSaleBegin < 0 || skuBindInfo.StatusSaleBegin > 2359 ||
|
||||
skuBindInfo.StatusSaleEnd < 0 || skuBindInfo.StatusSaleEnd > 2359 {
|
||||
dao.Rollback(db)
|
||||
return nil, fmt.Errorf("更改商品:%s, 可售时间不合法!时间范围:[%v] 至 [%v]", allBinds[0].Name, skuBindInfo.StatusSaleBegin, skuBindInfo.StatusSaleEnd)
|
||||
}
|
||||
if skuBindInfo.StatusSaleBegin >= skuBindInfo.StatusSaleEnd {
|
||||
dao.Rollback(db)
|
||||
return nil, fmt.Errorf("更改商品:%s, 可售时间不允许交叉!时间范围:[%v] 至 [%v]", allBinds[0].Name, skuBindInfo.StatusSaleBegin, skuBindInfo.StatusSaleEnd)
|
||||
}
|
||||
updateFieldMap["StatusSaleBegin"] = int(skuBindInfo.StatusSaleBegin)
|
||||
updateFieldMap["StatusSaleEnd"] = int(skuBindInfo.StatusSaleEnd)
|
||||
skuBind.StatusSaleBegin = skuBindInfo.StatusSaleBegin
|
||||
skuBind.StatusSaleEnd = skuBindInfo.StatusSaleEnd
|
||||
}
|
||||
|
||||
@@ -654,13 +654,13 @@ func (v *VendorSync) SyncSkuNames(ctx *jxcontext.Context, nameIDs []int, isForce
|
||||
return v.SyncSkus(ctx, db, nameIDs, nil, isAsync, isContinueWhenError, ctx.GetUserName())
|
||||
}
|
||||
|
||||
func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (err error) {
|
||||
func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, isContinueWhenError bool, storeID int) (err error) {
|
||||
var (
|
||||
storeIDs []int
|
||||
skuIDs []int
|
||||
)
|
||||
db := dao.GetDB()
|
||||
storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db)
|
||||
storeSkuList, err := dao.GetStoresSkusInfoBySaleTime(db, storeID)
|
||||
if len(storeSkuList) < 1 || err != nil {
|
||||
return errors.New(fmt.Sprintf("未查询到设置了可售时间的商品 GetStoresSkusInfoBySaleTime!err : %v", err))
|
||||
}
|
||||
@@ -677,7 +677,7 @@ func (v *VendorSync) ChangeStoreSkuSaleStatus(ctx *jxcontext.Context, isAsync, i
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetTimeMixByInt(begin1, end1, begin2, end2 int) (beginAt, endAt int) {
|
||||
func GetTimeMixByInt(begin1, end1, begin2, end2 int16) (beginAt, endAt int16) {
|
||||
if (begin1 > begin2 && begin1 > end2) || (begin2 > end1 && end2 > end1) {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
@@ -802,26 +802,26 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st
|
||||
return ""
|
||||
}
|
||||
|
||||
func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDetail, now int) bool {
|
||||
func isUpdateSkuSaleStatus(sku *dao.StoreSkuSyncInfo, storeDetail *dao.StoreDetail, now int16) bool {
|
||||
//商品可售时间的差集与门店营业时间的交集为不可售,其余为原本状态
|
||||
var openTime int
|
||||
var closeTime int
|
||||
var openTime int16
|
||||
var closeTime int16
|
||||
saleBeginTime := sku.StatusSaleBegin
|
||||
saleEndTime := sku.StatusSaleEnd
|
||||
if storeDetail.OpenTime2 != 0 && storeDetail.CloseTime2 != 0 {
|
||||
if storeDetail.OpenTime1 < storeDetail.OpenTime2 {
|
||||
openTime = int(storeDetail.OpenTime1)
|
||||
openTime = storeDetail.OpenTime1
|
||||
} else {
|
||||
openTime = int(storeDetail.OpenTime2)
|
||||
openTime = storeDetail.OpenTime2
|
||||
}
|
||||
if storeDetail.CloseTime1 > storeDetail.CloseTime2 {
|
||||
closeTime = int(storeDetail.CloseTime1)
|
||||
closeTime = storeDetail.CloseTime1
|
||||
} else {
|
||||
closeTime = int(storeDetail.CloseTime2)
|
||||
closeTime = storeDetail.CloseTime2
|
||||
}
|
||||
} else {
|
||||
openTime = int(storeDetail.OpenTime1)
|
||||
closeTime = int(storeDetail.CloseTime1)
|
||||
openTime = storeDetail.OpenTime1
|
||||
closeTime = storeDetail.CloseTime1
|
||||
}
|
||||
beginAt1, endAt1 := GetTimeMixByInt(0, saleBeginTime, openTime, closeTime)
|
||||
beginAt2, endAt2 := GetTimeMixByInt(saleEndTime, 2400, openTime, closeTime)
|
||||
|
||||
@@ -134,7 +134,7 @@ func Init() {
|
||||
"04:05:06",
|
||||
})
|
||||
ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() {
|
||||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, true, false)
|
||||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, true, false, 0)
|
||||
}, ChangeStoreSkuSaleStatusList)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,8 +688,8 @@ func OperationTimeStr4VendorStore(v *model.VendorStoreSnapshot) (str string) {
|
||||
return str
|
||||
}
|
||||
|
||||
func OperationTime2HourMinuteFormat(time time.Time) (i int) {
|
||||
return time.Hour()*100 + time.Minute()
|
||||
func OperationTime2HourMinuteFormat(time time.Time) (i int16) {
|
||||
return int16(time.Hour()*100 + time.Minute())
|
||||
}
|
||||
|
||||
// 得到饿百订单的取货码
|
||||
|
||||
@@ -84,8 +84,8 @@ type StoreSkuSyncInfo struct {
|
||||
VendorPrice int64
|
||||
MergedStatus int
|
||||
SkuName string
|
||||
StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围
|
||||
StatusSaleEnd int `json:"statusSaleEnd"`
|
||||
StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围
|
||||
StatusSaleEnd int16 `json:"statusSaleEnd"`
|
||||
}
|
||||
|
||||
type MissingStoreSkuInfo struct {
|
||||
@@ -589,7 +589,7 @@ func (s *StoreSkuSyncInfo) GetSeq() int {
|
||||
return int(s.VendorPrice)
|
||||
}
|
||||
|
||||
func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*model.StoreSkuBind, err error) {
|
||||
func GetStoresSkusInfoBySaleTime(db *DaoDB, storeID int) (storeSkuBindList []*model.StoreSkuBind, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM store_sku_bind t1
|
||||
@@ -601,6 +601,10 @@ func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*model.StoreSkuB
|
||||
model.SkuStatusNormal,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if storeID > 0 {
|
||||
sql += ` AND t1.store_id = ?`
|
||||
sqlParams = append(sqlParams, storeID)
|
||||
}
|
||||
err = GetRows(db, &storeSkuBindList, sql, sqlParams...)
|
||||
return storeSkuBindList, err
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ type StoreSkuBind struct {
|
||||
|
||||
AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
|
||||
|
||||
StatusSaleBegin int `json:"statusSaleBegin"` //商品可售时间范围
|
||||
StatusSaleEnd int `json:"statusSaleEnd"`
|
||||
StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围
|
||||
StatusSaleEnd int16 `json:"statusSaleEnd"`
|
||||
}
|
||||
|
||||
func (*StoreSkuBind) TableUnique() [][]string {
|
||||
|
||||
Reference in New Issue
Block a user