CaiWuXiTong/app/Utilities/FinanceLedgerBankDirectAccounts.php
shanshi 1114349ac7 feat(财务台账): 增加银行余额页与直连余额滚动 (#1399)
资金台账新增银行余额页、直连余额滚动、日期筛选、列设置和页内余额校正。
2026-11-25 12:01:46 +08:00

63 lines
2.2 KiB
PHP

<?php
namespace App\Utilities;
use Illuminate\Database\ConnectionInterface;
final class FinanceLedgerBankDirectAccounts
{
/** @return array<string,true> */
public static function map(ConnectionInterface $connection): array
{
$accounts = $connection->table('fin_accounts')
->whereNotNull('account_short')
->where('account_short', '<>', '')
->orderBy('id')
->get(['account_short', 'account_type', 'bank_name']);
if ($accounts->isEmpty()) {
return [];
}
$accountShorts = $accounts->pluck('account_short')->unique()->values()->all();
$typeOverrides = $connection->getSchemaBuilder()->hasTable('fin_account_type_overrides')
? $connection->table('fin_account_type_overrides')
->whereIn('account_short', $accountShorts)
->pluck('account_type', 'account_short')
: collect();
$sources = $connection->getSchemaBuilder()->hasTable('fin_flow_summary_account_sources')
? $connection->table('fin_flow_summary_account_sources')
->whereIn('account_short', $accountShorts)
->pluck('data_source', 'account_short')
: collect();
$direct = [];
foreach ($accounts as $account) {
$accountShort = trim((string) $account->account_short);
$accountType = trim((string) (
$typeOverrides[$accountShort]
?? $account->account_type
?? ''
));
if ($accountShort === '' || $accountType === '个人卡') {
continue;
}
if (FinanceLedgerFlowSummaryDataSource::normalize($sources[$accountShort] ?? null)
=== FinanceLedgerFlowSummaryDataSource::DIRECT) {
$direct[$accountShort] = true;
continue;
}
$bank = trim((string) ($account->bank_name ?? ''));
if (str_contains($accountShort, '招商')
|| str_contains($accountShort, '招行')
|| str_contains($bank, '招商')
|| str_contains($bank, '招行')) {
$direct[$accountShort] = true;
}
}
return $direct;
}
}