修改了返回值,增加了即将过期的检测
This commit is contained in:
parent
f0f79d6435
commit
d6e28d292e
@ -32,7 +32,7 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
|
|||||||
if user == nil {
|
if user == nil {
|
||||||
g = &dtoV1.ReceiveCouponDto{
|
g = &dtoV1.ReceiveCouponDto{
|
||||||
Status: 2,
|
Status: 2,
|
||||||
Message: "用户未注册",
|
Message: "未注册互联网医院患者端",
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}
|
}
|
||||||
return g, nil
|
return g, nil
|
||||||
@ -44,7 +44,7 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
|
|||||||
if userPatient == nil {
|
if userPatient == nil {
|
||||||
g = &dtoV1.ReceiveCouponDto{
|
g = &dtoV1.ReceiveCouponDto{
|
||||||
Status: 2,
|
Status: 2,
|
||||||
Message: "用户未注册",
|
Message: "未注册互联网医院患者端",
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}
|
}
|
||||||
return g, err
|
return g, err
|
||||||
@ -123,6 +123,35 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
|
|||||||
}
|
}
|
||||||
return g, nil
|
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 = make(map[string]interface{})
|
||||||
maps["user_id"] = user.UserId
|
maps["user_id"] = user.UserId
|
||||||
maps["coupon_id"] = coupon.CouponId
|
maps["coupon_id"] = coupon.CouponId
|
||||||
userCoupon, _ := userCouponDao.GetUserCoupon(maps)
|
maps["user_coupon_status"] = 0
|
||||||
if userCoupon != nil {
|
userCoupons, _ := userCouponDao.GetUserCouponList(maps)
|
||||||
|
if len(userCoupons) > 0 {
|
||||||
g = &dtoV1.ReceiveCouponDto{
|
g = &dtoV1.ReceiveCouponDto{
|
||||||
Status: 0,
|
Status: 0,
|
||||||
Message: "重复领取",
|
Message: "重复领取",
|
||||||
@ -168,7 +198,7 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
|
|||||||
UserCouponModel.ValidEndTime = now.AddDate(0, 0, coupon.ValidDays)
|
UserCouponModel.ValidEndTime = now.AddDate(0, 0, coupon.ValidDays)
|
||||||
}
|
}
|
||||||
|
|
||||||
userCoupon, _ = userCouponDao.AddUserCoupon(tx, UserCouponModel)
|
userCoupon, _ := userCouponDao.AddUserCoupon(tx, UserCouponModel)
|
||||||
if userCoupon == nil {
|
if userCoupon == nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return nil, errors.New("发放失败")
|
return nil, errors.New("发放失败")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user