From 3a0ebf9a366ca0b616fb16d27f311eff0e7025d1 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Tue, 11 Jun 2024 15:53:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E6=94=BE=E4=BC=98=E6=83=A0=E5=8D=B7?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=BF=87=E6=9C=9F=E9=98=9F=E5=88=97?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/service/coupon.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/api/service/coupon.go b/api/service/coupon.go index 2f4cbc6..8436a78 100644 --- a/api/service/coupon.go +++ b/api/service/coupon.go @@ -187,7 +187,14 @@ func (r *CouponService) AddSystemCoupon(req requests.AddSystemCoupon) (bool, err // 时间区间 if req.ValidStartTime != nil { - t, err := time.Parse("2006-01-02 15:04:05", *req.ValidStartTime) + // 获取本地时区 + location, err := time.LoadLocation("Local") + if err != nil { + tx.Rollback() + return false, errors.New("新增失败") + } + + t, err := time.ParseInLocation("2006-01-02 15:04:05", *req.ValidStartTime, location) if err != nil { tx.Rollback() return false, errors.New("新增失败") @@ -199,7 +206,15 @@ func (r *CouponService) AddSystemCoupon(req requests.AddSystemCoupon) (bool, err } if req.ValidEndTime != nil { - t, err := time.Parse("2006-01-02 15:04:05", *req.ValidEndTime) + // 获取本地时区 + location, err := time.LoadLocation("Local") + if err != nil { + tx.Rollback() + return false, errors.New("新增失败") + } + + t, err := time.ParseInLocation("2006-01-02 15:04:05", *req.ValidEndTime, location) + fmt.Println(t) if err != nil { tx.Rollback() return false, errors.New("新增失败") @@ -272,7 +287,7 @@ func (r *CouponService) AddSystemCoupon(req requests.AddSystemCoupon) (bool, err // 增加优惠卷过期队列 if coupon.ValidType == 1 { - validEndTime := time.Time(*coupon.ValidStartTime) + validEndTime := time.Time(*coupon.ValidEndTime) // 计算当天的结束时间 now := time.Now() @@ -293,7 +308,7 @@ func (r *CouponService) AddSystemCoupon(req requests.AddSystemCoupon) (bool, err data := make(map[string]interface{}) data["coupon_id"] = fmt.Sprintf("%d", coupon.CouponId) - delay := validEndTime.Sub(time.Now()) + delay := validEndTime.Sub(now) if delay < 10 { delay = 10 * time.Second