From 4d013ad28b42acb1d15fc162cd32f8315e03473d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 15 Nov 2019 11:58:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=88=B7=E6=96=B0=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=8F=AF=E5=94=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store.go | 3 +++ business/jxstore/cms/store_sku.go | 17 +++++++++++++---- business/jxstore/cms/sync.go | 6 +++--- business/jxstore/cms/sync_store_sku.go | 18 +++++++++--------- business/jxstore/misc/misc.go | 2 +- business/jxutils/jxutils.go | 4 ++-- business/model/dao/store_sku.go | 10 +++++++--- business/model/store_sku.go | 4 ++-- 8 files changed, 40 insertions(+), 24 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 5f2160e21..fa19987ba 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -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)) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 30257ce9c..6bdf996ad 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -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 } diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index a333fcb43..5e54a5a35 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -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 } diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index 90c041aad..b3c85f20c 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -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) diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 82d5bf82d..504976fe4 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -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) } } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index d43e503d0..386c2e465 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -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()) } // 得到饿百订单的取货码 diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index b20942a45..9d3496866 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -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 } diff --git a/business/model/store_sku.go b/business/model/store_sku.go index c7d54ed89..382a97b61 100644 --- a/business/model/store_sku.go +++ b/business/model/store_sku.go @@ -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 {