diff --git a/assets/js/routes/user-center.js b/assets/js/routes/user-center.js index eed259cb..7857390a 100644 --- a/assets/js/routes/user-center.js +++ b/assets/js/routes/user-center.js @@ -70,17 +70,17 @@ closeDrawer(); } - function loadPanel(name) { + function loadPanel(name, forceLoad, queryParams) { if (!panels[name]) return Promise.reject(new Error('panel-not-found')); var target = panels[name].panel; - if (target.dataset.panelLoaded === 'true') return Promise.resolve(); + if (!forceLoad && target.dataset.panelLoaded === 'true') return Promise.resolve(); if (target._aksrtPanelRequest) return target._aksrtPanelRequest; var restUrl = (window.aksrtData && (window.aksrtData.restUrl || window.aksrtData.apiUrl)) || cfg.restUrl || ''; if (!restUrl) return Promise.reject(new Error('rest-unavailable')); target.classList.add('is-loading'); var url = restUrl.replace(/\/$/, '') + '/user-center/panel/' + encodeURIComponent(name); if (name === 'creator') { - var params = new URLSearchParams(window.location.search); + var params = queryParams || new URLSearchParams(window.location.search); ['income_page'].forEach(function(key) { if (params.get(key)) url += (url.indexOf('?') === -1 ? '?' : '&') + key + '=' + encodeURIComponent(params.get(key)); }); @@ -101,9 +101,9 @@ return target._aksrtPanelRequest; } - function activate(name, updateHistory) { + function activate(name, updateHistory, forceLoad, queryParams) { if (!panels[name]) name = defaultTab; - return loadPanel(name).then(function() { + return loadPanel(name, forceLoad, queryParams).then(function() { switchTo(name); if (updateHistory) updateUrl(name); if (typeof window.AKSRTRevenueCenterInit === 'function') window.AKSRTRevenueCenterInit(panels[name].panel); @@ -138,7 +138,23 @@ activate(this.getAttribute('data-tab'), true); }); }); - window.addEventListener('popstate', function() { activate(tabFromUrl(), false); }); + var creatorPanel = panels.creator ? panels.creator.panel : null; + if (creatorPanel) { + creatorPanel.addEventListener('click', function(e) { + var link = e.target && e.target.closest ? e.target.closest('.creator-income__pagination a') : null; + if (!link || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return; + e.preventDefault(); + var pageUrl = new URL(link.href, window.location.href); + loadPanel('creator', true, pageUrl.searchParams).then(function() { + switchTo('creator'); + if (window.history.pushState) window.history.pushState({}, '', pageUrl.toString()); + if (typeof window.AKSRTRevenueCenterInit === 'function') window.AKSRTRevenueCenterInit(creatorPanel); + }).catch(function() { + if (typeof showToast === 'function') showToast(i18n.networkError || '加载失败,请重试'); + }); + }); + } + window.addEventListener('popstate', function() { activate(tabFromUrl(), false, true); }); if (drawerTrigger) drawerTrigger.addEventListener('click', openDrawer); if (drawerOverlay) drawerOverlay.addEventListener('click', closeDrawer); activate(tabFromUrl(), false); diff --git a/inc/helpers/aksrt-user-center.php b/inc/helpers/aksrt-user-center.php index 36adb10d..2e35a609 100644 --- a/inc/helpers/aksrt-user-center.php +++ b/inc/helpers/aksrt-user-center.php @@ -147,7 +147,6 @@ if (!function_exists('aksrt_capture_user_center_view')) { $map = [ 'level' => 'level', 'profile' => 'form', - 'posts' => 'posts', 'creator' => 'creator', 'comments' => 'comments', 'favorites' => 'favorites', @@ -180,7 +179,7 @@ if (!function_exists('aksrt_capture_user_center_panel')) { * Capture a built-in or registered user-center panel body. */ function aksrt_capture_user_center_panel(string $tab_key, array $tab, array $context): string { - $built_in_tabs = ['profile', 'level', 'posts', 'creator', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings']; + $built_in_tabs = ['profile', 'level', 'creator', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings']; if (in_array($tab_key, $built_in_tabs, true)) { return aksrt_capture_user_center_view($tab_key, $context); } @@ -274,7 +273,6 @@ if (!function_exists('aksrt_user_center_resolve_tabs')) { ? \AKSRT\User\Center::get_instance()->get_dashboard_tabs() : [ 'profile' => ['label' => __('个人信息', 'aksrt'), 'icon' => 'user'], - 'posts' => ['label' => __('我的文章', 'aksrt'), 'icon' => 'file-alt'], 'comments' => ['label' => __('我的评论', 'aksrt'), 'icon' => 'comment'], 'favorites' => ['label' => __('我的收藏', 'aksrt'), 'icon' => 'star'], 'settings' => ['label' => __('账号设置', 'aksrt'), 'icon' => 'cog'], @@ -310,29 +308,6 @@ if (!function_exists('aksrt_user_center_resolve_tabs')) { } } -if (!function_exists('aksrt_user_center_post_status_counts')) { - /** - * Count the current user's posts by status (posts tab only). - * - * @return array{counts:array,total:int} - */ - function aksrt_user_center_post_status_counts(int $user_id): array { - global $wpdb; - $counts = ['publish' => 0, 'draft' => 0, 'pending' => 0, 'private' => 0]; - $rows = $wpdb->get_results($wpdb->prepare( - "SELECT post_status, COUNT(*) AS num FROM {$wpdb->posts} WHERE post_author = %d AND post_type = 'post' AND post_status IN ('publish','draft','pending','private') GROUP BY post_status", - $user_id - )); - foreach ((array) $rows as $row) { - $counts[$row->post_status] = (int) $row->num; - } - return [ - 'counts' => $counts, - 'total' => (int) array_sum($counts), - ]; - } -} - if (!function_exists('aksrt_user_center_runtime_config')) { /** * Frontend runtime config injected into the private user center page. @@ -444,7 +419,7 @@ if (!function_exists('aksrt_get_user_center_render_context')) { $user_center_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_user_center_settings() : [ - 'tabs' => ['profile', 'posts', 'comments', 'favorites'], + 'tabs' => ['profile', 'comments', 'favorites'], 'avatar_upload' => true, 'cover_upload' => true, 'social_links' => true, @@ -475,17 +450,6 @@ if (!function_exists('aksrt_get_user_center_render_context')) { ? \AKSRT\User\Follow::get_instance()->get_follower_count($user_id) : 0; - $post_status_filter = isset($_GET['post_status']) ? sanitize_key(wp_unslash($_GET['post_status'])) : 'publish'; - if (!in_array($post_status_filter, ['all', 'publish', 'draft', 'pending', 'private'], true)) { - $post_status_filter = 'publish'; - } - $user_status_counts = ['publish' => 0, 'draft' => 0, 'pending' => 0, 'private' => 0]; - if ('posts' === $active_tab) { - $status = aksrt_user_center_post_status_counts($user_id); - $user_status_counts = $status['counts']; - $post_count = $status['total']; - } - $svgs = aksrt_user_center_empty_svgs(); require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php'; @@ -499,7 +463,6 @@ if (!function_exists('aksrt_get_user_center_render_context')) { $runtime_config['avatarUpload'] = aksrt_user_center_avatar_upload_config($allow_avatar_upload); $revenue_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_payment_revenue_settings() : []; $show_revenue_section = !empty($revenue_settings['enabled']) || !empty($affiliate_settings['enabled']); - $new_post_url = function_exists('aksrt_get_new_post_url') ? aksrt_get_new_post_url() : ''; $revenue_url = isset($tabs['tabs']['revenue']) ? aksrt_get_user_center_tab_url('revenue') : ''; @@ -525,15 +488,10 @@ if (!function_exists('aksrt_get_user_center_render_context')) { 'show_avatar_edit' => $allow_avatar_upload, 'notification_unread_count' => function_exists('aksrt_get_user_unread_notification_count') ? aksrt_get_user_unread_notification_count($user_id) : 0, 'messages_url' => $messages_enabled && function_exists('aksrt_get_messages_page_url') ? aksrt_get_messages_page_url() : '', - 'new_post_url' => $new_post_url, 'revenue_url' => $revenue_url, 'per_page' => 10, - 'posts_page' => max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1), 'comments_page' => max(1, isset($_GET['comments_page']) ? (int) $_GET['comments_page'] : 1), 'favorites_page' => max(1, isset($_GET['favorites_page']) ? (int) $_GET['favorites_page'] : 1), - 'post_status_filter' => $post_status_filter, - 'user_status_counts' => $user_status_counts, - 'svg_empty_post' => $svgs['post'], 'svg_empty_comment' => $svgs['comment'], 'svg_empty_favorite' => $svgs['favorite'], 'orders_url' => function_exists('aksrt_get_user_center_tab_url') diff --git a/src/Admin/Native/PayIncome.php b/src/Admin/Native/PayIncome.php index 61aae314..1a5cff43 100644 --- a/src/Admin/Native/PayIncome.php +++ b/src/Admin/Native/PayIncome.php @@ -40,14 +40,21 @@ class PayIncome { } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; + $order_status = isset($_GET['order_status']) ? sanitize_key((string) wp_unslash($_GET['order_status'])) : ''; $user_id = isset($_GET['user_id']) ? max(0, (int) $_GET['user_id']) : 0; $post_id = isset($_GET['post_id']) ? max(0, (int) $_GET['post_id']) : 0; - $currency = isset($_GET['currency']) ? sanitize_key((string) wp_unslash($_GET['currency'])) : ''; + $currency = isset($_GET['currency']) ? strtolower(sanitize_key((string) wp_unslash($_GET['currency']))) : ''; + if ($currency === 'cny') { + $currency = 'CNY'; + } $order_number = isset($_GET['order_number']) ? sanitize_text_field((string) wp_unslash($_GET['order_number'])) : ''; $date_from = isset($_GET['date_from']) ? sanitize_text_field((string) wp_unslash($_GET['date_from'])) : ''; $date_to = isset($_GET['date_to']) ? sanitize_text_field((string) wp_unslash($_GET['date_to'])) : ''; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; + $order_statuses = class_exists('\\AKSRT\\Payment\\Order') + ? \AKSRT\Payment\Order::get_valid_statuses() + : []; $svc = \AKSRT\Payment\Revenue::get_instance(); $stats = $user_id > 0 ? $svc->get_stats($user_id) : $svc->get_stats(); @@ -76,6 +83,11 @@ class PayIncome { printf('', esc_attr($key), selected($status, $key, false), esc_html($label)); } echo ' '; + echo ' '; echo ' '; echo ' '; echo ' '; @@ -89,6 +101,7 @@ class PayIncome { $list_args = [ 'status' => $status, + 'order_status' => $order_status, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, 'post_id' => $post_id, diff --git a/src/Admin/PaymentController.php b/src/Admin/PaymentController.php index b5c1e18b..1252a2a8 100644 --- a/src/Admin/PaymentController.php +++ b/src/Admin/PaymentController.php @@ -254,6 +254,7 @@ class PaymentController extends ControllerBase { 'user_id' => max(0, (int) $request->get_param('user_id')), 'post_id' => max(0, (int) $request->get_param('post_id')), 'currency' => sanitize_key((string) $request->get_param('currency')), + 'order_status' => sanitize_key((string) $request->get_param('order_status')), 'order_number' => sanitize_text_field((string) $request->get_param('order_number')), 'date_from' => sanitize_text_field((string) $request->get_param('date_from')), 'date_to' => sanitize_text_field((string) $request->get_param('date_to')), diff --git a/src/Payment/Revenue.php b/src/Payment/Revenue.php index f575e10e..17dbdb10 100644 --- a/src/Payment/Revenue.php +++ b/src/Payment/Revenue.php @@ -396,6 +396,15 @@ class Revenue { $where[] = 'currency = %s'; $params[] = $currency; } + $order_status = sanitize_key((string) ($args['order_status'] ?? '')); + $valid_order_statuses = class_exists('\\AKSRT\\Core\\DomainModel') + ? \AKSRT\Core\DomainModel::order_status_labels() + : []; + $orders_table = \AKSRT\Core\DBMigrator::table('order'); + if ($orders_table !== '' && isset($valid_order_statuses[$order_status])) { + $where[] = "EXISTS (SELECT 1 FROM {$orders_table} AS income_order WHERE income_order.order_number = {$this->table()}.order_number AND income_order.status = %s)"; + $params[] = $order_status; + } $order_number = sanitize_text_field((string) ($args['order_number'] ?? '')); if ($order_number !== '') { $where[] = 'order_number LIKE %s'; diff --git a/src/User/Center.php b/src/User/Center.php index 5605dd9f..b8f52701 100644 --- a/src/User/Center.php +++ b/src/User/Center.php @@ -116,7 +116,7 @@ class Center { $settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_user_center_settings() : [ - 'tabs' => ['profile', 'posts', 'comments', 'favorites'], + 'tabs' => ['profile', 'comments', 'favorites'], 'avatar_upload' => true, 'cover_upload' => true, 'social_links' => true, @@ -135,12 +135,6 @@ class Center { 'priority' => 15, 'type' => 'panel', ], - 'posts' => [ - 'label' => __('我的文章', 'aksrt'), - 'icon' => 'file-alt', - 'priority' => 20, - 'type' => 'panel', - ], 'creator' => [ 'label' => __('创作中心', 'aksrt'), 'icon' => 'feather-alt', @@ -206,9 +200,12 @@ class Center { ]; $this->panels = []; - $configured = array_values(array_filter(array_map('sanitize_key', (array) ($settings['tabs'] ?? [])))); + $configured = array_values(array_filter( + array_map('sanitize_key', (array) ($settings['tabs'] ?? [])), + static fn(string $key): bool => $key !== 'posts' + )); if ($configured === []) { - $configured = ['profile', 'posts', 'comments', 'favorites']; + $configured = ['profile', 'comments', 'favorites']; } $level_on = class_exists('\AKSRT\User\Level') @@ -246,7 +243,7 @@ class Center { if ($vip_on && !in_array('vip', $order, true)) { $insert_at = count($order); - foreach (['credits', 'favorites', 'posts'] as $anchor) { + foreach (['credits', 'favorites'] as $anchor) { $idx = array_search($anchor, $order, true); if ($idx !== false) { $insert_at = (int) $idx + 1; @@ -278,7 +275,7 @@ class Center { if ($revenue_tab_on && !in_array('revenue', $order, true)) { $insert_at = count($order); - foreach (['credits', 'favorites', 'posts'] as $anchor) { + foreach (['credits', 'favorites'] as $anchor) { $idx = array_search($anchor, $order, true); if ($idx !== false) { $insert_at = (int) $idx + 1;