Merge pull request 'feat(admin): complete native pay ops lists and users.php governance menus' (#142) from worktree-zibll-native-admin-menus into main
Reviewed-on: CYL/wordpress-theme-aksrt#142
This commit is contained in:
@@ -95,9 +95,9 @@ Note: zibll「商品管理」`zibpay_product_page` is **paid article sales**, no
|
||||
|-------|--------|
|
||||
| 0 Docs + matrix | done |
|
||||
| 1 Native CPT/tax menus | done |
|
||||
| 2a Pay menu + orders/withdraw/cards | done (skeleton + primary lists) |
|
||||
| 2b Shipping/after-sale/coupons/income/rebate | pending (stubs + SPA fallback) |
|
||||
| 3 users.php submenus | pending |
|
||||
| 2a Pay menu + orders/withdraw/cards | done |
|
||||
| 2b Shipping/after-sale/coupons/income/rebate | done |
|
||||
| 3 users.php submenus | done |
|
||||
| 4 SPA strip | pending (after 1–3) |
|
||||
| 5+ behavior parity | backlog |
|
||||
|
||||
|
||||
@@ -327,6 +327,11 @@ if (is_admin() && class_exists('AKSRT_Admin_Pay_Menus')) {
|
||||
AKSRT_Admin_Pay_Menus::get_instance()->init();
|
||||
}
|
||||
|
||||
// WordPress 原生用户菜单:消息/邀请码/认证/禁封(zibll users.php 子菜单对齐)
|
||||
if (is_admin() && class_exists('AKSRT_Admin_Users_Menus')) {
|
||||
AKSRT_Admin_Users_Menus::get_instance()->init();
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 主题删除时的数据库清理(仅在用户启用清理选项时生效)
|
||||
// uninstall.php 会检查 aksrt_cleanup_on_uninstall 选项
|
||||
|
||||
@@ -173,6 +173,7 @@ require_once AKSRT_DIR . '/inc/classes/class-aksrt-update-checker.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-category-rewrite.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/class-aksrt-admin-message-controller.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/native/class-aksrt-admin-pay-menus.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/admin/native/class-aksrt-admin-users-menus.php';
|
||||
|
||||
require_once AKSRT_DIR . '/inc/classes/class-aksrt-admin.php';
|
||||
require_once AKSRT_DIR . '/inc/classes/auth/class-aksrt-auth-email-verification.php';
|
||||
|
||||
@@ -33,6 +33,13 @@ class AKSRT_Admin_Pay_Menus {
|
||||
add_action('admin_post_aksrt_pay_update_order_status', [$this, 'handle_update_order_status']);
|
||||
add_action('admin_post_aksrt_pay_update_withdrawal', [$this, 'handle_update_withdrawal']);
|
||||
add_action('admin_post_aksrt_pay_disable_charge_card', [$this, 'handle_disable_charge_card']);
|
||||
add_action('admin_post_aksrt_pay_update_shipping', [$this, 'handle_update_shipping']);
|
||||
add_action('admin_post_aksrt_pay_update_after_sale', [$this, 'handle_update_after_sale']);
|
||||
add_action('admin_post_aksrt_pay_create_coupon', [$this, 'handle_create_coupon']);
|
||||
add_action('admin_post_aksrt_pay_disable_coupon', [$this, 'handle_disable_coupon']);
|
||||
add_action('admin_post_aksrt_pay_settle_income', [$this, 'handle_settle_income']);
|
||||
add_action('admin_post_aksrt_pay_settle_rebate', [$this, 'handle_settle_rebate']);
|
||||
add_action('admin_post_aksrt_pay_cancel_rebate', [$this, 'handle_cancel_rebate']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,17 +60,17 @@ class AKSRT_Admin_Pay_Menus {
|
||||
'shipping' => [
|
||||
'slug' => 'aksrt_shipping',
|
||||
'title' => __('发货及物流', 'aksrt'),
|
||||
'callback' => [$this, 'render_stub_page'],
|
||||
'callback' => [$this, 'render_shipping_page'],
|
||||
],
|
||||
'after_sale' => [
|
||||
'slug' => 'aksrt_after_sale',
|
||||
'title' => __('售后管理', 'aksrt'),
|
||||
'callback' => [$this, 'render_stub_page'],
|
||||
'callback' => [$this, 'render_after_sale_page'],
|
||||
],
|
||||
'coupons' => [
|
||||
'slug' => 'aksrt_coupons',
|
||||
'title' => __('优惠码', 'aksrt'),
|
||||
'callback' => [$this, 'render_stub_page'],
|
||||
'callback' => [$this, 'render_coupons_page'],
|
||||
],
|
||||
'charge_cards' => [
|
||||
'slug' => 'aksrt_charge_cards',
|
||||
@@ -73,12 +80,12 @@ class AKSRT_Admin_Pay_Menus {
|
||||
'income' => [
|
||||
'slug' => 'aksrt_income',
|
||||
'title' => __('创作分成', 'aksrt'),
|
||||
'callback' => [$this, 'render_stub_page'],
|
||||
'callback' => [$this, 'render_income_page'],
|
||||
],
|
||||
'rebate' => [
|
||||
'slug' => 'aksrt_rebate',
|
||||
'title' => __('推广返佣', 'aksrt'),
|
||||
'callback' => [$this, 'render_stub_page'],
|
||||
'callback' => [$this, 'render_rebate_page'],
|
||||
],
|
||||
'withdraw' => [
|
||||
'slug' => 'aksrt_withdraw',
|
||||
@@ -123,29 +130,39 @@ class AKSRT_Admin_Pay_Menus {
|
||||
}
|
||||
|
||||
$page = isset($_GET['page']) ? sanitize_key((string) wp_unslash($_GET['page'])) : '';
|
||||
if ($page === 'aksrt_withdraw') {
|
||||
return;
|
||||
|
||||
if ($page !== 'aksrt_withdraw' && class_exists('AKSRT_Withdrawal')) {
|
||||
$pending = (int) AKSRT_Withdrawal::get_instance()->get_count(['status' => AKSRT_Withdrawal::STATUS_PENDING]);
|
||||
if ($pending > 0) {
|
||||
$url = admin_url('admin.php?page=aksrt_withdraw&status=pending');
|
||||
echo '<div class="notice notice-info is-dismissible">';
|
||||
echo '<h3>' . esc_html__('提现申请待处理', 'aksrt') . '</h3>';
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: %d: pending withdrawal count */
|
||||
__('您有 %d 个提现申请待处理', 'aksrt'),
|
||||
$pending
|
||||
)) . '</p>';
|
||||
echo '<p><a class="button button-primary" href="' . esc_url($url) . '">' . esc_html__('立即处理', 'aksrt') . '</a></p>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists('AKSRT_Withdrawal')) {
|
||||
return;
|
||||
if ($page !== 'aksrt_after_sale' && class_exists('AKSRT_After_Sale')) {
|
||||
$as_stats = AKSRT_After_Sale::get_instance()->get_stats();
|
||||
$pending_as = (int) ($as_stats['pending'] ?? 0);
|
||||
if ($pending_as > 0) {
|
||||
$url = admin_url('admin.php?page=aksrt_after_sale&status=pending');
|
||||
echo '<div class="notice notice-info is-dismissible">';
|
||||
echo '<h3>' . esc_html__('售后工单待处理', 'aksrt') . '</h3>';
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: %d: pending after-sale count */
|
||||
__('您有 %d 个售后工单待处理', 'aksrt'),
|
||||
$pending_as
|
||||
)) . '</p>';
|
||||
echo '<p><a class="button button-primary" href="' . esc_url($url) . '">' . esc_html__('去处理', 'aksrt') . '</a></p>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$pending = (int) AKSRT_Withdrawal::get_instance()->get_count(['status' => AKSRT_Withdrawal::STATUS_PENDING]);
|
||||
if ($pending <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url = admin_url('admin.php?page=aksrt_withdraw&status=pending');
|
||||
echo '<div class="notice notice-info is-dismissible">';
|
||||
echo '<h3>' . esc_html__('提现申请待处理', 'aksrt') . '</h3>';
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: %d: pending withdrawal count */
|
||||
__('您有 %d 个提现申请待处理', 'aksrt'),
|
||||
$pending
|
||||
)) . '</p>';
|
||||
echo '<p><a class="button button-primary" href="' . esc_url($url) . '">' . esc_html__('立即处理', 'aksrt') . '</a></p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
@@ -174,12 +191,25 @@ class AKSRT_Admin_Pay_Menus {
|
||||
}
|
||||
$code = sanitize_key((string) wp_unslash($_GET['aksrt_pay_msg']));
|
||||
$map = [
|
||||
'order_updated' => __('订单状态已更新。', 'aksrt'),
|
||||
'order_failed' => __('订单状态更新失败。', 'aksrt'),
|
||||
'withdraw_updated' => __('提现状态已更新。', 'aksrt'),
|
||||
'withdraw_failed' => __('提现状态更新失败。', 'aksrt'),
|
||||
'card_disabled' => __('充值卡已禁用。', 'aksrt'),
|
||||
'card_failed' => __('充值卡禁用失败。', 'aksrt'),
|
||||
'order_updated' => __('订单状态已更新。', 'aksrt'),
|
||||
'order_failed' => __('订单状态更新失败。', 'aksrt'),
|
||||
'withdraw_updated' => __('提现状态已更新。', 'aksrt'),
|
||||
'withdraw_failed' => __('提现状态更新失败。', 'aksrt'),
|
||||
'card_disabled' => __('充值卡已禁用。', 'aksrt'),
|
||||
'card_failed' => __('充值卡禁用失败。', 'aksrt'),
|
||||
'shipping_updated' => __('物流状态已更新。', 'aksrt'),
|
||||
'shipping_failed' => __('物流状态更新失败。', 'aksrt'),
|
||||
'after_sale_updated' => __('售后状态已更新。', 'aksrt'),
|
||||
'after_sale_failed' => __('售后状态更新失败。', 'aksrt'),
|
||||
'coupon_created' => __('优惠码已创建。', 'aksrt'),
|
||||
'coupon_create_failed'=> __('优惠码创建失败(可能重复)。', 'aksrt'),
|
||||
'coupon_disabled' => __('优惠码已禁用。', 'aksrt'),
|
||||
'coupon_failed' => __('优惠码禁用失败。', 'aksrt'),
|
||||
'income_settled' => __('分成已结算。', 'aksrt'),
|
||||
'income_failed' => __('分成结算失败。', 'aksrt'),
|
||||
'rebate_settled' => __('返佣已结算。', 'aksrt'),
|
||||
'rebate_cancelled' => __('返佣已取消。', 'aksrt'),
|
||||
'rebate_failed' => __('返佣操作失败。', 'aksrt'),
|
||||
];
|
||||
if (!isset($map[$code])) {
|
||||
return;
|
||||
@@ -239,36 +269,6 @@ class AKSRT_Admin_Pay_Menus {
|
||||
echo '</a>';
|
||||
}
|
||||
|
||||
public function render_stub_page(): void {
|
||||
$this->ensure_cap();
|
||||
$page = isset($_GET['page']) ? sanitize_key((string) wp_unslash($_GET['page'])) : '';
|
||||
$title = __('支付中心', 'aksrt');
|
||||
foreach ($this->pages() as $item) {
|
||||
if ($item['slug'] === $page) {
|
||||
$title = $item['title'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->render_header($title);
|
||||
echo '<div class="notice notice-info"><p>';
|
||||
echo esc_html__('此运营页骨架已挂载到原生侧栏。完整列表与操作将在 Phase 2b 继续补齐;当前可暂时使用 SPA 对应页面。', 'aksrt');
|
||||
echo '</p></div>';
|
||||
|
||||
$spa_map = [
|
||||
'aksrt_shipping' => '#/shop/shipping',
|
||||
'aksrt_after_sale' => '#/shop/after-sale',
|
||||
'aksrt_coupons' => '#/shop/coupons',
|
||||
'aksrt_income' => '#/payment/revenue',
|
||||
'aksrt_rebate' => '#/payment/rebate',
|
||||
];
|
||||
if (isset($spa_map[$page])) {
|
||||
$url = admin_url('admin.php?page=aksrt-settings' . $spa_map[$page]);
|
||||
echo '<p><a class="button button-primary" href="' . esc_url($url) . '">' . esc_html__('打开 SPA 运营页(过渡)', 'aksrt') . '</a></p>';
|
||||
}
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* Orders
|
||||
* ----------------------------------------------------------------*/
|
||||
@@ -719,4 +719,575 @@ class AKSRT_Admin_Pay_Menus {
|
||||
]));
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* Shipping
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
public function render_shipping_page(): void {
|
||||
$this->ensure_cap();
|
||||
$this->render_header(__('发货及物流', 'aksrt'));
|
||||
|
||||
if (!class_exists('AKSRT_Shipping')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('物流模块未初始化。', 'aksrt') . '</p></div>';
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
|
||||
$search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : '';
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$svc = AKSRT_Shipping::get_instance();
|
||||
$stats = $svc->get_stats();
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1: total */
|
||||
__('物流记录共 %d 条', 'aksrt'),
|
||||
(int) ($stats['total'] ?? 0)
|
||||
)) . '</p>';
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_shipping" />';
|
||||
echo '<select name="status">';
|
||||
$status_options = [
|
||||
'' => __('全部状态', 'aksrt'),
|
||||
'shipped' => __('已发货', 'aksrt'),
|
||||
'in_transit' => __('运输中', 'aksrt'),
|
||||
'delivered' => __('已签收', 'aksrt'),
|
||||
'returned' => __('已退回', 'aksrt'),
|
||||
];
|
||||
foreach ($status_options as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
echo '<input type="search" name="s" value="' . esc_attr($search) . '" placeholder="' . esc_attr__('订单号 / 运单号', 'aksrt') . '" /> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$args = [
|
||||
'status' => $status,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
];
|
||||
if ($search !== '') {
|
||||
if (preg_match('/^[A-Za-z0-9_-]+$/', $search)) {
|
||||
$args['order_number'] = $search;
|
||||
} else {
|
||||
$args['tracking_no'] = $search;
|
||||
}
|
||||
}
|
||||
$result = $svc->get_list($args);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ceil(max(1, $total) / $per_page));
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('订单号', 'aksrt') . '</th><th>' . esc_html__('承运商', 'aksrt') . '</th><th>' . esc_html__('运单号', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无物流记录', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td><code>' . esc_html((string) ($row['order_number'] ?? '')) . '</code></td>';
|
||||
echo '<td>' . esc_html((string) ($row['carrier'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['tracking_no'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html($status_options[$st] ?? $st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td><form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:4px;align-items:center;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_update_shipping" />';
|
||||
echo '<input type="hidden" name="shipping_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_update_shipping_' . $id);
|
||||
echo '<select name="new_status">';
|
||||
foreach ($status_options as $key => $label) {
|
||||
if ($key === '') {
|
||||
continue;
|
||||
}
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($st, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('备注', 'aksrt') . '" />';
|
||||
submit_button(__('更新', 'aksrt'), 'small', '', false);
|
||||
echo '</form></td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
public function handle_update_shipping(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['shipping_id']) ? (int) $_POST['shipping_id'] : 0;
|
||||
$new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
check_admin_referer('aksrt_pay_update_shipping_' . $id);
|
||||
|
||||
$ok = false;
|
||||
if ($id > 0 && $new_status !== '' && class_exists('AKSRT_Shipping')) {
|
||||
$ok = AKSRT_Shipping::get_instance()->update_status($id, $new_status, $note, get_current_user_id());
|
||||
}
|
||||
wp_safe_redirect($this->page_url('aksrt_shipping', ['aksrt_pay_msg' => $ok ? 'shipping_updated' : 'shipping_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* After-sale
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
public function render_after_sale_page(): void {
|
||||
$this->ensure_cap();
|
||||
$this->render_header(__('售后管理', 'aksrt'));
|
||||
|
||||
if (!class_exists('AKSRT_After_Sale')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('售后模块未初始化。', 'aksrt') . '</p></div>';
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$svc = AKSRT_After_Sale::get_instance();
|
||||
$stats = $svc->get_stats();
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1: total 2: pending */
|
||||
__('售后工单共 %1$d · 待处理 %2$d', 'aksrt'),
|
||||
(int) ($stats['total'] ?? 0),
|
||||
(int) ($stats['pending'] ?? 0)
|
||||
)) . '</p>';
|
||||
|
||||
$status_options = [
|
||||
'' => __('全部状态', 'aksrt'),
|
||||
'pending' => __('待处理', 'aksrt'),
|
||||
'processing' => __('处理中', 'aksrt'),
|
||||
'approved' => __('已通过', 'aksrt'),
|
||||
'rejected' => __('已拒绝', 'aksrt'),
|
||||
'completed' => __('已完成', 'aksrt'),
|
||||
'cancelled' => __('已取消', 'aksrt'),
|
||||
];
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_after_sale" />';
|
||||
echo '<select name="status">';
|
||||
foreach ($status_options as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$result = $svc->get_list([
|
||||
'status' => $status,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
]);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ceil(max(1, $total) / $per_page));
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('订单号', 'aksrt') . '</th><th>' . esc_html__('类型', 'aksrt') . '</th><th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无售后工单', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$user_id = (int) ($row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td><code>' . esc_html((string) ($row['order_number'] ?? '')) . '</code></td>';
|
||||
echo '<td>' . esc_html((string) ($row['type'] ?? '')) . '</td>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '</td>';
|
||||
echo '<td>' . esc_html($status_options[$st] ?? $st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td><form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:4px;align-items:center;flex-wrap:wrap;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_update_after_sale" />';
|
||||
echo '<input type="hidden" name="ticket_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_update_after_sale_' . $id);
|
||||
echo '<select name="new_status">';
|
||||
foreach ($status_options as $key => $label) {
|
||||
if ($key === '') {
|
||||
continue;
|
||||
}
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($st, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('备注', 'aksrt') . '" />';
|
||||
submit_button(__('更新', 'aksrt'), 'small', '', false);
|
||||
echo '</form></td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
public function handle_update_after_sale(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['ticket_id']) ? (int) $_POST['ticket_id'] : 0;
|
||||
$new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
check_admin_referer('aksrt_pay_update_after_sale_' . $id);
|
||||
|
||||
$ok = false;
|
||||
if ($id > 0 && $new_status !== '' && class_exists('AKSRT_After_Sale')) {
|
||||
$ok = AKSRT_After_Sale::get_instance()->update_status($id, $new_status, get_current_user_id(), $note);
|
||||
}
|
||||
wp_safe_redirect($this->page_url('aksrt_after_sale', ['aksrt_pay_msg' => $ok ? 'after_sale_updated' : 'after_sale_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* Coupons
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
public function render_coupons_page(): void {
|
||||
$this->ensure_cap();
|
||||
$this->render_header(__('优惠码', 'aksrt'));
|
||||
|
||||
if (!class_exists('AKSRT_Coupon')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('优惠码模块未初始化。', 'aksrt') . '</p></div>';
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
|
||||
$search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : '';
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$svc = AKSRT_Coupon::get_instance();
|
||||
|
||||
echo '<h2>' . esc_html__('新建优惠码', 'aksrt') . '</h2>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="margin-bottom:20px;display:flex;gap:8px;flex-wrap:wrap;align-items:end;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_create_coupon" />';
|
||||
wp_nonce_field('aksrt_pay_create_coupon');
|
||||
echo '<p><label>' . esc_html__('代码', 'aksrt') . '<br><input type="text" name="code" required /></label></p>';
|
||||
echo '<p><label>' . esc_html__('类型', 'aksrt') . '<br><select name="type"><option value="fixed">' . esc_html__('固定金额', 'aksrt') . '</option><option value="percent">' . esc_html__('折扣百分比', 'aksrt') . '</option></select></label></p>';
|
||||
echo '<p><label>' . esc_html__('面值', 'aksrt') . '<br><input type="number" step="0.01" name="value" value="0" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('最低消费', 'aksrt') . '<br><input type="number" step="0.01" name="min_amount" value="0" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('总次数(0=不限)', 'aksrt') . '<br><input type="number" name="usage_limit" value="0" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('过期时间', 'aksrt') . '<br><input type="datetime-local" name="expires_at" /></label></p>';
|
||||
submit_button(__('创建', 'aksrt'), 'primary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_coupons" />';
|
||||
echo '<select name="status">';
|
||||
foreach (['' => __('全部状态', 'aksrt'), 'active' => __('可用', 'aksrt'), 'disabled' => __('已禁用', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
echo '<input type="search" name="s" value="' . esc_attr($search) . '" placeholder="' . esc_attr__('搜索代码', 'aksrt') . '" /> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$result = $svc->get_list([
|
||||
'status' => $status,
|
||||
'search' => $search,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
]);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ($result['total_pages'] ?? 1));
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('代码', 'aksrt') . '</th><th>' . esc_html__('类型', 'aksrt') . '</th><th>' . esc_html__('面值', 'aksrt') . '</th><th>' . esc_html__('已用/上限', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('过期', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="8">' . esc_html__('暂无优惠码', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td><code>' . esc_html((string) ($row['code'] ?? '')) . '</code></td>';
|
||||
echo '<td>' . esc_html((string) ($row['type'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['value'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ((int) ($row['used_count'] ?? 0)) . '/' . (string) ((int) ($row['usage_limit'] ?? 0))) . '</td>';
|
||||
echo '<td>' . esc_html($st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['expires_at'] ?? '')) . '</td>';
|
||||
echo '<td>';
|
||||
if ($st === 'active') {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_disable_coupon" />';
|
||||
echo '<input type="hidden" name="coupon_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_disable_coupon_' . $id);
|
||||
submit_button(__('禁用', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
} else {
|
||||
echo '—';
|
||||
}
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
public function handle_create_coupon(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
check_admin_referer('aksrt_pay_create_coupon');
|
||||
|
||||
$ok = false;
|
||||
if (class_exists('AKSRT_Coupon')) {
|
||||
$expires = isset($_POST['expires_at']) ? sanitize_text_field((string) wp_unslash($_POST['expires_at'])) : '';
|
||||
if ($expires !== '') {
|
||||
$expires = str_replace('T', ' ', $expires) . ':00';
|
||||
}
|
||||
$id = AKSRT_Coupon::get_instance()->create([
|
||||
'code' => sanitize_text_field((string) wp_unslash($_POST['code'] ?? '')),
|
||||
'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'fixed')),
|
||||
'value' => (float) ($_POST['value'] ?? 0),
|
||||
'min_amount' => (float) ($_POST['min_amount'] ?? 0),
|
||||
'usage_limit' => (int) ($_POST['usage_limit'] ?? 0),
|
||||
'expires_at' => $expires,
|
||||
]);
|
||||
$ok = $id > 0;
|
||||
}
|
||||
wp_safe_redirect($this->page_url('aksrt_coupons', ['aksrt_pay_msg' => $ok ? 'coupon_created' : 'coupon_create_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function handle_disable_coupon(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['coupon_id']) ? (int) $_POST['coupon_id'] : 0;
|
||||
check_admin_referer('aksrt_pay_disable_coupon_' . $id);
|
||||
$ok = $id > 0 && class_exists('AKSRT_Coupon') && AKSRT_Coupon::get_instance()->disable($id);
|
||||
wp_safe_redirect($this->page_url('aksrt_coupons', ['aksrt_pay_msg' => $ok ? 'coupon_disabled' : 'coupon_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* Income / rebate
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
public function render_income_page(): void {
|
||||
$this->ensure_cap();
|
||||
$this->render_header(__('创作分成', 'aksrt'));
|
||||
|
||||
if (!class_exists('AKSRT_Revenue')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('分成模块未初始化。', 'aksrt') . '</p></div>';
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$svc = AKSRT_Revenue::get_instance();
|
||||
$stats = $svc->get_stats();
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1: total 2: pending 3: settled */
|
||||
__('合计 %1$s · 待结算 %2$s · 已结算 %3$s', 'aksrt'),
|
||||
number_format((float) ($stats['total'] ?? 0), 2),
|
||||
number_format((float) ($stats['pending'] ?? 0), 2),
|
||||
number_format((float) ($stats['settled'] ?? 0), 2)
|
||||
)) . '</p>';
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_income" />';
|
||||
echo '<select name="status">';
|
||||
foreach (['' => __('全部状态', 'aksrt'), 'pending' => __('待结算', 'aksrt'), 'settled' => __('已结算', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$result = $svc->get_list([
|
||||
'status' => $status,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
]);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ($result['max_pages'] ?? 1));
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('订单号', 'aksrt') . '</th><th>' . esc_html__('金额', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无分成记录', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$user_id = (int) ($row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '</td>';
|
||||
echo '<td><code>' . esc_html((string) ($row['order_number'] ?? '')) . '</code></td>';
|
||||
echo '<td>' . esc_html(number_format((float) ($row['amount'] ?? 0), 2)) . '</td>';
|
||||
echo '<td>' . esc_html($st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td>';
|
||||
if ($st === 'pending') {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_settle_income" />';
|
||||
echo '<input type="hidden" name="revenue_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_settle_income_' . $id);
|
||||
submit_button(__('结算', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
} else {
|
||||
echo '—';
|
||||
}
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
public function handle_settle_income(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['revenue_id']) ? (int) $_POST['revenue_id'] : 0;
|
||||
check_admin_referer('aksrt_pay_settle_income_' . $id);
|
||||
$ok = $id > 0 && class_exists('AKSRT_Revenue') && AKSRT_Revenue::get_instance()->settle($id);
|
||||
wp_safe_redirect($this->page_url('aksrt_income', ['aksrt_pay_msg' => $ok ? 'income_settled' : 'income_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function render_rebate_page(): void {
|
||||
$this->ensure_cap();
|
||||
$this->render_header(__('推广返佣', 'aksrt'));
|
||||
|
||||
if (!class_exists('AKSRT_Rebate')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('返佣模块未初始化。', 'aksrt') . '</p></div>';
|
||||
$this->render_footer();
|
||||
return;
|
||||
}
|
||||
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : '';
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$svc = AKSRT_Rebate::get_instance();
|
||||
$stats = $svc->get_stats();
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1: total 2: pending 3: settled amount */
|
||||
__('记录 %1$d · 待结算 %2$d · 已结算金额 %3$s', 'aksrt'),
|
||||
(int) ($stats['total'] ?? 0),
|
||||
(int) ($stats['pending'] ?? 0),
|
||||
number_format((float) ($stats['settled_amount'] ?? 0), 2)
|
||||
)) . '</p>';
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_rebate" />';
|
||||
echo '<select name="status">';
|
||||
foreach (['' => __('全部状态', 'aksrt'), 'pending' => __('待结算', 'aksrt'), 'settled' => __('已结算', 'aksrt'), 'cancelled' => __('已取消', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$result = $svc->get_list([
|
||||
'status' => $status,
|
||||
'limit' => $per_page,
|
||||
'offset' => ($page_num - 1) * $per_page,
|
||||
]);
|
||||
$items = $result['items'] ?? [];
|
||||
$total = (int) ($result['total'] ?? 0);
|
||||
$pages = max(1, (int) ceil(max(1, $total) / $per_page));
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('订单号', 'aksrt') . '</th><th>' . esc_html__('金额', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无返佣记录', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$user_id = (int) ($row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '</td>';
|
||||
echo '<td><code>' . esc_html((string) ($row['order_number'] ?? '')) . '</code></td>';
|
||||
echo '<td>' . esc_html(number_format((float) ($row['amount'] ?? 0), 2)) . '</td>';
|
||||
echo '<td>' . esc_html($st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td style="display:flex;gap:4px;">';
|
||||
if ($st === 'pending') {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_settle_rebate" />';
|
||||
echo '<input type="hidden" name="rebate_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_settle_rebate_' . $id);
|
||||
submit_button(__('结算', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_pay_cancel_rebate" />';
|
||||
echo '<input type="hidden" name="rebate_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_pay_cancel_rebate_' . $id);
|
||||
submit_button(__('取消', 'aksrt'), 'small', '', false);
|
||||
echo '</form>';
|
||||
} else {
|
||||
echo '—';
|
||||
}
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->render_pagination($pages, $page_num);
|
||||
$this->render_footer();
|
||||
}
|
||||
|
||||
public function handle_settle_rebate(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['rebate_id']) ? (int) $_POST['rebate_id'] : 0;
|
||||
check_admin_referer('aksrt_pay_settle_rebate_' . $id);
|
||||
$ok = $id > 0 && class_exists('AKSRT_Rebate') && AKSRT_Rebate::get_instance()->settle($id);
|
||||
wp_safe_redirect($this->page_url('aksrt_rebate', ['aksrt_pay_msg' => $ok ? 'rebate_settled' : 'rebate_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function handle_cancel_rebate(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['rebate_id']) ? (int) $_POST['rebate_id'] : 0;
|
||||
check_admin_referer('aksrt_pay_cancel_rebate_' . $id);
|
||||
$ok = $id > 0 && class_exists('AKSRT_Rebate') && AKSRT_Rebate::get_instance()->cancel($id);
|
||||
wp_safe_redirect($this->page_url('aksrt_rebate', ['aksrt_pay_msg' => $ok ? 'rebate_cancelled' : 'rebate_failed']));
|
||||
exit;
|
||||
}
|
||||
|
||||
private function render_pagination(int $pages, int $page_num): void {
|
||||
if ($pages <= 1) {
|
||||
return;
|
||||
}
|
||||
echo '<div class="tablenav"><div class="tablenav-pages">';
|
||||
echo paginate_links([
|
||||
'base' => add_query_arg('paged', '%#%'),
|
||||
'format' => '',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => $pages,
|
||||
'current' => $page_num,
|
||||
]);
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,610 @@
|
||||
<?php
|
||||
/**
|
||||
* Native users.php submenus for governance ops (zibll-aligned).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class AKSRT_Admin_Users_Menus {
|
||||
|
||||
public const CAPABILITY = 'manage_options';
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function get_instance(): self {
|
||||
if (null === self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function init(): void {
|
||||
if (!is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action('admin_menu', [$this, 'register_menus']);
|
||||
add_action('admin_notices', [$this, 'pending_notices']);
|
||||
add_action('admin_post_aksrt_users_send_message', [$this, 'handle_send_message']);
|
||||
add_action('admin_post_aksrt_users_review_verify', [$this, 'handle_review_verify']);
|
||||
add_action('admin_post_aksrt_users_update_report', [$this, 'handle_update_report']);
|
||||
add_action('admin_post_aksrt_users_add_restriction', [$this, 'handle_add_restriction']);
|
||||
add_action('admin_post_aksrt_users_remove_restriction', [$this, 'handle_remove_restriction']);
|
||||
}
|
||||
|
||||
public function register_menus(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_submenu_page(
|
||||
'users.php',
|
||||
__('消息管理', 'aksrt'),
|
||||
__('消息管理', 'aksrt'),
|
||||
self::CAPABILITY,
|
||||
'aksrt_messages',
|
||||
[$this, 'render_messages_page']
|
||||
);
|
||||
add_submenu_page(
|
||||
'users.php',
|
||||
__('邀请码管理', 'aksrt'),
|
||||
__('邀请码管理', 'aksrt'),
|
||||
self::CAPABILITY,
|
||||
'aksrt_invite_codes',
|
||||
[$this, 'render_invite_codes_page']
|
||||
);
|
||||
add_submenu_page(
|
||||
'users.php',
|
||||
__('身份认证', 'aksrt'),
|
||||
__('身份认证', 'aksrt'),
|
||||
self::CAPABILITY,
|
||||
'aksrt_user_auth',
|
||||
[$this, 'render_verify_page']
|
||||
);
|
||||
add_submenu_page(
|
||||
'users.php',
|
||||
__('举报&禁封', 'aksrt'),
|
||||
__('举报&禁封', 'aksrt'),
|
||||
self::CAPABILITY,
|
||||
'aksrt_user_ban',
|
||||
[$this, 'render_ban_page']
|
||||
);
|
||||
}
|
||||
|
||||
public function pending_notices(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
return;
|
||||
}
|
||||
$page = isset($_GET['page']) ? sanitize_key((string) wp_unslash($_GET['page'])) : '';
|
||||
|
||||
if ($page !== 'aksrt_user_auth') {
|
||||
$pending_verify = $this->count_verify_status('pending');
|
||||
if ($pending_verify > 0) {
|
||||
$url = admin_url('users.php?page=aksrt_user_auth&status=pending');
|
||||
echo '<div class="notice notice-info is-dismissible"><h3>' . esc_html__('用户身份认证申请待处理', 'aksrt') . '</h3>';
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: %d count */
|
||||
__('您有 %d 个用户身份认证申请待处理', 'aksrt'),
|
||||
$pending_verify
|
||||
)) . '</p>';
|
||||
echo '<p><a class="button button-primary" href="' . esc_url($url) . '">' . esc_html__('立即处理', 'aksrt') . '</a></p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($page !== 'aksrt_user_ban' && class_exists('AKSRT_Report_Center')) {
|
||||
$pending_reports = (int) AKSRT_Report_Center::get_instance()->get_pending_count();
|
||||
if ($pending_reports > 0) {
|
||||
$url = admin_url('users.php?page=aksrt_user_ban&tab=reports&status=pending');
|
||||
echo '<div class="notice notice-info is-dismissible"><h3>' . esc_html__('举报待处理', 'aksrt') . '</h3>';
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: %d count */
|
||||
__('您有 %d 条举报待处理', 'aksrt'),
|
||||
$pending_reports
|
||||
)) . '</p>';
|
||||
echo '<p><a class="button button-primary" href="' . esc_url($url) . '">' . esc_html__('立即处理', 'aksrt') . '</a></p></div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function ensure_cap(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('您没有权限访问此页面。', 'aksrt'));
|
||||
}
|
||||
}
|
||||
|
||||
private function flash(): void {
|
||||
if (empty($_GET['aksrt_users_msg'])) {
|
||||
return;
|
||||
}
|
||||
$code = sanitize_key((string) wp_unslash($_GET['aksrt_users_msg']));
|
||||
$map = [
|
||||
'message_sent' => __('消息已发送。', 'aksrt'),
|
||||
'message_failed' => __('消息发送失败。', 'aksrt'),
|
||||
'verify_updated' => __('认证状态已更新。', 'aksrt'),
|
||||
'verify_failed' => __('认证审核失败。', 'aksrt'),
|
||||
'report_updated' => __('举报状态已更新。', 'aksrt'),
|
||||
'report_failed' => __('举报更新失败。', 'aksrt'),
|
||||
'restriction_added' => __('限制已添加。', 'aksrt'),
|
||||
'restriction_removed' => __('限制已移除。', 'aksrt'),
|
||||
'restriction_failed'=> __('限制操作失败。', 'aksrt'),
|
||||
];
|
||||
if (!isset($map[$code])) {
|
||||
return;
|
||||
}
|
||||
$class = str_contains($code, 'failed') ? 'notice-error' : 'notice-success';
|
||||
echo '<div class="notice ' . esc_attr($class) . ' is-dismissible"><p>' . esc_html($map[$code]) . '</p></div>';
|
||||
}
|
||||
|
||||
private function redirect(string $page, string $msg, array $extra = []): void {
|
||||
wp_safe_redirect(add_query_arg(array_merge(['page' => $page, 'aksrt_users_msg' => $msg], $extra), admin_url('users.php')));
|
||||
exit;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* Messages
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
public function render_messages_page(): void {
|
||||
$this->ensure_cap();
|
||||
echo '<div class="wrap"><h1>' . esc_html__('消息管理', 'aksrt') . '</h1>';
|
||||
$this->flash();
|
||||
|
||||
echo '<h2>' . esc_html__('发送系统消息', 'aksrt') . '</h2>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="margin-bottom:20px;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_users_send_message" />';
|
||||
wp_nonce_field('aksrt_users_send_message');
|
||||
echo '<p><label>' . esc_html__('用户 ID(0=广播给管理员自己测试)', 'aksrt') . '<br><input type="number" name="user_id" value="0" min="0" /></label></p>';
|
||||
echo '<p><label>' . esc_html__('标题', 'aksrt') . '<br><input type="text" name="title" class="regular-text" required /></label></p>';
|
||||
echo '<p><label>' . esc_html__('内容', 'aksrt') . '<br><textarea name="content" class="large-text" rows="4" required></textarea></label></p>';
|
||||
submit_button(__('发送', 'aksrt'));
|
||||
echo '</form>';
|
||||
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 30;
|
||||
$offset = ($page_num - 1) * $per_page;
|
||||
$table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('notification') : '';
|
||||
|
||||
if ($table === '') {
|
||||
echo '<div class="notice notice-warning"><p>' . esc_html__('通知表不可用。', 'aksrt') . '</p></div></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$total = (int) $wpdb->get_var("SELECT COUNT(*) FROM {$table}");
|
||||
$items = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT * FROM {$table} ORDER BY created_at DESC LIMIT %d OFFSET %d",
|
||||
$per_page,
|
||||
$offset
|
||||
), ARRAY_A);
|
||||
$pages = max(1, (int) ceil(max(1, $total) / $per_page));
|
||||
|
||||
echo '<h2>' . esc_html__('最近消息', 'aksrt') . '</h2>';
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('类型', 'aksrt') . '</th><th>' . esc_html__('标题', 'aksrt') . '</th><th>' . esc_html__('已读', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="6">' . esc_html__('暂无消息', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ((array) $items as $row) {
|
||||
$user_id = (int) ($row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) ($row['id'] ?? '')) . '</td>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name . ' (#' . $user_id . ')') : esc_html((string) $user_id)) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['type'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['title'] ?? $row['description'] ?? '')) . '</td>';
|
||||
echo '<td>' . (!empty($row['is_read']) ? esc_html__('是', 'aksrt') : esc_html__('否', 'aksrt')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->pagination($pages, $page_num);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function handle_send_message(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
check_admin_referer('aksrt_users_send_message');
|
||||
|
||||
$user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
|
||||
$title = isset($_POST['title']) ? sanitize_text_field((string) wp_unslash($_POST['title'])) : '';
|
||||
$content = isset($_POST['content']) ? sanitize_textarea_field((string) wp_unslash($_POST['content'])) : '';
|
||||
if ($user_id <= 0) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
|
||||
$ok = false;
|
||||
if ($content !== '' && class_exists('AKSRT_Message')) {
|
||||
$ok = AKSRT_Message::get_instance()->send($user_id, 'system', $content, ['title' => $title !== '' ? $title : $content]);
|
||||
}
|
||||
$this->redirect('aksrt_messages', $ok ? 'message_sent' : 'message_failed');
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* Invite codes
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
public function render_invite_codes_page(): void {
|
||||
$this->ensure_cap();
|
||||
echo '<div class="wrap"><h1>' . esc_html__('邀请码管理', 'aksrt') . '</h1>';
|
||||
$this->flash();
|
||||
|
||||
$spa = admin_url('admin.php?page=aksrt-settings#/users/invite-codes');
|
||||
echo '<p><a class="button" href="' . esc_url($spa) . '">' . esc_html__('SPA 批量生成(过渡)', 'aksrt') . '</a></p>';
|
||||
|
||||
global $wpdb;
|
||||
$rows = $wpdb->get_results(
|
||||
"SELECT user_id, meta_value AS invite_code FROM {$wpdb->usermeta} WHERE meta_key = 'aksrt_invite_code' ORDER BY umeta_id DESC LIMIT 200",
|
||||
ARRAY_A
|
||||
);
|
||||
|
||||
echo '<h2>' . esc_html__('用户邀请码', 'aksrt') . '</h2>';
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('邀请码', 'aksrt') . '</th><th>' . esc_html__('邀请人数', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$rows) {
|
||||
echo '<tr><td colspan="3">' . esc_html__('暂无用户邀请码', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
$invite_table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('invite') : '';
|
||||
foreach ((array) $rows as $row) {
|
||||
$user_id = (int) ($row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
$count = 0;
|
||||
if ($invite_table) {
|
||||
$count = (int) $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT COUNT(*) FROM {$invite_table} WHERE inviter_id = %d",
|
||||
$user_id
|
||||
));
|
||||
}
|
||||
echo '<tr>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name . ' (#' . $user_id . ')') : esc_html((string) $user_id)) . '</td>';
|
||||
echo '<td><code>' . esc_html((string) ($row['invite_code'] ?? '')) . '</code></td>';
|
||||
echo '<td>' . esc_html((string) $count) . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</tbody></table></div>';
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* Verify
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
private function count_verify_status(string $status): int {
|
||||
global $wpdb;
|
||||
return (int) $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT COUNT(*) FROM {$wpdb->usermeta} WHERE meta_key = 'aksrt_user_verify_status' AND meta_value = %s",
|
||||
$status
|
||||
));
|
||||
}
|
||||
|
||||
public function render_verify_page(): void {
|
||||
$this->ensure_cap();
|
||||
echo '<div class="wrap"><h1>' . esc_html__('身份认证', 'aksrt') . '</h1>';
|
||||
$this->flash();
|
||||
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : 'pending';
|
||||
$page_num = max(1, (int) ($_GET['paged'] ?? 1));
|
||||
$per_page = 20;
|
||||
$offset = ($page_num - 1) * $per_page;
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_user_auth" />';
|
||||
echo '<select name="status">';
|
||||
foreach (['pending' => __('待审核', 'aksrt'), 'verified' => __('已通过', 'aksrt'), 'rejected' => __('已拒绝', 'aksrt'), '' => __('全部', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
global $wpdb;
|
||||
$where = "INNER JOIN {$wpdb->usermeta} status ON status.user_id = u.ID AND status.meta_key = 'aksrt_user_verify_status'";
|
||||
$params = [];
|
||||
$sql_where = '';
|
||||
if ($status !== '') {
|
||||
$sql_where = ' WHERE status.meta_value = %s';
|
||||
$params[] = $status;
|
||||
}
|
||||
|
||||
$count_sql = "SELECT COUNT(DISTINCT u.ID) FROM {$wpdb->users} u {$where}{$sql_where}";
|
||||
$total = $params
|
||||
? (int) $wpdb->get_var($wpdb->prepare($count_sql, $params))
|
||||
: (int) $wpdb->get_var($count_sql);
|
||||
|
||||
$sql = "SELECT u.ID, u.display_name, u.user_email, u.user_registered, status.meta_value AS verify_status,
|
||||
reason.meta_value AS verify_reason
|
||||
FROM {$wpdb->users} u
|
||||
{$where}
|
||||
LEFT JOIN {$wpdb->usermeta} reason ON reason.user_id = u.ID AND reason.meta_key = 'aksrt_user_verify_reason'
|
||||
{$sql_where}
|
||||
ORDER BY u.user_registered DESC
|
||||
LIMIT %d OFFSET %d";
|
||||
$params[] = $per_page;
|
||||
$params[] = $offset;
|
||||
$items = $wpdb->get_results($wpdb->prepare($sql, $params), ARRAY_A);
|
||||
$pages = max(1, (int) ceil(max(1, $total) / $per_page));
|
||||
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('邮箱', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('备注', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="6">' . esc_html__('暂无认证申请', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ((array) $items as $row) {
|
||||
$uid = (int) ($row['ID'] ?? 0);
|
||||
$st = (string) ($row['verify_status'] ?? '');
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $uid) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['display_name'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['user_email'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html($st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['verify_reason'] ?? '')) . '</td>';
|
||||
echo '<td>';
|
||||
if ($st === 'pending') {
|
||||
foreach (['verified' => __('通过', 'aksrt'), 'rejected' => __('拒绝', 'aksrt')] as $action => $label) {
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:inline-block;margin-right:4px;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_users_review_verify" />';
|
||||
echo '<input type="hidden" name="user_id" value="' . esc_attr((string) $uid) . '" />';
|
||||
echo '<input type="hidden" name="status" value="' . esc_attr($action) . '" />';
|
||||
wp_nonce_field('aksrt_users_review_verify_' . $uid);
|
||||
if ($action === 'rejected') {
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('拒绝原因', 'aksrt') . '" /> ';
|
||||
}
|
||||
submit_button($label, 'small', '', false);
|
||||
echo '</form>';
|
||||
}
|
||||
} else {
|
||||
echo '—';
|
||||
}
|
||||
echo '</td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
$this->pagination($pages, $page_num);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function handle_review_verify(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
|
||||
$status = isset($_POST['status']) ? sanitize_key((string) wp_unslash($_POST['status'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
check_admin_referer('aksrt_users_review_verify_' . $user_id);
|
||||
|
||||
$ok = false;
|
||||
if ($user_id > 0 && in_array($status, ['verified', 'rejected'], true) && get_userdata($user_id)) {
|
||||
update_user_meta($user_id, 'aksrt_user_verify_status', $status);
|
||||
update_user_meta($user_id, 'aksrt_user_verify_reviewed_at', current_time('mysql'));
|
||||
update_user_meta($user_id, 'aksrt_user_verify_reviewer', get_current_user_id());
|
||||
if ($note !== '') {
|
||||
update_user_meta($user_id, 'aksrt_user_verify_reason', $note);
|
||||
} elseif ($status === 'verified') {
|
||||
delete_user_meta($user_id, 'aksrt_user_verify_reason');
|
||||
}
|
||||
$log = get_option('aksrt_verify_review_log', []);
|
||||
$log = is_array($log) ? $log : [];
|
||||
$log[] = [
|
||||
'user_id' => $user_id,
|
||||
'status' => $status,
|
||||
'reason' => $note,
|
||||
'reviewer' => get_current_user_id(),
|
||||
'time' => current_time('mysql'),
|
||||
];
|
||||
update_option('aksrt_verify_review_log', array_slice($log, -500), false);
|
||||
$ok = true;
|
||||
}
|
||||
$this->redirect('aksrt_user_auth', $ok ? 'verify_updated' : 'verify_failed', ['status' => 'pending']);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
* Ban / reports
|
||||
* ----------------------------------------------------------------*/
|
||||
|
||||
public function render_ban_page(): void {
|
||||
$this->ensure_cap();
|
||||
echo '<div class="wrap"><h1>' . esc_html__('举报&禁封', 'aksrt') . '</h1>';
|
||||
$this->flash();
|
||||
|
||||
$tab = isset($_GET['tab']) ? sanitize_key((string) wp_unslash($_GET['tab'])) : 'reports';
|
||||
echo '<h2 class="nav-tab-wrapper">';
|
||||
printf('<a class="nav-tab%s" href="%s">%s</a>', $tab === 'reports' ? ' nav-tab-active' : '', esc_url(admin_url('users.php?page=aksrt_user_ban&tab=reports')), esc_html__('举报', 'aksrt'));
|
||||
printf('<a class="nav-tab%s" href="%s">%s</a>', $tab === 'restrictions' ? ' nav-tab-active' : '', esc_url(admin_url('users.php?page=aksrt_user_ban&tab=restrictions')), esc_html__('禁封限制', 'aksrt'));
|
||||
echo '</h2>';
|
||||
|
||||
if ($tab === 'restrictions') {
|
||||
$this->render_restrictions_tab();
|
||||
} else {
|
||||
$this->render_reports_tab();
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
private function render_reports_tab(): void {
|
||||
if (!class_exists('AKSRT_Report_Center')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('举报中心未初始化。', 'aksrt') . '</p></div>';
|
||||
return;
|
||||
}
|
||||
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : 'pending';
|
||||
$svc = AKSRT_Report_Center::get_instance();
|
||||
$counts = $svc->get_status_counts();
|
||||
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1 pending 2 total */
|
||||
__('待处理 %1$d / 共 %2$d', 'aksrt'),
|
||||
(int) ($counts['pending'] ?? 0),
|
||||
(int) ($counts['total'] ?? 0)
|
||||
)) . '</p>';
|
||||
|
||||
echo '<form method="get" style="margin:12px 0;">';
|
||||
echo '<input type="hidden" name="page" value="aksrt_user_ban" /><input type="hidden" name="tab" value="reports" />';
|
||||
echo '<select name="status">';
|
||||
foreach (['pending' => __('待处理', 'aksrt'), 'reviewing' => __('审核中', 'aksrt'), 'resolved' => __('已处理', 'aksrt'), 'dismissed' => __('已驳回', 'aksrt'), '' => __('全部', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
|
||||
}
|
||||
echo '</select> ';
|
||||
submit_button(__('筛选', 'aksrt'), 'secondary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
$items = $svc->get_reports(['status' => $status, 'limit' => 50, 'offset' => 0]);
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('举报人', 'aksrt') . '</th><th>' . esc_html__('目标', 'aksrt') . '</th><th>' . esc_html__('原因', 'aksrt') . '</th><th>' . esc_html__('状态', 'aksrt') . '</th><th>' . esc_html__('时间', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无举报', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ($items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$st = (string) ($row['status'] ?? '');
|
||||
$rid = (int) ($row['reporter_id'] ?? 0);
|
||||
$ru = $rid > 0 ? get_userdata($rid) : null;
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td>' . ($ru ? esc_html($ru->display_name) : esc_html((string) $rid)) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['target_type'] ?? '') . ' #' . (string) ($row['target_id'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['reason'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html($st) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['created_at'] ?? '')) . '</td>';
|
||||
echo '<td><form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="display:flex;gap:4px;align-items:center;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_users_update_report" />';
|
||||
echo '<input type="hidden" name="report_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_users_update_report_' . $id);
|
||||
echo '<select name="new_status">';
|
||||
foreach (['pending', 'reviewing', 'resolved', 'dismissed'] as $key) {
|
||||
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($st, $key, false), esc_html($key));
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="text" name="note" placeholder="' . esc_attr__('备注', 'aksrt') . '" />';
|
||||
submit_button(__('更新', 'aksrt'), 'small', '', false);
|
||||
echo '</form></td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
}
|
||||
|
||||
private function render_restrictions_tab(): void {
|
||||
if (!class_exists('AKSRT_User_Restriction')) {
|
||||
echo '<div class="notice notice-error"><p>' . esc_html__('限制模块未初始化。', 'aksrt') . '</p></div>';
|
||||
return;
|
||||
}
|
||||
$svc = AKSRT_User_Restriction::get_instance();
|
||||
$stats = $svc->get_stats();
|
||||
echo '<p>' . esc_html(sprintf(
|
||||
/* translators: 1 total 2 active 3 banned */
|
||||
__('限制记录 %1$d · 生效中 %2$d · 封禁中 %3$d', 'aksrt'),
|
||||
(int) ($stats['total'] ?? 0),
|
||||
(int) ($stats['active'] ?? 0),
|
||||
(int) ($stats['banned'] ?? 0)
|
||||
)) . '</p>';
|
||||
|
||||
echo '<h2>' . esc_html__('添加限制', 'aksrt') . '</h2>';
|
||||
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="margin-bottom:20px;display:flex;gap:8px;flex-wrap:wrap;align-items:end;">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_users_add_restriction" />';
|
||||
wp_nonce_field('aksrt_users_add_restriction');
|
||||
echo '<p><label>' . esc_html__('用户 ID', 'aksrt') . '<br><input type="number" name="user_id" min="1" required /></label></p>';
|
||||
echo '<p><label>' . esc_html__('类型', 'aksrt') . '<br><select name="type">';
|
||||
foreach (['warn' => __('警告', 'aksrt'), 'mute' => __('禁言', 'aksrt'), 'suspend' => __('停权', 'aksrt'), 'ban' => __('封禁', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s">%s</option>', esc_attr($key), esc_html($label));
|
||||
}
|
||||
echo '</select></label></p>';
|
||||
echo '<p><label>' . esc_html__('范围', 'aksrt') . '<br><select name="scope">';
|
||||
foreach (['global' => __('全局', 'aksrt'), 'forum' => __('论坛', 'aksrt'), 'shop' => __('商城', 'aksrt'), 'comment' => __('评论', 'aksrt')] as $key => $label) {
|
||||
printf('<option value="%s">%s</option>', esc_attr($key), esc_html($label));
|
||||
}
|
||||
echo '</select></label></p>';
|
||||
echo '<p><label>' . esc_html__('原因', 'aksrt') . '<br><input type="text" name="reason" class="regular-text" required /></label></p>';
|
||||
submit_button(__('添加', 'aksrt'), 'primary', '', false);
|
||||
echo '</form>';
|
||||
|
||||
global $wpdb;
|
||||
$table = class_exists('AKSRT_DB_Migrator') ? AKSRT_DB_Migrator::table('user_restriction') : '';
|
||||
if ($table === '') {
|
||||
echo '<div class="notice notice-warning"><p>' . esc_html__('限制表不可用。', 'aksrt') . '</p></div>';
|
||||
return;
|
||||
}
|
||||
$items = $wpdb->get_results("SELECT * FROM {$table} ORDER BY id DESC LIMIT 100", ARRAY_A);
|
||||
echo '<table class="wp-list-table widefat fixed striped"><thead><tr>';
|
||||
echo '<th>ID</th><th>' . esc_html__('用户', 'aksrt') . '</th><th>' . esc_html__('类型', 'aksrt') . '</th><th>' . esc_html__('范围', 'aksrt') . '</th><th>' . esc_html__('原因', 'aksrt') . '</th><th>' . esc_html__('过期', 'aksrt') . '</th><th>' . esc_html__('操作', 'aksrt') . '</th>';
|
||||
echo '</tr></thead><tbody>';
|
||||
if (!$items) {
|
||||
echo '<tr><td colspan="7">' . esc_html__('暂无限制记录', 'aksrt') . '</td></tr>';
|
||||
}
|
||||
foreach ((array) $items as $row) {
|
||||
$id = (int) ($row['id'] ?? 0);
|
||||
$user_id = (int) ($row['user_id'] ?? 0);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : null;
|
||||
echo '<tr>';
|
||||
echo '<td>' . esc_html((string) $id) . '</td>';
|
||||
echo '<td>' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['type'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['scope'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['reason'] ?? '')) . '</td>';
|
||||
echo '<td>' . esc_html((string) ($row['expires_at'] ?? '—')) . '</td>';
|
||||
echo '<td><form method="post" action="' . esc_url(admin_url('admin-post.php')) . '">';
|
||||
echo '<input type="hidden" name="action" value="aksrt_users_remove_restriction" />';
|
||||
echo '<input type="hidden" name="restriction_id" value="' . esc_attr((string) $id) . '" />';
|
||||
wp_nonce_field('aksrt_users_remove_restriction_' . $id);
|
||||
submit_button(__('移除', 'aksrt'), 'small', '', false);
|
||||
echo '</form></td></tr>';
|
||||
}
|
||||
echo '</tbody></table>';
|
||||
}
|
||||
|
||||
public function handle_update_report(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['report_id']) ? (int) $_POST['report_id'] : 0;
|
||||
$new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : '';
|
||||
$note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : '';
|
||||
check_admin_referer('aksrt_users_update_report_' . $id);
|
||||
$ok = $id > 0 && class_exists('AKSRT_Report_Center') && AKSRT_Report_Center::get_instance()->update_status($id, $new_status, $note);
|
||||
$this->redirect('aksrt_user_ban', $ok ? 'report_updated' : 'report_failed', ['tab' => 'reports']);
|
||||
}
|
||||
|
||||
public function handle_add_restriction(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
check_admin_referer('aksrt_users_add_restriction');
|
||||
$user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0;
|
||||
$type = isset($_POST['type']) ? sanitize_key((string) wp_unslash($_POST['type'])) : 'warn';
|
||||
$scope = isset($_POST['scope']) ? sanitize_key((string) wp_unslash($_POST['scope'])) : 'global';
|
||||
$reason = isset($_POST['reason']) ? sanitize_text_field((string) wp_unslash($_POST['reason'])) : '';
|
||||
$ok = false;
|
||||
if ($user_id > 0 && $reason !== '' && class_exists('AKSRT_User_Restriction')) {
|
||||
$result = AKSRT_User_Restriction::get_instance()->restrict($user_id, $type, $reason, $scope, '', get_current_user_id());
|
||||
$ok = !empty($result['id']) || !empty($result['success']) || is_array($result);
|
||||
}
|
||||
$this->redirect('aksrt_user_ban', $ok ? 'restriction_added' : 'restriction_failed', ['tab' => 'restrictions']);
|
||||
}
|
||||
|
||||
public function handle_remove_restriction(): void {
|
||||
if (!current_user_can(self::CAPABILITY)) {
|
||||
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||
}
|
||||
$id = isset($_POST['restriction_id']) ? (int) $_POST['restriction_id'] : 0;
|
||||
check_admin_referer('aksrt_users_remove_restriction_' . $id);
|
||||
$ok = $id > 0 && class_exists('AKSRT_User_Restriction') && AKSRT_User_Restriction::get_instance()->remove_restriction($id);
|
||||
$this->redirect('aksrt_user_ban', $ok ? 'restriction_removed' : 'restriction_failed', ['tab' => 'restrictions']);
|
||||
}
|
||||
|
||||
private function pagination(int $pages, int $page_num): void {
|
||||
if ($pages <= 1) {
|
||||
return;
|
||||
}
|
||||
echo '<div class="tablenav"><div class="tablenav-pages">';
|
||||
echo paginate_links([
|
||||
'base' => add_query_arg('paged', '%#%'),
|
||||
'format' => '',
|
||||
'prev_text' => '«',
|
||||
'next_text' => '»',
|
||||
'total' => $pages,
|
||||
'current' => $page_num,
|
||||
]);
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,45 @@ class AKSRT_Revenue {
|
||||
return (array) $wpdb->get_results($wpdb->prepare($sql, $params), ARRAY_A);
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin list (all users) with optional status filter.
|
||||
*
|
||||
* @param array{status?:string,limit?:int,offset?:int} $args
|
||||
* @return array{items:array<int,array>,total:int,page:int,max_pages:int}
|
||||
*/
|
||||
public function get_list(array $args = []): array {
|
||||
global $wpdb;
|
||||
|
||||
$limit = max(1, min(100, (int) ($args['limit'] ?? 20)));
|
||||
$offset = max(0, (int) ($args['offset'] ?? 0));
|
||||
$status = sanitize_key((string) ($args['status'] ?? ''));
|
||||
|
||||
$where = [];
|
||||
$params = [];
|
||||
if ($status !== '') {
|
||||
$where[] = 'status = %s';
|
||||
$params[] = $status;
|
||||
}
|
||||
$where_sql = $where ? 'WHERE ' . implode(' AND ', $where) : '';
|
||||
|
||||
$count_sql = "SELECT COUNT(*) FROM {$this->table()} {$where_sql}";
|
||||
$total = $params
|
||||
? (int) $wpdb->get_var($wpdb->prepare($count_sql, $params))
|
||||
: (int) $wpdb->get_var($count_sql);
|
||||
|
||||
$sql = "SELECT * FROM {$this->table()} {$where_sql} ORDER BY created_at DESC LIMIT %d OFFSET %d";
|
||||
$params[] = $limit;
|
||||
$params[] = $offset;
|
||||
$items = $wpdb->get_results($wpdb->prepare($sql, $params), ARRAY_A);
|
||||
|
||||
return [
|
||||
'items' => $items ?: [],
|
||||
'total' => $total,
|
||||
'page' => (int) floor($offset / $limit) + 1,
|
||||
'max_pages' => (int) ceil(max(1, $total) / $limit),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取收益统计
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user