55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Utilities;
|
|
|
|
final class FinanceLedgerAccountType
|
|
{
|
|
public const ALIPAY = '支付宝';
|
|
|
|
public const BANK_ACCOUNT_TYPES = ['公户', '个人卡', '网商银行'];
|
|
|
|
public const DEFAULT_OPTIONS = [
|
|
'个人卡',
|
|
'公户',
|
|
self::ALIPAY,
|
|
'网商银行',
|
|
];
|
|
|
|
public static function options(array ...$groups): array
|
|
{
|
|
$types = self::DEFAULT_OPTIONS;
|
|
foreach ($groups as $group) {
|
|
foreach ($group as $type) {
|
|
$type = trim((string) $type);
|
|
if ($type !== '') {
|
|
$types[] = $type;
|
|
}
|
|
}
|
|
}
|
|
|
|
$types = array_values(array_unique($types));
|
|
sort($types, SORT_NATURAL | SORT_FLAG_CASE);
|
|
|
|
return $types;
|
|
}
|
|
|
|
public static function last4(?string $accountType, ?string $accountNo, ?string $fallback = null): string
|
|
{
|
|
$type = trim((string) $accountType);
|
|
if ($type === self::ALIPAY) {
|
|
return '/';
|
|
}
|
|
|
|
if (in_array($type, self::BANK_ACCOUNT_TYPES, true)) {
|
|
$digits = preg_replace('/\D+/', '', (string) $accountNo);
|
|
if (strlen((string) $digits) >= 4) {
|
|
return substr((string) $digits, -4);
|
|
}
|
|
}
|
|
|
|
$fallback = trim((string) $fallback);
|
|
|
|
return $fallback !== '' ? $fallback : '/';
|
|
}
|
|
}
|