feat: merge promotion and earnings center

This commit is contained in:
2026-08-16 19:54:12 +08:00
parent f70eca09d1
commit 6dbb556d60
11 changed files with 65 additions and 87 deletions
+2
View File
@@ -416,6 +416,8 @@
});
}
window.AKSRTAffiliatePromotionInit = initAffiliatePromotion;
// ===== VIP 积分兑换 =====
+3 -2
View File
@@ -144,7 +144,7 @@
function reloadRevenuePanel() {
var current = document.querySelector('[data-aksrt-revenue-page]');
if (!current) return Promise.resolve();
var panelUrl = rest + '/user-center/panel/revenue';
var panelUrl = rest + '/user-center/panel/promotion';
var query = new URL(window.location.href).searchParams;
query.delete('tab');
panelUrl += '?' + query.toString();
@@ -171,7 +171,7 @@
link.addEventListener('click', function (event) {
event.preventDefault();
var targetUrl = new URL(link.href, window.location.href);
var panelUrl = rest + '/user-center/panel/revenue?' + targetUrl.searchParams.toString();
var panelUrl = rest + '/user-center/panel/promotion?' + targetUrl.searchParams.toString();
fetch(panelUrl, {
credentials: 'same-origin',
headers: { 'X-WP-Nonce': data.restNonce || data.nonce || '' }
@@ -187,6 +187,7 @@
current.replaceWith(next);
window.history.pushState({}, '', targetUrl);
window.AKSRTRevenueCenterInit(next);
if (typeof window.AKSRTAffiliatePromotionInit === 'function') window.AKSRTAffiliatePromotionInit();
if (typeof window.AKSRTWithdrawInit === 'function') window.AKSRTWithdrawInit();
});
}).catch(function () {
+4 -3
View File
@@ -82,10 +82,10 @@
}
target.classList.add('is-loading');
var url = restUrl.replace(/\/$/, '') + '/user-center/panel/' + encodeURIComponent(name);
if (name === 'creator' || name === 'revenue' || name === 'posts' || name === 'follow') {
if (name === 'creator' || name === 'promotion' || name === 'posts' || name === 'follow') {
var params = queryParams || new URLSearchParams(window.location.search);
var allowedParams = name === 'creator' ? ['income_page'] :
(name === 'revenue' ? ['reward_tab', 'commission_page', 'invite_page'] :
(name === 'promotion' ? ['reward_tab', 'commission_page', 'invite_page'] :
(name === 'posts' ? ['post_status', 'posts_page'] : ['follow_list', 'follow_page']));
allowedParams.forEach(function(key) {
if (params.get(key)) url += (url.indexOf('?') === -1 ? '?' : '&') + key + '=' + encodeURIComponent(params.get(key));
@@ -120,7 +120,8 @@
return loadPanel(name, forceLoad, queryParams).then(function() {
switchTo(name);
if (updateHistory) updateUrl(name);
if (typeof window.AKSRTRevenueCenterInit === 'function') window.AKSRTRevenueCenterInit(panels[name].panel);
if (name === 'promotion' && typeof window.AKSRTRevenueCenterInit === 'function') window.AKSRTRevenueCenterInit(panels[name].panel);
if (name === 'promotion' && typeof window.AKSRTAffiliatePromotionInit === 'function') window.AKSRTAffiliatePromotionInit();
}).catch(function() {
if (typeof showToast === 'function') showToast(i18n.networkError || '加载失败,请重试');
});
+7 -9
View File
@@ -135,6 +135,8 @@ if (!function_exists('aksrt_get_user_center_tab_url')) {
$tab = sanitize_key($tab);
if ('invite' === $tab) {
$tab = 'promotion';
} elseif ('revenue' === $tab) {
$tab = 'promotion';
}
return aksrt_get_user_center_url($tab);
}
@@ -181,7 +183,6 @@ if (!function_exists('aksrt_capture_user_center_view')) {
'orders' => 'orders',
'auth' => 'auth',
'promotion' => 'promotion',
'revenue' => 'revenue',
'settings' => 'settings',
'header' => 'header',
'sidebar' => 'sidebar',
@@ -206,7 +207,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', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'promotion', 'revenue', 'settings'];
$built_in_tabs = ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'promotion', 'settings'];
if (in_array($tab_key, $built_in_tabs, true)) {
return aksrt_capture_user_center_view($tab_key, $context);
}
@@ -317,6 +318,8 @@ if (!function_exists('aksrt_user_center_resolve_tabs')) {
$active = 'credits';
} elseif ('invite' === $active) {
$active = 'promotion';
} elseif ('revenue' === $active) {
$active = 'promotion';
} elseif ('vip' === $active) {
// Prefer dedicated vip tab when registered; else credits (VIP shop).
$active = in_array('vip', $keys, true) ? 'vip' : 'credits';
@@ -356,6 +359,7 @@ if (!function_exists('aksrt_user_center_runtime_config')) {
'tabAliases' => [
'signin' => 'credits',
'invite' => 'promotion',
'revenue' => 'promotion',
'assets' => 'credits',
// vip → vip when panel exists; SPA may still map missing keys via server resolve.
'vip' => 'vip',
@@ -507,11 +511,7 @@ if (!function_exists('aksrt_get_user_center_render_context')) {
$wallet_balance = (float) ($dashboard['wallet_balance'] ?? 0.0);
$runtime_config = aksrt_user_center_runtime_config($user_id, $tabs['default'], $active_tab, $tabs['urls']);
$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']);
$revenue_url = isset($tabs['tabs']['revenue'])
? aksrt_get_user_center_tab_url('revenue')
: '';
$render_context = [
'user_center_settings' => $user_center_settings,
@@ -535,7 +535,6 @@ 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() : '',
'revenue_url' => $revenue_url,
'per_page' => 10,
'posts_page' => max(1, isset($_GET['posts_page']) ? (int) $_GET['posts_page'] : 1),
'post_status_filter' => $post_status_filter,
@@ -550,7 +549,6 @@ if (!function_exists('aksrt_get_user_center_render_context')) {
'show_vip' => !empty($vip_settings['enabled']),
'show_credit_tabs' => $show_credit_tabs,
'affiliate_enabled' => $show_credit_tabs && !empty($affiliate_settings['enabled']),
'show_revenue_section' => $show_revenue_section,
'currency_name' => $currency_name,
'credit_balance' => (float) ($dashboard['credit_balance'] ?? 0.0),
'credits_enabled' => $show_credit_tabs,
@@ -1,27 +1,14 @@
<?php
/**
* User center promotion panel (invite / 推广中心).
* Unified user-center promotion earnings panel.
*
* Standalone dashboard tab for the forward-only promotion contract.
* The promotion tab is the single entry point for referral links, commission
* details and withdrawals. The renderer lives in profile-revenue.php so the
* existing earnings markup and AJAX refresh path remain in one place.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
$user_id = (int) ($context['user_id'] ?? get_current_user_id());
if ($user_id <= 0) {
echo '<div class="uc-panel-empty muted-2-color">' . esc_html__('请先登录', 'aksrt') . '</div>';
return;
}
$settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_affiliate_settings() : [];
?>
<section class="uc-promotion-page aksrt-affiliate-panel" data-aksrt-promotion-page>
<header class="uc-panel-heading"><h2><?php esc_html_e('推广中心', 'aksrt'); ?></h2><p><?php echo esc_html($settings['promotion_text'] ?? __('分享推广链接,好友完成会员或付费内容订单后获得佣金。', 'aksrt')); ?></p></header>
<div class="uc-affiliate-link-card" data-affiliate-card><div><span class="muted-2-color"><?php esc_html_e('推广链接', 'aksrt'); ?></span><input type="text" readonly data-affiliate-link aria-label="<?php esc_attr_e('推广链接', 'aksrt'); ?>"></div><button type="button" class="btn-primary btn-sm" data-affiliate-copy><i class="fas fa-copy" aria-hidden="true"></i><?php esc_html_e('复制链接', 'aksrt'); ?></button><p data-affiliate-feedback role="status" aria-live="polite"></p></div>
<div class="uc-affiliate-stats" data-affiliate-stats><article><span><?php esc_html_e('当前比例', 'aksrt'); ?></span><strong data-affiliate-ratio>—</strong></article><article><span><?php esc_html_e('推广人数', 'aksrt'); ?></span><strong data-affiliate-promoters>—</strong></article><article><span><?php esc_html_e('有效付费人数', 'aksrt'); ?></span><strong data-affiliate-payers>—</strong></article></div>
<form class="uc-affiliate-accounts" data-affiliate-accounts><label><?php esc_html_e('支付宝收款码/账户', 'aksrt'); ?><input type="text" name="alipay" autocomplete="off"></label><label><?php esc_html_e('微信收款码/账户', 'aksrt'); ?><input type="text" name="wechat" autocomplete="off"></label><button type="submit" class="btn-secondary btn-sm"><?php esc_html_e('保存收款方式', 'aksrt'); ?></button><p data-affiliate-account-feedback role="status" aria-live="polite"></p></form>
<p class="uc-affiliate-note"><?php esc_html_e('仅会员和付费内容订单参与返佣;首次触达后 30 天内绑定,禁止自邀和换绑。', 'aksrt'); ?></p>
</section>
require __DIR__ . '/profile-revenue.php';
@@ -50,8 +50,8 @@ if (!in_array($active_reward_tab, ['detail', 'orders'], true)) {
$active_reward_tab = 'detail';
}
$base_url = function_exists('aksrt_get_user_center_tab_url')
? aksrt_get_user_center_tab_url('revenue')
: home_url('/profile/?tab=revenue');
? aksrt_get_user_center_tab_url('promotion')
: home_url('/user/promotion/');
$reward_url = static function (string $tab, array $extra = []) use ($base_url): string {
return add_query_arg(array_merge(['reward_tab' => $tab], $extra), $base_url);
};
@@ -85,6 +85,34 @@ $status_labels = [
];
?>
<div class="aksrt-revenue-page uc-revenue-panel" data-aksrt-revenue-page data-min-amount="<?php echo esc_attr((string) $withdraw_min); ?>">
<section class="uc-affiliate-panel aksrt-affiliate-panel" data-aksrt-promotion-page aria-labelledby="uc-affiliate-title">
<header class="uc-panel-heading">
<h2 id="uc-affiliate-title"><?php esc_html_e('推广收益', 'aksrt'); ?></h2>
<p><?php echo esc_html($affiliate['promotion_text'] ?? __('分享推广链接,好友完成会员或付费内容订单后获得佣金。', 'aksrt')); ?></p>
</header>
<div class="uc-affiliate-link-card" data-affiliate-card>
<div>
<span class="muted-2-color"><?php esc_html_e('推广链接', 'aksrt'); ?></span>
<input type="text" readonly data-affiliate-link aria-label="<?php esc_attr_e('推广链接', 'aksrt'); ?>">
</div>
<button type="button" class="btn-primary btn-sm" data-affiliate-copy>
<i class="fas fa-copy" aria-hidden="true"></i><?php esc_html_e('复制链接', 'aksrt'); ?>
</button>
<p data-affiliate-feedback role="status" aria-live="polite"></p>
</div>
<div class="uc-affiliate-stats" data-affiliate-stats>
<article><span><?php esc_html_e('当前比例', 'aksrt'); ?></span><strong data-affiliate-ratio>—</strong></article>
<article><span><?php esc_html_e('推广人数', 'aksrt'); ?></span><strong data-affiliate-promoters>—</strong></article>
<article><span><?php esc_html_e('有效付费人数', 'aksrt'); ?></span><strong data-affiliate-payers>—</strong></article>
</div>
<form class="uc-affiliate-accounts" data-affiliate-accounts>
<label><?php esc_html_e('支付宝收款码/账户', 'aksrt'); ?><input type="text" name="alipay" autocomplete="off"></label>
<label><?php esc_html_e('微信收款码/账户', 'aksrt'); ?><input type="text" name="wechat" autocomplete="off"></label>
<button type="submit" class="btn-secondary btn-sm"><?php esc_html_e('保存收款方式', 'aksrt'); ?></button>
<p data-affiliate-account-feedback role="status" aria-live="polite"></p>
</form>
<p class="uc-affiliate-note"><?php esc_html_e('仅会员和付费内容订单参与返佣;首次触达后 30 天内绑定,禁止自邀和换绑。', 'aksrt'); ?></p>
</section>
<section class="uc-commission-summary" aria-label="<?php esc_attr_e('佣金概览', 'aksrt'); ?>">
<article class="uc-commission-card uc-commission-card--ratio">
<div class="uc-commission-card__icon"><i class="fas fa-percentage" aria-hidden="true"></i></div>
@@ -1,6 +1,6 @@
<?php
/**
* User center sidebar: creation and revenue center pair.
* User center sidebar: creation center card.
*
* @package AKSRT
*/
@@ -8,9 +8,8 @@
defined('ABSPATH') || exit;
$creation_url = isset($dashboard_tabs['creator']) ? aksrt_get_user_center_tab_url('creator') : '';
$revenue_url = (string) ($revenue_url ?? '');
if ($creation_url === '' && $revenue_url === '') {
if ($creation_url === '') {
return;
}
?>
@@ -22,11 +21,4 @@ if ($creation_url === '' && $revenue_url === '') {
<i class="fas fa-angle-right" aria-hidden="true"></i>
</a>
<?php endif; ?>
<?php if ($revenue_url !== '') : ?>
<a class="uc-center-card uc-center-card--revenue" href="<?php echo esc_url($revenue_url); ?>" data-tab="revenue">
<span class="uc-center-card__icon"><i class="fas fa-chart-line" aria-hidden="true"></i></span>
<span><strong><?php esc_html_e('推广收益', 'aksrt'); ?></strong><small><?php esc_html_e('返佣与收益提现', 'aksrt'); ?></small></span>
<i class="fas fa-angle-right" aria-hidden="true"></i>
</a>
<?php endif; ?>
</div>
@@ -10,31 +10,11 @@ defined('ABSPATH') || exit;
$level_url = isset($dashboard_tabs['level'])
? aksrt_get_user_center_tab_url('level')
: '';
$promotion_url = isset($dashboard_tabs['promotion'])
? aksrt_get_user_center_tab_url('promotion')
: '';
$revenue_url = isset($dashboard_tabs['revenue'])
? aksrt_get_user_center_tab_url('revenue')
: '';
$auth_url = isset($dashboard_tabs['auth']) ? aksrt_get_user_center_tab_url('auth') : '';
$orders_available = isset($dashboard_tabs['orders']);
$orders_url = $orders_available ? (string) ($orders_url ?? '') : '';
$services = array_values(array_filter([
[
'label' => __('推广中心', 'aksrt'),
'icon' => 'share-alt',
'tone' => 'promotion',
'url' => $promotion_url,
'tab' => 'promotion',
],
[
'label' => __('收益中心', 'aksrt'),
'icon' => 'chart-line',
'tone' => 'revenue',
'url' => $revenue_url,
'tab' => 'revenue',
],
[
'label' => __('我的等级', 'aksrt'),
'icon' => 'chart-line',
+4 -1
View File
@@ -53,9 +53,12 @@ add_action('template_redirect', function () {
return;
}
$tab = $tab === 'balance' ? 'credits' : sanitize_key($tab);
if ($tab === 'revenue') {
$tab = 'promotion';
}
$allowed = class_exists('\\AKSRT\\User\\Center')
? array_keys(\AKSRT\User\Center::get_instance()->get_dashboard_tabs())
: ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'revenue', 'settings'];
: ['profile', 'level', 'creator', 'posts', 'follow', 'comments', 'favorites', 'credits', 'vip', 'orders', 'auth', 'promotion', 'settings'];
if (!in_array($tab, $allowed, true)) {
global $wp_query;
if ($wp_query instanceof WP_Query) { $wp_query->set_404(); }
+1 -1
View File
@@ -20,7 +20,7 @@ if (!function_exists('aksrt_get_user_center_url')) :
*/
function aksrt_get_user_center_url(string $tab = ''): string {
$tab = sanitize_key($tab ?: 'vip');
$aliases = ['assets' => 'credits', 'signin' => 'credits', 'invite' => 'promotion', 'promotion' => 'promotion'];
$aliases = ['assets' => 'credits', 'signin' => 'credits', 'invite' => 'promotion', 'promotion' => 'promotion', 'revenue' => 'promotion'];
$tab = $aliases[$tab] ?? $tab;
$path_tab = $tab === 'credits' ? 'balance' : $tab;
return get_option('permalink_structure')
+7 -21
View File
@@ -55,6 +55,9 @@ class Center {
*/
public function rest_panel(\WP_REST_Request $request) {
$tab = sanitize_key((string) $request->get_param('tab'));
if ($tab === 'revenue') {
$tab = 'promotion';
}
$tabs = $this->get_dashboard_tabs();
if (!isset($tabs[$tab])) {
return new \WP_Error('aksrt_user_center_panel', __('用户中心面板不存在', 'aksrt'), ['status' => 404]);
@@ -76,7 +79,7 @@ class Center {
$context['creator_income_request'] = $income_request;
}
$revenue_request = [];
if ($tab === 'revenue') {
if ($tab === 'promotion') {
$reward_tab = sanitize_key((string) $request->get_param('reward_tab'));
if (!in_array($reward_tab, ['detail', 'orders'], true)) {
$reward_tab = 'detail';
@@ -182,18 +185,12 @@ class Center {
'priority' => 50,
'type' => 'panel',
],
'revenue' => [
'label' => __('收益中心', 'aksrt'),
'promotion' => [
'label' => __('推广收益', 'aksrt'),
'icon' => 'chart-line',
'priority' => 55,
'type' => 'panel',
],
'promotion' => [
'label' => __('推广中心', 'aksrt'),
'icon' => 'share-alt',
'priority' => 54,
'type' => 'panel',
],
'notif' => [
'label' => __('消息通知', 'aksrt'),
'icon' => 'bell',
@@ -226,8 +223,6 @@ class Center {
$balance_on = class_exists('\AKSRT\Credits\Balance') && \AKSRT\Credits\Balance::enabled();
$promotion_tab_on = class_exists('\AKSRT\Settings\Settings')
&& !empty(\AKSRT\Settings\Settings::get_affiliate_settings()['enabled']);
$revenue_tab_on = $promotion_tab_on || (class_exists('\AKSRT\Settings\Settings')
&& !empty(\AKSRT\Settings\Settings::get_payment_revenue_settings()['enabled']));
$creator_tab_on = class_exists('\AKSRT\Settings\Settings')
&& !empty(\AKSRT\Settings\Settings::get_payment_revenue_settings()['enabled']);
$vip_on = class_exists('\AKSRT\Settings\Settings')
@@ -295,7 +290,7 @@ class Center {
$order[] = 'credits';
}
if ($revenue_tab_on && !in_array('revenue', $order, true)) {
if ($promotion_tab_on && !in_array('promotion', $order, true)) {
$insert_at = count($order);
foreach (['credits', 'favorites'] as $anchor) {
$idx = array_search($anchor, $order, true);
@@ -304,12 +299,6 @@ class Center {
break;
}
}
array_splice($order, $insert_at, 0, ['revenue']);
}
if ($promotion_tab_on && !in_array('promotion', $order, true)) {
$insert_at = count($order);
$idx = array_search('revenue', $order, true);
if ($idx !== false) { $insert_at = (int) $idx; }
array_splice($order, $insert_at, 0, ['promotion']);
}
$auth_on = class_exists('\AKSRT\User\AuthApply')
@@ -331,9 +320,6 @@ class Center {
if ($key === 'credits' && !$credits_on && !$balance_on) {
continue;
}
if ($key === 'revenue' && !$revenue_tab_on) {
continue;
}
if ($key === 'promotion' && !$promotion_tab_on) {
continue;
}