From e15e7ed9e2541d0a2182dfeb1e29b8b8d4c11bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 14 Nov 2019 11:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BF=AE=E6=94=B9=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/sync.go | 30 +++++++++++++++++++++++++++++ business/jxstore/misc/misc.go | 29 ++++++++++++++++++++++++++++ business/jxstore/yonghui/yonghui.go | 8 +++++++- business/model/dao/store_sku.go | 27 ++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 750931e3e..844e3ec09 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -3,6 +3,7 @@ package cms import ( "errors" "fmt" + "time" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -653,3 +654,32 @@ 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) { + var ( + storeIDs []int + skuIDs []int + vendorIDs = []int{0, 1, 3} + ) + 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) + } + } + v.SyncStoresSkus(ctx, db, vendorIDs, storeIDs, skuIDs, false, isAsync, isContinueWhenError) + if err != nil { + return err + } + return nil +} diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 807ba34a5..84c8c83a9 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -46,6 +46,32 @@ var ( "19:00:00", "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", + "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", + "23:00:00", + } openRemoteStoreTimeList = []string{ "23:30:00", } @@ -117,6 +143,9 @@ func Init() { }, []string{ "04:05:06", }) + ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() { + cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, false, false) + }, ChangeStoreSkuSaleStatusList) } } diff --git a/business/jxstore/yonghui/yonghui.go b/business/jxstore/yonghui/yonghui.go index 1d96e02c8..08722141e 100644 --- a/business/jxstore/yonghui/yonghui.go +++ b/business/jxstore/yonghui/yonghui.go @@ -203,10 +203,16 @@ func LoadExcelByYongHui(ctx *jxcontext.Context, files []*multipart.FileHeader, i } taskSeq := tasksch.NewSeqTask("读取永辉Excel文件修改微盟商品价格可售状态-序列任务", ctx, taskSeqFunc, 4) tasksch.HandleTask(taskSeq, nil, true).Run() + if !isAsync { + _, err = taskSeq.GetResult(0) + hint = "1" + } else { + hint = taskSeq.GetID() + } if errMsg != "" { baseapi.SugarLogger.Debugf(errMsg) } - return "", err + return hint, err } func PutAwayWeiMobSku(goodsIDListForPutAway []int64) { diff --git a/business/model/dao/store_sku.go b/business/model/dao/store_sku.go index 310e2ad7b..2bc996ed9 100644 --- a/business/model/dao/store_sku.go +++ b/business/model/dao/store_sku.go @@ -107,6 +107,14 @@ type StoreSkuNameInfo struct { UnitPrice int64 } +type StoreSkuBindWithSaleTime struct { + StoreSkuBind model.StoreSkuBind + TimeBegin1 int + TimeEnd1 int + TimeBegin2 int + TimeEnd2 int +} + // todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑 // 单门店模式厂商适用 // 从store_sku_bind中,得到所有依赖的商家分类信息 @@ -584,3 +592,22 @@ func (s *StoreSkuSyncInfo) GetSeq() int { } return int(s.VendorPrice) } + +func GetStoresSkusInfoBySaleTime(db *DaoDB) (storeSkuBindList []*StoreSkuBindWithSaleTime, err error) { + sql := ` + 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 + JOIN store t2 ON t1.store_id = t2.id + WHERE t1.status_sale_begin <> 0 AND t1.status_sale_end <> 0 + AND t1.status != ? + ` + sqlParams := []interface{}{ + model.SkuStatusDeleted, + } + err = GetRows(db, &storeSkuBindList, sql, sqlParams...) + return storeSkuBindList, err +}