进行了一些小优化

This commit is contained in:
2026-08-25 06:02:26 +08:00
parent 75d1e6e53b
commit 8ddbfdd7b7
2 changed files with 3 additions and 6 deletions
+1 -4
View File
@@ -669,10 +669,7 @@ 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'] ?? '');
$display_length = mb_strlen($display, 'UTF-8'); $row['display_account'] = $display;
$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;
} }
+2 -2
View File
@@ -4,7 +4,7 @@ use AKSRT\Payment\Withdrawal;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
final class WithdrawalTest extends TestCase { final class WithdrawalTest extends TestCase {
public function test_account_display_mask_preserves_utf8_characters(): void { public function test_admin_account_display_keeps_the_full_account(): void {
$method = new ReflectionMethod(Withdrawal::class, 'normalize_row'); $method = new ReflectionMethod(Withdrawal::class, 'normalize_row');
$row = $method->invoke(Withdrawal::get_instance(), [ $row = $method->invoke(Withdrawal::get_instance(), [
'account_info' => wp_json_encode(['account' => '账户名称 账户号码']), 'account_info' => wp_json_encode(['account' => '账户名称 账户号码']),
@@ -12,7 +12,7 @@ final class WithdrawalTest extends TestCase {
'amount' => '95.00', 'amount' => '95.00',
]); ]);
self::assertSame('账户*****号码', $row['display_account']); self::assertSame('账户名称 账户号码', $row['display_account']);
self::assertSame(1, preg_match('//u', $row['display_account'])); self::assertSame(1, preg_match('//u', $row['display_account']));
} }
} }