better-staridc-MNBT
1<?php mnbt_admin_include('head'); ?>
2<?php header("Cache-Control: no-cache, must-revalidate"); ?>
3<link rel="stylesheet" href="<?=mnbt_theme_asset('set-page.css', 'admin')?>">
4<link rel="stylesheet" href="<?=mnbt_theme_asset('pay-settings.css', 'admin')?>">
5
6<div class="mn-set-page">
7<?php
8// 已注册的支付插件
9$payment_plugins = function_exists('mnbt_get_payment_plugins') ? mnbt_get_payment_plugins() : [];
10// 当前已启用的付款方式
11$enabled_methods = function_exists('mnbt_get_enabled_payment_methods') ? mnbt_get_enabled_payment_methods() : [];
12// 所有插件设置页签(用于检测插件是否提供设置页)
13$settings_tabs = function_exists('mnbt_plugin_settings_tabs') ? mnbt_plugin_settings_tabs() : [];
14
15// 把已启用方式按 plugin__method 做成查找表
16$enabled_map = [];
17foreach ($enabled_methods as $row) {
18 $key = $row['plugin'] . '__' . $row['method'];
19 $enabled_map[$key] = $row;
20}
21
22// 检测某插件是否有设置页
23$plugin_has_settings = function ($plugin_id) use ($settings_tabs) {
24 foreach ($settings_tabs as $tab) {
25 if (($tab['plugin'] ?? '') === $plugin_id && !empty($tab['url'])) {
26 return $tab['url'];
27 }
28 }
29 return '';
30};
31?>
32
33<div class="mn-set-card">
34 <div class="mn-set-card-hd">
35 <div class="mn-set-icon"><i class="mdi mdi-credit-card-outline"></i></div>
36 <div>
37 <h4>支付方式设置</h4>
38 <p>启用支付插件提供的付款方式,并设置客户端显示名</p>
39 </div>
40 </div>
41 <div class="mn-set-card-bd">
42 <div class="mn-pay-note">
43 <b>使用说明:</b>
44 <ol class="mb-0 mt-1">
45 <li>在 <a href="plugin.php" class="alert-link">插件管理</a> 中安装并启用所需支付插件(如易支付、支付宝官方等)。</li>
46 <li>支付插件的 API 凭证(商户号、密钥等)请在<b>插件自身的设置页</b>中配置,本页面仅负责启用与显示。</li>
47 <li>勾选要启用的子付款方式,设置客户端显示名、图标与排序(数字越小越靠前),保存后立即生效。</li>
48 </ol>
49 </div>
50 </div>
51</div>
52
53<?php if (empty($payment_plugins)): ?>
54<div class="mn-set-card">
55 <div class="mn-set-card-bd text-center text-muted py-5">
56 <i class="mdi mdi-package-variant-closed" style="font-size:48px;color:#cbd5e1"></i>
57 <h5 class="mt-3 mb-1">暂无可用支付插件</h5>
58 <p class="text-muted mb-3">请先安装并启用至少一个支付插件,然后返回本页面配置付款方式。</p>
59 <a href="plugin.php" class="btn btn-outline-primary"><i class="mdi mdi-puzzle"></i> 前往插件管理</a>
60 </div>
61</div>
62<?php else: ?>
63
64<form id="payMethodsForm" autocomplete="off">
65<?php foreach ($payment_plugins as $pid => $pinfo): ?>
66<?php
67 $plugin_name = isset($pinfo['name']) ? $pinfo['name'] : $pid;
68 $plugin_desc = isset($pinfo['description']) ? $pinfo['description'] : '';
69 $methods = isset($pinfo['methods']) && is_array($pinfo['methods']) ? $pinfo['methods'] : [];
70 $settings_url = $plugin_has_settings($pid);
71?>
72<div class="mn-set-card mn-pay-plugin-card" data-plugin="<?=htmlspecialchars($pid)?>">
73 <div class="mn-set-card-hd">
74 <div class="mn-set-icon"><i class="mdi <?=htmlspecialchars(isset($pinfo['icon']) ? $pinfo['icon'] : 'mdi-credit-card-multiple')?>"></i></div>
75 <div class="mn-pay-plugin-title">
76 <h4><?=htmlspecialchars($plugin_name)?>
77 <code class="mn-pay-slug"><?=htmlspecialchars($pid)?></code>
78 </h4>
79 <p><?=htmlspecialchars($plugin_desc)?></p>
80 </div>
81 <?php if ($settings_url): ?>
82 <a href="<?=htmlspecialchars($settings_url)?>" class="btn btn-sm btn-outline-secondary mn-pay-settings-btn">
83 <i class="mdi mdi-cog-outline"></i> 插件设置
84 </a>
85 <?php endif; ?>
86 </div>
87 <div class="mn-set-card-bd">
88 <?php if (empty($methods)): ?>
89 <div class="text-muted py-2">该插件未声明任何付款方式</div>
90 <?php else: ?>
91 <div class="table-responsive">
92 <table class="table mn-set-table mn-pay-methods-table">
93 <thead>
94 <tr>
95 <th style="width:56px">启用</th>
96 <th>子付款方式</th>
97 <th style="width:240px">客户端显示名</th>
98 <th style="width:200px">图标 class</th>
99 <th style="width:90px">排序</th>
100 </tr>
101 </thead>
102 <tbody>
103 <?php foreach ($methods as $mid => $minfo): ?>
104 <?php
105 $type_key = $pid . '__' . $mid;
106 $enabled = isset($enabled_map[$type_key]);
107 $cur = $enabled ? $enabled_map[$type_key] : [];
108 $default_name = isset($minfo['name']) ? $minfo['name'] : $mid;
109 $default_icon = isset($minfo['icon']) ? $minfo['icon'] : 'mdi-payment';
110 $display_name = $enabled && isset($cur['display_name']) && $cur['display_name'] !== '' ? $cur['display_name'] : $default_name;
111 $icon = $enabled && isset($cur['icon']) && $cur['icon'] !== '' ? $cur['icon'] : $default_icon;
112 $sort = $enabled && isset($cur['sort']) ? (int)$cur['sort'] : 99;
113 ?>
114 <tr data-type="<?=htmlspecialchars($type_key)?>">
115 <td class="text-center">
116 <div class="custom-control custom-switch">
117 <input type="checkbox" class="custom-control-input pay-method-enable" id="pm_<?=htmlspecialchars($pid)?>_<?=htmlspecialchars($mid)?>" data-plugin="<?=htmlspecialchars($pid)?>" data-method="<?=htmlspecialchars($mid)?>" <?=$enabled ? 'checked' : ''?>>
118 <label class="custom-control-label" for="pm_<?=htmlspecialchars($pid)?>_<?=htmlspecialchars($mid)?>"></label>
119 </div>
120 </td>
121 <td>
122 <i class="mdi <?=htmlspecialchars($default_icon)?> mr-1"></i>
123 <strong><?=htmlspecialchars($default_name)?></strong>
124 <code class="ml-1"><?=htmlspecialchars($mid)?></code>
125 </td>
126 <td>
127 <input type="text" class="form-control form-control-sm pay-method-name" value="<?=htmlspecialchars($display_name)?>" placeholder="<?=htmlspecialchars($default_name)?>" maxlength="40">
128 </td>
129 <td>
130 <input type="text" class="form-control form-control-sm pay-method-icon" value="<?=htmlspecialchars($icon)?>" placeholder="mdi-payment" maxlength="60">
131 </td>
132 <td>
133 <input type="number" class="form-control form-control-sm pay-method-sort" value="<?=$sort?>" min="0" max="999" style="text-align:center">
134 </td>
135 </tr>
136 <?php endforeach; ?>
137 </tbody>
138 </table>
139 </div>
140 <?php endif; ?>
141 </div>
142</div>
143<?php endforeach; ?>
144
145<div class="mn-set-card">
146 <div class="mn-set-card-bd">
147 <div class="mn-set-actions" style="border-top:0;padding-top:0;margin-top:0">
148 <button class="btn btn-primary btn-block" type="button" onclick="savePayMethods()"><i class="mdi mdi-content-save-outline"></i> 保存支付方式配置</button>
149 </div>
150 </div>
151</div>
152</form>
153
154<?php endif; ?>
155</div>
156
157<script type="text/javascript">
158function savePayMethods() {
159 var rows = [];
160 var sortCounter = 1;
161 $('#payMethodsForm .pay-method-enable').each(function () {
162 if (!this.checked) return;
163 var $tr = $(this).closest('tr');
164 var plugin = $(this).data('plugin');
165 var method = $(this).data('method');
166 var name = $.trim($tr.find('.pay-method-name').val());
167 var icon = $.trim($tr.find('.pay-method-icon').val());
168 var sort = parseInt($tr.find('.pay-method-sort').val(), 10);
169 if (isNaN(sort) || sort < 0) sort = 99;
170 rows.push({
171 plugin: plugin,
172 method: method,
173 display_name: name,
174 icon: icon,
175 sort: sort
176 });
177 });
178 msloading('正在保存支付方式配置...','text-info','text-info');
179 var data = {};
180 data['gn'] = 'setpaymethods';
181 data['methods'] = JSON.stringify(rows);
182 $.post('./ajax.php', data, function (date) {
183 var jsoe = JSON.parse(date);
184 var qk = jsoe.code;
185 if (qk == '修改成功') {
186 msalert(1, '保存成功!共启用 ' + rows.length + ' 个付款方式', 2000);
187 msloadingde();
188 } else {
189 msalert(4, qk, 3000);
190 msloadingde();
191 }
192 }).fail(function () {
193 msalert(4, '网络错误,保存失败', 3000);
194 msloadingde();
195 });
196}
197</script>