You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
17 KiB
Smarty

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{assign var=admin_active value='yipay'}
{assign var=admin_title value='易支付'}
{include file='admin/static_header.tpl'}
{literal}<style>
.yp-page{display:grid;gap:20px;min-width:0;max-width:100%;padding-bottom:28px}.yp-head{display:flex;align-items:flex-start;justify-content:space-between;gap:16px}.yp-head h1{margin:0 0 6px;font-size:28px}.yp-head p{margin:0;color:#64748b}.yp-stats{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:14px}.yp-stat,.yp-panel{min-width:0;border:1px solid #e2e8f0;background:#fff;border-radius:8px;box-shadow:0 8px 24px rgba(15,23,42,.05)}.yp-stat{padding:18px}.yp-stat span{display:block;color:#64748b;font-size:13px;margin-bottom:8px}.yp-stat strong{font-size:25px;color:#0f172a}.yp-panel{padding:22px}.yp-panel-head{display:flex;align-items:flex-start;justify-content:space-between;gap:14px;margin-bottom:18px}.yp-panel-head h2{margin:0 0 4px;font-size:20px}.yp-panel-head p{margin:0;color:#64748b}.yp-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}.yp-field{display:grid;gap:7px}.yp-field.is-wide{grid-column:1/-1}.yp-field label{font-weight:700;color:#334155}.yp-help{font-size:12px;color:#64748b}.yp-switch{display:flex;align-items:center;gap:10px}.yp-switch input{width:18px;height:18px}.yp-actions{display:flex;flex-wrap:wrap;align-items:center;gap:10px;margin-top:18px}.yp-notice{display:none;flex:1 1 280px;padding:10px 12px;border-radius:6px;font-size:13px}.yp-notice.is-show{display:block}.yp-notice.is-ok{background:#ecfdf5;color:#047857}.yp-notice.is-error{background:#fef2f2;color:#b91c1c}.yp-warning{padding:12px 14px;background:#fff7ed;color:#9a3412;border-radius:6px;margin-bottom:16px}.yp-filter{display:grid;grid-template-columns:minmax(220px,1fr) 160px 160px auto;gap:10px}.yp-table-wrap{width:100%;max-width:100%;overflow-x:auto;overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch}.yp-table{width:100%;min-width:920px;table-layout:fixed;border-collapse:collapse}.yp-table th,.yp-table td{padding:12px 10px;border-bottom:1px solid #e2e8f0;text-align:left;vertical-align:top}.yp-table th{font-size:12px;color:#64748b;text-transform:uppercase}.yp-table th:first-child,.yp-table td:first-child{width:230px}.yp-table th:nth-child(2),.yp-table td:nth-child(2){width:180px;overflow-wrap:anywhere}.yp-mono{font-family:SFMono-Regular,Consolas,monospace;font-size:12px}.yp-order-line{display:flex;align-items:center;gap:6px;min-width:0;max-width:210px}.yp-order-line+.yp-order-line{margin-top:5px}.yp-order-value{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.yp-copy{flex:0 0 28px;width:28px;height:28px;display:inline-grid;place-items:center;padding:0;border:1px solid #e2e8f0;border-radius:6px;background:#fff;color:#64748b}.yp-copy:hover{border-color:#94a3b8;color:#0f172a}.yp-pill{display:inline-flex;padding:4px 8px;border-radius:999px;background:#f1f5f9;color:#475569;font-size:12px;font-weight:700}.yp-pill.is-paid{background:#dcfce7;color:#15803d}.yp-pill.is-refunded{background:#e0f2fe;color:#0369a1}.yp-pill.is-pending{background:#fef3c7;color:#a16207}.yp-pill.is-failed{background:#fee2e2;color:#b91c1c}.yp-refund{white-space:nowrap}.yp-empty{padding:22px;text-align:center;color:#64748b}.yp-pagination{margin-top:16px}@media(max-width:1100px){.yp-stats{grid-template-columns:repeat(3,minmax(0,1fr))}}@media(max-width:900px){.yp-stats{grid-template-columns:repeat(2,minmax(0,1fr))}.yp-grid{grid-template-columns:1fr}.yp-filter{grid-template-columns:1fr}.yp-field.is-wide{grid-column:auto}.yp-head{display:block}}@media(max-width:520px){.yp-stats{grid-template-columns:1fr}.yp-panel{padding:16px}.yp-table th:first-child,.yp-table td:first-child{width:200px}.yp-order-line{max-width:180px}}
</style>{/literal}
<div class="yp-page">
<header class="yp-head">
<div><h1>易支付</h1><p>管理支付宝、微信支付连接与本地入账订单。</p></div>
<span class="badge {if $yipay_config.yipay_enabled}bg-success{else}bg-secondary{/if}">{if $yipay_config.yipay_enabled}已启用{else}未启用{/if}</span>
</header>
<section class="yp-stats">
<article class="yp-stat"><span>全部订单</span><strong>{$yipay_summary.total}</strong></article>
<article class="yp-stat"><span>等待支付</span><strong>{$yipay_summary.pending}</strong></article>
<article class="yp-stat"><span>成功订单</span><strong>{$yipay_summary.paid}</strong></article>
<article class="yp-stat"><span>已退款</span><strong>{$yipay_summary.refunded}</strong></article>
<article class="yp-stat"><span>当前净入账</span><strong>¥ {$yipay_summary.paid_amount}</strong></article>
</section>
<section class="yp-panel">
<div class="yp-panel-head">
<div><h2>商户配置</h2><p>默认关闭并开启测试模式,不会影响现有支付宝通道。</p></div>
<i class="mdi mdi-credit-card-outline fs-3 text-primary"></i>
</div>
<form id="ypConfigForm" method="post" action="/admin/yipay/config" data-can-manage="{if $admin_can_manage|default:false}1{else}0{/if}">
<div class="yp-grid">
<div class="yp-field is-wide">
<label class="yp-switch"><input type="checkbox" name="yipay_enabled" value="true" {if $yipay_config.yipay_enabled}checked{/if}>启用易支付</label>
<span class="yp-help">只有配置完整并启用后,用户充值页才会显示对应入口。</span>
</div>
<div class="yp-field is-wide">
<label class="yp-switch"><input type="checkbox" name="yipay_test_mode" value="true" {if $yipay_config.yipay_test_mode}checked{/if}>测试模式</label>
<span class="yp-help">开启后仅管理员能在用户充值页看到和调用易支付,普通用户直接请求接口也会被拒绝。</span>
</div>
<div class="yp-field">
<label class="yp-switch"><input type="checkbox" name="yipay_alipay_enabled" value="true" {if $yipay_config.yipay_alipay_enabled}checked{/if}>支付宝</label>
</div>
<div class="yp-field">
<label class="yp-switch"><input type="checkbox" name="yipay_wxpay_enabled" value="true" {if $yipay_config.yipay_wxpay_enabled}checked{/if}>微信支付</label>
</div>
<div class="yp-field is-wide">
<label for="ypGatewayUrl">易支付网关地址</label>
<input class="form-control" id="ypGatewayUrl" name="yipay_gateway_base_url" type="url" value="" autocomplete="off" placeholder="{if $yipay_config.yipay_gateway_base_url_configured}已配置,留空不修改{else}请输入 HTTPS 网关根地址{/if}">
<span class="yp-help">真实地址不会回显。填写新值时不要包含 <span class="yp-mono">/mapi.php</span>,系统会自动拼接接口路径。</span>
</div>
<div class="yp-field is-wide">
<label for="ypCallbackUrl">网站异步通知地址</label>
<input class="form-control" id="ypCallbackUrl" name="yipay_callback_base_url" type="url" value="" autocomplete="off" placeholder="{if $yipay_config.yipay_callback_base_url_configured}已配置,留空不修改{else}请输入固定 HTTPS 面板域名{/if}">
<span class="yp-help">真实地址不会回显。通知路径为 <span class="yp-mono">/yipay/callback</span>;用户支付完成后仍返回其实际访问域名。</span>
</div>
<div class="yp-field">
<label for="ypPid">商户 PID</label>
<input class="form-control yp-mono" id="ypPid" name="yipay_pid" type="text" inputmode="numeric" value="" autocomplete="off" placeholder="{if $yipay_config.yipay_pid_configured}已配置,留空不修改{else}请输入商户 PID{/if}">
<span class="yp-help">商户 PID 不会回显到浏览器。</span>
</div>
<div class="yp-field">
<label for="ypSecret">商户密钥</label>
<input class="form-control yp-mono" id="ypSecret" name="yipay_secret_key" type="password" value="" autocomplete="new-password" placeholder="{if $yipay_config.yipay_secret_configured}已配置,留空不修改{else}请输入商户 KEY{/if}">
<span class="yp-help">服务器必须先配置 <span class="yp-mono">YIPAY_CREDENTIAL_KEY</span>,商户密钥会加密写入数据库。</span>
</div>
<div class="yp-field is-wide">
<label for="ypOrderName">商品名称</label>
<input class="form-control" id="ypOrderName" name="yipay_order_name" type="text" maxlength="127" value="{$yipay_config.yipay_order_name|escape}">
</div>
<div class="yp-field">
<label for="ypMinimum">最低充值金额</label>
<input class="form-control" id="ypMinimum" name="yipay_min_amount" type="number" min="0.01" max="1000000" step="0.01" value="{$yipay_config.yipay_min_amount|escape}">
</div>
<div class="yp-field">
<label for="ypMaximum">最高充值金额</label>
<input class="form-control" id="ypMaximum" name="yipay_max_amount" type="number" min="0.01" max="1000000" step="0.01" value="{$yipay_config.yipay_max_amount|escape}">
</div>
<div class="yp-field">
<label for="ypTimeout">请求超时(秒)</label>
<input class="form-control" id="ypTimeout" name="yipay_request_timeout_seconds" type="number" min="3" max="60" value="{$yipay_config.yipay_request_timeout_seconds|escape}">
</div>
</div>
<div class="yp-actions">
<button class="btn btn-primary" id="ypSave" type="submit" {if !$admin_can_manage|default:false}disabled{/if}><i class="mdi mdi-content-save-outline me-1"></i>保存配置</button>
<button class="btn btn-light" id="ypTest" type="button" {if !$admin_can_manage|default:false}disabled{/if}><i class="mdi mdi-lan-connect me-1"></i>测试连接</button>
<div class="yp-notice" id="ypNotice" role="status" aria-live="polite"></div>
</div>
</form>
</section>
<section class="yp-panel">
<div class="yp-panel-head"><div><h2>充值订单</h2><p>退款仅支持已支付订单全额原路退回,并同步扣回用户余额及对应邀请返利;余额不足时会形成负余额。</p></div></div>
{if $yipay_table_error != ''}<div class="yp-warning">{$yipay_table_error|escape}</div>{/if}
<form class="yp-filter" method="get" action="/admin/yipay">
<input class="form-control" name="keyword" type="search" value="{$yipay_filters.keyword|escape}" placeholder="{if $admin_can_manage|default:false}记录 ID、用户 ID 或用户邮箱{else}记录 ID 或用户 ID{/if}">
<select class="form-select" name="payment_type">
<option value="">全部方式</option>
<option value="alipay" {if $yipay_filters.payment_type == 'alipay'}selected{/if}>支付宝</option>
<option value="wxpay" {if $yipay_filters.payment_type == 'wxpay'}selected{/if}>微信支付</option>
</select>
<select class="form-select" name="status">
<option value="">全部状态</option>
<option value="creating" {if $yipay_filters.status == 'creating'}selected{/if}>创建中</option>
<option value="pending" {if $yipay_filters.status == 'pending'}selected{/if}>待支付</option>
<option value="paid" {if $yipay_filters.status == 'paid'}selected{/if}>已支付</option>
<option value="refunded" {if $yipay_filters.status == 'refunded'}selected{/if}>已退款</option>
<option value="failed" {if $yipay_filters.status == 'failed'}selected{/if}>失败</option>
</select>
<button class="btn btn-light" type="submit"><i class="mdi mdi-magnify me-1"></i>筛选</button>
</form>
{if $yipay_orders}
<div class="yp-table-wrap">
<table class="yp-table">
<thead><tr><th>用户</th><th>方式</th><th>金额</th><th>状态</th><th>创建时间</th><th>操作</th></tr></thead>
<tbody>
{foreach $yipay_orders as $order}
<tr>
<td><span>{$order->user_email|default:'已删除用户'|escape}</span><br><small class="text-muted">用户 ID {$order->user_id} · 记录 ID {$order->id}</small></td>
<td>{if $order->payment_type == 'wxpay'}微信支付{else}支付宝{/if}</td>
<td>¥ {$order->amount}</td>
<td><span class="yp-pill {if $order->status == 'paid'}is-paid{elseif $order->status == 'refunded'}is-refunded{elseif $order->status == 'pending' || $order->status == 'creating'}is-pending{elseif $order->status == 'failed'}is-failed{/if}">{if $order->status == 'creating'}创建中{elseif $order->status == 'pending'}待支付{elseif $order->status == 'paid'}已支付{elseif $order->status == 'refunded'}已退款{elseif $order->status == 'failed'}失败{else}{$order->status|escape}{/if}</span></td>
<td>{date('Y-m-d H:i:s', $order->created_at)}</td>
<td>{if $order->status == 'paid' && $yipay_refund_available}<button class="btn btn-sm btn-outline-danger yp-refund" type="button" data-refund-record="{$order->id}" data-refund-amount="{$order->amount|escape}" {if !$admin_can_manage|default:false}disabled aria-disabled="true"{/if}><i class="mdi mdi-cash-refund me-1"></i>退款</button>{else}<span class="text-muted">--</span>{/if}</td>
</tr>
{foreachelse}
<tr><td colspan="6" class="yp-empty">暂无订单</td></tr>
{/foreach}
</tbody>
</table>
</div>
<div class="yp-pagination">{$yipay_orders->links()}</div>
{/if}
</section>
</div>
{literal}
<script>
(function () {
'use strict';
var form = document.getElementById('ypConfigForm');
var notice = document.getElementById('ypNotice');
var save = document.getElementById('ypSave');
var test = document.getElementById('ypTest');
var canManage = form.dataset.canManage === '1';
function show(message, ok) {
notice.textContent = message;
notice.className = 'yp-notice is-show ' + (ok ? 'is-ok' : 'is-error');
}
function formBody(source) {
var body = new URLSearchParams();
new FormData(source).forEach(function (value, key) { body.append(key, String(value)); });
return body.toString();
}
function request(url, body) {
return fetch(url, {
method: 'POST', credentials: 'same-origin',
headers: {'Accept':'application/json','Content-Type':'application/x-www-form-urlencoded; charset=UTF-8','X-Requested-With':'XMLHttpRequest'},
body: body
}).then(function (response) {
return response.text().then(function (text) {
var data;
try { data = JSON.parse(text); } catch (error) { throw new Error('服务器未返回有效结果(HTTP ' + response.status + ')'); }
if (!response.ok || Number(data.ret) !== 1) throw new Error(data.msg || '请求失败');
return data;
});
});
}
form.addEventListener('submit', function (event) {
event.preventDefault(); if (save.disabled) return; save.disabled = true; show('正在保存配置...', true);
request('/admin/yipay/config', formBody(form)).then(function (data) {
['ypGatewayUrl', 'ypCallbackUrl', 'ypPid', 'ypSecret'].forEach(function (id) {
var input = document.getElementById(id);
if (input) input.value = '';
});
show(data.msg, true);
})
.catch(function (error) { show(error.message, false); }).finally(function () { save.disabled = !canManage; });
});
test.addEventListener('click', function () {
if (test.disabled) return; test.disabled = true; show('正在测试连接...', true);
request('/admin/yipay/test', '').then(function (data) { show(data.msg, true); })
.catch(function (error) { show(error.message, false); }).finally(function () { test.disabled = !canManage; });
});
document.addEventListener('click', function (event) {
var button = event.target.closest('[data-refund-record]');
if (!button || button.disabled) return;
var recordId = button.getAttribute('data-refund-record');
var amount = button.getAttribute('data-refund-amount');
if (!window.confirm('确认将这笔充值全额退款 ¥' + amount + '?\n退款成功后会立即扣回用户余额和对应邀请返利,余额不足时将形成负余额。此操作不可撤销。')) return;
button.disabled = true;
show('正在提交退款,请勿重复操作...', true);
request('/admin/yipay/refund', new URLSearchParams({record_id: recordId, confirm: 'REFUND'}).toString())
.then(function (data) { show(data.msg, true); window.setTimeout(function () { window.location.reload(); }, 900); })
.catch(function (error) { show(error.message, false); button.disabled = false; });
});
})();
</script>
{/literal}
{include file='admin/static_footer.tpl'}