fix(user-center): close creator income review gaps

This commit is contained in:
2026-08-07 13:16:10 +08:00
parent c16add0807
commit cfb0a1368c
6 changed files with 56 additions and 62 deletions
+22 -6
View File
@@ -70,17 +70,17 @@
closeDrawer(); closeDrawer();
} }
function loadPanel(name) { function loadPanel(name, forceLoad, queryParams) {
if (!panels[name]) return Promise.reject(new Error('panel-not-found')); if (!panels[name]) return Promise.reject(new Error('panel-not-found'));
var target = panels[name].panel; 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; if (target._aksrtPanelRequest) return target._aksrtPanelRequest;
var restUrl = (window.aksrtData && (window.aksrtData.restUrl || window.aksrtData.apiUrl)) || cfg.restUrl || ''; var restUrl = (window.aksrtData && (window.aksrtData.restUrl || window.aksrtData.apiUrl)) || cfg.restUrl || '';
if (!restUrl) return Promise.reject(new Error('rest-unavailable')); if (!restUrl) return Promise.reject(new Error('rest-unavailable'));
target.classList.add('is-loading'); target.classList.add('is-loading');
var url = restUrl.replace(/\/$/, '') + '/user-center/panel/' + encodeURIComponent(name); var url = restUrl.replace(/\/$/, '') + '/user-center/panel/' + encodeURIComponent(name);
if (name === 'creator') { if (name === 'creator') {
var params = new URLSearchParams(window.location.search); var params = queryParams || new URLSearchParams(window.location.search);
['income_page'].forEach(function(key) { ['income_page'].forEach(function(key) {
if (params.get(key)) url += (url.indexOf('?') === -1 ? '?' : '&') + key + '=' + encodeURIComponent(params.get(key)); if (params.get(key)) url += (url.indexOf('?') === -1 ? '?' : '&') + key + '=' + encodeURIComponent(params.get(key));
}); });
@@ -101,9 +101,9 @@
return target._aksrtPanelRequest; return target._aksrtPanelRequest;
} }
function activate(name, updateHistory) { function activate(name, updateHistory, forceLoad, queryParams) {
if (!panels[name]) name = defaultTab; if (!panels[name]) name = defaultTab;
return loadPanel(name).then(function() { return loadPanel(name, forceLoad, queryParams).then(function() {
switchTo(name); switchTo(name);
if (updateHistory) updateUrl(name); if (updateHistory) updateUrl(name);
if (typeof window.AKSRTRevenueCenterInit === 'function') window.AKSRTRevenueCenterInit(panels[name].panel); if (typeof window.AKSRTRevenueCenterInit === 'function') window.AKSRTRevenueCenterInit(panels[name].panel);
@@ -138,7 +138,23 @@
activate(this.getAttribute('data-tab'), true); 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 (drawerTrigger) drawerTrigger.addEventListener('click', openDrawer);
if (drawerOverlay) drawerOverlay.addEventListener('click', closeDrawer); if (drawerOverlay) drawerOverlay.addEventListener('click', closeDrawer);
activate(tabFromUrl(), false); activate(tabFromUrl(), false);
+2 -44
View File
@@ -147,7 +147,6 @@ if (!function_exists('aksrt_capture_user_center_view')) {
$map = [ $map = [
'level' => 'level', 'level' => 'level',
'profile' => 'form', 'profile' => 'form',
'posts' => 'posts',
'creator' => 'creator', 'creator' => 'creator',
'comments' => 'comments', 'comments' => 'comments',
'favorites' => 'favorites', 'favorites' => 'favorites',
@@ -180,7 +179,7 @@ if (!function_exists('aksrt_capture_user_center_panel')) {
* Capture a built-in or registered user-center panel body. * Capture a built-in or registered user-center panel body.
*/ */
function aksrt_capture_user_center_panel(string $tab_key, array $tab, array $context): string { 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)) { if (in_array($tab_key, $built_in_tabs, true)) {
return aksrt_capture_user_center_view($tab_key, $context); 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() ? \AKSRT\User\Center::get_instance()->get_dashboard_tabs()
: [ : [
'profile' => ['label' => __('个人信息', 'aksrt'), 'icon' => 'user'], 'profile' => ['label' => __('个人信息', 'aksrt'), 'icon' => 'user'],
'posts' => ['label' => __('我的文章', 'aksrt'), 'icon' => 'file-alt'],
'comments' => ['label' => __('我的评论', 'aksrt'), 'icon' => 'comment'], 'comments' => ['label' => __('我的评论', 'aksrt'), 'icon' => 'comment'],
'favorites' => ['label' => __('我的收藏', 'aksrt'), 'icon' => 'star'], 'favorites' => ['label' => __('我的收藏', 'aksrt'), 'icon' => 'star'],
'settings' => ['label' => __('账号设置', 'aksrt'), 'icon' => 'cog'], '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<string,int>,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')) { if (!function_exists('aksrt_user_center_runtime_config')) {
/** /**
* Frontend runtime config injected into the private user center page. * 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') $user_center_settings = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_user_center_settings() ? \AKSRT\Settings\Settings::get_user_center_settings()
: [ : [
'tabs' => ['profile', 'posts', 'comments', 'favorites'], 'tabs' => ['profile', 'comments', 'favorites'],
'avatar_upload' => true, 'avatar_upload' => true,
'cover_upload' => true, 'cover_upload' => true,
'social_links' => 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) ? \AKSRT\User\Follow::get_instance()->get_follower_count($user_id)
: 0; : 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(); $svgs = aksrt_user_center_empty_svgs();
require_once AKSRT_DIR . '/templates/parts/user-shared-helpers.php'; 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); $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() : []; $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']); $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']) $revenue_url = isset($tabs['tabs']['revenue'])
? aksrt_get_user_center_tab_url('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, '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, '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() : '', '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, 'revenue_url' => $revenue_url,
'per_page' => 10, '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), '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), '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_comment' => $svgs['comment'],
'svg_empty_favorite' => $svgs['favorite'], 'svg_empty_favorite' => $svgs['favorite'],
'orders_url' => function_exists('aksrt_get_user_center_tab_url') 'orders_url' => function_exists('aksrt_get_user_center_tab_url')
+14 -1
View File
@@ -40,14 +40,21 @@ class PayIncome {
} }
$status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $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; $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; $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'])) : ''; $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_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'])) : ''; $date_to = isset($_GET['date_to']) ? sanitize_text_field((string) wp_unslash($_GET['date_to'])) : '';
$page_num = max(1, (int) ($_GET['paged'] ?? 1)); $page_num = max(1, (int) ($_GET['paged'] ?? 1));
$per_page = 20; $per_page = 20;
$order_statuses = class_exists('\\AKSRT\\Payment\\Order')
? \AKSRT\Payment\Order::get_valid_statuses()
: [];
$svc = \AKSRT\Payment\Revenue::get_instance(); $svc = \AKSRT\Payment\Revenue::get_instance();
$stats = $user_id > 0 ? $svc->get_stats($user_id) : $svc->get_stats(); $stats = $user_id > 0 ? $svc->get_stats($user_id) : $svc->get_stats();
@@ -76,6 +83,11 @@ class PayIncome {
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label)); printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($status, $key, false), esc_html($label));
} }
echo '</select> '; echo '</select> ';
echo '<select name="order_status"><option value="">' . esc_html__('全部订单状态', 'aksrt') . '</option>';
foreach ((array) $order_statuses as $key => $label) {
printf('<option value="%s"%s>%s</option>', esc_attr($key), selected($order_status, $key, false), esc_html($label));
}
echo '</select> ';
echo '<input type="number" min="0" name="user_id" value="' . esc_attr($user_id > 0 ? (string) $user_id : '') . '" placeholder="' . esc_attr__('用户 ID', 'aksrt') . '" class="small-text" /> '; echo '<input type="number" min="0" name="user_id" value="' . esc_attr($user_id > 0 ? (string) $user_id : '') . '" placeholder="' . esc_attr__('用户 ID', 'aksrt') . '" class="small-text" /> ';
echo '<input type="number" min="0" name="post_id" value="' . esc_attr($post_id > 0 ? (string) $post_id : '') . '" placeholder="' . esc_attr__('文章 ID', 'aksrt') . '" class="small-text" /> '; echo '<input type="number" min="0" name="post_id" value="' . esc_attr($post_id > 0 ? (string) $post_id : '') . '" placeholder="' . esc_attr__('文章 ID', 'aksrt') . '" class="small-text" /> ';
echo '<select name="currency"><option value="">' . esc_html__('全部货币', 'aksrt') . '</option><option value="CNY"' . selected($currency, 'CNY', false) . '>CNY</option><option value="points"' . selected($currency, 'points', false) . '>' . esc_html__('积分', 'aksrt') . '</option></select> '; echo '<select name="currency"><option value="">' . esc_html__('全部货币', 'aksrt') . '</option><option value="CNY"' . selected($currency, 'CNY', false) . '>CNY</option><option value="points"' . selected($currency, 'points', false) . '>' . esc_html__('积分', 'aksrt') . '</option></select> ';
@@ -89,6 +101,7 @@ class PayIncome {
$list_args = [ $list_args = [
'status' => $status, 'status' => $status,
'order_status' => $order_status,
'limit' => $per_page, 'limit' => $per_page,
'offset' => ($page_num - 1) * $per_page, 'offset' => ($page_num - 1) * $per_page,
'post_id' => $post_id, 'post_id' => $post_id,
+1
View File
@@ -254,6 +254,7 @@ class PaymentController extends ControllerBase {
'user_id' => max(0, (int) $request->get_param('user_id')), 'user_id' => max(0, (int) $request->get_param('user_id')),
'post_id' => max(0, (int) $request->get_param('post_id')), 'post_id' => max(0, (int) $request->get_param('post_id')),
'currency' => sanitize_key((string) $request->get_param('currency')), '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')), 'order_number' => sanitize_text_field((string) $request->get_param('order_number')),
'date_from' => sanitize_text_field((string) $request->get_param('date_from')), 'date_from' => sanitize_text_field((string) $request->get_param('date_from')),
'date_to' => sanitize_text_field((string) $request->get_param('date_to')), 'date_to' => sanitize_text_field((string) $request->get_param('date_to')),
+9
View File
@@ -396,6 +396,15 @@ class Revenue {
$where[] = 'currency = %s'; $where[] = 'currency = %s';
$params[] = $currency; $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'] ?? '')); $order_number = sanitize_text_field((string) ($args['order_number'] ?? ''));
if ($order_number !== '') { if ($order_number !== '') {
$where[] = 'order_number LIKE %s'; $where[] = 'order_number LIKE %s';
+8 -11
View File
@@ -116,7 +116,7 @@ class Center {
$settings = class_exists('\AKSRT\Settings\Settings') $settings = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_user_center_settings() ? \AKSRT\Settings\Settings::get_user_center_settings()
: [ : [
'tabs' => ['profile', 'posts', 'comments', 'favorites'], 'tabs' => ['profile', 'comments', 'favorites'],
'avatar_upload' => true, 'avatar_upload' => true,
'cover_upload' => true, 'cover_upload' => true,
'social_links' => true, 'social_links' => true,
@@ -135,12 +135,6 @@ class Center {
'priority' => 15, 'priority' => 15,
'type' => 'panel', 'type' => 'panel',
], ],
'posts' => [
'label' => __('我的文章', 'aksrt'),
'icon' => 'file-alt',
'priority' => 20,
'type' => 'panel',
],
'creator' => [ 'creator' => [
'label' => __('创作中心', 'aksrt'), 'label' => __('创作中心', 'aksrt'),
'icon' => 'feather-alt', 'icon' => 'feather-alt',
@@ -206,9 +200,12 @@ class Center {
]; ];
$this->panels = []; $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 === []) { if ($configured === []) {
$configured = ['profile', 'posts', 'comments', 'favorites']; $configured = ['profile', 'comments', 'favorites'];
} }
$level_on = class_exists('\AKSRT\User\Level') $level_on = class_exists('\AKSRT\User\Level')
@@ -246,7 +243,7 @@ class Center {
if ($vip_on && !in_array('vip', $order, true)) { if ($vip_on && !in_array('vip', $order, true)) {
$insert_at = count($order); $insert_at = count($order);
foreach (['credits', 'favorites', 'posts'] as $anchor) { foreach (['credits', 'favorites'] as $anchor) {
$idx = array_search($anchor, $order, true); $idx = array_search($anchor, $order, true);
if ($idx !== false) { if ($idx !== false) {
$insert_at = (int) $idx + 1; $insert_at = (int) $idx + 1;
@@ -278,7 +275,7 @@ class Center {
if ($revenue_tab_on && !in_array('revenue', $order, true)) { if ($revenue_tab_on && !in_array('revenue', $order, true)) {
$insert_at = count($order); $insert_at = count($order);
foreach (['credits', 'favorites', 'posts'] as $anchor) { foreach (['credits', 'favorites'] as $anchor) {
$idx = array_search($anchor, $order, true); $idx = array_search($anchor, $order, true);
if ($idx !== false) { if ($idx !== false) {
$insert_at = (int) $idx + 1; $insert_at = (int) $idx + 1;