Files
wordpress-theme-aksrt/inc/helpers/user-center-renderers/credits-balance.php
T
kate522 09b1e535e4 fix(user-center): use the reference colour sprites on the balance and points cards
Both asset cards opened with the same solid `fa-money-bill` glyph, so the
wallet and the points card showed an identical icon and neither matched the
reference, which pairs a blue wallet mark with the balance card and an orange
coin mark with the points card.

The theme already ships both sprites — the header wallet popover and the user
center sidebar resolve to `jiosvg-money-color-2` and `jiosvg-points-color`
through the same helper. Only these two cards were still on Font Awesome.
Swapping them keeps one icon family across the user center; the existing
`em12 mr6` sizing carries over unchanged because `svg` is 1em tall.

The wallet/points icon contract test now pins both keys and fails if either
card falls back to `fa-money-bill` or `fa-coins`.

Verification: rendered both cards through a PHP stub and screenshotted them
against the real theme stylesheet — the blue wallet and orange coin render at
the same optical size as the labels. 861 widget/navigation tests pass.
2026-11-04 17:08:09 +08:00

183 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* User center credits: points asset card + sign-in + credits card-pass.
*
* @package Jio
*/
defined('ABSPATH') || exit;
$balance = max(0, (int) ($credit_balance ?? 0));
$credits_enabled = !empty($credits_enabled);
if (!$credits_enabled) {
return;
}
$all_settings = class_exists('\Jio\Settings\Settings') ? \Jio\Settings\Settings::get_all() : [];
$points_uid = (int) ($user_id ?? get_current_user_id());
$points_transfer_on = !empty($all_settings['points_transfer_s']);
if ($points_transfer_on && class_exists('\Jio\Settings\Capabilities') && !\Jio\Settings\Capabilities::user_can('points_transfer', $points_uid)) {
$points_transfer_on = false;
}
$points_transfer_min = max(1, (int) ($all_settings['points_transfer_min'] ?? 1));
$points_exchange = class_exists('\Jio\Settings\Settings') ? \Jio\Settings\Settings::get_payment_recharge_settings()['points_exchange'] ?? [] : [];
$recharge = class_exists('\Jio\Settings\Settings') ? \Jio\Settings\Settings::get_payment_recharge_settings() : [];
$points_exchange_on = !empty($points_exchange['enabled']) && !empty($recharge['enabled']);
$currency = (string) ($currency_name ?? __('积分', 'jio'));
// 文案里的货币名统一走自定义名称(后台「积分配置 → 自定义货币名称」)。
$points_buy_label = sprintf(__('购买%s', 'jio'), $currency);
$points_earn_label = sprintf(__('做任务赚%s', 'jio'), $currency);
$points_signin_label = sprintf(__('签到领%s', 'jio'), $currency);
?>
<div class="uc-asset-card uc-asset-card--points">
<div class="uc-asset-card__head flex jsb ac">
<div class="uc-asset-card__title">
<?php echo function_exists('jio_icon_markup') ? jio_icon_markup('jiosvg-points-color', 'em12 mr6') : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><?php echo esc_html($currency); ?>
</div>
<?php if (!empty($signin_enabled)) : ?>
<span class="uc-asset-card__head-action muted-color px12" data-jio-signin>
<?php if (!empty($signin_signed_today)) : ?>
<?php echo jio_get_user_checkin_details_link('uc-asset-card__signin muted-color px12', '<span>' . esc_html__('已签到', 'jio') . '</span><i class="fa fas fa-angle-right em12 ml3" aria-hidden="true"></i>'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php else : ?>
<button type="button" class="uc-asset-card__signin muted-color px12" data-signin-btn data-signin-done-label="<?php esc_attr_e('已签到', 'jio'); ?>">
<span data-signin-label><?php echo esc_html($points_signin_label); ?></span><i class="fa fas fa-angle-right em12 ml3" aria-hidden="true"></i>
</button>
<?php endif; ?>
<span class="uc-asset-card__signin-status" data-signin-status></span>
</span>
<?php endif; ?>
</div>
<div class="uc-asset-card__body flex jsb ac">
<div class="uc-asset-card__amount c-green">
<span class="uc-asset-card__value font-bold" data-jio-points-value data-credits-value title="<?php echo esc_attr(jio_format_points($balance)); ?>"><?php echo esc_html(jio_format_points($balance)); ?></span>
</div>
<div class="uc-asset-card__actions flex0">
<?php if ($points_transfer_on) : ?>
<button type="button" class="but c-green mr6 hollow" data-jio-transfer-open="points" data-jio-transfer-min="<?php echo esc_attr((string) $points_transfer_min); ?>"><?php esc_html_e('转账', 'jio'); ?></button>
<?php endif; ?>
<?php if ($points_exchange_on) : ?>
<button type="button" class="but c-green hollow" data-jio-points-pay-open><?php echo esc_html($points_buy_label); ?></button>
<?php endif; ?>
</div>
</div>
<button type="button" class="uc-asset-card__link muted-2-color em09" data-jio-asset-tab="points_free"><?php echo esc_html($points_earn_label); ?><i class="fa fas fa-angle-right em12 ml3" aria-hidden="true"></i></button>
</div>
<?php if ($points_exchange_on) :
// 购买积分弹窗(商品盒 / 自定义 / 支付方式含卡密 / 立即支付)。
$pb_rate = max(1, (int) ($points_exchange['rate'] ?? 100));
$pb_min_points = max(1, (int) ($points_exchange['min_points'] ?? 100));
$pb_daily_max_points = max(1, (int) ($points_exchange['daily_max_points'] ?? 100000));
// 依赖 $pb_min_points / $pb_daily_max_points,必须排在它们赋值之后。
$points_limit_html = sprintf(
/* translators: 1: currency name, 2: minimum purchase, 3: currency name, 4: maximum purchase */
__('最低购买%2$s%1$s,最高购买%4$s%3$s', 'jio'),
$currency,
$pb_min_points,
$currency,
$pb_daily_max_points
);
$points_packages = class_exists('\Jio\Credits\BalanceService')
? \Jio\Credits\BalanceService::get_instance()->parse_points_packages((string) ($points_exchange['products_raw'] ?? ''))
: [];
// 卡密兑换积分渠道(后台 启用卡密兑换积分功能)。
$points_card_pass = ['enabled' => false, 'desc' => '', 'only_password' => false];
if (class_exists('\Jio\Payment\ChargeCard')) {
$points_card_opts = \Jio\Payment\ChargeCard::get_instance()->get_public_options();
$points_card_pass = is_array($points_card_opts['credits'] ?? null) ? $points_card_opts['credits'] : $points_card_pass;
}
$points_methods = [['id' => 'balance', 'name' => __('余额', 'jio')]];
if (!empty($points_card_pass['enabled'])) {
$points_methods[] = ['id' => 'card_pass', 'name' => __('卡密', 'jio')];
}
// 「收款接口显示顺序」:购买积分弹窗只含余额与卡密两个槽位。
if (function_exists('jio_sort_payment_methods')) {
$points_methods = jio_sort_payment_methods($points_methods);
}
$points_custom_limit_html = $points_limit_html;
$points_gateway = class_exists('\Jio\Settings\Settings') ? \Jio\Settings\Settings::get_payment_gateway_settings() : [];
$points_mark = (string) ($points_gateway['currency']['mark'] ?? '¥');
$points_default_product = $points_packages ? (string) $points_packages[0]['key'] : 'custom';
?>
<div class="modal flex jc fade" id="jio-points-pay-modal" tabindex="-1" role="dialog" data-jio-points-pay-modal>
<div class="modal-dialog modal-mini full-sm" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="mb10 touch"><button type="button" class="close" data-dismiss="modal" aria-label="<?php esc_attr_e('关闭', 'jio'); ?>"><svg class="ic-close" aria-hidden="true"><use xlink:href="#icon-close"></use></svg></button><b class="modal-title flex ac"><span class="mr6 em14"><i class="fa fas fa-coins" aria-hidden="true"></i></span><?php echo esc_html($points_buy_label); ?></b></div>
<form class="balance-charge-form mini-scrollbar scroll-y max-vh7" data-jio-points-pay-form>
<div class="charge-box mb20">
<?php if ($points_packages) : ?>
<div class="muted-color mb6"><?php printf(esc_html__('请选择需购买的%s', 'jio'), esc_html($currency)); ?></div>
<?php foreach ($points_packages as $pidx => $ppkg) : ?>
<div class="jio-widget-box vip-product relative product-box<?php echo $pidx === 0 ? ' active' : ''; ?>" data-for="points_product" data-value="<?php echo esc_attr((string) $ppkg['key']); ?>">
<?php if (!empty($ppkg['tag'])) : ?>
<div class="abs-right vip-tag badg jb-yellow"><?php echo esc_html((string) $ppkg['tag']); ?></div>
<?php endif; ?>
<div class="em14"><span class="px12"><i class="fa fas fa-coins" aria-hidden="true"></i></span><?php echo esc_html(jio_format_points((int) $ppkg['points'])); ?></div>
<div class="c-red"><span class="px12"><?php echo esc_html($points_mark); ?></span><span class="em12"><?php echo esc_html((string) $ppkg['pay_price']); ?></span></div>
</div>
<?php endforeach; ?>
<div class="muted-color mt20 mb6"><?php printf(esc_html__('自定义%1$s数量(1%2$s=%3$s%1$s)', 'jio'), esc_html($currency), esc_html($points_mark), esc_html((string) $pb_rate)); ?></div>
<div data-for="points_product" data-value="custom">
<div class="relative flex ab">
<span class="ml6 mr10 muted-color shrink0"><i class="fa fas fa-coins" aria-hidden="true"></i></span>
<input class="line-form-input em16 key-color" style="padding: 1px;" name="points_custom" type="number" limit-min="<?php echo esc_attr((string) $pb_min_points); ?>" limit-max="<?php echo esc_attr((string) $pb_daily_max_points); ?>" placeholder="<?php echo esc_attr($pb_min_points . ' ~ ' . $pb_daily_max_points); ?>">
<i class="line-form-line"></i>
</div>
<div class="muted-2-color em09 mt6"><?php echo esc_html($points_custom_limit_html); ?></div>
</div>
<?php else : ?>
<div class="muted-color mb6"><?php printf(esc_html__('请输入需购买的%s数额', 'jio'), esc_html($currency)); ?></div>
<div data-for="points_product" data-value="custom">
<div class="relative flex ab">
<span class="ml6 mr10 muted-color shrink0"><i class="fa fas fa-coins" aria-hidden="true"></i></span>
<input class="line-form-input em16 key-color" style="padding: 1px;" name="points_custom" type="number" limit-min="<?php echo esc_attr((string) $pb_min_points); ?>" limit-max="<?php echo esc_attr((string) $pb_daily_max_points); ?>" placeholder="<?php echo esc_attr($pb_min_points . ' ~ ' . $pb_daily_max_points); ?>">
<i class="line-form-line"></i>
</div>
<div class="muted-2-color em09 mt6"><?php echo esc_html($points_custom_limit_html); ?></div>
</div>
<?php endif; ?>
</div>
<?php if (!empty($points_exchange['desc'])) : ?>
<div class="muted-box muted-2-color padding-10 mb20 em09"><?php echo esc_html((string) $points_exchange['desc']); ?></div>
<?php endif; ?>
<div class="dependency-box">
<?php if (count($points_methods) > 1) : ?>
<div class="muted-2-color em09 mb6"><?php esc_html_e('请选择支付方式', 'jio'); ?></div>
<div class="flex mb10">
<?php foreach ($points_methods as $pmi => $pm) :
$pm_id = (string) ($pm['id'] ?? '');
$pm_logo = 'card_pass' === $pm_id ? 'pay-card-pass-logo.svg' : 'pay-balance-logo.svg';
?>
<div class="flex jc hh payment-method-radio hollow-radio flex-auto pointer<?php echo $pmi === 0 ? ' active' : ''; ?>" data-for="payment_method" data-value="<?php echo esc_attr($pm_id); ?>">
<img src="<?php echo esc_url(get_template_directory_uri() . '/assets/img/' . $pm_logo); ?>" alt="<?php echo esc_attr($pm_id); ?>-logo">
<div><?php echo esc_html((string) ($pm['name'] ?? $pm_id)); ?></div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (!empty($points_card_pass['enabled'])) : ?>
<div class="mb10 padding-h10 padding-w6" data-controller="payment_method" data-condition="==" data-value="card_pass" style="display: none;">
<?php if (!empty($points_card_pass['desc'])) : ?>
<div class="muted-box muted-2-color padding-10 mb10 em09"><?php echo esc_html((string) $points_card_pass['desc']); ?></div>
<?php endif; ?>
<div class="muted-2-color em09 mb6"><?php echo !empty($points_card_pass['only_password']) ? esc_html__('请输入卡密', 'jio') : esc_html__('请输入卡号和密码', 'jio'); ?></div>
<?php if (empty($points_card_pass['only_password'])) : ?>
<div class="mb6"><input type="input" class="form-control" name="card_pass[card]" placeholder="<?php esc_attr_e('卡号', 'jio'); ?>" value=""></div>
<?php endif; ?>
<div class="">
<input type="input" class="form-control" name="card_pass[password]" placeholder="<?php esc_attr_e('卡密', 'jio'); ?>" value="">
</div>
</div>
<?php endif; ?>
<input type="hidden" name="points_product" value="<?php echo esc_attr($points_default_product); ?>">
<input type="hidden" name="payment_method" value="<?php echo esc_attr((string) ($points_methods[0]['id'] ?? '')); ?>">
<button type="submit" class="mt6 but jb-red initiate-pay btn-block radius"><?php esc_html_e('立即支付', 'jio'); ?></button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php endif; ?>