新增微信支付

This commit is contained in:
2026-04-13 17:25:33 +08:00
parent dca43a2d0d
commit d060e1b797
8 changed files with 165 additions and 29 deletions
@@ -1695,11 +1695,24 @@ async function generateWechatBindCode() {
<span style="font-size:11px; font-weight:normal; color:#94a3b8;">/ ${v.duration_days}</span>
</div>
${showUpgradeInfo ? `<div style="font-size:10px; color:#4f46e5; font-weight:bold; margin-bottom:8px;">已省 ¥${(v.price - v.upgrade_price).toFixed(2)}</div>` : ''}
<button onclick="buyVip(${v.id})" ${isDisabled ? 'disabled' : ''}
style="width:100%; border:none; border-radius:8px; padding:10px; font-size:13px; font-weight:bold; cursor:pointer; transition:all .2s;
background:${btnColor}; color:${btnTextColor}; ${isDisabled ? 'cursor:not-allowed;' : ''}">
${!d.vipPaymentEnabled && !isLower ? '支付暂未开启' : btnText}
</button>
${!d.vipPaymentEnabled || isDisabled
? `<button ${isDisabled ? 'disabled' : 'disabled'}
style="width:100%; border:none; border-radius:8px; padding:10px; font-size:13px; font-weight:bold; cursor:not-allowed; transition:all .2s;
background:${btnColor}; color:${btnTextColor};">
${!d.vipPaymentEnabled && !isLower ? '支付暂未开启' : btnText}
</button>`
: `<div style="display:grid; grid-template-columns:1fr 1fr; gap:8px;">
<button onclick="buyVip(${v.id}, 'alipay')"
style="border:none; border-radius:8px; padding:10px; font-size:13px; font-weight:bold; cursor:pointer; transition:all .2s; background:${btnColor}; color:${btnTextColor};">
支付宝
</button>
<button onclick="buyVip(${v.id}, 'wechat')"
style="border:none; border-radius:8px; padding:10px; font-size:13px; font-weight:bold; cursor:pointer; transition:all .2s; background:#16a34a; color:#fff;">
微信
</button>
</div>
<div style="font-size:10px; color:#64748b; margin-top:8px; text-align:center;">${btnText}后将跳转到对应支付页面</div>`
}
</div>
</div>
`;
@@ -1798,7 +1811,7 @@ async function generateWechatBindCode() {
}
}
window.buyVip = function(levelId) {
window.buyVip = function(levelId, provider = 'alipay') {
// 这里我们模拟提交表单,因为支付逻辑通常需要页面跳转
// 修改为在新窗口打开支付,避免聊天室页面丢失
const form = document.createElement('form');
@@ -1818,6 +1831,12 @@ async function generateWechatBindCode() {
idInput.value = levelId;
form.appendChild(idInput);
const providerInput = document.createElement('input');
providerInput.type = 'hidden';
providerInput.name = 'provider';
providerInput.value = provider;
form.appendChild(providerInput);
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
@@ -1825,7 +1844,8 @@ async function generateWechatBindCode() {
// 提交后关闭弹窗并提示用户
closeVipModal();
if (window.chatDialog) {
window.chatDialog.alert('正在为您前往支付中心,请在新页面完成支付。', '支付提示', '#3b82f6');
const providerText = provider === 'wechat' ? '微信支付二维码页' : '支付宝支付页';
window.chatDialog.alert(`正在为您打开${providerText},请在新页面完成支付。`, '支付提示', '#3b82f6');
}
};
+9 -3
View File
@@ -406,12 +406,18 @@
@if ($vip->price > 0 && $vipPaymentEnabled)
<form action="{{ route('vip.payment.store') }}" method="POST"
onsubmit="return confirm('确认支付 {{ $vip->price }} 元购买【{{ $vip->name }}】吗?');">
class="inline-flex items-center gap-2">
@csrf
<input type="hidden" name="vip_level_id" value="{{ $vip->id }}">
<button type="submit"
<button type="submit" name="provider" value="alipay"
onclick="return confirm('确认使用支付宝支付 {{ $vip->price }} 元购买【{{ $vip->name }}】吗?');"
class="px-3 py-1.5 rounded-lg bg-indigo-600 text-white text-xs font-bold hover:bg-indigo-700 transition">
{{ $isCurrentVipLevel ? '立即续费' : '立即购买' }}
支付宝
</button>
<button type="submit" name="provider" value="wechat"
onclick="return confirm('确认使用微信支付 {{ $vip->price }} 元购买【{{ $vip->name }}】吗?');"
class="px-3 py-1.5 rounded-lg bg-emerald-600 text-white text-xs font-bold hover:bg-emerald-700 transition">
微信
</button>
</form>
@elseif ($vip->price > 0)
+21 -6
View File
@@ -165,14 +165,29 @@
</div>
@if ($vipPaymentEnabled)
<form action="{{ route('vip.payment.store') }}" method="POST" class="mt-6" target="_blank">
<form action="{{ route('vip.payment.store') }}" method="POST" class="mt-6 space-y-3" target="_blank">
@csrf
<input type="hidden" name="vip_level_id" value="{{ $vip->id }}">
<button type="submit"
@if($isDisabled) disabled @endif
class="w-full py-3.5 rounded-2xl {{ $btnColor }} font-bold text-sm transition-all duration-200 active:scale-[0.98] shadow-sm">
{{ $btnText }}
</button>
@if ($isDisabled)
<button type="button" disabled
class="w-full py-3.5 rounded-2xl {{ $btnColor }} font-bold text-sm transition-all duration-200 shadow-sm">
{{ $btnText }}
</button>
@else
<div class="grid grid-cols-2 gap-3">
<button type="submit" name="provider" value="alipay"
class="py-3.5 rounded-2xl {{ $btnColor }} font-bold text-sm transition-all duration-200 active:scale-[0.98] shadow-sm">
支付宝支付
</button>
<button type="submit" name="provider" value="wechat"
class="py-3.5 rounded-2xl border border-emerald-200 bg-emerald-50 text-emerald-700 font-bold text-sm transition-all duration-200 active:scale-[0.98] shadow-sm hover:bg-emerald-100">
微信支付
</button>
</div>
<p class="text-[11px] text-gray-400">
{{ $btnText }}后,支付宝会打开支付页,微信会跳转到平台二维码页。
</p>
@endif
</form>
@endif
</div>