179 lines
7.6 KiB
PHP
179 lines
7.6 KiB
PHP
<?php
|
|
/**
|
|
* User center profile credits part.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
$context = is_array($args['context'] ?? null) ? $args['context'] : [];
|
|
extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
|
|
?>
|
|
<?php
|
|
$balance = function_exists( 'aksrt_user_credits' ) ? aksrt_user_credits( $user_id ) : 0;
|
|
$currency_name = class_exists( 'AKSRT_Settings' ) ? AKSRT_Settings::get_currency_name() : __( '积分', 'aksrt' );
|
|
$credits_enabled = class_exists( 'AKSRT_Settings' ) && AKSRT_Settings::credits_enabled();
|
|
$vip_settings = class_exists( 'AKSRT_Settings' ) ? AKSRT_Settings::get_payment_vip_settings() : [];
|
|
$show_vip_card = ! empty( $vip_settings['enabled'] );
|
|
$is_vip_user = function_exists( 'aksrt_is_vip' ) && aksrt_is_vip( $user_id );
|
|
$vip_badge_text = function_exists( 'aksrt_get_vip_badge_text' ) ? aksrt_get_vip_badge_text() : 'VIP';
|
|
?>
|
|
<!-- ==================== 账户余额 ==================== -->
|
|
|
|
<!-- 余额卡片 -->
|
|
<div class="uc-balance-card">
|
|
<div class="uc-balance-card__bg"></div>
|
|
<div class="uc-balance-card__content">
|
|
<div class="uc-balance-card__header">
|
|
<span class="uc-balance-card__label"><?php esc_html_e( '账户余额', 'aksrt' ); ?></span>
|
|
<span class="uc-balance-card__currency"><?php echo esc_html( $currency_name ); ?></span>
|
|
</div>
|
|
<div class="uc-balance-card__amount">
|
|
<span class="uc-balance-card__value"><?php echo esc_html( aksrt_format_credits( $balance ) ); ?></span>
|
|
</div>
|
|
<?php if ( $credits_enabled ) : ?>
|
|
<div class="uc-balance-card__actions" data-aksrt-signin>
|
|
<span class="uc-balance-card__sign-status" data-signin-status></span>
|
|
<button type="button" class="uc-balance-card__sign-btn" data-signin-btn disabled>
|
|
<i class="fas fa-calendar-check" aria-hidden="true"></i>
|
|
<span><?php esc_html_e( '签到', 'aksrt' ); ?></span>
|
|
</button>
|
|
</div>
|
|
<p class="uc-balance-card__tip" data-signin-tip></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ( $show_vip_card ) : ?>
|
|
<!-- VIP 会员卡片 -->
|
|
<div class="uc-vip-card<?php echo $is_vip_user ? ' uc-vip-card--active' : ''; ?>">
|
|
<div class="uc-vip-card__bg"></div>
|
|
<div class="uc-vip-card__content">
|
|
<div class="uc-vip-card__header">
|
|
<div class="uc-vip-card__icon">
|
|
<i class="fas fa-crown" aria-hidden="true"></i>
|
|
</div>
|
|
<div class="uc-vip-card__info">
|
|
<span class="uc-vip-card__label"><?php echo esc_html( $vip_settings['name'] ?? __( 'VIP会员', 'aksrt' ) ); ?></span>
|
|
<?php if ( $is_vip_user ) : ?>
|
|
<span class="uc-vip-card__status uc-vip-card__status--active"><?php esc_html_e( '已开通', 'aksrt' ); ?></span>
|
|
<?php else : ?>
|
|
<span class="uc-vip-card__status"><?php esc_html_e( '未开通', 'aksrt' ); ?></span>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php if ( $is_vip_user ) : ?>
|
|
<div class="uc-vip-card__benefits">
|
|
<span class="uc-vip-card__benefit"><i class="fas fa-download" aria-hidden="true"></i> <?php esc_html_e( '免费下载', 'aksrt' ); ?></span>
|
|
<span class="uc-vip-card__benefit"><i class="fas fa-crown" aria-hidden="true"></i> <?php esc_html_e( '专属身份', 'aksrt' ); ?></span>
|
|
</div>
|
|
<?php else : ?>
|
|
<div class="uc-vip-card__benefits">
|
|
<span class="uc-vip-card__benefit"><i class="fas fa-download" aria-hidden="true"></i> <?php esc_html_e( '解锁免费下载', 'aksrt' ); ?></span>
|
|
<span class="uc-vip-card__benefit"><i class="fas fa-tag" aria-hidden="true"></i> <?php esc_html_e( '享专属折扣', 'aksrt' ); ?></span>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ( ! $is_vip_user ) : ?>
|
|
<a href="<?php echo esc_url( aksrt_get_user_center_url( 'credits' ) ); ?>" class="uc-vip-card__btn">
|
|
<?php esc_html_e( '立即开通', 'aksrt' ); ?>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ( $credits_enabled && function_exists('aksrt_is_captcha_enabled_for') && aksrt_is_captcha_enabled_for('signin') ) : ?>
|
|
<div class="aksrt-signin-captcha" data-signin-captcha style="margin-bottom:16px;">
|
|
<?php aksrt_render_captcha('signin'); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
// 签到日历可视化
|
|
$signin_dates = [];
|
|
if ($credits_enabled && class_exists('AKSRT_Signin')) {
|
|
$signin_log = AKSRT_Signin::get_instance()->get_recent_signins($user_id, 30);
|
|
$signin_dates = array_map(function ($entry) {
|
|
return $entry['signin_date'] ?? '';
|
|
}, $signin_log);
|
|
$signin_dates = array_filter($signin_dates);
|
|
}
|
|
?>
|
|
<?php if (!empty($signin_dates)) : ?>
|
|
<div class="uc-signin-calendar" style="margin-bottom:16px;">
|
|
<h4 class="uc-signin-calendar__title">
|
|
<i class="fas fa-calendar-alt" aria-hidden="true"></i>
|
|
<?php esc_html_e('最近 30 天签到', 'aksrt'); ?>
|
|
</h4>
|
|
<div data-aksrt-signin-calendar='<?php echo esc_attr(wp_json_encode(array_values($signin_dates))); ?>'></div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- 积分流水 -->
|
|
<div class="uc-transactions">
|
|
<div class="uc-transactions__header">
|
|
<h3 class="uc-transactions__title">
|
|
<i class="fas fa-list-ul" aria-hidden="true"></i>
|
|
<?php echo esc_html( sprintf( __( '%s明细', 'aksrt' ), $currency_name ) ); ?>
|
|
</h3>
|
|
</div>
|
|
<?php
|
|
$credits_page = max(1, isset($_GET['credits_page']) ? (int) $_GET['credits_page'] : 1);
|
|
if ( class_exists( 'AKSRT_Credits' ) ) {
|
|
$log = AKSRT_Credits::get_log( [ 'user_id' => $user_id, 'page' => $credits_page, 'per_page' => 10 ] );
|
|
} else {
|
|
$log = [ 'items' => [], 'total' => 0 ];
|
|
}
|
|
if ( ! empty( $log['items'] ) ) :
|
|
?>
|
|
<div class="uc-transactions__list">
|
|
<?php foreach ( $log['items'] as $row ) :
|
|
$delta = (int) $row['delta'];
|
|
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
|
|
?>
|
|
<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( aksrt_credits_label( (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 > 0 ? '+' : '' ) . $delta ); ?>
|
|
</span>
|
|
<span class="uc-transactions__balance">
|
|
<?php
|
|
/* translators: %s: 余额 */
|
|
printf( esc_html__( '余额 %s', 'aksrt' ), esc_html( (string) (int) $row['balance_after'] ) );
|
|
?>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php
|
|
$total_pages = (int) ceil( (int) ($log['total'] ?? 0) / 10 );
|
|
if ( $total_pages > 1 ) {
|
|
aksrt_render_profile_pagination( $total_pages, $credits_page, 'credits_page' );
|
|
}
|
|
?>
|
|
<?php else : ?>
|
|
<div class="uc-transactions__empty">
|
|
<div class="uc-transactions__empty-icon">
|
|
<i class="fas fa-receipt" aria-hidden="true"></i>
|
|
</div>
|
|
<p><?php echo esc_html( sprintf( __( '还没有任何%s流水', 'aksrt' ), $currency_name ) ); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|