进行了一些小优化
This commit is contained in:
1 parent
5549f81901
commit
75d1e6e53b
7 files changed
+52
-8
No files matched your search
@@ -251,6 +251,9 @@ endif; ?>
|
|||||||
$delta = (int) $row['delta_minor'];
|
$delta = (int) $row['delta_minor'];
|
||||||
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
|
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
|
||||||
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
|
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
|
||||||
|
$record_note = in_array((string) $row['reason'], ['withdraw_hold', 'withdraw_refund'], true)
|
||||||
|
? (string) ($row['withdrawal_number'] ?? '')
|
||||||
|
: (string) ($row['remark'] ?? '');
|
||||||
?>
|
?>
|
||||||
<div class="uc-transactions__item">
|
<div class="uc-transactions__item">
|
||||||
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
|
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
|
||||||
@@ -259,8 +262,8 @@ endif; ?>
|
|||||||
<div class="uc-transactions__info">
|
<div class="uc-transactions__info">
|
||||||
<div class="uc-transactions__reason">
|
<div class="uc-transactions__reason">
|
||||||
<?php echo esc_html(aksrt_asset_reason_label((string) $row['reason'])); ?>
|
<?php echo esc_html(aksrt_asset_reason_label((string) $row['reason'])); ?>
|
||||||
<?php if (!empty($row['remark'])) : ?>
|
<?php if ($record_note !== '') : ?>
|
||||||
<span class="uc-transactions__remark">(<?php echo esc_html((string) $row['remark']); ?>)</span>
|
<span class="uc-transactions__remark">(<?php echo esc_html($record_note); ?>)</span>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</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 class="uc-transactions__time"><?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?></div>
|
||||||
|
|||||||
@@ -82,9 +82,12 @@ if ($show_wallet || $show_credits) :
|
|||||||
$delta = (int) $row['delta_minor'];
|
$delta = (int) $row['delta_minor'];
|
||||||
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
|
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
|
||||||
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
|
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
|
||||||
$record_note = (string) $row['reason'] === 'points_exchange'
|
$record_note = (string) $row['reason'] === 'points_exchange'
|
||||||
? (string) $row['ref_key']
|
? (string) $row['ref_key']
|
||||||
: (string) $row['remark'];
|
: (string) $row['remark'];
|
||||||
|
if (in_array((string) $row['reason'], ['withdraw_hold', 'withdraw_refund'], true)) {
|
||||||
|
$record_note = (string) ($row['withdrawal_number'] ?? '');
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<div class="uc-transactions__item">
|
<div class="uc-transactions__item">
|
||||||
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
|
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ final class LedgerQuery {
|
|||||||
|
|
||||||
$entry_table = \AKSRT\Core\DBMigrator::table('asset_entry');
|
$entry_table = \AKSRT\Core\DBMigrator::table('asset_entry');
|
||||||
$transaction_table = \AKSRT\Core\DBMigrator::table('asset_transaction');
|
$transaction_table = \AKSRT\Core\DBMigrator::table('asset_transaction');
|
||||||
|
$flow_table = \AKSRT\Core\DBMigrator::table('financial_flow');
|
||||||
$where = ['1=1'];
|
$where = ['1=1'];
|
||||||
$params = [];
|
$params = [];
|
||||||
if ($user_id > 0) {
|
if ($user_id > 0) {
|
||||||
@@ -107,8 +108,10 @@ final class LedgerQuery {
|
|||||||
$entry_params[] = $asset;
|
$entry_params[] = $asset;
|
||||||
}
|
}
|
||||||
$rows = $wpdb->get_results($wpdb->prepare(
|
$rows = $wpdb->get_results($wpdb->prepare(
|
||||||
"SELECT e.*, t.operation_key, t.reason, t.ref_type, t.ref_key, t.actor_user_id, t.metadata, t.created_at transaction_created_at
|
"SELECT e.*, t.operation_key, t.reason, t.ref_type, t.ref_key, t.actor_user_id, t.metadata, t.created_at transaction_created_at, f.withdrawal_number
|
||||||
FROM {$entry_table} e INNER JOIN {$transaction_table} t ON t.id = e.transaction_id
|
FROM {$entry_table} e
|
||||||
|
INNER JOIN {$transaction_table} t ON t.id = e.transaction_id
|
||||||
|
LEFT JOIN {$flow_table} f ON f.ledger_transaction_id = t.id
|
||||||
WHERE " . implode(' AND ', $entry_where) . ' ORDER BY e.transaction_id DESC, e.line_no ASC',
|
WHERE " . implode(' AND ', $entry_where) . ' ORDER BY e.transaction_id DESC, e.line_no ASC',
|
||||||
$entry_params
|
$entry_params
|
||||||
), ARRAY_A);
|
), ARRAY_A);
|
||||||
@@ -123,6 +126,7 @@ final class LedgerQuery {
|
|||||||
'reason' => (string) $row['reason'],
|
'reason' => (string) $row['reason'],
|
||||||
'ref_type' => (string) ($row['ref_type'] ?? ''),
|
'ref_type' => (string) ($row['ref_type'] ?? ''),
|
||||||
'ref_key' => (string) ($row['ref_key'] ?? ''),
|
'ref_key' => (string) ($row['ref_key'] ?? ''),
|
||||||
|
'withdrawal_number' => (string) ($row['withdrawal_number'] ?? ''),
|
||||||
'actor_user_id' => (int) ($row['actor_user_id'] ?? 0),
|
'actor_user_id' => (int) ($row['actor_user_id'] ?? 0),
|
||||||
'metadata' => json_decode((string) ($row['metadata'] ?? ''), true) ?: [],
|
'metadata' => json_decode((string) ($row['metadata'] ?? ''), true) ?: [],
|
||||||
'created_at' => (string) $row['transaction_created_at'],
|
'created_at' => (string) $row['transaction_created_at'],
|
||||||
|
|||||||
@@ -669,7 +669,10 @@ class Withdrawal {
|
|||||||
$row['amount'] = $this->database_balance_decimal((string) ($row['amount'] ?? '0'));
|
$row['amount'] = $this->database_balance_decimal((string) ($row['amount'] ?? '0'));
|
||||||
$row['fee_rate'] = (int) ($meta['fee_rate'] ?? 0);
|
$row['fee_rate'] = (int) ($meta['fee_rate'] ?? 0);
|
||||||
$display = (string) ($meta['account'] ?? $row['account_info'] ?? '');
|
$display = (string) ($meta['account'] ?? $row['account_info'] ?? '');
|
||||||
$row['display_account'] = strlen($display) > 4 ? substr($display, 0, 2) . str_repeat('*', max(2, strlen($display) - 4)) . substr($display, -2) : '****';
|
$display_length = mb_strlen($display, 'UTF-8');
|
||||||
|
$row['display_account'] = $display_length > 4
|
||||||
|
? mb_substr($display, 0, 2, 'UTF-8') . str_repeat('*', max(2, $display_length - 4)) . mb_substr($display, -2, null, 'UTF-8')
|
||||||
|
: '****';
|
||||||
$row['source'] = (string) ($meta['source'] ?? 'balance');
|
$row['source'] = (string) ($meta['source'] ?? 'balance');
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use AKSRT\Payment\Withdrawal;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
final class WithdrawalTest extends TestCase {
|
||||||
|
public function test_account_display_mask_preserves_utf8_characters(): void {
|
||||||
|
$method = new ReflectionMethod(Withdrawal::class, 'normalize_row');
|
||||||
|
$row = $method->invoke(Withdrawal::get_instance(), [
|
||||||
|
'account_info' => wp_json_encode(['account' => '账户名称 账户号码']),
|
||||||
|
'gross_amount' => '100.00',
|
||||||
|
'amount' => '95.00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
self::assertSame('账户*****号码', $row['display_account']);
|
||||||
|
self::assertSame(1, preg_match('//u', $row['display_account']));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,3 +70,4 @@ require_once dirname(__DIR__, 2) . '/src/Ledger/LedgerCommand.php';
|
|||||||
require_once dirname(__DIR__, 2) . '/src/Ledger/LedgerResult.php';
|
require_once dirname(__DIR__, 2) . '/src/Ledger/LedgerResult.php';
|
||||||
require_once dirname(__DIR__, 2) . '/src/Ledger/OperationKey.php';
|
require_once dirname(__DIR__, 2) . '/src/Ledger/OperationKey.php';
|
||||||
require_once dirname(__DIR__, 2) . '/src/Finance/BusinessNumber.php';
|
require_once dirname(__DIR__, 2) . '/src/Finance/BusinessNumber.php';
|
||||||
|
require_once dirname(__DIR__, 2) . '/src/Payment/Withdrawal.php';
|
||||||
@@ -41,3 +41,15 @@ test('native and front-end surfaces expose immutable business numbers', () => {
|
|||||||
assert.match(read('assets/js/order-center.js'), /\["流水号", order\.flow_number \|\| "—"\]/)
|
assert.match(read('assets/js/order-center.js'), /\["流水号", order\.flow_number \|\| "—"\]/)
|
||||||
assert.match(read('inc/helpers/user-center-renderers/credits-wallet.php'), /withdrawal_number/)
|
assert.match(read('inc/helpers/user-center-renderers/credits-wallet.php'), /withdrawal_number/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('balance history renders withdrawal numbers from the committed flow', () => {
|
||||||
|
const query = read('src/Ledger/LedgerQuery.php')
|
||||||
|
const profile = read('inc/helpers/user-center-renderers/profile-credits.php')
|
||||||
|
const wallet = read('inc/helpers/user-center-renderers/credits-wallet.php')
|
||||||
|
assert.match(query, /LEFT JOIN \{\$flow_table\} f ON f\.ledger_transaction_id = t\.id/)
|
||||||
|
assert.match(query, /'withdrawal_number'\s*=>\s*\(string\)/)
|
||||||
|
for (const source of [profile, wallet]) {
|
||||||
|
assert.match(source, /\['withdraw_hold', 'withdraw_refund'\]/)
|
||||||
|
assert.match(source, /\$row\['withdrawal_number'\]/)
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in new issue
Block a user