后台「收款接口 → 收款接口显示顺序」有三处缺陷叠加: 1) sortable 渲染组件读取 item.label,而 schema 写的是 title,导致 6 行 只剩上下箭头; 2) SchemaProvider 的 sortable 分支遍历 items 定义重建数组,而该字段的 键顺序本身就是配置值,用户排序被静默改回 schema 静态顺序; 3) 真正构建收银台支付方式列表的 aksrt_list_cash_payment_methods() 使用 硬编码顺序,Gateway::get_available()/apply_sdk_order() 那套排序逻辑 无任何调用方,配置对前台毫无影响。 改为:schema 项统一使用 label(JS 与 PHP 两处对齐);sortable 持久化按 提交键顺序重建,items 定义仅作白名单;新增唯一排序实现 aksrt_sort_payment_methods()(语义对齐参考主题 zibpay_get_payment_methods + pay_sdk_order 键顺序),并接入内容收银台、余额充值、购买积分与会员 购买四个入口。卡密输入盒改为按渠道存在与否判断,不再假定卡密固定在末位。 清理死代码:无调用方的 Gateway::get_available/apply_sdk_order/ get_status_summary、VipServicePackages 中不可达的支付方式列表回退分支、 零引用的 settings-defaults 模块及 schema/index.js 未使用的导出、支付 sortable 的 fields 死元数据、无拖拽实现却声明的 cursor:move。 未配置 pay_sdk_order 时顺序保持不变;未写数据迁移。 验证:php -l 8 个改动文件全部通过;新增 pay-sdk-order-contract 契约测试 (6 项);node --test tests/widget-system/*.test.cjs 301 项全部通过; 后台 SPA 已重新构建。
596 lines
22 KiB
PHP
596 lines
22 KiB
PHP
<?php
|
|
/**
|
|
* @package AKSRT
|
|
*/
|
|
|
|
namespace AKSRT\Content;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
trait VipServicePackages {
|
|
|
|
|
|
|
|
/**
|
|
* Parse per-level product lines (legacy vip_product).
|
|
*
|
|
* Preferred: price|show_price|time|unit|tag|title
|
|
* Legacy: price|days|title
|
|
*
|
|
* @return array<int, array{price:string,show_price:string,time:int,unit:string,tag:string,tag_class:string,title:string,days:int}>
|
|
*/
|
|
public function parse_level_products(string $raw): array {
|
|
$lines = preg_split('/\r\n|\r|\n/', $raw) ?: [];
|
|
$out = [];
|
|
foreach ($lines as $line) {
|
|
$line = trim((string) $line);
|
|
if ($line === '') {
|
|
continue;
|
|
}
|
|
$parts = array_map('trim', explode('|', $line));
|
|
$price_minor = $this->parse_vip_money_minor($parts[0] ?? '');
|
|
if ($price_minor <= 0) {
|
|
continue;
|
|
}
|
|
|
|
$n = count($parts);
|
|
// New format: price|show_price|time|unit|tag|title (6+)
|
|
// Or: price|show_price|time|unit|title (5)
|
|
if ($n >= 4 && (in_array(strtolower((string) ($parts[3] ?? '')), ['day', 'month', 'd', 'm'], true)
|
|
|| (isset($parts[3]) && $parts[3] !== '' && !is_numeric($parts[3])))) {
|
|
$show_minor = $this->parse_vip_money_minor($parts[1] ?? '0');
|
|
$time = isset($parts[2]) ? (int) $parts[2] : 0;
|
|
$unit_raw = strtolower((string) ($parts[3] ?? 'month'));
|
|
$unit = ($unit_raw === 'day' || $unit_raw === 'd') ? 'day' : 'month';
|
|
$tag = '';
|
|
$title = '';
|
|
if ($n >= 6) {
|
|
$tag = sanitize_text_field((string) ($parts[4] ?? ''));
|
|
$title = sanitize_text_field((string) ($parts[5] ?? ''));
|
|
} elseif ($n === 5) {
|
|
// price|show|time|unit|title
|
|
$title = sanitize_text_field((string) ($parts[4] ?? ''));
|
|
}
|
|
} else {
|
|
// Legacy: price|days|title
|
|
$show_minor = 0;
|
|
$days_legacy = isset($parts[1]) ? (int) $parts[1] : 0;
|
|
$time = $days_legacy;
|
|
$unit = 'day';
|
|
$tag = '';
|
|
$title = isset($parts[2]) ? sanitize_text_field($parts[2]) : '';
|
|
}
|
|
|
|
$time = max(0, $time);
|
|
$days = $this->duration_to_days($time, $unit);
|
|
if ($title === '') {
|
|
if ($time <= 0) {
|
|
$title = __('永久会员', 'aksrt');
|
|
} elseif ($unit === 'day') {
|
|
$title = sprintf(__('%d天会员', 'aksrt'), $time);
|
|
} else {
|
|
$title = sprintf(__('%d个月会员', 'aksrt'), $time);
|
|
}
|
|
}
|
|
|
|
$out[] = [
|
|
'price' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($price_minor),
|
|
'show_price' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($show_minor),
|
|
'time' => $time,
|
|
'unit' => $unit,
|
|
'tag' => $tag,
|
|
'tag_class' => '',
|
|
'title' => $title,
|
|
'days' => $days,
|
|
];
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Approximate days for catalog labels / order meta; activate prefers time+unit calendar math.
|
|
*/
|
|
public function duration_to_days(int $time, string $unit = 'day'): int {
|
|
if ($time <= 0) {
|
|
return 0;
|
|
}
|
|
if ($unit === 'month') {
|
|
return $time * 30;
|
|
}
|
|
return $time;
|
|
}
|
|
|
|
/**
|
|
* @deprecated Use parse_level_products — kept as thin adapter for upgrade fixed lines.
|
|
*
|
|
* @return array<int, array{price:string,days:int,title:string}>
|
|
*/
|
|
public function parse_packages(string $raw): array {
|
|
$parsed = $this->parse_level_products($raw);
|
|
$out = [];
|
|
foreach ($parsed as $p) {
|
|
$out[] = [
|
|
'price' => (string) $p['price'],
|
|
'days' => (int) $p['days'],
|
|
'title' => (string) $p['title'],
|
|
];
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Build upgrade package items (legacy vip_upgrade_product parity).
|
|
*
|
|
* upgrade.product multi-line formats:
|
|
* - permanent VIP1: permanent|price|title[|show_price]
|
|
* - fixed (alias): price|days|title
|
|
* - timed unit: unit|daily_price|title
|
|
* - timed jump permanent: jump|price|title[|show_price]
|
|
*
|
|
* Rules:
|
|
* - permanent user: only permanent/fixed (days=0 preferred)
|
|
* - timed user: unit (keep expiry) + optional jump (to permanent)
|
|
*
|
|
* package index: 901 permanent/fixed, 902 unit, 903 jump
|
|
*
|
|
* @return array<int, array<string,mixed>>
|
|
*/
|
|
private function build_upgrade_items(int $user_id, int $expires, bool $is_permanent, string $raw): array {
|
|
$raw = trim($raw);
|
|
if ($raw === '') {
|
|
return [];
|
|
}
|
|
$items = [];
|
|
$lines = preg_split('/\r\n|\r|\n/', $raw) ?: [];
|
|
$has_permanent = false;
|
|
$has_unit = false;
|
|
$has_jump = false;
|
|
|
|
foreach ($lines as $line) {
|
|
$line = trim((string) $line);
|
|
if ($line === '') {
|
|
continue;
|
|
}
|
|
$parts = array_map('trim', explode('|', $line));
|
|
$mode = strtolower((string) ($parts[0] ?? ''));
|
|
|
|
// unit|daily|title — timed VIP1 only.
|
|
if ($mode === 'unit') {
|
|
if ($is_permanent || $expires <= time() || $has_unit) {
|
|
continue;
|
|
}
|
|
$daily_minor = $this->parse_vip_money_minor($parts[1] ?? '');
|
|
if ($daily_minor <= 0) {
|
|
continue;
|
|
}
|
|
$remaining = (int) ceil(max(1, ($expires - time()) / DAY_IN_SECONDS));
|
|
if ($daily_minor > intdiv(PHP_INT_MAX, $remaining)) {
|
|
continue;
|
|
}
|
|
$price_minor = $remaining * $daily_minor;
|
|
$price = \AKSRT\Ledger\AssetAmount::decimal_from_minor($price_minor);
|
|
$title = sanitize_text_field((string) ($parts[2] ?? ''));
|
|
if ($title === '') {
|
|
$title = sprintf(__('按剩余 %d 天升级', 'aksrt'), $remaining);
|
|
}
|
|
$items[] = [
|
|
'package_id' => $this->encode_package_id(2, 902),
|
|
'level' => 2,
|
|
'index' => 902,
|
|
'action' => 'upgrade',
|
|
'price' => $price,
|
|
'base_price' => $price,
|
|
'show_price' => '0.00',
|
|
'discount_tag' => __('剩余天数', 'aksrt'),
|
|
'days' => $remaining,
|
|
'title' => $title,
|
|
'price_label' => $this->format_cash_label($price),
|
|
'show_price_label' => '',
|
|
'days_label' => sprintf(__('%d 天', 'aksrt'), $remaining),
|
|
'cta_label' => __('立即升级', 'aksrt'),
|
|
'is_upgrade_product' => true,
|
|
'upgrade_mode' => 'unit',
|
|
];
|
|
$has_unit = true;
|
|
continue;
|
|
}
|
|
|
|
// jump|price|title[|show_price] — timed VIP1 only → permanent VIP2.
|
|
if ($mode === 'jump') {
|
|
if ($is_permanent || $has_jump) {
|
|
continue;
|
|
}
|
|
$price_minor = $this->parse_vip_money_minor($parts[1] ?? '');
|
|
if ($price_minor <= 0) {
|
|
continue;
|
|
}
|
|
$price = \AKSRT\Ledger\AssetAmount::decimal_from_minor($price_minor);
|
|
$title = sanitize_text_field((string) ($parts[2] ?? ''));
|
|
if ($title === '') {
|
|
$title = __('升级为永久会员', 'aksrt');
|
|
}
|
|
$show_minor = $this->parse_vip_money_minor($parts[3] ?? '0');
|
|
$show = \AKSRT\Ledger\AssetAmount::decimal_from_minor($show_minor);
|
|
$items[] = [
|
|
'package_id' => $this->encode_package_id(2, 903),
|
|
'level' => 2,
|
|
'index' => 903,
|
|
'action' => 'upgrade',
|
|
'price' => $price,
|
|
'base_price' => $price,
|
|
'show_price' => $show,
|
|
'discount_tag' => __('永久升级', 'aksrt'),
|
|
'days' => 0,
|
|
'title' => $title,
|
|
'price_label' => $this->format_cash_label($price),
|
|
'show_price_label' => $show_minor > 0 ? $this->format_cash_label($show) : '',
|
|
'days_label' => __('永久', 'aksrt'),
|
|
'cta_label' => __('立即升级', 'aksrt'),
|
|
'is_upgrade_product' => true,
|
|
'upgrade_mode' => 'jump',
|
|
];
|
|
$has_jump = true;
|
|
continue;
|
|
}
|
|
|
|
// permanent|price|title[|show_price]
|
|
if ($mode === 'permanent') {
|
|
if ($has_permanent) {
|
|
continue;
|
|
}
|
|
$price_minor = $this->parse_vip_money_minor($parts[1] ?? '');
|
|
if ($price_minor <= 0) {
|
|
continue;
|
|
}
|
|
$price = \AKSRT\Ledger\AssetAmount::decimal_from_minor($price_minor);
|
|
$title = sanitize_text_field((string) ($parts[2] ?? ''));
|
|
if ($title === '') {
|
|
$title = __('永久会员升级', 'aksrt');
|
|
}
|
|
$show_minor = $this->parse_vip_money_minor($parts[3] ?? '0');
|
|
$show = \AKSRT\Ledger\AssetAmount::decimal_from_minor($show_minor);
|
|
$items[] = [
|
|
'package_id' => $this->encode_package_id(2, 901),
|
|
'level' => 2,
|
|
'index' => 901,
|
|
'action' => 'upgrade',
|
|
'price' => $price,
|
|
'base_price' => $price,
|
|
'show_price' => $show,
|
|
'discount_tag' => __('升级专享', 'aksrt'),
|
|
'days' => 0,
|
|
'title' => $title,
|
|
'price_label' => $this->format_cash_label($price),
|
|
'show_price_label' => $show_minor > 0 ? $this->format_cash_label($show) : '',
|
|
'days_label' => __('永久', 'aksrt'),
|
|
'cta_label' => __('立即升级', 'aksrt'),
|
|
'is_upgrade_product' => true,
|
|
'upgrade_mode' => 'permanent',
|
|
];
|
|
$has_permanent = true;
|
|
continue;
|
|
}
|
|
|
|
// fixed: price|days|title
|
|
$parsed = $this->parse_packages($line);
|
|
if (empty($parsed[0]) || $has_permanent) {
|
|
continue;
|
|
}
|
|
// For permanent VIP1, only accept days=0 fixed lines as permanent upgrade.
|
|
if ($is_permanent && (int) $parsed[0]['days'] > 0) {
|
|
continue;
|
|
}
|
|
$pkg = $parsed[0];
|
|
$items[] = [
|
|
'package_id' => $this->encode_package_id(2, 901),
|
|
'level' => 2,
|
|
'index' => 901,
|
|
'action' => 'upgrade',
|
|
'price' => (string) $pkg['price'],
|
|
'base_price' => (string) $pkg['price'],
|
|
'show_price' => '0.00',
|
|
'discount_tag' => __('升级专享', 'aksrt'),
|
|
'days' => (int) $pkg['days'],
|
|
'title' => (string) $pkg['title'],
|
|
'price_label' => $this->format_cash_label((string) $pkg['price']),
|
|
'show_price_label' => '',
|
|
'days_label' => ((int) $pkg['days'] <= 0)
|
|
? __('永久', 'aksrt')
|
|
: sprintf(__('%d 天', 'aksrt'), (int) $pkg['days']),
|
|
'cta_label' => __('立即升级', 'aksrt'),
|
|
'is_upgrade_product' => true,
|
|
'upgrade_mode' => ((int) $pkg['days'] <= 0) ? 'permanent' : 'fixed',
|
|
];
|
|
$has_permanent = true;
|
|
}
|
|
|
|
// Permanent VIP1 should not see unit/jump.
|
|
if ($is_permanent) {
|
|
$items = array_values(array_filter($items, static function ($it) {
|
|
$m = (string) ($it['upgrade_mode'] ?? '');
|
|
return in_array($m, ['permanent', 'fixed'], true);
|
|
}));
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Points exchange packages: level|points|days|title
|
|
*
|
|
* @param array<string,mixed> $vip
|
|
* @param array<int,mixed> $levels
|
|
* @return array<int, array<string,mixed>>
|
|
*/
|
|
public function get_points_exchange_packages(array $vip, array $levels): array {
|
|
$points_ex = is_array($vip['points_exchange'] ?? null) ? $vip['points_exchange'] : [];
|
|
$raw = (string) ($points_ex['packages_raw'] ?? '');
|
|
$currency = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_currency_name() : __('积分', 'aksrt');
|
|
$out = [];
|
|
$lines = preg_split('/\r\n|\r|\n/', $raw) ?: [];
|
|
$i = 0;
|
|
foreach ($lines as $line) {
|
|
$line = trim((string) $line);
|
|
if ($line === '') {
|
|
continue;
|
|
}
|
|
$parts = array_map('trim', explode('|', $line));
|
|
if (count($parts) < 3) {
|
|
continue;
|
|
}
|
|
$lv = (int) ($parts[0] ?? 0);
|
|
$pts = (int) ($parts[1] ?? 0);
|
|
$days = (int) ($parts[2] ?? 0);
|
|
$title = sanitize_text_field((string) ($parts[3] ?? ''));
|
|
if ($lv < 1 || $lv > 2 || $pts <= 0) {
|
|
continue;
|
|
}
|
|
if (empty($levels[$lv]['enabled'])) {
|
|
continue;
|
|
}
|
|
$i++;
|
|
if ($title === '') {
|
|
$lv_name = (string) ($levels[$lv]['name'] ?? ('VIP' . $lv));
|
|
$title = $days > 0
|
|
? sprintf(__('%1$s · %2$d天', 'aksrt'), $lv_name, $days)
|
|
: sprintf(__('%s · 永久', 'aksrt'), $lv_name);
|
|
}
|
|
$out[] = [
|
|
'package_id' => 5000 + $i,
|
|
'level' => $lv,
|
|
'index' => $i,
|
|
'points' => $pts,
|
|
'days' => max(0, $days),
|
|
'title' => $title,
|
|
'price_label' => $pts . ' ' . $currency,
|
|
'days_label' => $days > 0 ? sprintf(__('%d 天', 'aksrt'), $days) : __('永久', 'aksrt'),
|
|
'cta_label' => __('立即兑换', 'aksrt'),
|
|
];
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Single upgrade product line: price|days|title
|
|
*
|
|
* @return array{price:float,days:int,title:string}|null
|
|
*/
|
|
public function parse_upgrade_product_line(string $raw): ?array {
|
|
$raw = trim($raw);
|
|
if ($raw === '') {
|
|
return null;
|
|
}
|
|
$lines = preg_split('/\r\n|\r|\n/', $raw) ?: [];
|
|
foreach ($lines as $line) {
|
|
$line = trim((string) $line);
|
|
if ($line === '' || str_starts_with(strtolower($line), 'unit|')) {
|
|
continue;
|
|
}
|
|
$parsed = $this->parse_packages($line);
|
|
if (!empty($parsed[0])) {
|
|
return $parsed[0];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Apply renew discount/reduce to same-level packages.
|
|
*
|
|
* @param array<string,mixed> $renew
|
|
* @param array<string,mixed> $upgrade
|
|
* @return array{price:string,show_price:string,tag:string}|null
|
|
*/
|
|
private function apply_action_price(
|
|
string $base_price,
|
|
string $action,
|
|
array $renew,
|
|
array $upgrade,
|
|
int $target_level,
|
|
int $user_level,
|
|
int $expires,
|
|
bool $is_permanent,
|
|
int $days
|
|
): ?array {
|
|
$base_minor = $this->parse_vip_money_minor($base_price);
|
|
if ($base_minor <= 0) {
|
|
return null;
|
|
}
|
|
|
|
if ($action === 'renew' && $is_permanent) {
|
|
return null;
|
|
}
|
|
|
|
if ($action !== 'renew') {
|
|
return [
|
|
'price' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($base_minor),
|
|
'show_price' => '0.00',
|
|
'tag' => '',
|
|
];
|
|
}
|
|
|
|
$type = sanitize_key((string) ($renew['price_type'] ?? 'discount'));
|
|
$price_minor = $base_minor;
|
|
$show_minor = $base_minor;
|
|
$tag = '';
|
|
|
|
if ($type === 'discount') {
|
|
$discount = (int) ($renew['discount'] ?? 8);
|
|
if ($discount <= 0) {
|
|
$discount = 8;
|
|
}
|
|
if ($discount <= 10) {
|
|
$percent = $discount * 10;
|
|
$price_minor = \AKSRT\Ledger\AssetAmount::percentage($base_minor, $percent);
|
|
$tag = sprintf(
|
|
/* translators: %s: discount like 8 */
|
|
__('%s折续费', 'aksrt'),
|
|
(string) $discount
|
|
);
|
|
} else {
|
|
$percent = min(100, $discount);
|
|
$price_minor = \AKSRT\Ledger\AssetAmount::percentage($base_minor, $percent);
|
|
$tag = sprintf(__('%s%% 续费价', 'aksrt'), (string) (int) $discount);
|
|
}
|
|
} elseif ($type === 'reduce') {
|
|
$reduce_minor = $this->parse_vip_money_minor($renew['reduce'] ?? '20');
|
|
$price_minor = max(1, $base_minor - $reduce_minor);
|
|
$tag = sprintf(
|
|
/* translators: %s: amount */
|
|
__('续费立减%s', 'aksrt'),
|
|
$this->format_cash_label(\AKSRT\Ledger\AssetAmount::decimal_from_minor($reduce_minor))
|
|
);
|
|
} else {
|
|
$show_minor = 0;
|
|
$tag = __('续费同价', 'aksrt');
|
|
}
|
|
|
|
if ($price_minor < 1) {
|
|
$price_minor = 1;
|
|
}
|
|
if ($show_minor > 0 && $price_minor >= $show_minor) {
|
|
$show_minor = 0;
|
|
$tag = __('续费', 'aksrt');
|
|
}
|
|
|
|
return [
|
|
'price' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($price_minor),
|
|
'show_price' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($show_minor > $price_minor ? $show_minor : 0),
|
|
'tag' => $tag,
|
|
];
|
|
}
|
|
|
|
|
|
|
|
public function encode_package_id(int $level, int $index): int {
|
|
return (max(1, min(2, $level)) * 1000) + max(1, $index);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @return array{level:int,index:int}|null
|
|
*/
|
|
public function decode_package_id(int $package_id): ?array {
|
|
if ($package_id < 1001) {
|
|
return null;
|
|
}
|
|
$level = intdiv($package_id, 1000);
|
|
$index = $package_id % 1000;
|
|
if ($level < 1 || $level > 2 || $index < 1) {
|
|
return null;
|
|
}
|
|
return ['level' => $level, 'index' => $index];
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @return array<int, array{id:string,name:string}>
|
|
*/
|
|
private function available_payment_methods(): array {
|
|
$methods = function_exists('aksrt_list_cash_payment_methods')
|
|
? aksrt_list_cash_payment_methods(true)
|
|
: [];
|
|
|
|
// 卡密兑换会员渠道(后台 会员购买 → 启用卡密兑换会员功能):
|
|
// 提交走 /pay/card-pass/redeem type=vip,不创建支付订单。
|
|
$card_pass = $this->vip_card_pass_context();
|
|
if (!empty($card_pass['enabled'])) {
|
|
$methods[] = ['id' => 'card_pass', 'name' => __('卡密', 'aksrt')];
|
|
}
|
|
// 卡密渠道追加后需按「收款接口显示顺序」重新定位(含 card_pass 槽位)。
|
|
return function_exists('aksrt_sort_payment_methods')
|
|
? aksrt_sort_payment_methods($methods)
|
|
: $methods;
|
|
}
|
|
|
|
/**
|
|
* 卡密兑换会员渠道上下文(ChargeCard vip 公开选项)。
|
|
*
|
|
* @return array{enabled:bool,desc:string,only_password:bool}
|
|
*/
|
|
private function vip_card_pass_context(): array {
|
|
$empty = ['enabled' => false, 'desc' => '', 'only_password' => false];
|
|
if (!class_exists('\AKSRT\Payment\ChargeCard')) {
|
|
return $empty;
|
|
}
|
|
$opts = \AKSRT\Payment\ChargeCard::get_instance()->get_public_options();
|
|
return is_array($opts['vip'] ?? null) ? array_merge($empty, $opts['vip']) : $empty;
|
|
}
|
|
|
|
|
|
|
|
private function format_cash_label(string $amount): string {
|
|
$symbol = '¥';
|
|
if (method_exists($this, 'get_paid_display_context')) {
|
|
$paid = $this->get_paid_display_context();
|
|
$symbol = (string) ($paid['display']['currency_symbol'] ?? '¥');
|
|
} elseif (class_exists('\AKSRT\Settings\Settings')) {
|
|
$paid = \AKSRT\Settings\Settings::get_paid_content_settings();
|
|
$symbol = (string) ($paid['display']['currency_symbol'] ?? '¥');
|
|
}
|
|
$n = function_exists('aksrt_format_price') ? aksrt_format_price($amount) : (string) $amount;
|
|
return $symbol . $n;
|
|
}
|
|
|
|
private function parse_vip_money_minor($value): int {
|
|
if (!is_string($value)) {
|
|
return 0;
|
|
}
|
|
try {
|
|
return \AKSRT\Ledger\AssetAmount::balance_minor($value);
|
|
} catch (\InvalidArgumentException $e) {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function format_expires_label(int $expires, int $level): string {
|
|
if ($level <= 0) {
|
|
return __('未开通', 'aksrt');
|
|
}
|
|
if ($expires <= 0) {
|
|
return __('永久有效', 'aksrt');
|
|
}
|
|
if ($expires < time()) {
|
|
return __('已过期', 'aksrt');
|
|
}
|
|
return sprintf(
|
|
/* translators: %s: date */
|
|
__('到期时间:%s', 'aksrt'),
|
|
wp_date('Y-m-d H:i', $expires)
|
|
);
|
|
}
|
|
|
|
}
|