feat: unify referral promotion tabs and compact earnings UI

This commit is contained in:
2026-08-16 20:40:21 +08:00
parent 8799063c6c
commit ff730ab593
7 changed files with 144 additions and 52 deletions
+3 -4
View File
@@ -599,10 +599,9 @@ if (!function_exists('aksrt_get_post_rebate_discount')) {
return 0.0;
}
$uid = $user_id > 0 ? $user_id : (function_exists('get_current_user_id') ? (int) get_current_user_id() : 0);
$referrer_id = 0;
if (class_exists('\AKSRT\Credits\Invite') && method_exists(\AKSRT\Credits\Invite::get_instance(), 'get_referrer')) {
$referrer_id = (int) \AKSRT\Credits\Invite::get_instance()->get_referrer($uid);
}
$referrer_id = class_exists('\AKSRT\Payment\ReferralAttribution')
? \AKSRT\Payment\ReferralAttribution::get_instance()->resolve($uid)
: 0;
if ($referrer_id <= 0) {
return 0.0;
}
@@ -46,7 +46,7 @@ if ($details_text === '') {
$revenue_request = is_array($context['revenue_request'] ?? null) ? $context['revenue_request'] : [];
$active_reward_tab = sanitize_key((string) ($revenue_request['reward_tab'] ?? ($_GET['reward_tab'] ?? 'detail')));
if (!in_array($active_reward_tab, ['detail', 'orders'], true)) {
if (!in_array($active_reward_tab, ['detail', 'orders', 'users'], true)) {
$active_reward_tab = 'detail';
}
$base_url = function_exists('aksrt_get_user_center_tab_url')
@@ -67,6 +67,15 @@ $commission_view = class_exists('\AKSRT\Payment\CommissionLedger')
])
: ['items' => [], 'total' => 0, 'max_pages' => 1, 'page' => 1];
$commission_items = (array) ($commission_view['items'] ?? []);
$user_page = max(1, (int) ($_GET['user_page'] ?? 1));
$user_view = class_exists('\AKSRT\Payment\ReferralAttribution')
? \AKSRT\Payment\ReferralAttribution::get_instance()->list_referred_users($user_id, $user_page, 10)
: ['items' => [], 'total' => 0, 'max_pages' => 1, 'page' => 1];
$user_total_pages = max(1, (int) ($user_view['max_pages'] ?? 1));
if ($user_page > $user_total_pages && class_exists('\AKSRT\Payment\ReferralAttribution')) {
$user_page = $user_total_pages;
$user_view = \AKSRT\Payment\ReferralAttribution::get_instance()->list_referred_users($user_id, $user_page, 10);
}
$commission_total_pages = max(1, (int) ($commission_view['max_pages'] ?? ceil(max(1, (int) ($commission_view['total'] ?? 0)) / 10)));
if ($commission_page > $commission_total_pages) {
$commission_page = $commission_total_pages;
@@ -104,44 +113,31 @@ $status_labels = [
<?php endif; ?>
</article>
</section>
<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>
<p class="uc-affiliate-note"><?php esc_html_e('仅会员和付费内容订单参与返佣;首次触达后 30 天内绑定,禁止自邀和换绑。', 'aksrt'); ?></p>
<section class="uc-reward-area" aria-labelledby="uc-reward-area-title">
<div class="uc-reward-area__heading">
<h3 id="uc-reward-area-title"><?php esc_html_e('佣金详情', 'aksrt'); ?></h3>
<span><?php esc_html_e('推广订单与结算状态', 'aksrt'); ?></span>
<h3 id="uc-reward-area-title"><?php esc_html_e('推广收益', 'aksrt'); ?></h3>
<span><?php esc_html_e('推广链接、佣金订单与推广用户', 'aksrt'); ?></span>
</div>
<nav class="uc-reward-tabs" aria-label="<?php esc_attr_e('收益明细', 'aksrt'); ?>">
<a <?php echo $active_reward_tab === 'detail' ? 'aria-current="page"' : ''; ?> class="<?php echo $active_reward_tab === 'detail' ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('detail')); ?>"><?php esc_html_e('佣金详情', 'aksrt'); ?></a>
<a <?php echo $active_reward_tab === 'detail' ? 'aria-current="page"' : ''; ?> class="<?php echo $active_reward_tab === 'detail' ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('detail')); ?>"><?php esc_html_e('佣金详细', 'aksrt'); ?></a>
<a <?php echo $active_reward_tab === 'orders' ? 'aria-current="page"' : ''; ?> class="<?php echo $active_reward_tab === 'orders' ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('orders')); ?>"><?php esc_html_e('佣金明细', 'aksrt'); ?></a>
<a <?php echo $active_reward_tab === 'users' ? 'aria-current="page"' : ''; ?> class="<?php echo $active_reward_tab === 'users' ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('users')); ?>"><?php esc_html_e('推广用户', 'aksrt'); ?></a>
</nav>
<?php if ($active_reward_tab === 'detail') : ?>
<div class="uc-reward-pane uc-reward-pane--detail">
<section class="uc-reward-block uc-reward-block--details" aria-labelledby="uc-details-title">
<div class="uc-reward-block__heading"><h4 id="uc-details-title"><?php esc_html_e('返佣详解', 'aksrt'); ?></h4></div>
<div class="uc-reward-richtext"><?php echo wp_kses_post(wpautop($details_text)); ?></div>
</section>
<div class="uc-reward-pane uc-reward-pane--detail" data-aksrt-promotion-page>
<div class="uc-promotion-summary-list">
<div class="uc-promotion-summary-row uc-promotion-summary-row--link">
<span><?php esc_html_e('推广链接', 'aksrt'); ?></span>
<input type="text" readonly data-affiliate-link aria-label="<?php esc_attr_e('推广链接', 'aksrt'); ?>">
<button type="button" class="btn-primary btn-sm" data-affiliate-copy><?php esc_html_e('复制', 'aksrt'); ?></button>
<small data-affiliate-feedback role="status" aria-live="polite"></small>
</div>
<div class="uc-promotion-summary-row"><span><?php esc_html_e('佣金比例', 'aksrt'); ?></span><strong data-affiliate-ratio><?php echo esc_html((string) $commission_ratio); ?>%</strong></div>
<div class="uc-promotion-summary-row"><span><?php esc_html_e('推广人数', 'aksrt'); ?></span><strong data-affiliate-promoters>—</strong><em><?php esc_html_e('人', 'aksrt'); ?></em></div>
<div class="uc-promotion-summary-row uc-promotion-summary-row--total"><span><?php esc_html_e('累计佣金', 'aksrt'); ?></span><div><strong>累计<?php echo esc_html($format_amount($commission_stats['total'] ?? 0)); ?>元</strong><strong>已提现<?php echo esc_html($format_amount($commission_stats['withdrawn'] ?? 0)); ?>元</strong></div></div>
<div class="uc-promotion-summary-row uc-promotion-summary-row--explain"><span><?php esc_html_e('返佣详解', 'aksrt'); ?></span><div class="uc-reward-richtext"><?php echo wp_kses_post(wpautop($details_text)); ?></div></div>
</div>
</div>
<?php elseif ($active_reward_tab === 'orders') : ?>
<div class="uc-reward-pane">
@@ -160,10 +156,19 @@ $status_labels = [
<?php else : ?><p class="uc-reward-empty"><?php esc_html_e('暂无佣金订单', 'aksrt'); ?></p><?php endif; ?>
</div>
<?php else : ?>
<div class="uc-reward-pane"><p class="uc-reward-empty"><?php esc_html_e('暂无收益明细。', 'aksrt'); ?></p></div>
<div class="uc-reward-pane">
<div class="uc-reward-list-heading"><div><h4><?php esc_html_e('推广用户', 'aksrt'); ?></h4><p><?php esc_html_e('通过你的 ref 推广链接完成绑定的用户。', 'aksrt'); ?></p></div><strong><?php printf(esc_html__('%d 人', 'aksrt'), (int) ($user_view['total'] ?? 0)); ?></strong></div>
<?php if (!empty($user_view['items'])) : ?>
<div class="uc-promotion-user-list">
<?php foreach ($user_view['items'] as $item) : ?>
<article class="uc-promotion-user-row"><img src="<?php echo esc_url((string) ($item['avatar'] ?? '')); ?>" alt=""><div><strong><?php echo esc_html((string) ($item['name'] ?? __('推广用户', 'aksrt'))); ?></strong><small><?php echo esc_html((string) ($item['bound_at'] ?? '')); ?></small></div><span><?php esc_html_e('已绑定', 'aksrt'); ?></span></article>
<?php endforeach; ?>
</div>
<?php if ($user_total_pages > 1) : ?><nav class="uc-reward-pagination" aria-label="<?php esc_attr_e('推广用户分页', 'aksrt'); ?>"><?php for ($i = 1; $i <= $user_total_pages; $i++) : ?><a class="<?php echo $i === $user_page ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('users', ['user_page' => $i])); ?>"><?php echo esc_html((string) $i); ?></a><?php endfor; ?></nav><?php endif; ?>
<?php else : ?><p class="uc-reward-empty"><?php esc_html_e('暂无推广用户', 'aksrt'); ?></p><?php endif; ?>
</div>
<?php endif; ?>
</section>
</section>
</div>
<?php if ($withdraw_on) {
require __DIR__ . '/withdraw-modal.php';