128 lines
5.7 KiB
PHP
128 lines
5.7 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: AKSRT - Revenue
|
|
* Template Post Type: page
|
|
*
|
|
* 创作者收益中心页面 — 显示收益概览、分成记录和提现入口
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
get_header();
|
|
|
|
if (!is_user_logged_in()) {
|
|
$login_url = function_exists('aksrt_get_login_url') ? aksrt_get_login_url() : wp_login_url(get_permalink());
|
|
wp_safe_redirect($login_url);
|
|
exit;
|
|
}
|
|
|
|
$user_id = get_current_user_id();
|
|
|
|
// 通过 helper 获取收益视图模型
|
|
$revenue_view = function_exists('aksrt_get_revenue_page_view')
|
|
? aksrt_get_revenue_page_view($user_id)
|
|
: ['balance' => 0, 'total_earned' => 0, 'total_withdrawn' => 0, 'records' => []];
|
|
|
|
$balance = (float) ($revenue_view['balance'] ?? 0);
|
|
$total_earned = (float) ($revenue_view['total_earned'] ?? 0);
|
|
$total_withdrawn = (float) ($revenue_view['total_withdrawn'] ?? 0);
|
|
$records = $revenue_view['records'] ?? [];
|
|
|
|
$per_page = 20;
|
|
$paged = max(1, (int) ($_GET['rev_page'] ?? 1));
|
|
$total_records = count($records);
|
|
$total_pages = max(1, (int) ceil($total_records / $per_page));
|
|
$paged_records = array_slice($records, ($paged - 1) * $per_page, $per_page);
|
|
?>
|
|
|
|
<div class="container aksrt-revenue-page">
|
|
<div class="aksrt-revenue-page__header">
|
|
<h2><?php esc_html_e('创作收益', 'aksrt'); ?></h2>
|
|
</div>
|
|
|
|
<!-- 收益概览 -->
|
|
<div class="aksrt-revenue-page__stats">
|
|
<div class="aksrt-revenue-page__stat-card">
|
|
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-wallet"></i></div>
|
|
<div class="aksrt-revenue-page__stat-info">
|
|
<span class="aksrt-revenue-page__stat-value">¥<?php echo esc_html(number_format($balance, 2)); ?></span>
|
|
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('可提现余额', 'aksrt'); ?></span>
|
|
</div>
|
|
</div>
|
|
<div class="aksrt-revenue-page__stat-card">
|
|
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-chart-line"></i></div>
|
|
<div class="aksrt-revenue-page__stat-info">
|
|
<span class="aksrt-revenue-page__stat-value">¥<?php echo esc_html(number_format($total_earned, 2)); ?></span>
|
|
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('累计收益', 'aksrt'); ?></span>
|
|
</div>
|
|
</div>
|
|
<div class="aksrt-revenue-page__stat-card">
|
|
<div class="aksrt-revenue-page__stat-icon"><i class="fas fa-money-check-alt"></i></div>
|
|
<div class="aksrt-revenue-page__stat-info">
|
|
<span class="aksrt-revenue-page__stat-value">¥<?php echo esc_html(number_format($total_withdrawn, 2)); ?></span>
|
|
<span class="aksrt-revenue-page__stat-label"><?php esc_html_e('已提现', 'aksrt'); ?></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 提现按钮 -->
|
|
<?php if ($balance > 0) : ?>
|
|
<div class="aksrt-revenue-page__actions">
|
|
<a href="<?php echo esc_url(add_query_arg(['action' => 'withdraw'])); ?>" class="aksrt-revenue-page__withdraw-btn">
|
|
<i class="fas fa-hand-holding-usd"></i> <?php esc_html_e('申请提现', 'aksrt'); ?>
|
|
</a>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- 分成记录 -->
|
|
<div class="aksrt-revenue-page__section">
|
|
<h3><?php esc_html_e('收益明细', 'aksrt'); ?></h3>
|
|
|
|
<?php if (!empty($paged_records)) : ?>
|
|
<div class="aksrt-revenue-page__list">
|
|
<?php foreach ($paged_records as $record) :
|
|
$r_type = (string) ($record['type'] ?? 'earning');
|
|
?>
|
|
<div class="aksrt-revenue-page__item">
|
|
<div class="aksrt-revenue-page__item-icon">
|
|
<i class="<?php echo $r_type === 'withdrawal' ? 'fas fa-arrow-up' : 'fas fa-arrow-down'; ?>"
|
|
style="color: <?php echo $r_type === 'withdrawal' ? '#f5222d' : '#52c41a'; ?>;"></i>
|
|
</div>
|
|
<div class="aksrt-revenue-page__item-info">
|
|
<span class="aksrt-revenue-page__item-title"><?php echo esc_html($record['title'] ?? ''); ?></span>
|
|
<span class="aksrt-revenue-page__item-time"><?php echo esc_html($record['created_at'] ?? ''); ?></span>
|
|
</div>
|
|
<div class="aksrt-revenue-page__item-amount" style="color: <?php echo $r_type === 'withdrawal' ? '#f5222d' : '#52c41a'; ?>;">
|
|
<?php echo $r_type === 'withdrawal' ? '-' : '+'; ?>¥<?php echo esc_html(number_format((float) ($record['amount'] ?? 0), 2)); ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<?php if ($total_pages > 1) : ?>
|
|
<div class="aksrt-revenue-page__pagination">
|
|
<?php for ($i = 1; $i <= $total_pages; $i++) :
|
|
$page_url = add_query_arg(['rev_page' => $i]);
|
|
?>
|
|
<?php if ($i === $paged) : ?>
|
|
<span class="aksrt-revenue-page__page-chip is-active"><?php echo esc_html((string) $i); ?></span>
|
|
<?php else : ?>
|
|
<a href="<?php echo esc_url($page_url); ?>" class="aksrt-revenue-page__page-chip"><?php echo esc_html((string) $i); ?></a>
|
|
<?php endif; ?>
|
|
<?php endfor; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php else : ?>
|
|
<div class="aksrt-revenue-page__empty">
|
|
<i class="fas fa-chart-pie"></i>
|
|
<p><?php esc_html_e('暂无收益记录', 'aksrt'); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php get_footer(); ?>
|