Wire product cat/tag archives to settings-driven sort and AJAX paging, seller product options/video/params editing, revenue withdraw form and order review submit — finishing remaining shop frontend gaps after buy-path.
173 lines
7.1 KiB
PHP
173 lines
7.1 KiB
PHP
<?php
|
|
/**
|
|
* Template Name: AKSRT - Revenue
|
|
* Template Post Type: page
|
|
*
|
|
* Creator revenue center: overview, ledger, withdraw request.
|
|
*
|
|
* @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();
|
|
$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'] ?? [];
|
|
|
|
$settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_withdrawal_settings() : [];
|
|
$min_amount = (float) ($settings['min_amount'] ?? 50);
|
|
$fee_rate = (float) ($settings['service_charge_rate'] ?? 0);
|
|
$withdraw_text = (string) ($settings['text'] ?? '');
|
|
|
|
$withdrawals = [];
|
|
if (class_exists('AKSRT_Withdrawal')) {
|
|
$withdrawals = AKSRT_Withdrawal::get_instance()->get_user_withdrawals($user_id, ['limit' => 20]);
|
|
}
|
|
|
|
$per_page = 20;
|
|
$paged = max(1, (int) ($_GET['rev_page'] ?? 1));
|
|
$total_records = count($records);
|
|
$total_pages = max(1, (int) ceil(max(1, $total_records) / $per_page));
|
|
if ($total_records === 0) {
|
|
$total_pages = 1;
|
|
}
|
|
$paged_records = array_slice($records, ($paged - 1) * $per_page, $per_page);
|
|
?>
|
|
|
|
<main id="main-content" class="site-main content-shell" tabindex="-1">
|
|
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
|
|
|
|
<div class="container aksrt-revenue-page" data-aksrt-revenue-page
|
|
data-min-amount="<?php echo esc_attr((string) $min_amount); ?>"
|
|
data-fee-rate="<?php echo esc_attr((string) $fee_rate); ?>">
|
|
<div class="aksrt-revenue-page__header">
|
|
<h1><?php esc_html_e('创作收益', 'aksrt'); ?></h1>
|
|
<p class="aksrt-revenue-page__subtitle"><?php esc_html_e('查看分成明细并发起提现。', 'aksrt'); ?></p>
|
|
</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" data-aksrt-revenue-balance>¥<?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>
|
|
|
|
<div class="aksrt-revenue-page__layout">
|
|
<section class="aksrt-revenue-page__panel">
|
|
<h2><?php esc_html_e('申请提现', 'aksrt'); ?></h2>
|
|
<?php if ($withdraw_text !== '') : ?>
|
|
<div class="aksrt-revenue-page__note"><?php echo wp_kses_post(wpautop($withdraw_text)); ?></div>
|
|
<?php endif; ?>
|
|
<form class="aksrt-revenue-page__withdraw-form" data-aksrt-withdraw-form>
|
|
<label>
|
|
<span><?php esc_html_e('提现金额', 'aksrt'); ?></span>
|
|
<input type="number" name="amount" min="<?php echo esc_attr((string) $min_amount); ?>" step="0.01" required>
|
|
</label>
|
|
<label>
|
|
<span><?php esc_html_e('提现方式', 'aksrt'); ?></span>
|
|
<select name="method">
|
|
<option value="alipay"><?php esc_html_e('支付宝', 'aksrt'); ?></option>
|
|
<option value="wechat"><?php esc_html_e('微信', 'aksrt'); ?></option>
|
|
<option value="bank"><?php esc_html_e('银行卡', 'aksrt'); ?></option>
|
|
</select>
|
|
</label>
|
|
<label>
|
|
<span><?php esc_html_e('收款账户信息', 'aksrt'); ?></span>
|
|
<textarea name="account_info" rows="3" required></textarea>
|
|
</label>
|
|
<p class="aksrt-revenue-page__fee-hint"><?php printf(esc_html__('手续费 %s%%', 'aksrt'), esc_html((string) $fee_rate)); ?></p>
|
|
<button type="submit" class="btn-primary"><?php esc_html_e('提交提现申请', 'aksrt'); ?></button>
|
|
<p class="aksrt-revenue-page__form-msg" data-aksrt-withdraw-msg hidden></p>
|
|
</form>
|
|
</section>
|
|
|
|
<section class="aksrt-revenue-page__panel">
|
|
<h2><?php esc_html_e('提现记录', 'aksrt'); ?></h2>
|
|
<?php if (!empty($withdrawals)) : ?>
|
|
<div class="aksrt-revenue-page__list" data-aksrt-withdraw-list>
|
|
<?php foreach ($withdrawals as $w) : ?>
|
|
<div class="aksrt-revenue-page__item">
|
|
<div>
|
|
<strong>¥<?php echo esc_html(number_format((float) ($w['amount'] ?? 0), 2)); ?></strong>
|
|
<span><?php echo esc_html((string) ($w['method'] ?? '')); ?></span>
|
|
</div>
|
|
<div>
|
|
<span><?php echo esc_html((string) ($w['status'] ?? '')); ?></span>
|
|
<time><?php echo esc_html((string) ($w['created_at'] ?? '')); ?></time>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php else : ?>
|
|
<p class="aksrt-revenue-page__empty"><?php esc_html_e('暂无提现记录', 'aksrt'); ?></p>
|
|
<?php endif; ?>
|
|
</section>
|
|
</div>
|
|
|
|
<section class="aksrt-revenue-page__section">
|
|
<h2><?php esc_html_e('收益明细', 'aksrt'); ?></h2>
|
|
<?php if (!empty($paged_records)) : ?>
|
|
<div class="aksrt-revenue-page__list">
|
|
<?php foreach ($paged_records as $rec) : ?>
|
|
<div class="aksrt-revenue-page__item">
|
|
<div>
|
|
<strong><?php echo esc_html((string) ($rec['title'] ?? '')); ?></strong>
|
|
<time><?php echo esc_html((string) ($rec['created_at'] ?? '')); ?></time>
|
|
</div>
|
|
<span class="<?php echo (($rec['type'] ?? '') === 'withdrawal') ? 'is-out' : 'is-in'; ?>">
|
|
<?php echo (($rec['type'] ?? '') === 'withdrawal') ? '-' : '+'; ?>¥<?php echo esc_html(number_format((float) ($rec['amount'] ?? 0), 2)); ?>
|
|
</span>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php if ($total_pages > 1 && $total_records > 0) : ?>
|
|
<nav class="aksrt-revenue-page__pagination">
|
|
<?php for ($i = 1; $i <= $total_pages; $i++) :
|
|
$url = add_query_arg(['rev_page' => $i]);
|
|
?>
|
|
<a class="<?php echo $i === $paged ? 'is-active' : ''; ?>" href="<?php echo esc_url($url); ?>"><?php echo (int) $i; ?></a>
|
|
<?php endfor; ?>
|
|
</nav>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<p class="aksrt-revenue-page__empty"><?php esc_html_e('暂无收益明细', 'aksrt'); ?></p>
|
|
<?php endif; ?>
|
|
</section>
|
|
</div>
|
|
</main>
|
|
|
|
<?php
|
|
wp_enqueue_script('aksrt-revenue', get_template_directory_uri() . '/assets/js/revenue.js', ['aksrt-script'], AKSRT_VERSION, true);
|
|
get_footer();
|