修改了返回值,增加了即将过期的检测

This commit is contained in:
wucongxing8150 2024-05-31 17:57:11 +08:00
parent f0f79d6435
commit d6e28d292e

View File

@ -32,7 +32,7 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
if user == nil {
g = &dtoV1.ReceiveCouponDto{
Status: 2,
Message: "用户未注册",
Message: "未注册互联网医院患者端",
Data: nil,
}
return g, nil
@ -44,7 +44,7 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
if userPatient == nil {
g = &dtoV1.ReceiveCouponDto{
Status: 2,
Message: "用户未注册",
Message: "未注册互联网医院患者端",
Data: nil,
}
return g, err
@ -123,6 +123,35 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
}
return g, nil
}
// 即将过期检测
now = now.Add(time.Minute * 10)
// 1:绝对时效
validStartTime = time.Time(coupon.ValidStartTime)
if now.Before(validStartTime) {
g = &dtoV1.ReceiveCouponDto{
Status: 0,
Message: "优惠卷还未启用",
Data: nil,
}
return g, nil
}
validEndTime = time.Time(coupon.ValidEndTime)
if now.After(validEndTime) {
g = &dtoV1.ReceiveCouponDto{
Status: 0,
Message: "优惠卷即将过期",
Data: nil,
}
return g, nil
}
}
// 检测优惠卷过期时间
now = now.Add(time.Minute * 10)
if coupon.ValidType == 1 {
}
// 检测用户是否已领取该优惠卷
@ -131,8 +160,9 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
maps = make(map[string]interface{})
maps["user_id"] = user.UserId
maps["coupon_id"] = coupon.CouponId
userCoupon, _ := userCouponDao.GetUserCoupon(maps)
if userCoupon != nil {
maps["user_coupon_status"] = 0
userCoupons, _ := userCouponDao.GetUserCouponList(maps)
if len(userCoupons) > 0 {
g = &dtoV1.ReceiveCouponDto{
Status: 0,
Message: "重复领取",
@ -168,7 +198,7 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
UserCouponModel.ValidEndTime = now.AddDate(0, 0, coupon.ValidDays)
}
userCoupon, _ = userCouponDao.AddUserCoupon(tx, UserCouponModel)
userCoupon, _ := userCouponDao.AddUserCoupon(tx, UserCouponModel)
if userCoupon == nil {
tx.Rollback()
return nil, errors.New("发放失败")