better-staridc-MNBT
1<?php
2/**
3 * 主机总览页视图。
4 *
5 * @package MnbtWp
6 */
7
8if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10}
11
12$mnbtwp_nonce = wp_create_nonce( 'mnbtwp_admin' );
13?>
14<div class="wrap">
15 <h1><?php esc_html_e( '主机管理', 'wp-seller-plugin' ); ?></h1>
16 <p class="description"><?php esc_html_e( '所有已开通主机(含购买自动开通与手动开通)。操作会直接调用 MNBT 生效。', 'wp-seller-plugin' ); ?></p>
17
18 <?php if ( ! empty( $failed_orders ) ) : ?>
19 <h2 style="margin-top:20px;"><?php esc_html_e( '开通失败订单', 'wp-seller-plugin' ); ?></h2>
20 <p class="description"><?php esc_html_e( '以下订单支付成功但自动开通失败,可重试开通。', 'wp-seller-plugin' ); ?></p>
21 <table class="widefat striped">
22 <thead>
23 <tr>
24 <th><?php esc_html_e( '订单', 'wp-seller-plugin' ); ?></th>
25 <th><?php esc_html_e( '客户', 'wp-seller-plugin' ); ?></th>
26 <th><?php esc_html_e( '金额', 'wp-seller-plugin' ); ?></th>
27 <th><?php esc_html_e( '错误信息', 'wp-seller-plugin' ); ?></th>
28 <th><?php esc_html_e( '操作', 'wp-seller-plugin' ); ?></th>
29 </tr>
30 </thead>
31 <tbody>
32 <?php foreach ( $failed_orders as $mnbtwp_fo ) : ?>
33 <?php $mnbtwp_err = get_post_meta( $mnbtwp_fo->get_id(), '_mnbtwp_provision_error', true ); ?>
34 <tr>
35 <td><a href="<?php echo esc_url( $mnbtwp_fo->get_edit_order_url() ); ?>">#<?php echo (int) $mnbtwp_fo->get_id(); ?></a></td>
36 <td><?php echo esc_html( $mnbtwp_fo->get_billing_email() ? $mnbtwp_fo->get_billing_email() : '#' . (int) $mnbtwp_fo->get_user_id() ); ?></td>
37 <td><?php echo esc_html( $mnbtwp_fo->get_total() . ' ' . $mnbtwp_fo->get_currency() ); ?></td>
38 <td style="color:#c62828;"><?php echo esc_html( $mnbtwp_err ); ?></td>
39 <td>
40 <button type="button" class="button button-small button-primary" onclick="mnbtwpRetry(<?php echo (int) $mnbtwp_fo->get_id(); ?>)"><?php esc_html_e( '重试开通', 'wp-seller-plugin' ); ?></button>
41 </td>
42 </tr>
43 <?php endforeach; ?>
44 </tbody>
45 </table>
46 <?php endif; ?>
47
48 <h2 style="margin-top:20px;"><?php esc_html_e( '主机列表', 'wp-seller-plugin' ); ?></h2>
49 <?php if ( empty( $hosts ) ) : ?>
50 <p><?php esc_html_e( '暂无主机记录。', 'wp-seller-plugin' ); ?></p>
51 <?php else : ?>
52 <table class="widefat striped">
53 <thead>
54 <tr>
55 <th><?php esc_html_e( 'ID', 'wp-seller-plugin' ); ?></th>
56 <th><?php esc_html_e( '节点', 'wp-seller-plugin' ); ?></th>
57 <th><?php esc_html_e( '用户名', 'wp-seller-plugin' ); ?></th>
58 <th><?php esc_html_e( '站点', 'wp-seller-plugin' ); ?></th>
59 <th><?php esc_html_e( '状态', 'wp-seller-plugin' ); ?></th>
60 <th><?php esc_html_e( '到期', 'wp-seller-plugin' ); ?></th>
61 <th><?php esc_html_e( '订单', 'wp-seller-plugin' ); ?></th>
62 <th><?php esc_html_e( '操作', 'wp-seller-plugin' ); ?></th>
63 </tr>
64 </thead>
65 <tbody>
66 <?php foreach ( $hosts as $mnbtwp_h ) : ?>
67 <?php
68 $mnbtwp_p = isset( $provider_map[ $mnbtwp_h['provider_id'] ] ) ? $provider_map[ $mnbtwp_h['provider_id'] ] : null;
69 $mnbtwp_label = Helpers::host_status_label( $mnbtwp_h['status'] );
70 ?>
71 <tr>
72 <td><?php echo (int) $mnbtwp_h['id']; ?></td>
73 <td><?php echo $mnbtwp_p ? esc_html( $mnbtwp_p['name'] ) : esc_html( '#' . (int) $mnbtwp_h['provider_id'] ); ?></td>
74 <td><code><?php echo esc_html( $mnbtwp_h['username'] ); ?></code></td>
75 <td><?php echo esc_html( $mnbtwp_h['site_domain'] ? $mnbtwp_h['site_domain'] : '-' ); ?></td>
76 <td>
77 <?php if ( in_array( $mnbtwp_h['status'], array( 'active', 'provisioning' ), true ) ) : ?>
78 <span style="color:#1a7f37;"><?php echo esc_html( $mnbtwp_label ); ?></span>
79 <?php else : ?>
80 <span style="color:#c62828;"><?php echo esc_html( $mnbtwp_label ); ?></span>
81 <?php endif; ?>
82 </td>
83 <td><?php echo esc_html( $mnbtwp_h['expire_date'] && '0000-00-00' !== $mnbtwp_h['expire_date'] ? $mnbtwp_h['expire_date'] : __( '长期', 'wp-seller-plugin' ) ); ?></td>
84 <td><?php echo $mnbtwp_h['order_id'] ? '<a href="' . esc_url( get_edit_post_link( (int) $mnbtwp_h['order_id'] ) ) . '">#' . (int) $mnbtwp_h['order_id'] . '</a>' : '-'; ?></td>
85 <td>
86 <button type="button" class="button button-small" onclick="mnbtwpHostAction(<?php echo (int) $mnbtwp_h['id']; ?>,'start')"><?php esc_html_e( '启动', 'wp-seller-plugin' ); ?></button>
87 <button type="button" class="button button-small" onclick="mnbtwpHostAction(<?php echo (int) $mnbtwp_h['id']; ?>,'stop')"><?php esc_html_e( '停止', 'wp-seller-plugin' ); ?></button>
88 <button type="button" class="button button-small" onclick="mnbtwpHostAction(<?php echo (int) $mnbtwp_h['id']; ?>,'suspend')"><?php esc_html_e( '暂停', 'wp-seller-plugin' ); ?></button>
89 <button type="button" class="button button-small" onclick="mnbtwpHostAction(<?php echo (int) $mnbtwp_h['id']; ?>,'resume')"><?php esc_html_e( '恢复', 'wp-seller-plugin' ); ?></button>
90 <button type="button" class="button button-small" onclick="mnbtwpPass(<?php echo (int) $mnbtwp_h['id']; ?>)"><?php esc_html_e( '改密', 'wp-seller-plugin' ); ?></button>
91 <button type="button" class="button button-small" onclick="mnbtwpRenew(<?php echo (int) $mnbtwp_h['id']; ?>)"><?php esc_html_e( '续费', 'wp-seller-plugin' ); ?></button>
92 <button type="button" class="button button-small" onclick="mnbtwpPackage(<?php echo (int) $mnbtwp_h['id']; ?>)"><?php esc_html_e( '升降级', 'wp-seller-plugin' ); ?></button>
93 <button type="button" class="button button-small button-link-delete" onclick="mnbtwpDelete(<?php echo (int) $mnbtwp_h['id']; ?>)"><?php esc_html_e( '删除', 'wp-seller-plugin' ); ?></button>
94 <?php if ( 'failed' === $mnbtwp_h['status'] && $mnbtwp_h['order_id'] ) : ?>
95 <button type="button" class="button button-small button-primary" onclick="mnbtwpRetry(<?php echo (int) $mnbtwp_h['order_id']; ?>)"><?php esc_html_e( '重试开通', 'wp-seller-plugin' ); ?></button>
96 <?php endif; ?>
97 </td>
98 </tr>
99 <?php endforeach; ?>
100 </tbody>
101 </table>
102 <?php endif; ?>
103</div>
104
105<script type="text/javascript">
106 var mnbtwpAdminNonce = '<?php echo esc_js( $mnbtwp_nonce ); ?>';
107
108 function mnbtwpAdminAjax(data, done) {
109 data.nonce = mnbtwpAdminNonce;
110 jQuery.post(ajaxurl, data, function (r) {
111 if (r && r.success) {
112 if (done) done(r); else location.reload();
113 } else {
114 alert((r && r.data) ? r.data : '<?php echo esc_js( __( '操作失败', 'wp-seller-plugin' ) ); ?>');
115 }
116 }).fail(function () {
117 alert('<?php echo esc_js( __( '网络错误', 'wp-seller-plugin' ) ); ?>');
118 });
119 }
120
121 function mnbtwpHostAction(id, action) {
122 mnbtwpAdminAjax({ action: 'mnbtwp_admin_host_action', host_action: action, host_id: id });
123 }
124
125 function mnbtwpPass(id) {
126 var pw = prompt('<?php echo esc_js( __( '请输入新密码(至少 6 位)', 'wp-seller-plugin' ) ); ?>');
127 if (!pw || pw.length < 6) return;
128 mnbtwpAdminAjax({ action: 'mnbtwp_admin_host_action', host_action: 'change_pass', host_id: id, password: pw });
129 }
130
131 function mnbtwpRenew(id) {
132 var d = prompt('<?php echo esc_js( __( '请输入新到期日期(YYYY-MM-DD)', 'wp-seller-plugin' ) ); ?>');
133 if (!d || !/^\d{4}-\d{2}-\d{2}$/.test(d)) return;
134 mnbtwpAdminAjax({ action: 'mnbtwp_admin_host_action', host_action: 'renew', host_id: id, setdate: d });
135 }
136
137 function mnbtwpPackage(id) {
138 var web = prompt('<?php echo esc_js( __( '网站空间 (MB)', 'wp-seller-plugin' ) ); ?>', '0');
139 if (web === null) return;
140 var sql = prompt('<?php echo esc_js( __( '数据库空间 (MB)', 'wp-seller-plugin' ) ); ?>', '0');
141 if (sql === null) return;
142 var ll = prompt('<?php echo esc_js( __( '流量 (MB,0=不限)', 'wp-seller-plugin' ) ); ?>', '0');
143 if (ll === null) return;
144 mnbtwpAdminAjax({
145 action: 'mnbtwp_admin_host_action',
146 host_action: 'change_package',
147 host_id: id,
148 websize: parseInt(web, 10) || 0,
149 sqlsize: parseInt(sql, 10) || 0,
150 ll: parseInt(ll, 10) || 0
151 });
152 }
153
154 function mnbtwpDelete(id) {
155 if (!confirm('<?php echo esc_js( __( '删除后站点、数据库、FTP 将被清除且不可恢复,确定删除?', 'wp-seller-plugin' ) ); ?>')) return;
156 mnbtwpAdminAjax({ action: 'mnbtwp_admin_host_action', host_action: 'delete', host_id: id });
157 }
158
159 function mnbtwpRetry(orderId) {
160 if (!confirm('<?php echo esc_js( __( '确定重试开通该订单?', 'wp-seller-plugin' ) ); ?>')) return;
161 mnbtwpAdminAjax({ action: 'mnbtwp_admin_retry_provision', order_id: orderId });
162 }
163</script>