Files
wordpress-theme-aksrt/inc/helpers/user-center-renderers/profile-credits.php
T
kate522 1f87ab3b1b feat(vip): Batch 3 dedicated user-center VIP tab
Register 我的会员 panel, zibll-style status/equity cards, sidebar deep-link,
and slim credits-tab entry so VIP is no longer nested only under assets.
2026-07-21 17:09:23 +08:00

160 lines
7.5 KiB
PHP

<?php
/**
* User center assets panel orchestrator (wallet + points).
*
* Zibll user-tab-balance parity: dual cards + tabbed ledgers.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
$dir = __DIR__;
$show_wallet = !empty($balance_enabled);
$show_credits = !empty($credits_enabled);
// Dual cards row (Zibll row gutters-10).
if ($show_wallet || $show_credits) :
?>
<div class="uc-assets-row<?php echo ($show_wallet && $show_credits) ? ' uc-assets-row--dual' : ''; ?>">
<?php if ($show_wallet) : ?>
<div class="uc-assets-col">
<?php
// Ledger moved to tab section below.
$skip_wallet_ledger = true;
require $dir . '/credits-wallet.php';
?>
</div>
<?php endif; ?>
<?php if ($show_credits) : ?>
<div class="uc-assets-col">
<?php require $dir . '/credits-balance.php'; ?>
</div>
<?php endif; ?>
</div>
<?php
endif;
if (!empty($show_vip)) {
// Slim entry to dedicated VIP tab (full shop lives under tab=vip).
$vip_url = function_exists('aksrt_get_user_center_tab_url')
? aksrt_get_user_center_tab_url('vip')
: '#';
echo '<div class="zib-widget flex ac jsb padding-15 mb15 uc-vip-assets-entry">';
echo '<div class="flex ac gap10"><i class="fas fa-crown c-yellow"></i><div><div class="font-bold">' . esc_html__('我的会员', 'aksrt') . '</div>';
echo '<div class="muted-2-color em09">' . esc_html__('查看权益、续费与升级', 'aksrt') . '</div></div></div>';
echo '<a class="but jb-yellow radius" href="' . esc_url($vip_url) . '">' . esc_html__('进入会员中心', 'aksrt') . '</a>';
echo '</div>';
}
if ($show_credits) {
require $dir . '/credits-signin.php';
}
if (class_exists('\AKSRT\User\Level')) {
require $dir . '/credits-level.php';
}
// Tabbed ledgers (Zibll record tabs).
if ($show_wallet || $show_credits) :
$active_record = isset($_GET['asset_tab']) ? sanitize_key(wp_unslash($_GET['asset_tab'])) : '';
if ($active_record === '' || !in_array($active_record, ['balance', 'points', 'points_free', 'points_date'], true)) {
$active_record = $show_wallet ? 'balance' : 'points';
}
$show_tasks = $show_credits && class_exists('\AKSRT\Credits\PointsFree') && \AKSRT\Credits\PointsFree::enabled();
?>
<div class="uc-asset-tabs">
<ul class="uc-asset-tabs__nav list-inline tab-nav-theme font-bold">
<?php if ($show_wallet) : ?>
<li class="<?php echo $active_record === 'balance' ? 'active' : ''; ?>">
<a href="#record_tab_balance" data-aksrt-asset-tab="balance"><?php esc_html_e('余额记录', 'aksrt'); ?></a>
</li>
<?php endif; ?>
<?php if ($show_credits) : ?>
<li class="<?php echo $active_record === 'points' ? 'active' : ''; ?>">
<a href="#record_tab_points" data-aksrt-asset-tab="points"><?php esc_html_e('积分记录', 'aksrt'); ?></a>
</li>
<?php endif; ?>
<?php if (!empty($show_tasks)) : ?>
<li class="<?php echo in_array($active_record, ['points_free', 'points_date'], true) ? 'active' : ''; ?>">
<a href="#record_tab_points_free" data-aksrt-asset-tab="points_free"><?php esc_html_e('积分任务', 'aksrt'); ?></a>
</li>
<?php endif; ?>
</ul>
<div class="uc-asset-tabs__content tab-content">
<?php if ($show_wallet) : ?>
<div class="tab-pane<?php echo $active_record === 'balance' ? ' is-active' : ''; ?>" id="record_tab_balance" data-aksrt-asset-pane="balance"<?php echo $active_record === 'balance' ? '' : ' hidden'; ?>>
<?php
$skip_wallet_ledger = false;
// Render only the ledger portion by reusing balance log markup.
$user_id = (int) ($user_id ?? 0);
$wallet_page = max(1, isset($_GET['wallet_page']) ? (int) $_GET['wallet_page'] : 1);
$wlog = class_exists('\AKSRT\Credits\Balance')
? \AKSRT\Credits\Balance::get_log(['user_id' => $user_id, 'page' => $wallet_page, 'per_page' => 10])
: ['items' => [], 'total' => 0];
?>
<div class="uc-transactions uc-transactions--wallet">
<?php if (!empty($wlog['items'])) : ?>
<div class="uc-transactions__list">
<?php foreach ($wlog['items'] as $row) :
$delta = (float) $row['delta'];
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
$delta_txt = ($delta > 0 ? '+' : '') . (class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format($delta) : number_format_i18n($delta, 2));
?>
<div class="uc-transactions__item">
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
<i class="fas fa-<?php echo $delta >= 0 ? 'arrow-up' : 'arrow-down'; ?>" aria-hidden="true"></i>
</div>
<div class="uc-transactions__info">
<div class="uc-transactions__reason">
<?php echo esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::reason_label((string) $row['reason']) : (string) $row['reason']); ?>
<?php if (!empty($row['remark'])) : ?>
<span class="uc-transactions__remark">(<?php echo esc_html((string) $row['remark']); ?>)</span>
<?php endif; ?>
</div>
<div class="uc-transactions__time"><?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?></div>
</div>
<div class="uc-transactions__amount">
<span class="uc-transactions__delta <?php echo esc_attr($delta_class); ?>"><?php echo esc_html($delta_txt); ?></span>
<span class="uc-transactions__balance"><?php printf(esc_html__('余额 %s', 'aksrt'), esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format((float) ($row['balance_after'] ?? 0)) : number_format_i18n((float) ($row['balance_after'] ?? 0), 2))); ?></span>
<?php if (!empty($row['ref_id'])) : ?>
<span class="uc-transactions__ref muted-2-color em09"><?php printf(esc_html__('单号 %s', 'aksrt'), esc_html((string) $row['ref_id'])); ?></span>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php
$total_pages = (int) ceil((int) ($wlog['total'] ?? 0) / 10);
if ($total_pages > 1 && function_exists('aksrt_render_profile_pagination')) {
aksrt_render_profile_pagination($total_pages, $wallet_page, 'wallet_page');
}
?>
<?php else : ?>
<div class="uc-transactions__empty">
<p><?php esc_html_e('还没有任何余额流水', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php if ($show_credits) : ?>
<div class="tab-pane<?php echo $active_record === 'points' ? ' is-active' : ''; ?>" id="record_tab_points" data-aksrt-asset-pane="points"<?php echo $active_record === 'points' ? '' : ' hidden'; ?>>
<?php require $dir . '/credits-transactions.php'; ?>
</div>
<?php endif; ?>
<?php if (!empty($show_tasks)) : ?>
<div class="tab-pane<?php echo $active_record === 'points_free' ? ' is-active' : ''; ?>" id="record_tab_points_free" data-aksrt-asset-pane="points_free"<?php echo $active_record === 'points_free' ? '' : ' hidden'; ?>>
<?php $points_tasks_pane = 'tasks'; require $dir . '/credits-points-tasks.php'; ?>
</div>
<div class="tab-pane<?php echo $active_record === 'points_date' ? ' is-active' : ''; ?>" id="tab_points_date" data-aksrt-asset-pane="points_date"<?php echo $active_record === 'points_date' ? '' : ' hidden'; ?>>
<?php $points_tasks_pane = 'date'; require $dir . '/credits-points-tasks.php'; ?>
</div>
<?php endif; ?>
</div>
</div>
<?php
endif;
?>