后台「积分配置 → 自定义货币名称」改名后,用户中心仍有大量硬编码 「积分」:做任务赚积分 / 购买积分 / 签到领积分、积分记录 / 积分任务、 每日可免费获取 XX 积分、我的积分、积分+1、创作中心积分收益等。 get_currency_name() 早已存在且可用,问题只是这些文案没有走它。 本PR 全部替换,无双路、无迁移: 服务端渲染(用户中心 renderers) - credits-balance.php:购买/做任务赚/签到领 + 整个购买弹窗 - profile-credits.php:积分记录 / 积分任务 页签 - credits-points-tasks.php:每日上限三态与空态 - sidebar-creator.php / profile-creator.php:积分收益 - transfer-modal.php:积分转账提示 - Signin.php:签到详情弹窗(我的积分 / 奖励 tooltip / 积分+N) - VipServiceModal.php:我的积分 / 积分兑换会员 - download-permission-card.php:购买价格 客户端渲染(JS 无法调用 PHP,注入 currencyName 到 aksrtData) - signin.js:签到状态行「已签到 N 天 +1」 - credits.js:转账标题/金额标签 + 购买提示 toast - cms-download.js:积分不足视图、我的积分 入口、余额不足文案 - pay-vip.js:积分兑换会员入口(优先 catalog.currency_name) - order-center.js:订单行单位回退 契约测试同步改为断言模板构造而非死字符串,并新增两例: 改名后跟随、未注入时回退「积分」。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
153 lines
7.9 KiB
PHP
153 lines
7.9 KiB
PHP
<?php
|
|
/**
|
|
* User center creator income panel.
|
|
*
|
|
* @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) {
|
|
echo '<div class="uc-panel-empty muted-2-color">' . esc_html__('请先登录', 'aksrt') . '</div>';
|
|
return;
|
|
}
|
|
|
|
$settings = class_exists('\\AKSRT\\Settings\\Settings')
|
|
? \AKSRT\Settings\Settings::get_payment_revenue_settings()
|
|
: [];
|
|
if (empty($settings['enabled'])) {
|
|
echo '<div class="uc-panel-empty muted-2-color">' . esc_html__('创作收益功能暂未开启。', 'aksrt') . '</div>';
|
|
return;
|
|
}
|
|
|
|
$request = is_array($context['creator_income_request'] ?? null) ? $context['creator_income_request'] : [];
|
|
$page = max(1, min(100, (int) ($request['page'] ?? ($_GET['income_page'] ?? 1))));
|
|
$view = class_exists('\\AKSRT\\Payment\\Revenue')
|
|
? \AKSRT\Payment\Revenue::get_instance()->get_user_income_view($user_id, ['page' => $page])
|
|
: ['stats' => [], 'items' => [], 'total' => 0, 'max_pages' => 1, 'page' => 1];
|
|
$stats = (array) ($view['stats'] ?? []);
|
|
$items = (array) ($view['items'] ?? []);
|
|
$base_url = function_exists('aksrt_get_user_center_tab_url')
|
|
? aksrt_get_user_center_tab_url('creator')
|
|
: home_url('/profile/?tab=creator');
|
|
$page_url = static function (int $target_page) use ($base_url): string {
|
|
return add_query_arg(
|
|
['tab' => 'creator', 'income_page' => max(1, $target_page)],
|
|
remove_query_arg(['income_currency', 'income_status', 'income_page'], $base_url)
|
|
);
|
|
};
|
|
$format = static function ($amount, string $unit): string {
|
|
if ($unit === 'points') {
|
|
return aksrt_format_points(max(0, (int) $amount));
|
|
}
|
|
try {
|
|
return \AKSRT\Ledger\AssetAmount::balance(is_string($amount) ? $amount : '')->formatted();
|
|
} catch (\InvalidArgumentException $e) {
|
|
return '0.00';
|
|
}
|
|
};
|
|
$note = trim((string) ($settings['note'] ?? ''));
|
|
if ($note === '') {
|
|
$note = __('<p>订单完成并经过结算周期后,作者分成会自动转入对应的钱包。</p>', 'aksrt');
|
|
}
|
|
$status_labels = [
|
|
'pending' => __('待结算', 'aksrt'),
|
|
'settled' => __('已结算', 'aksrt'),
|
|
];
|
|
// 收益单位名跟随自定义货币名称(后台「积分配置 → 自定义货币名称」)。
|
|
$currency_name = class_exists('\\AKSRT\\Settings\\Settings')
|
|
? \AKSRT\Settings\Settings::get_currency_name()
|
|
: __('积分', 'aksrt');
|
|
$points_income_label = sprintf(__('%s收益', 'aksrt'), $currency_name);
|
|
$currency_labels = [
|
|
'CNY' => __('现金收益', 'aksrt'),
|
|
'points' => $points_income_label,
|
|
];
|
|
?>
|
|
<div class="creator-income" data-creator-income>
|
|
<section class="creator-income__cards" aria-label="<?php esc_attr_e('收益概览', 'aksrt'); ?>">
|
|
<?php foreach ($currency_labels as $unit => $label) : ?>
|
|
<article class="creator-income-card creator-income-card--<?php echo esc_attr(strtolower($unit)); ?>">
|
|
<h2><?php echo esc_html($label); ?></h2>
|
|
<div class="creator-income-card__metrics">
|
|
<?php foreach (['today' => __('今日收入', 'aksrt'), 'total' => __('累计收益', 'aksrt'), 'pending' => __('待结算', 'aksrt'), 'settled' => __('已结算', 'aksrt')] as $metric => $metric_label) : ?>
|
|
<span>
|
|
<strong><?php echo esc_html($format($stats[$metric][$unit] ?? 0, $unit)); ?></strong>
|
|
<small><?php echo esc_html($metric_label); ?></small>
|
|
</span>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
</section>
|
|
|
|
<section class="creator-income__info widget-card">
|
|
<h2><?php esc_html_e('结算备注', 'aksrt'); ?></h2>
|
|
<div><?php echo wp_kses_post($note); ?></div>
|
|
</section>
|
|
|
|
<section class="creator-income__details widget-card">
|
|
<div class="creator-income__toolbar">
|
|
<div>
|
|
<h2><?php esc_html_e('收入明细', 'aksrt'); ?></h2>
|
|
<p><?php esc_html_e('按产生时间倒序显示,每页 20 条。', 'aksrt'); ?></p>
|
|
</div>
|
|
</div>
|
|
<?php if (!$items) : ?>
|
|
<div class="creator-income__empty">
|
|
<i class="fa fas fa-chart-line" aria-hidden="true"></i>
|
|
<p><?php esc_html_e('暂无收益明细', 'aksrt'); ?></p>
|
|
</div>
|
|
<?php else : ?>
|
|
<div class="creator-income__list" role="list" aria-label="<?php esc_attr_e('收入明细', 'aksrt'); ?>">
|
|
<?php foreach ($items as $item) :
|
|
$unit = (string) ($item['currency'] ?? 'CNY') === 'points' ? 'points' : 'CNY';
|
|
$status = (string) ($item['status'] ?? '') === 'pending' ? 'pending' : 'settled';
|
|
$amount = $format($item['amount'] ?? 0, $unit);
|
|
$order_number = trim((string) ($item['order_number'] ?? ''));
|
|
$order_number = $order_number !== '' ? $order_number : __('订单号未知', 'aksrt');
|
|
$post = get_post((int) ($item['post_id'] ?? 0));
|
|
$source = $post instanceof WP_Post && $post->post_type === 'post'
|
|
? get_the_title($post)
|
|
: __('内容已删除', 'aksrt');
|
|
$source = trim((string) $source) !== '' ? (string) $source : __('内容已删除', 'aksrt');
|
|
$created_at = trim((string) ($item['created_at'] ?? ''));
|
|
$time_label = '';
|
|
$time_datetime = '';
|
|
if ($created_at !== '') {
|
|
try {
|
|
$created = new DateTimeImmutable($created_at, wp_timezone());
|
|
$time_datetime = $created->format('c');
|
|
$time_label = wp_date(get_option('date_format') . ' ' . get_option('time_format'), $created->getTimestamp());
|
|
} catch (Exception $exception) {
|
|
$time_label = '';
|
|
}
|
|
}
|
|
?>
|
|
<article class="creator-income-row" role="listitem">
|
|
<span class="creator-income-row__order" title="<?php echo esc_attr($order_number); ?>"><?php echo esc_html($order_number); ?></span>
|
|
<span class="creator-income-row__currency"><?php echo esc_html($currency_labels[$unit === 'points' ? 'points' : 'CNY']); ?></span>
|
|
<span class="creator-income-row__source" title="<?php echo esc_attr($source); ?>"><?php echo esc_html($source); ?></span>
|
|
<span class="creator-income-row__detail">
|
|
<strong class="creator-income-row__amount">+<?php echo esc_html($amount . ($unit === 'points' ? $currency_name : __('现金', 'aksrt'))); ?></strong>
|
|
<?php if ($time_label !== '') : ?>
|
|
<time class="creator-income-row__time" datetime="<?php echo esc_attr($time_datetime); ?>"><?php echo esc_html($time_label); ?></time>
|
|
<?php endif; ?>
|
|
<span class="creator-income-row__status creator-income-row__status--<?php echo esc_attr($status); ?>"><?php echo esc_html($status_labels[$status]); ?></span>
|
|
</span>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php if ((int) ($view['max_pages'] ?? 1) > 1) : ?>
|
|
<nav class="creator-income__pagination" aria-label="<?php esc_attr_e('收入明细分页', 'aksrt'); ?>">
|
|
<?php for ($i = 1; $i <= (int) $view['max_pages']; $i++) : ?>
|
|
<a class="<?php echo $i === (int) ($view['page'] ?? $page) ? 'is-active' : ''; ?>" href="<?php echo esc_url($page_url($i)); ?>"><?php echo esc_html((string) $i); ?></a>
|
|
<?php endfor; ?>
|
|
</nav>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</section>
|
|
</div>
|