150 lines
9.2 KiB
PHP
150 lines
9.2 KiB
PHP
<?php
|
|
/**
|
|
* User center commission and promotion rewards panel.
|
|
*
|
|
* @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;
|
|
}
|
|
|
|
$affiliate = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::get_payment_affiliate_settings()
|
|
: [];
|
|
$withdrawal = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::get_withdrawal_settings()
|
|
: [];
|
|
$withdraw_on = !empty($affiliate['enabled'])
|
|
&& class_exists('\AKSRT\Credits\Balance')
|
|
&& \AKSRT\Credits\Balance::enabled();
|
|
if ($withdraw_on && class_exists('\AKSRT\Settings\Capabilities') && !\AKSRT\Settings\Capabilities::user_can('balance_withdraw', $user_id)) {
|
|
$withdraw_on = false;
|
|
}
|
|
$withdraw_min = max(1, (float) ($affiliate['min_withdrawal'] ?? $withdrawal['min_amount'] ?? 50));
|
|
$wallet_fmt = class_exists('\AKSRT\Credits\Balance')
|
|
? \AKSRT\Credits\Balance::format((float) \AKSRT\Credits\Balance::balance($user_id))
|
|
: '0.00';
|
|
|
|
$commission_stats = class_exists('\AKSRT\Payment\CommissionLedger')
|
|
? \AKSRT\Payment\CommissionLedger::get_instance()->overview($user_id)
|
|
: ['total' => 0, 'pending' => 0, 'settled' => 0, 'wallet' => 0];
|
|
$available_commission = class_exists('\AKSRT\Credits\Balance')
|
|
? (float) \AKSRT\Credits\Balance::balance($user_id)
|
|
: (float) ($commission_stats['settled'] ?? 0);
|
|
$vip_ratios = [];
|
|
$commission_ratio = (float) ($affiliate['ratio'] ?? 0);
|
|
$details_text = trim((string) ($affiliate['earnings_text'] ?? ''));
|
|
if ($details_text === '') {
|
|
$details_text = __('好友通过推广链接完成符合条件的订单后,系统会按当前佣金比例记录返佣,结算后进入可提现余额。', 'aksrt');
|
|
}
|
|
|
|
$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)) {
|
|
$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');
|
|
$reward_url = static function (string $tab, array $extra = []) use ($base_url): string {
|
|
return add_query_arg(array_merge(['reward_tab' => $tab], $extra), $base_url);
|
|
};
|
|
$format_amount = static function ($amount): string {
|
|
return number_format_i18n((float) $amount, 2);
|
|
};
|
|
|
|
$commission_page = max(1, (int) ($revenue_request['commission_page'] ?? ($_GET['commission_page'] ?? 1)));
|
|
$commission_view = class_exists('\AKSRT\Payment\CommissionLedger')
|
|
? \AKSRT\Payment\CommissionLedger::get_instance()->list_entries($user_id, [
|
|
'per_page' => 10,
|
|
'page' => $commission_page,
|
|
])
|
|
: ['items' => [], 'total' => 0, 'max_pages' => 1, 'page' => 1];
|
|
$commission_items = (array) ($commission_view['items'] ?? []);
|
|
$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;
|
|
if (class_exists('\AKSRT\Payment\CommissionLedger')) {
|
|
$commission_view = \AKSRT\Payment\CommissionLedger::get_instance()->list_entries($user_id, [
|
|
'per_page' => 10,
|
|
'page' => $commission_page,
|
|
]);
|
|
}
|
|
}
|
|
$commission_items = (array) ($commission_view['items'] ?? []);
|
|
$status_labels = [
|
|
'pending' => __('待结算', 'aksrt'),
|
|
'settled' => __('已结算', 'aksrt'),
|
|
'cancelled' => __('已取消', 'aksrt'),
|
|
];
|
|
?>
|
|
<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-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>
|
|
<div class="uc-commission-card__body">
|
|
<span><?php esc_html_e('佣金比例', 'aksrt'); ?></span>
|
|
<strong><?php echo esc_html((string) $commission_ratio); ?><small>%</small></strong>
|
|
<p><?php esc_html_e('普通用户推广订单返佣比例', 'aksrt'); ?></p>
|
|
</div>
|
|
</article>
|
|
<article class="uc-commission-card uc-commission-card--balance">
|
|
<div class="uc-commission-card__icon"><i class="fas fa-wallet" aria-hidden="true"></i></div>
|
|
<div class="uc-commission-card__body">
|
|
<span><?php esc_html_e('我的佣金', 'aksrt'); ?></span>
|
|
<strong><?php echo esc_html($format_amount($available_commission)); ?></strong>
|
|
<span><?php printf(esc_html__('累计佣金 %s,待结算 %s', 'aksrt'), esc_html($format_amount($commission_stats['total'] ?? 0)), esc_html($format_amount($commission_stats['pending'] ?? 0))); ?></span>
|
|
</div>
|
|
<?php if ($withdraw_on) : ?>
|
|
<button type="button" class="uc-commission-card__action" data-aksrt-withdraw-open><i class="fas fa-arrow-right" aria-hidden="true"></i><?php esc_html_e('立即提现', 'aksrt'); ?></button>
|
|
<?php endif; ?>
|
|
</article>
|
|
</section>
|
|
|
|
<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>
|
|
</div>
|
|
<nav class="uc-reward-tabs" aria-label="<?php esc_attr_e('收益明细', 'aksrt'); ?>">
|
|
<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>
|
|
</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>
|
|
<?php elseif ($active_reward_tab === 'orders') : ?>
|
|
<div class="uc-reward-pane">
|
|
<div class="uc-reward-list-heading"><div><h4><?php esc_html_e('佣金订单', 'aksrt'); ?></h4><p><?php esc_html_e('每页显示 10 条佣金记录。', 'aksrt'); ?></p></div><strong><?php printf(esc_html__('%d 条', 'aksrt'), (int) ($commission_view['total'] ?? 0)); ?></strong></div>
|
|
<?php if ($commission_items) : ?>
|
|
<div class="uc-commission-list">
|
|
<?php foreach ($commission_items as $item) :
|
|
$status = sanitize_key((string) ($item['status'] ?? 'pending'));
|
|
$source_user = !empty($item['source_user_id']) ? get_userdata((int) $item['source_user_id']) : null;
|
|
$source_name = $source_user instanceof WP_User ? $source_user->display_name : __('推广用户', 'aksrt');
|
|
?>
|
|
<article class="uc-commission-row"><span class="uc-commission-row__icon"><i class="fas fa-receipt" aria-hidden="true"></i></span><div class="uc-commission-row__main"><strong><?php echo esc_html($source_name); ?></strong><span><?php printf(esc_html__('订单 %s', 'aksrt'), esc_html((string) ($item['order_number'] ?? '-'))); ?></span><time><?php echo esc_html((string) ($item['created_at'] ?? '')); ?></time></div><div class="uc-commission-row__value"><strong><?php echo esc_html($format_amount((float) ($item['original_amount'] ?? 0) + (float) ($item['adjustment_total'] ?? 0))); ?></strong><span class="is-<?php echo esc_attr($status); ?>"><?php echo esc_html($status_labels[$status] ?? $status); ?></span></div></article>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php if ($commission_total_pages > 1) : ?><nav class="uc-reward-pagination" aria-label="<?php esc_attr_e('佣金明细分页', 'aksrt'); ?>"><?php for ($i = 1; $i <= $commission_total_pages; $i++) : ?><a class="<?php echo $i === $commission_page ? 'is-active' : ''; ?>" href="<?php echo esc_url($reward_url('orders', ['commission_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 else : ?>
|
|
<div class="uc-reward-pane"><p class="uc-reward-empty"><?php esc_html_e('暂无收益明细。', 'aksrt'); ?></p></div>
|
|
<?php endif; ?>
|
|
</section>
|
|
</div>
|
|
<?php if ($withdraw_on) {
|
|
require __DIR__ . '/withdraw-modal.php';
|
|
} ?>
|