Files
wordpress-theme-aksrt/inc/helpers/user-center-renderers/profile-credits.php
T
2026-08-25 05:59:50 +08:00

143 lines
6.2 KiB
PHP

<?php
/**
* User center assets panel orchestrator (wallet + points).
*
* legacy 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 (legacy 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 ($show_wallet || $show_credits) {
require $dir . '/transfer-modal.php';
}
// Tabbed ledgers (legacy record tabs).
if ($show_wallet || $show_credits) :
$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 = \AKSRT\Ledger\LedgerQuery::get_instance()->history(['user_id' => $user_id, 'asset' => 'balance', 'page' => $wallet_page, 'per_page' => 10]);
?>
<div class="uc-transactions uc-transactions--wallet">
<?php if (!empty($wlog['items'])) : ?>
<div class="uc-transactions__list">
<?php foreach ($wlog['items'] as $row) :
$delta = (int) $row['delta_minor'];
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
$record_note = (string) $row['reason'] === 'points_exchange'
? (string) $row['ref_key']
: (string) $row['remark'];
if (in_array((string) $row['reason'], ['withdraw_hold', 'withdraw_refund'], true)) {
$record_note = (string) ($row['withdrawal_number'] ?? '');
}
?>
<div class="uc-transactions__item">
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
<i class="fa 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(aksrt_asset_reason_label((string) $row['reason'])); ?>
<?php if ($record_note !== '') : ?>
<span class="uc-transactions__remark">(<?php echo esc_html($record_note); ?>)</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>
</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;
?>