启用微信支付逻辑;调整支付金额处理方式以支持调试模式
This commit is contained in:
@@ -31,6 +31,14 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
var tType = data.Type
|
||||
var method = data.Method
|
||||
var amount = data.Amount
|
||||
|
||||
// 实际支付金额,只在创建真实订单时使用
|
||||
var amountReal = data.Amount
|
||||
if env.RunMode == "debug" {
|
||||
amountReal = 0.01
|
||||
}
|
||||
|
||||
// 附加优惠券
|
||||
if data.CouponCode != "" {
|
||||
coupon, err := q.Coupon.WithContext(ctx).
|
||||
Where(
|
||||
@@ -101,7 +109,7 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
ProductCode: "FAST_INSTANT_TRADE_PAY",
|
||||
OutTradeNo: tradeNo,
|
||||
Subject: subject,
|
||||
TotalAmount: strconv.FormatFloat(amount, 'f', 2, 64),
|
||||
TotalAmount: strconv.FormatFloat(amountReal, 'f', 2, 64),
|
||||
TimeExpire: expire.Format("2006-01-02 15:04:05"),
|
||||
},
|
||||
})
|
||||
@@ -120,7 +128,7 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
TimeExpire: &expire,
|
||||
NotifyUrl: &env.WechatPayCallbackUrl,
|
||||
Amount: &native.Amount{
|
||||
Total: u.P(int64(amount * 100)),
|
||||
Total: u.P(int64(amountReal * 100)),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -152,7 +160,6 @@ func (s *transactionService) PrepareTransaction(ctx context.Context, q *q.Query,
|
||||
Method: int32(method),
|
||||
Type: int32(tradeType),
|
||||
Amount: amount,
|
||||
Status: 0, // 0-待支付
|
||||
PayURL: payUrl,
|
||||
}
|
||||
err = q.Trade.Create(&trade)
|
||||
|
||||
Reference in New Issue
Block a user