diff --git a/api/service/OrderMember.go b/api/service/OrderMember.go index aeb3802..181f8d4 100644 --- a/api/service/OrderMember.go +++ b/api/service/OrderMember.go @@ -14,6 +14,7 @@ import ( "hepa-calc-api/extend/weChat" "hepa-calc-api/global" "hepa-calc-api/utils" + "math" "time" ) @@ -102,7 +103,11 @@ func (r *OrderMemberService) AddOrderMember(tx *gorm.DB, UserId, SystemMemberId userCouponService := &UserCouponService{} isCanUse, err := userCouponService.CheckUserCoupon(userCoupon, SystemMemberId, 2, amountTotal) - if err != nil || isCanUse == false { + if err != nil { + return nil, err + } + + if isCanUse == false { return nil, errors.New("价格异常") } @@ -112,6 +117,7 @@ func (r *OrderMemberService) AddOrderMember(tx *gorm.DB, UserId, SystemMemberId // 实际付款金额 paymentAmountTotal = amountTotal - couponAmountTotal // 实际付款金额 + paymentAmountTotal = math.Round(paymentAmountTotal*100) / 100 if paymentAmountTotal < 0 { paymentAmountTotal = 0 } diff --git a/api/service/OrderSingle.go b/api/service/OrderSingle.go index 22494cf..694ec7d 100644 --- a/api/service/OrderSingle.go +++ b/api/service/OrderSingle.go @@ -14,6 +14,7 @@ import ( "hepa-calc-api/extend/weChat" "hepa-calc-api/global" "hepa-calc-api/utils" + "math" "time" ) @@ -84,6 +85,13 @@ func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int6 // 检测用户优惠卷 var userCoupon *model.UserCoupon if UserCouponId != nil { + // 检测用户是否购买过单项产品 + userService := &UserService{} + isBuy := userService.CheckUserBuySingle(UserId) + if isBuy == false { + return nil, errors.New("不可使用优惠卷") + } + // 获取优惠卷数据 UserCouponDao := dao.UserCouponDao{} userCoupon, err = UserCouponDao.GetUserCouponPreloadById(*UserCouponId) @@ -94,7 +102,11 @@ func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int6 // 检测用户优惠卷 userCouponService := &UserCouponService{} isCanUse, err := userCouponService.CheckUserCoupon(userCoupon, QuestionId, 1, amountTotal) - if err != nil || isCanUse == false { + if err != nil { + return nil, err + } + + if isCanUse == false { return nil, errors.New("价格异常") } @@ -131,9 +143,11 @@ func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int6 // 实际付款金额 paymentAmountTotal = amountTotal - couponAmountTotal + paymentAmountTotal = math.Round(paymentAmountTotal*100) / 100 if paymentAmountTotal < 0 { paymentAmountTotal = 0 } + if *orderPrice != paymentAmountTotal { return nil, errors.New("价格异常") }