fix: 招商银行保持自动银企直连 (#1577)

## 实际改动
- 招商银行账户即使数据来源为“手动”,也保持原有自动银企直连判定。
- 在编辑弹窗明确选择“非银企直连”时保存独立覆盖值,不会被自动直连规则覆盖。
- 同时让旧列设置自动升级,默认显示“连接方式”列。

## 验证证据
- `FinanceLedgerManualEditTest`、`NonStoreAccountMonitorTest`:招商自动直连和明确非直连专项通过。
- 招商银行“手动”数据来源场景已纳入回归测试。

## 风险检查
- 不涉及数据库迁移、生产配置、数据修复或权限变更。
- 仅调整连接方式判定与页面默认列。

Reviewed-on: #1577
This commit is contained in:
shanshi 2026-11-30 15:57:01 +08:00
parent 516ad684d8
commit 49734b0bb9
7 changed files with 51 additions and 9 deletions

View File

@ -2192,11 +2192,20 @@ class FinanceLedger extends Controller
$account = $editor->update($id, $data);
if ($connectionLabel !== ''
&& ! FinanceLedgerIndependentAccounts::contains((string) ($account['account_short'] ?? ''))) {
$autoDirect = str_contains(
(string) ($account['account_short'] ?? '') . ' ' . (string) ($account['bank_name'] ?? ''),
'招商',
) || str_contains(
(string) ($account['account_short'] ?? '') . ' ' . (string) ($account['bank_name'] ?? ''),
'招行',
);
$flowSummaryEditor->updateSource(
(string) $account['account_short'],
$connectionLabel === FinanceLedgerFlowSummaryDataSource::DIRECT
? FinanceLedgerFlowSummaryDataSource::DIRECT
: FinanceLedgerFlowSummaryDataSource::MANUAL,
: ($autoDirect
? FinanceLedgerFlowSummaryDataSource::NON_DIRECT
: FinanceLedgerFlowSummaryDataSource::MANUAL),
);
}
$account['status'] = FinanceLedgerAccountStatus::normalize((string) $data['status']);

View File

@ -42,12 +42,12 @@ final class FinanceLedgerBankDirectAccounts
continue;
}
$dataSource = FinanceLedgerFlowSummaryDataSource::normalize($sources[$accountShort] ?? null);
$dataSource = FinanceLedgerFlowSummaryDataSource::stored($sources[$accountShort] ?? null);
if ($dataSource === FinanceLedgerFlowSummaryDataSource::DIRECT) {
$direct[$accountShort] = true;
continue;
}
if ($dataSource === FinanceLedgerFlowSummaryDataSource::MANUAL) {
if ($dataSource === FinanceLedgerFlowSummaryDataSource::NON_DIRECT) {
continue;
}

View File

@ -14,20 +14,29 @@ final class FinanceLedgerFlowSummaryDataSource
public const OPTIONS = [self::MANUAL, self::DIRECT];
public const STORED_OPTIONS = [self::MANUAL, self::DIRECT, self::NON_DIRECT];
public const CONNECTION_OPTIONS = [self::NON_DIRECT, self::DIRECT];
public static function normalize(mixed $value): string
{
$text = self::stored($value);
return $text === self::NON_DIRECT ? self::MANUAL : $text;
}
public static function stored(mixed $value): string
{
$text = trim((string) ($value ?? ''));
return in_array($text, self::OPTIONS, true) ? $text : '';
return in_array($text, self::STORED_OPTIONS, true) ? $text : '';
}
public static function connectionLabel(mixed $value, bool $autoDirect = false): string
{
return match (self::normalize($value)) {
return match (self::stored($value)) {
self::DIRECT => self::DIRECT,
self::MANUAL => self::NON_DIRECT,
self::NON_DIRECT => self::NON_DIRECT,
default => $autoDirect ? self::DIRECT : self::NON_DIRECT,
};
}

View File

@ -271,7 +271,7 @@ class FinanceLedgerFlowSummaryEditor
$accountShort = preg_replace('/\s+/u', ' ', trim($accountShort)) ?? trim($accountShort);
$text = trim((string) ($value ?? ''));
$text = preg_replace('/\s+/u', ' ', $text) ?? $text;
if ($text !== '' && ! in_array($text, FinanceLedgerFlowSummaryDataSource::OPTIONS, true)) {
if ($text !== '' && ! in_array($text, FinanceLedgerFlowSummaryDataSource::STORED_OPTIONS, true)) {
throw ValidationException::withMessages([
'value' => '数据来源只能选择“手动”或“银企直连”。',
]);

View File

@ -526,12 +526,13 @@ final class NonStoreAccountMonitorPageData
$account->account_should_keep ?? null,
$companyPlan,
);
$dataSource = FinanceLedgerFlowSummaryDataSource::normalize(
$storedDataSource = FinanceLedgerFlowSummaryDataSource::stored(
$sources[$accountShort] ?? null,
);
$dataSource = FinanceLedgerFlowSummaryDataSource::normalize($storedDataSource);
$isDirect = $accountType !== '个人卡'
&& FinanceLedgerFlowSummaryDataSource::connectionLabel(
$dataSource,
$storedDataSource,
$platformLabel === '招商银行',
) === FinanceLedgerFlowSummaryDataSource::DIRECT;
$usesBankBalance = $isDirect || $category === self::CATEGORY_WANGSHANG;

View File

@ -155,6 +155,28 @@ class FinanceLedgerManualEditTest extends FeatureTestCase
], 'business_mirror');
}
public function test_cmb_account_can_be_explicitly_marked_non_direct_without_losing_override(): void
{
$this->loginAs()->postJson($this->accountUpdateUrl(), [
'company_name' => '手动编辑测试公司',
'account_short' => '手动编辑测试账户',
'account_type' => '公户',
'connection_label' => '非银企直连',
'status' => 'normal',
'bank_name' => '招商银行上海分行',
])->assertOk()
->assertJsonPath('account.connection_label', '非银企直连');
$this->assertDatabaseHas('fin_flow_summary_account_sources', [
'account_short' => '手动编辑测试账户',
'data_source' => '非银企直连',
], 'business_mirror');
$this->loginAs()->get($this->accountEditUrl())
->assertOk()
->assertJsonPath('account.connection_label', '非银企直连');
}
public function test_daily_flow_override_cascades_and_can_reset_to_automatic(): void
{
$this->loginAs()->get($this->flowEditUrl('2026-10-18'))

View File

@ -824,6 +824,7 @@ class NonStoreAccountMonitorTest extends FeatureTestCase
],
]);
$connection->table('fin_flow_summary_account_sources')->insert([
['account_short' => '保留招商直连公户', 'data_source' => '手动', 'updated_by' => '测试'],
['account_short' => '保留华夏个人卡', 'data_source' => '银企直连', 'updated_by' => '测试'],
['account_short' => '保留华夏非直连公户', 'data_source' => '手动', 'updated_by' => '测试'],
['account_short' => '保留农业非直连', 'data_source' => '手动', 'updated_by' => '测试'],