38283-vm/payment.php
2026-02-08 08:34:40 +00:00

146 lines
7.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
include 'includes/header.php';
$order_no = $_GET['order_no'] ?? '';
$db = db();
$stmt = $db->prepare("SELECT * FROM orders WHERE order_no = ?");
$stmt->execute([$order_no]);
$order = $stmt->fetch();
if (!$order) {
echo "<div class='container my-5 py-5 text-center'><div class='alert glass-card text-danger border-danger p-5'><i class='bi bi-exclamation-octagon display-1 d-block mb-4'></i><h2>订单不存在</h2><p>请检查您的订单号是否正确或联系客服。</p><a href='index.php' class='btn btn-primary mt-4'>返回首页</a></div></div>";
include 'includes/footer.php';
exit;
}
// Fetch total quantity
$stmt = $db->prepare("SELECT SUM(quantity) as total_qty FROM order_items WHERE order_id = ?");
$stmt->execute([$order['id']]);
$qty_data = $stmt->fetch();
$total_qty = $qty_data['total_qty'] ?? 1;
$usdt_address = $settings['usdt_address'] ?? 'Txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
?>
<div class="row justify-content-center">
<div class="col-lg-10">
<div class="glass-card p-0 overflow-hidden bg-white shadow-lg border-0 rounded-4">
<div class="bg-primary bg-opacity-10 p-4 border-bottom d-flex justify-content-between align-items-center">
<h4 class="text-dark mb-0 fw-bold"><i class="bi bi-shield-lock-fill me-2 text-primary"></i>安全支付收银台</h4>
<div class="badge bg-primary px-4 py-2 rounded-pill fw-bold">USDT - TRC20</div>
</div>
<div class="p-4 p-lg-5">
<div class="row g-5">
<div class="col-lg-5 text-center">
<div class="p-4 rounded-4 d-inline-block border border-light bg-light mb-4">
<img src="https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=<?php echo urlencode($usdt_address); ?>" alt="QR Code" class="img-fluid" style="width: 250px;">
</div>
<div class="p-4 bg-light rounded-4 mb-4">
<label class="text-muted small d-block mb-2 fw-bold">支付倒计时</label>
<div id="countdown" class="display-4 fw-bold text-primary">60:00</div>
</div>
<p class="text-muted small"><i class="bi bi-info-circle me-1"></i> 请在倒计时结束前完成支付以保证订单有效</p>
</div>
<div class="col-lg-7">
<div class="mb-5 p-4 bg-light rounded-4">
<h5 class="text-dark fw-bold mb-4 border-bottom pb-3">订单信息</h5>
<div class="d-flex justify-content-between align-items-center mb-3">
<span class="text-muted">订单编号:</span>
<span class="text-dark fw-bold"><?php echo $order_no; ?></span>
</div>
<div class="d-flex justify-content-between align-items-center mb-3">
<span class="text-muted">商品数量:</span>
<span class="text-dark fw-bold"><?php echo $total_qty; ?> 件</span>
</div>
<div class="d-flex justify-content-between align-items-center pt-3 border-top mt-3">
<span class="text-dark fs-5 fw-bold">应付金额:</span>
<span class="display-5 fw-bold text-primary"><?php echo $order['total_amount']; ?> <small class="fs-4">USDT</small></span>
</div>
</div>
<div class="mb-5">
<h5 class="text-dark fw-bold mb-4">收款地址 (TRC20)</h5>
<div class="input-group input-group-lg">
<input type="text" id="usdtAddress" class="form-control bg-light border-0 text-dark p-4 font-monospace fs-6" value="<?php echo $usdt_address; ?>" readonly>
<button class="btn btn-primary px-4" onclick="copyAddress()">
<i class="bi bi-copy me-2"></i> 复制地址
</button>
</div>
</div>
<div class="p-4 rounded-4 border border-info border-opacity-10 bg-info bg-opacity-10 mb-5">
<h6 class="text-info fw-bold mb-3"><i class="bi bi-info-square-fill me-2"></i> 支付说明:</h6>
<ul class="text-muted small mb-0 ps-3 lh-lg">
<li>请务必使用 <strong class="text-primary">TRC20 (波场网络)</strong> 进行转账,暂不支持其他网络。</li>
<li>支付金额必须与订单金额 <strong class="text-primary">完全一致</strong> (<?php echo $order['total_amount']; ?> USDT),否则系统无法自动识别。</li>
<li>转账完成后,请点击下方的“已完成支付”按钮,联系客服确认发货。</li>
<li>区块确认通常需要 1-3 分钟,请耐心等待。</li>
<li>如需帮助,请提供订单号 <?php echo $order_no; ?> 给在线客服。</li>
</ul>
</div>
<div class="d-grid gap-3">
<button id="checkPaymentBtn" class="btn btn-primary btn-lg py-3 rounded-pill fw-bold shadow-lg">
<i class="bi bi-check-circle-fill me-2"></i> 我已完成支付,联系客服发货
</button>
<a href="index.php" class="btn btn-outline-secondary py-3 rounded-pill">
返回首页
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
function copyAddress() {
var copyText = document.getElementById("usdtAddress");
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
const btn = document.querySelector('button[onclick="copyAddress()"]');
const originalText = btn.innerHTML;
btn.innerHTML = '<i class="bi bi-check2"></i> 已复制';
btn.classList.replace('btn-primary', 'btn-success');
setTimeout(() => {
btn.innerHTML = originalText;
btn.classList.replace('btn-success', 'btn-primary');
}, 2000);
}
// Countdown Timer
let timeLeft = 60 * 60; // 60 minutes
const countdownEl = document.getElementById('countdown');
const timer = setInterval(() => {
const minutes = Math.floor(timeLeft / 60);
let seconds = timeLeft % 60;
seconds = seconds < 10 ? '0' + seconds : seconds;
countdownEl.innerHTML = `${minutes}:${seconds}`;
if (timeLeft <= 0) {
clearInterval(timer);
countdownEl.innerHTML = "EXPIRED";
}
timeLeft--;
}, 1000);
// TG redirect with order details
document.getElementById('checkPaymentBtn').addEventListener('click', function() {
const message = encodeURIComponent(`您好,我已支付订单。\n\n订单编号<?php echo $order_no; ?>\n商品数量<?php echo $total_qty; ?> 件\n实付金额<?php echo $order['total_amount']; ?> USDT\n\n请核实并处理。`);
const tgLink = `<?php echo $tg_link; ?>?text=${message}`;
// Redirect to Telegram
window.open(tgLink, '_blank');
});
// Clear cart after reaching payment page
localStorage.removeItem('cart');
if (typeof updateCartBadge === 'function') updateCartBadge();
</script>
<?php include 'includes/footer.php'; ?>