Files
wordpress-theme-aksrt/templates/parts/user-center/uc-credits.php
T

60 lines
2.6 KiB
PHP

<?php
/**
* 用户中心 — 我的积分
*
* @package AKSRT
* @since 5.0.0
*/
defined('ABSPATH') || exit;
$user_id = get_current_user_id();
$credits_enabled = class_exists('AKSRT_Settings') && AKSRT_Settings::get_credits_settings()['enabled'] ?? false;
if (!$credits_enabled) {
return;
}
$balance = function_exists('aksrt_get_user_credits') ? aksrt_get_user_credits($user_id) : 0;
$currency_name = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_credits_settings()['currency_name'] ?? __('积分', 'aksrt') : __('积分', 'aksrt');
// 获取积分记录
$records = function_exists('aksrt_get_credit_logs') ? aksrt_get_credit_logs($user_id, 20) : [];
?>
<div class="uc-credits" id="uc-credits">
<!-- 积分概览 -->
<div class="uc-credits__overview">
<div class="uc-credits__balance">
<span class="uc-credits__balance-num"><?php echo esc_html(number_format($balance, 2)); ?></span>
<span class="uc-credits__balance-label"><?php echo esc_html($currency_name); ?></span>
</div>
</div>
<!-- 积分记录 -->
<?php if (!empty($records)) : ?>
<div class="uc-credits__records">
<h4 class="uc-credits__section-title"><?php esc_html_e('积分记录', 'aksrt'); ?></h4>
<div class="uc-credits__list">
<?php foreach ($records as $record) : ?>
<div class="uc-credits__record">
<div class="uc-credits__record-info">
<span class="uc-credits__record-desc"><?php echo esc_html($record['description'] ?? ''); ?></span>
<span class="uc-credits__record-date"><?php echo esc_html($record['date'] ?? ''); ?></span>
</div>
<span class="uc-credits__record-amount <?php echo ($record['amount'] ?? 0) > 0 ? 'uc-credits__record-amount--plus' : 'uc-credits__record-amount--minus'; ?>">
<?php echo ($record['amount'] ?? 0) > 0 ? '+' : ''; ?><?php echo esc_html(number_format($record['amount'] ?? 0, 2)); ?>
</span>
</div>
<?php endforeach; ?>
</div>
</div>
<?php else : ?>
<div class="empty-state empty-state--sm">
<div class="empty-state__icon"><i class="fas fa-coins"></i></div>
<p class="empty-state__title"><?php esc_html_e('暂无积分记录', 'aksrt'); ?></p>
<p class="empty-state__desc"><?php esc_html_e('每天签到、发布内容都可以获得积分哦~', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>