Compare commits
34 Commits
f5b70d1ce9
...
6c0b41639b
Author | SHA1 | Date |
---|---|---|
|
6c0b41639b | |
|
15f296806f | |
|
072c094878 | |
|
ac48291008 | |
|
8457574a8e | |
|
64d79d4f3e | |
|
eaed2d4a0b | |
|
e62a311c0e | |
|
26d1caa42c | |
|
70c35cd5d1 | |
|
f83b34d1ba | |
|
e85454f926 | |
|
5a47b55f67 | |
|
c30484e7f7 | |
|
1fe90a5ccf | |
|
401bcc93e1 | |
|
3d7431a8d8 | |
|
240fda37a8 | |
|
4d45e6a29b | |
|
f5061b558e | |
|
d39d581a80 | |
|
c65d00689f | |
|
6ebbd46ae4 | |
|
d20b0e99be | |
|
a97843a8f2 | |
|
394d68624d | |
|
707c1d20c1 | |
|
a527a44e20 | |
|
47c3a408a1 | |
|
85c585ee02 | |
|
8293761701 | |
|
0d77c47a60 | |
|
162fe878b5 | |
|
cdcfaaecd6 |
|
@ -108,3 +108,30 @@ func GetPayLink(c *gin.Context) {
|
||||||
"message": message,
|
"message": message,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 订单查询
|
||||||
|
func PayPageCheckOrder(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
code int
|
||||||
|
orderInfo ordersmodel.Orders
|
||||||
|
returnUrl string
|
||||||
|
)
|
||||||
|
orderId := strings.TrimSpace(c.Query("no"))
|
||||||
|
|
||||||
|
if orderId == "" || len(orderId) < 18 || len(orderId) > 20 {
|
||||||
|
controllers.ErrWithCode(c, errorcode.OrdersNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
orderInfo, returnUrl, code = thirdpay.PayPageCheckOrder(orderId)
|
||||||
|
if code == errorcode.OrderPayed {
|
||||||
|
code = errorcode.Success
|
||||||
|
}
|
||||||
|
|
||||||
|
rsp := front.PayPageCheckOrderResponse{
|
||||||
|
ReturnUrl: returnUrl,
|
||||||
|
Status: orderInfo.Status,
|
||||||
|
}
|
||||||
|
controllers.HandCodeRes(c, rsp, code)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -98,3 +98,8 @@ type GetPayLinkRequest struct {
|
||||||
OrderId string `json:"no" form:"no"`
|
OrderId string `json:"no" form:"no"`
|
||||||
ClientIp string
|
ClientIp string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PayPageCheckOrderResponse struct {
|
||||||
|
ReturnUrl string `json:"return_url"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
}
|
||||||
|
|
|
@ -99,6 +99,8 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
{
|
{
|
||||||
// 收银台地址
|
// 收银台地址
|
||||||
router.GET(common.PayPageAddress, front.PayPage)
|
router.GET(common.PayPageAddress, front.PayPage)
|
||||||
|
// 订单查询
|
||||||
|
router.GET(common.PayPageAddress+"/query", front.PayPageCheckOrder)
|
||||||
|
|
||||||
payPage := router.Group(common.PayPageAddress, middlewares.ValidateRequest())
|
payPage := router.Group(common.PayPageAddress, middlewares.ValidateRequest())
|
||||||
// 收银台 支付渠道列表
|
// 收银台 支付渠道列表
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: 200px;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-spinner {
|
.loading-spinner {
|
||||||
|
@ -124,7 +124,7 @@
|
||||||
{{if eq .code 200 }}
|
{{if eq .code 200 }}
|
||||||
<body>
|
<body>
|
||||||
<!-- 页面内容 -->
|
<!-- 页面内容 -->
|
||||||
<div class="payment-info" id="payment-info">
|
<div class="payment-info" id="payment-info" style="display: none;">
|
||||||
<h2>订单支付</h2>
|
<h2>订单支付</h2>
|
||||||
<p>{{.desc}}</p>
|
<p>{{.desc}}</p>
|
||||||
<p>交易号:{{ .id }}</p>
|
<p>交易号:{{ .id }}</p>
|
||||||
|
@ -132,14 +132,14 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 支付方式选择区域 -->
|
<!-- 支付方式选择区域 -->
|
||||||
<div id="pay-container">
|
<div id="pay-container" style="display: none;">
|
||||||
<div id="pay"></div>
|
<div id="pay"></div>
|
||||||
<!-- 支付方式列表 -->
|
<!-- 支付方式列表 -->
|
||||||
<ul id="payment-list"></ul>
|
<ul id="payment-list"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Loading状态 -->
|
<!-- Loading状态 -->
|
||||||
<div id="loading" class="loading-container" style="display: none;">
|
<div id="loading" class="loading-container" style="display: flex;">
|
||||||
<div class="loading-spinner"></div>
|
<div class="loading-spinner"></div>
|
||||||
<p class="loading-text">支付处理中,请稍等...</p>
|
<p class="loading-text">支付处理中,请稍等...</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -147,7 +147,7 @@
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 从 URL 中提取参数
|
// 从URL中提取参数
|
||||||
function getQueryParam(param) {
|
function getQueryParam(param) {
|
||||||
const queryString = window.location.search.substring(1);
|
const queryString = window.location.search.substring(1);
|
||||||
const params = queryString.split('&');
|
const params = queryString.split('&');
|
||||||
|
@ -160,30 +160,62 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示Loading状态
|
// 显示Loading效果
|
||||||
function showLoading() {
|
function showLoading() {
|
||||||
document.getElementById('payment-info').style.display = 'none';
|
document.getElementById('payment-info').style.display = 'none';
|
||||||
document.getElementById('pay-container').style.display = 'none';
|
document.getElementById('pay-container').style.display = 'none';
|
||||||
document.getElementById('loading').style.display = 'flex';
|
document.getElementById('loading').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭Loading效果
|
||||||
|
function closeLoading() {
|
||||||
|
document.getElementById('loading').style.display = 'none';
|
||||||
|
document.getElementById('payment-info').style.display = 'block';
|
||||||
|
document.getElementById('pay-container').style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理支付回调
|
// 处理支付回调
|
||||||
function handlePaymentCallback() {
|
function handlePaymentCallback() {
|
||||||
showLoading();
|
const id = getQueryParam('no');
|
||||||
const loadingText = document.querySelector('.loading-text');
|
if (!id) {
|
||||||
loadingText.textContent = `支付处理中,请稍等...`;
|
closeLoading();
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
// 1秒后刷新页面
|
// 查询订单状态
|
||||||
setTimeout(() => {
|
fetch(`/pay/front/api/v1/payPage/query?no=${id}`, {
|
||||||
clearInterval(dotInterval);
|
method: 'POST',
|
||||||
|
})
|
||||||
|
.then(async response => {
|
||||||
|
if (!response.ok) throw new Error('请求失败');
|
||||||
|
return await response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
closeLoading();
|
||||||
|
switch(data.status) {
|
||||||
|
case 2: // 处理中
|
||||||
|
handlePaymentCallback(); // 重查状态
|
||||||
|
break;
|
||||||
|
case 3: // 支付成功
|
||||||
|
if (data.return_url) {
|
||||||
|
window.location.href = data.return_url; // 自动跳转
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: // 其他状态(待支付/失败/关闭)
|
||||||
|
fetchPaymentMethods();
|
||||||
|
// window.location.reload();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
// closeLoading();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}, 1000);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取支付方式列表
|
// 获取支付方式列表
|
||||||
function fetchPaymentMethods() {
|
function fetchPaymentMethods() {
|
||||||
|
|
||||||
const id = getQueryParam('no');
|
const id = getQueryParam('no');
|
||||||
console.log('Order no:', id);
|
|
||||||
if (id) {
|
if (id) {
|
||||||
fetch(`/pay/front/api/v1/payPage/list?id=${id}`, {
|
fetch(`/pay/front/api/v1/payPage/list?id=${id}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -207,19 +239,28 @@
|
||||||
const pay = document.getElementById('pay');
|
const pay = document.getElementById('pay');
|
||||||
pay.innerHTML = '<h3>支付环境异常,请检查</h3>';
|
pay.innerHTML = '<h3>支付环境异常,请检查</h3>';
|
||||||
} else if (data.data.length === 1) {
|
} else if (data.data.length === 1) {
|
||||||
// 只有一个支付方式时,显示空白页并直接跳转
|
if(localStorage.getItem('auto-redirect') != 2){
|
||||||
showLoading();
|
// 否则设置自动跳转标记,并跳转
|
||||||
|
localStorage.setItem('auto-redirect', 2);
|
||||||
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`;
|
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`;
|
||||||
} else {
|
} else {
|
||||||
|
closeLoading();
|
||||||
|
renderPaymentMethods(data.data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
closeLoading();
|
||||||
|
// 多种支付方式,展示支付界面
|
||||||
renderPaymentMethods(data.data);
|
renderPaymentMethods(data.data);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
closeLoading();
|
||||||
console.error('获取支付方式失败:', error);
|
console.error('获取支付方式失败:', error);
|
||||||
const pay = document.getElementById('pay');
|
const pay = document.getElementById('pay');
|
||||||
pay.innerHTML = '<h3 style="color: red;">获取支付方式失败,请刷新重试</h3>';
|
pay.innerHTML = '<h3 style="color: red;">获取支付方式失败,请刷新重试</h3>';
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
closeLoading();
|
||||||
console.error('Order no not found in URL');
|
console.error('Order no not found in URL');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,7 +330,6 @@
|
||||||
const no = getQueryParam('no');
|
const no = getQueryParam('no');
|
||||||
const selectedMethod = document.querySelector('input[name="paymentMethod"]:checked');
|
const selectedMethod = document.querySelector('input[name="paymentMethod"]:checked');
|
||||||
if (selectedMethod) {
|
if (selectedMethod) {
|
||||||
showLoading();
|
|
||||||
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${selectedMethod.value}&no=${no}`;
|
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${selectedMethod.value}&no=${no}`;
|
||||||
} else {
|
} else {
|
||||||
alert('请选择支付方式');
|
alert('请选择支付方式');
|
||||||
|
@ -303,15 +343,23 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// 页面加载时执行
|
// 页面加载时执行
|
||||||
window.onload = function() {
|
// 监听页面可见性变化
|
||||||
if (getQueryParam('return')) {
|
document.addEventListener('visibilitychange', function() {
|
||||||
// 如果是支付回调,处理支付结果
|
if (!document.hidden && localStorage.getItem('auto-redirect') == 2) {
|
||||||
handlePaymentCallback();
|
// 页面从后台返回且处于支付状态
|
||||||
} else {
|
|
||||||
// 否则获取支付方式
|
|
||||||
fetchPaymentMethods();
|
fetchPaymentMethods();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
if (localStorage.getItem('auto-redirect') && localStorage.getItem('auto-redirect') == 2) {
|
||||||
|
handlePaymentCallback(); // 如果是支付回调且不是自动跳转,处理支付结果
|
||||||
|
} else {
|
||||||
|
localStorage.setItem('auto-redirect', 1); // 设置自动跳转标记
|
||||||
|
fetchPaymentMethods(); // 获取支付方式
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{ else}}
|
{{ else}}
|
||||||
|
@ -320,7 +368,7 @@
|
||||||
<div class="payment-info" style="text-align: center;">
|
<div class="payment-info" style="text-align: center;">
|
||||||
<h2 style="color: #ff0000;">支付异常</h2>
|
<h2 style="color: #ff0000;">支付异常</h2>
|
||||||
<p>{{.message}}</p>
|
<p>{{.message}}</p>
|
||||||
<button onclick="window.location.href='/'">返回首页</button>
|
<button onclick="window.location.href='/'">返回</button>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue