134 lines
6.6 KiB
PHP
134 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* User center: growth level, route and experience history.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
|
|
$user_id = (int) ($context['user_id'] ?? get_current_user_id());
|
|
if ($user_id <= 0 || !class_exists('\AKSRT\User\Level')) {
|
|
return;
|
|
}
|
|
|
|
$cfg = \AKSRT\User\Level::settings();
|
|
if (empty($cfg['enabled'])) {
|
|
return;
|
|
}
|
|
|
|
$progress = \AKSRT\User\Level::get_progress($user_id);
|
|
$details = \AKSRT\User\Level::get_details($user_id);
|
|
$date_details = \AKSRT\User\Level::get_date_details($user_id);
|
|
$labels = \AKSRT\User\Level::integral_labels();
|
|
$opt = is_array($cfg['level_opt'] ?? null) ? $cfg['level_opt'] : [];
|
|
$today = current_time('Y-m-d');
|
|
$today_integral = max(0, (int) ($date_details[$today] ?? 0));
|
|
$day_max = \AKSRT\User\Level::day_max();
|
|
?>
|
|
<div class="uc-level-page">
|
|
<section class="uc-level-hero zib-widget">
|
|
<div class="uc-level-hero__identity">
|
|
<div class="uc-level-hero__icon">
|
|
<?php echo \AKSRT\User\Level::get_badge_html($user_id); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
</div>
|
|
<div>
|
|
<p><?php esc_html_e('我的等级', 'aksrt'); ?></p>
|
|
<h2><?php echo esc_html((string) $progress['name']); ?></h2>
|
|
</div>
|
|
</div>
|
|
<div class="uc-level-hero__stats">
|
|
<div><strong><?php echo esc_html((string) $progress['integral']); ?></strong><span><?php esc_html_e('累计经验', 'aksrt'); ?></span></div>
|
|
<div><strong><?php echo esc_html((string) $today_integral); ?><?php echo $day_max > 0 ? '/' . esc_html((string) $day_max) : ''; ?></strong><span><?php esc_html_e('今日经验', 'aksrt'); ?></span></div>
|
|
<div><strong><?php echo esc_html((string) $progress['remaining']); ?></strong><span><?php echo !empty($progress['is_max']) ? esc_html__('已达最高等级', 'aksrt') : esc_html__('升级还需', 'aksrt'); ?></span></div>
|
|
</div>
|
|
<div class="uc-level-hero__progress">
|
|
<div class="uc-level-hero__progress-meta">
|
|
<span><?php echo esc_html((string) $progress['integral']); ?> EXP</span>
|
|
<span><?php echo !empty($progress['is_max']) ? esc_html__('最高等级', 'aksrt') : esc_html((string) $progress['next_need']) . ' EXP'; ?></span>
|
|
</div>
|
|
<div class="uc-level-progress"><span style="width:<?php echo esc_attr((string) $progress['progress']); ?>%"></span></div>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="uc-level-section zib-widget">
|
|
<div class="uc-level-section__head"><h3><?php esc_html_e('成长路线', 'aksrt'); ?></h3><span><?php printf(esc_html__('最高 %d 级', 'aksrt'), (int) $cfg['max']); ?></span></div>
|
|
<div class="uc-level-road">
|
|
<?php for ($level = 1; $level <= (int) $cfg['max']; $level++) :
|
|
$need = $level === 1 ? 0 : max(0, (int) ($opt['upgrade_integral_' . $level] ?? (($level - 1) * 500 * $level)));
|
|
$name = \AKSRT\User\Level::get_level_name($level);
|
|
$state = $level < (int) $progress['level'] ? ' is-done' : ($level === (int) $progress['level'] ? ' is-current' : '');
|
|
?>
|
|
<div class="uc-level-road__item<?php echo esc_attr($state); ?>">
|
|
<div class="uc-level-road__icon">
|
|
<?php $icon = \AKSRT\User\Level::get_level_icon_url($level); ?>
|
|
<?php if ($icon !== '') : ?><img src="<?php echo esc_url($icon); ?>" alt="" loading="lazy"><?php else : ?><span>LV<?php echo esc_html((string) $level); ?></span><?php endif; ?>
|
|
</div>
|
|
<strong><?php echo esc_html($name); ?></strong>
|
|
<small><?php echo esc_html((string) $need); ?> EXP</small>
|
|
</div>
|
|
<?php endfor; ?>
|
|
</div>
|
|
</section>
|
|
|
|
<section class="uc-level-section zib-widget">
|
|
<div class="uc-level-section__head"><h3><?php esc_html_e('获取经验值', 'aksrt'); ?></h3><span><?php esc_html_e('完成互动即可成长', 'aksrt'); ?></span></div>
|
|
<div class="uc-level-methods">
|
|
<?php
|
|
$methods = \AKSRT\User\Level::integral_defaults();
|
|
$methods['checkin'] = 0;
|
|
$methods['referral'] = 0;
|
|
$methods['shop_gift'] = 0;
|
|
$referral_settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_referral_reward_settings() : [];
|
|
$methods['referral'] = max(0, (int) ($referral_settings['level_points'] ?? 0));
|
|
foreach ($methods as $key => $default_value) :
|
|
if ($key === 'day_max') continue;
|
|
$value = in_array($key, ['checkin', 'shop_gift'], true) ? 0 : ($key === 'referral' ? (int) $default_value : \AKSRT\User\Level::task_points($key));
|
|
if ($value <= 0 && !in_array($key, ['checkin', 'shop_gift'], true)) continue;
|
|
?>
|
|
<div class="uc-level-methods__item">
|
|
<span><i class="fas fa-bolt" aria-hidden="true"></i></span>
|
|
<div><strong><?php echo esc_html($labels[$key] ?? $key); ?></strong><small><?php echo in_array($key, ['checkin', 'shop_gift'], true) ? esc_html__('按活动或商品配置发放', 'aksrt') : esc_html__('完成后自动计入经验', 'aksrt'); ?></small></div>
|
|
<b><?php echo $value > 0 ? '+' . esc_html((string) $value) : esc_html__('动态', 'aksrt'); ?></b>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</section>
|
|
|
|
<div class="uc-level-history-grid">
|
|
<section class="uc-level-section zib-widget">
|
|
<div class="uc-level-section__head"><h3><?php esc_html_e('经验明细', 'aksrt'); ?></h3><span><?php esc_html_e('最近 50 条', 'aksrt'); ?></span></div>
|
|
<?php if ($details) : ?>
|
|
<div class="uc-level-ledger">
|
|
<?php foreach ($details as $row) :
|
|
$key = sanitize_key((string) ($row['key'] ?? ''));
|
|
$value = max(0, (int) ($row['value'] ?? 0));
|
|
?>
|
|
<div class="uc-level-ledger__row">
|
|
<span class="uc-level-ledger__icon"><i class="fas fa-chart-line" aria-hidden="true"></i></span>
|
|
<div><strong><?php echo esc_html($labels[$key] ?? $key); ?></strong><time><?php echo esc_html((string) ($row['time'] ?? '')); ?></time><small><?php printf(esc_html__('累计:%d', 'aksrt'), max(0, (int) ($row['integral'] ?? 0))); ?></small></div>
|
|
<b>+<?php echo esc_html((string) $value); ?></b>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php else : ?>
|
|
<p class="uc-level-empty"><?php esc_html_e('还没有经验获取记录。', 'aksrt'); ?></p>
|
|
<?php endif; ?>
|
|
</section>
|
|
|
|
<section class="uc-level-section zib-widget">
|
|
<div class="uc-level-section__head"><h3><?php esc_html_e('每日经验', 'aksrt'); ?></h3><span><?php esc_html_e('最近 30 天', 'aksrt'); ?></span></div>
|
|
<?php if ($date_details) : ?>
|
|
<div class="uc-level-dates">
|
|
<?php foreach ($date_details as $date => $value) : ?>
|
|
<div><time><?php echo esc_html((string) $date); ?></time><span>+<?php echo esc_html((string) max(0, (int) $value)); ?> EXP</span></div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php else : ?>
|
|
<p class="uc-level-empty"><?php esc_html_e('还没有每日经验记录。', 'aksrt'); ?></p>
|
|
<?php endif; ?>
|
|
</section>
|
|
</div>
|
|
</div>
|