diff --git a/api/controller/OrderSingle.go b/api/controller/OrderSingle.go index 02efc13..e06741c 100644 --- a/api/controller/OrderSingle.go +++ b/api/controller/OrderSingle.go @@ -97,7 +97,7 @@ func (b *OrderSingle) AddOrderSingle(c *gin.Context) { userCouponId = &id } - if req.OrderPrice < 0 { + if *req.OrderPrice < 0 { responses.FailWithMessage("价格错误", c) return } diff --git a/api/requests/OrderSingle.go b/api/requests/OrderSingle.go index 585c4be..27deb0d 100644 --- a/api/requests/OrderSingle.go +++ b/api/requests/OrderSingle.go @@ -24,10 +24,10 @@ type GetOrderSinglePage struct { // AddOrderSingle 创建单项订单 type AddOrderSingle struct { - QuestionId string `json:"question_id" form:"question_id" label:"问题" validate:"required"` - UserCouponId string `json:"user_coupon_id" form:"user_coupon_id" label:"优惠卷"` - PayChannel int `json:"pay_channel" form:"pay_channel" label:"支付渠道" validate:"required,oneof=1 2 3"` // 支付渠道(1:h5支付 2:app支付 3:会员支付) - OrderPrice float64 `json:"order_price" form:"order_price" label:"订单金额" validate:"required"` // 订单金额 + QuestionId string `json:"question_id" form:"question_id" label:"问题" validate:"required"` + UserCouponId string `json:"user_coupon_id" form:"user_coupon_id" label:"优惠卷"` + PayChannel int `json:"pay_channel" form:"pay_channel" label:"支付渠道" validate:"required,oneof=1 2 3"` // 支付渠道(1:h5支付 2:app支付 3:会员支付) + OrderPrice *float64 `json:"order_price" form:"order_price" label:"订单金额"` // 订单金额 } // GetOrderSinglePay 获取单项订单支付数据 diff --git a/api/service/OrderSingle.go b/api/service/OrderSingle.go index a6f955c..42d68d7 100644 --- a/api/service/OrderSingle.go +++ b/api/service/OrderSingle.go @@ -22,7 +22,7 @@ type OrderSingleService struct { // AddOrderSingle 创建单项订单 // payChannel:支付渠道(1:h5支付 2:app支付 3:会员支付) -func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int64, UserCouponId *int64, payChannel int, orderPrice float64) (orderSingle *model.OrderSingle, err error) { +func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int64, UserCouponId *int64, payChannel int, orderPrice *float64) (orderSingle *model.OrderSingle, err error) { // 检测并发请求 redisKey := "AddOrderSingle" + fmt.Sprintf("%d", UserId) + fmt.Sprintf("%d", QuestionId) res, _ := global.Redis.Get(context.Background(), redisKey).Result() @@ -112,9 +112,13 @@ func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int6 escrowTradeNo = "GD" + global.Snowflake.Generate().String() // 第三方支付流水号 } else { + if orderPrice == nil { + return nil, errors.New("价格异常") + } + // 实际付款金额 paymentAmountTotal = amountTotal - couponAmountTotal - if orderPrice != paymentAmountTotal { + if *orderPrice != paymentAmountTotal { return nil, errors.New("价格异常") }