修改订单金额精度问题

This commit is contained in:
wucongxing8150 2024-09-05 15:38:46 +08:00
parent 7e9afc1010
commit dadebbb87d
2 changed files with 22 additions and 2 deletions

View File

@ -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
}

View File

@ -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("价格异常")
}