- 启用门店商品临时不可售,暂时不建AutoSaleAt相关的索引

This commit is contained in:
gazebo
2019-08-01 10:37:23 +08:00
parent 84c0b93ec4
commit a7b9a49982
3 changed files with 54 additions and 38 deletions

View File

@@ -1318,10 +1318,10 @@ func updateStoreSkusSaleWithoutSync(ctx *jxcontext.Context, storeID int, skuBind
model.FieldElmSyncStatus: skuBind.ElmSyncStatus | model.SyncFlagSaleMask,
model.FieldWscSyncStatus: skuBind.WscSyncStatus | model.SyncFlagSaleMask,
}
// if utils.IsTimeZero(autoSaleTime) || skuBind.Status == model.SkuStatusNormal {
// autoSaleTime = utils.DefaultTimeValue
// }
// kvs["AutoSaleAt"] = autoSaleTime
if utils.IsTimeZero(autoSaleTime) || skuBind.Status == model.SkuStatusNormal {
autoSaleTime = utils.DefaultTimeValue
}
kvs["AutoSaleAt"] = autoSaleTime
if num, err = dao.UpdateEntityLogically(db, skuBind, kvs, userName, nil); err != nil {
dao.Rollback(db)
return nil, err
@@ -2178,35 +2178,35 @@ func GetMissingStoreSkuFromOrder(ctx *jxcontext.Context, fromTime time.Time) (mi
}
func AutoSaleStoreSku(ctx *jxcontext.Context, storeIDs []int) (err error) {
// db := dao.GetDB()
// storeSkuList, err := dao.GetAutoSaleStoreSku(db, storeIDs)
// if err != nil {
// return err
// }
// storeSkuMap := make(map[int][]*model.StoreSkuBind)
// for _, v := range storeSkuList {
// storeSkuMap[v.StoreID] = append(storeSkuMap[v.StoreID], v)
// }
// now := time.Now()
// for storeID, storeSkuList := range storeSkuMap {
// var skuIDs []int
// for _, storeSku := range storeSkuList {
// if now.Sub(storeSku.AutoSaleAt) > 0 {
// storeSku.AutoSaleAt = utils.DefaultTimeValue
// if storeSku.Status != model.SkuStatusNormal {
// storeSku.Status = model.SkuStatusNormal
// skuIDs = append(skuIDs, storeSku.SkuID)
// }
// if _, err = dao.UpdateEntity(db, storeSku, "AutoSaleAt", model.FieldStatus); err != nil {
// return err
// }
// }
// }
// if len(skuIDs) > 0 {
// if _, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, []int{storeID}, skuIDs, false, true, true); err != nil {
// return err
// }
// }
// }
db := dao.GetDB()
storeSkuList, err := dao.GetAutoSaleStoreSku(db, storeIDs)
if err != nil {
return err
}
storeSkuMap := make(map[int][]*model.StoreSkuBind)
for _, v := range storeSkuList {
storeSkuMap[v.StoreID] = append(storeSkuMap[v.StoreID], v)
}
now := time.Now()
for storeID, storeSkuList := range storeSkuMap {
var skuIDs []int
for _, storeSku := range storeSkuList {
if now.Sub(storeSku.AutoSaleAt) > 0 {
storeSku.AutoSaleAt = utils.DefaultTimeValue
if storeSku.Status != model.SkuStatusNormal {
storeSku.Status = model.SkuStatusNormal
skuIDs = append(skuIDs, storeSku.SkuID)
}
if _, err = dao.UpdateEntity(db, storeSku, "AutoSaleAt", model.FieldStatus); err != nil {
return err
}
}
}
if len(skuIDs) > 0 {
if _, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, []int{storeID}, skuIDs, false, true, true); err != nil {
return err
}
}
}
return err
}

View File

@@ -47,7 +47,20 @@ var (
autoEnableStoreSkuTimeList = []string{
"7:00:00",
"8:00:00",
"9:00:00",
"10:00:00",
"11:00:00",
"12:00:00",
"13:00:00",
"14:00:00",
"15:00:00",
"16:00:00",
"17:00:00",
"18:00:00",
"19:00:00",
"20:00:00",
"21:00:00",
"22:00:00",
}
)
@@ -77,9 +90,9 @@ func Init() {
dao.UpdateActStatusByTime(dao.GetDB(), time.Now().Add(-48*time.Hour))
}, updateActStatusTimeList)
// ScheduleTimerFunc(func() {
// cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil)
// }, autoEnableStoreSkuTimeList)
ScheduleTimerFunc(func() {
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil)
}, autoEnableStoreSkuTimeList)
}
}

View File

@@ -1,5 +1,7 @@
package model
import "time"
const (
StoreSkuBindStatusNA = -2
StoreSkuBindStatusDeleted = -1
@@ -104,7 +106,7 @@ type StoreSkuBind struct {
MtwmSyncStatus int8 `orm:"default(2)"`
WscSyncStatus int8 `orm:"default(2)"`
// AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
}
func (*StoreSkuBind) TableUnique() [][]string {
@@ -116,6 +118,7 @@ func (*StoreSkuBind) TableUnique() [][]string {
func (*StoreSkuBind) TableIndex() [][]string {
return [][]string{
[]string{"SkuID", "StoreID", "DeletedAt"},
// []string{"AutoSaleAt", "DeletedAt", "StoreID"},
}
}