fix: 收银台金额和二维码修复-提取payment_url用于二维码和支付链接
This commit is contained in:
@@ -141,10 +141,23 @@ func (h *PaymentHandler) CreatePayment(c *gin.Context) {
|
|||||||
|
|
||||||
tradeID, _ := data["trade_id"].(string)
|
tradeID, _ := data["trade_id"].(string)
|
||||||
token, _ := data["token"].(string)
|
token, _ := data["token"].(string)
|
||||||
|
paymentURL, _ := data["payment_url"].(string)
|
||||||
|
|
||||||
|
var amount float64
|
||||||
|
if v, ok := data["amount"].(float64); ok {
|
||||||
|
amount = v
|
||||||
|
} else if v, ok := data["amount"].(string); ok {
|
||||||
|
amount, _ = strconv.ParseFloat(v, 64)
|
||||||
|
}
|
||||||
|
|
||||||
var actualAmount float64
|
var actualAmount float64
|
||||||
if v, ok := data["actual_amount"].(float64); ok {
|
if v, ok := data["actual_amount"].(float64); ok {
|
||||||
actualAmount = v
|
actualAmount = v
|
||||||
|
} else if v, ok := data["actual_amount"].(string); ok {
|
||||||
|
actualAmount, _ = strconv.ParseFloat(v, 64)
|
||||||
|
}
|
||||||
|
if actualAmount == 0 {
|
||||||
|
actualAmount = amount
|
||||||
}
|
}
|
||||||
|
|
||||||
var expiration int64
|
var expiration int64
|
||||||
@@ -170,9 +183,10 @@ func (h *PaymentHandler) CreatePayment(c *gin.Context) {
|
|||||||
paymentInfo := map[string]interface{}{
|
paymentInfo := map[string]interface{}{
|
||||||
"trade_id": tradeID,
|
"trade_id": tradeID,
|
||||||
"order_id": order.ID,
|
"order_id": order.ID,
|
||||||
"amount": data["amount"],
|
"amount": amount,
|
||||||
"actual_amount": actualAmount,
|
"actual_amount": actualAmount,
|
||||||
"token": token,
|
"token": token,
|
||||||
|
"payment_url": paymentURL,
|
||||||
"expiration_time": remainingSeconds,
|
"expiration_time": remainingSeconds,
|
||||||
"trade_type": tradeType,
|
"trade_type": tradeType,
|
||||||
"channel_id": channel.ID,
|
"channel_id": channel.ID,
|
||||||
|
|||||||
@@ -21,28 +21,30 @@
|
|||||||
|
|
||||||
<div class="amount-section">
|
<div class="amount-section">
|
||||||
<div class="amount-label">支付金额</div>
|
<div class="amount-label">支付金额</div>
|
||||||
<div class="amount-value">{{ paymentInfo.actual_amount }} <small>USDT</small></div>
|
<div class="amount-value">{{ paymentInfo.actual_amount || paymentInfo.amount }} <small>USDT</small></div>
|
||||||
<div class="amount-cny">≈ ¥{{ paymentInfo.amount }}</div>
|
<div class="amount-cny">订单金额:¥{{ orderAmount }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="address-section">
|
<div class="address-section" v-if="paymentInfo.payment_url">
|
||||||
<div class="address-label">收款地址</div>
|
<div class="address-label">支付链接</div>
|
||||||
<div class="address-box">
|
<div class="address-box">
|
||||||
<span class="address-text">{{ paymentInfo.token }}</span>
|
<span class="address-text">{{ paymentInfo.payment_url }}</span>
|
||||||
<el-button type="primary" size="small" @click="copyAddress">复制</el-button>
|
<el-button type="primary" size="small" @click="copyText(paymentInfo.payment_url)">复制</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
<el-button type="success" size="small" class="open-link-btn" @click="openPaymentUrl">打开支付页面</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="qr-section">
|
<div class="qr-section" v-if="paymentInfo.payment_url">
|
||||||
<div class="qr-label">扫码支付</div>
|
<div class="qr-label">扫码支付</div>
|
||||||
<div class="qr-wrapper">
|
<div class="qr-wrapper">
|
||||||
<canvas ref="qrCanvas"></canvas>
|
<canvas ref="qrCanvas"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="qr-tip">请使用手机浏览器扫码打开支付页面</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tips">
|
<div class="tips">
|
||||||
<p>1. 请使用 {{ paymentInfo.trade_type?.toUpperCase() }} 网络转账</p>
|
<p>1. 请使用 {{ paymentInfo.trade_type?.toUpperCase() }} 网络转账</p>
|
||||||
<p>2. 请准确转账 <strong>{{ paymentInfo.actual_amount }} USDT</strong></p>
|
<p>2. 请准确转账 <strong>{{ paymentInfo.actual_amount || paymentInfo.amount }} USDT</strong></p>
|
||||||
<p>3. 转账后系统会自动确认,无需手动操作</p>
|
<p>3. 转账后系统会自动确认,无需手动操作</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -84,6 +86,7 @@ const paymentInfo = ref<any>(null)
|
|||||||
const paymentError = ref('')
|
const paymentError = ref('')
|
||||||
const remaining = ref(0)
|
const remaining = ref(0)
|
||||||
const totalTime = ref(0)
|
const totalTime = ref(0)
|
||||||
|
const orderAmount = ref(0)
|
||||||
let pollTimer: any = null
|
let pollTimer: any = null
|
||||||
let countdownTimer: any = null
|
let countdownTimer: any = null
|
||||||
|
|
||||||
@@ -95,11 +98,16 @@ async function createPayment() {
|
|||||||
totalTime.value = res.data.expiration_time || 600
|
totalTime.value = res.data.expiration_time || 600
|
||||||
remaining.value = totalTime.value
|
remaining.value = totalTime.value
|
||||||
|
|
||||||
await QRCode.toCanvas(qrCanvas.value, res.data.token, {
|
const orderRes: any = await orderApi.getById(orderId)
|
||||||
|
orderAmount.value = orderRes.data?.total_amount || 0
|
||||||
|
|
||||||
|
if (qrCanvas.value && res.data.payment_url) {
|
||||||
|
await QRCode.toCanvas(qrCanvas.value, res.data.payment_url, {
|
||||||
width: 180,
|
width: 180,
|
||||||
margin: 2,
|
margin: 2,
|
||||||
color: { dark: '#000', light: '#fff' }
|
color: { dark: '#000', light: '#fff' }
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
startCountdown()
|
startCountdown()
|
||||||
startPolling()
|
startPolling()
|
||||||
@@ -133,10 +141,14 @@ function startPolling() {
|
|||||||
}, 5000)
|
}, 5000)
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyAddress() {
|
function copyText(text: string) {
|
||||||
if (paymentInfo.value?.token) {
|
navigator.clipboard.writeText(text)
|
||||||
navigator.clipboard.writeText(paymentInfo.value.token)
|
ElMessage.success('已复制')
|
||||||
ElMessage.success('地址已复制')
|
}
|
||||||
|
|
||||||
|
function openPaymentUrl() {
|
||||||
|
if (paymentInfo.value?.payment_url) {
|
||||||
|
window.open(paymentInfo.value.payment_url, '_blank')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,6 +299,17 @@ onUnmounted(() => {
|
|||||||
padding: 12px;
|
padding: 12px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.qr-tip {
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgba(255, 255, 255, 0.4);
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.open-link-btn {
|
||||||
|
margin-top: 8px;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tips {
|
.tips {
|
||||||
|
|||||||
Reference in New Issue
Block a user