积分与余额账务系统硬切重构
This commit is contained in:
1 parent
ca12226b39
commit
5cae5b5c93
159 files changed
+7275
-4718
No files matched your search
@@ -13,10 +13,15 @@ if (empty($balance_enabled)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wallet = (float) ($wallet_balance ?? 0.0);
|
||||
$wallet_fmt = class_exists('\AKSRT\Credits\Balance')
|
||||
? \AKSRT\Credits\Balance::format($wallet)
|
||||
: number_format_i18n($wallet, 2);
|
||||
$normalize_balance = static function ($value): \AKSRT\Ledger\AssetAmount {
|
||||
try {
|
||||
return \AKSRT\Ledger\AssetAmount::balance(is_string($value) ? $value : '');
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return \AKSRT\Ledger\AssetAmount::balance('0');
|
||||
}
|
||||
};
|
||||
$wallet = $normalize_balance($wallet_balance ?? '0');
|
||||
$wallet_fmt = $wallet->formatted();
|
||||
|
||||
$recharge = class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_payment_recharge_settings')
|
||||
? \AKSRT\Settings\Settings::get_payment_recharge_settings()
|
||||
@@ -32,9 +37,9 @@ if ($withdraw_on && class_exists('\AKSRT\Settings\Capabilities') && !\AKSRT\Sett
|
||||
$withdraw_on = false;
|
||||
}
|
||||
$withdraw_settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_withdrawal_settings() : [];
|
||||
$withdraw_min = max(0, (float) ($withdraw_settings['min_amount'] ?? 50));
|
||||
$withdraw_usage = ['remaining_count' => 0, 'remaining_amount' => 0];
|
||||
$withdraw_pending_hold = 0.0;
|
||||
$withdraw_min = $normalize_balance($withdraw_settings['min_amount'] ?? '50')->decimal();
|
||||
$withdraw_usage = ['remaining_count' => 0, 'remaining_amount' => '0.00'];
|
||||
$withdraw_pending_hold = '0.00';
|
||||
$withdraw_history = [];
|
||||
if ($withdraw_on && class_exists('\AKSRT\Payment\Withdrawal')) {
|
||||
$wd_svc = \AKSRT\Payment\Withdrawal::get_instance();
|
||||
@@ -42,7 +47,7 @@ if ($withdraw_on && class_exists('\AKSRT\Payment\Withdrawal')) {
|
||||
$withdraw_history = $wd_svc->get_user_withdrawals((int) ($user_id ?? 0), ['limit' => 30]);
|
||||
$withdraw_usage = $wd_svc->daily_usage((int) ($user_id ?? 0), $withdraw_settings);
|
||||
}
|
||||
$withdraw_processing = $withdraw_pending_hold > 0;
|
||||
$withdraw_processing = $normalize_balance($withdraw_pending_hold)->minor() > 0;
|
||||
$card_pass_balance = ['enabled' => false, 'desc' => '', 'only_password' => true];
|
||||
if (class_exists('\AKSRT\Payment\ChargeCard')) {
|
||||
$opts = \AKSRT\Payment\ChargeCard::get_instance()->get_public_options();
|
||||
@@ -90,7 +95,7 @@ $mark = (string) ($charge_view['currency_mark'] ?? '元');
|
||||
</div>
|
||||
<?php if ($withdraw_on) : ?>
|
||||
<div class="uc-asset-card__foot muted-2-color em09 mt6">
|
||||
<span><?php printf(esc_html__('冻结中 %s', 'aksrt'), esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format((float) $withdraw_pending_hold) : number_format_i18n((float) $withdraw_pending_hold, 2))); ?></span>
|
||||
<span><?php printf(esc_html__('冻结中 %s', 'aksrt'), esc_html($normalize_balance($withdraw_pending_hold)->formatted())); ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -128,13 +133,17 @@ $mark = (string) ($charge_view['currency_mark'] ?? '元');
|
||||
<?php if ($packages) : ?>
|
||||
<div class="muted-color mb6"><?php esc_html_e('请选择充值金额', 'aksrt'); ?></div>
|
||||
<div class="uc-charge-packages">
|
||||
<?php foreach ($packages as $idx => $pkg) : ?>
|
||||
<?php foreach ($packages as $idx => $pkg) :
|
||||
$package_credit = $normalize_balance($pkg['price'] ?? '');
|
||||
$package_pay = $normalize_balance($pkg['pay_price'] ?? '');
|
||||
$package_saving_minor = max(0, $package_credit->minor() - $package_pay->minor());
|
||||
?>
|
||||
<label class="uc-charge-package<?php echo $idx === 0 ? ' is-active' : ''; ?>">
|
||||
<input type="radio" name="balance_package" value="<?php echo esc_attr((string) $pkg['key']); ?>" <?php checked($idx === 0); ?>>
|
||||
<div class="uc-charge-package__credit"><span class="px12">¥</span><?php echo esc_html((string) $pkg['price']); ?></div>
|
||||
<div class="uc-charge-package__pay c-red"><span class="px12">¥</span><?php echo esc_html((string) $pkg['pay_price']); ?>
|
||||
<?php if ((float) $pkg['pay_price'] < (float) $pkg['price']) : ?>
|
||||
<span class="ml6 c-yellow smail"><?php printf(esc_html__('省%s', 'aksrt'), esc_html((string) ((float) $pkg['price'] - (float) $pkg['pay_price']))); ?></span>
|
||||
<?php if ($package_saving_minor > 0) : ?>
|
||||
<span class="ml6 c-yellow smail"><?php printf(esc_html__('省%s', 'aksrt'), esc_html(\AKSRT\Ledger\AssetAmount::decimal_from_minor($package_saving_minor))); ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (!empty($pkg['tag'])) : ?>
|
||||
@@ -195,19 +204,19 @@ endif; ?>
|
||||
<?php if (!empty($withdraw_history)) : ?>
|
||||
<?php foreach ($withdraw_history as $wd) :
|
||||
$st = sanitize_key((string) ($wd['status'] ?? ''));
|
||||
$gross = (float) ($wd['gross_amount'] ?? $wd['amount'] ?? 0);
|
||||
$net = (float) ($wd['amount'] ?? 0);
|
||||
$gross = $normalize_balance($wd['gross_amount'] ?? $wd['amount'] ?? '0');
|
||||
$net = $normalize_balance($wd['amount'] ?? '0');
|
||||
$st_class = $st === 'rejected' ? 'c-red' : ($st === 'completed' ? 'c-green' : 'c-blue');
|
||||
?>
|
||||
<div class="uc-withdraw-history__item border-bottom padding-h10">
|
||||
<div class="flex jsb ac">
|
||||
<span class="badg badg-sm <?php echo esc_attr($st_class); ?>"><?php echo esc_html($status_labels[$st] ?? $st); ?></span>
|
||||
<b class="em12"><?php echo esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format($gross) : number_format_i18n($gross, 2)); ?></b>
|
||||
<b class="em12"><?php echo esc_html($gross->formatted()); ?></b>
|
||||
</div>
|
||||
<div class="muted-2-color em09 mt6">
|
||||
<?php echo esc_html((string) ($wd['created_at'] ?? '')); ?>
|
||||
<?php if (abs($gross - $net) > 0.001) : ?>
|
||||
· <?php printf(esc_html__('到账 %s', 'aksrt'), esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format($net) : number_format_i18n($net, 2))); ?>
|
||||
<?php if ($gross->minor() !== $net->minor()) : ?>
|
||||
· <?php printf(esc_html__('到账 %s', 'aksrt'), esc_html($net->formatted())); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (!empty($wd['note'])) : ?>
|
||||
@@ -233,16 +242,14 @@ endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
$wallet_page = max(1, isset($_GET['wallet_page']) ? (int) $_GET['wallet_page'] : 1);
|
||||
$wlog = class_exists('\AKSRT\Credits\Balance')
|
||||
? \AKSRT\Credits\Balance::get_log(['user_id' => (int) $user_id, 'page' => $wallet_page, 'per_page' => 10])
|
||||
: ['items' => [], 'total' => 0];
|
||||
$wlog = \AKSRT\Ledger\LedgerQuery::get_instance()->history(['user_id' => (int) $user_id, 'asset' => 'balance', 'page' => $wallet_page, 'per_page' => 10]);
|
||||
if (!empty($wlog['items'])) :
|
||||
?>
|
||||
<div class="uc-transactions__list">
|
||||
<?php foreach ($wlog['items'] as $row) :
|
||||
$delta = (float) $row['delta'];
|
||||
$delta = (int) $row['delta_minor'];
|
||||
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
|
||||
$delta_txt = ($delta > 0 ? '+' : '') . (class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format($delta) : number_format_i18n($delta, 2));
|
||||
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
|
||||
?>
|
||||
<div class="uc-transactions__item">
|
||||
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
|
||||
@@ -250,7 +257,7 @@ endif; ?>
|
||||
</div>
|
||||
<div class="uc-transactions__info">
|
||||
<div class="uc-transactions__reason">
|
||||
<?php echo esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::reason_label((string) $row['reason']) : (string) $row['reason']); ?>
|
||||
<?php echo esc_html(aksrt_asset_reason_label((string) $row['reason'])); ?>
|
||||
<?php if (!empty($row['remark'])) : ?>
|
||||
<span class="uc-transactions__remark">(<?php echo esc_html((string) $row['remark']); ?>)</span>
|
||||
<?php endif; ?>
|
||||
@@ -263,7 +270,7 @@ endif; ?>
|
||||
<?php
|
||||
printf(
|
||||
esc_html__('余额 %s', 'aksrt'),
|
||||
esc_html(class_exists('\AKSRT\Credits\Balance') ? \AKSRT\Credits\Balance::format((float) $row['balance_after']) : number_format_i18n((float) $row['balance_after'], 2))
|
||||
esc_html(\AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, (int) $row['balance_after_minor'])->formatted())
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
|
||||
Reference in new issue
Block a user