From 49734b0bb989302703d644325cbdcc833c4ec8a7 Mon Sep 17 00:00:00 2001 From: shanshi <3316401569@qq.com> Date: Mon, 30 Nov 2026 15:57:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8B=9B=E5=95=86=E9=93=B6=E8=A1=8C?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E8=87=AA=E5=8A=A8=E9=93=B6=E4=BC=81=E7=9B=B4?= =?UTF-8?q?=E8=BF=9E=20(#1577)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 实际改动 - 招商银行账户即使数据来源为“手动”,也保持原有自动银企直连判定。 - 在编辑弹窗明确选择“非银企直连”时保存独立覆盖值,不会被自动直连规则覆盖。 - 同时让旧列设置自动升级,默认显示“连接方式”列。 ## 验证证据 - `FinanceLedgerManualEditTest`、`NonStoreAccountMonitorTest`:招商自动直连和明确非直连专项通过。 - 招商银行“手动”数据来源场景已纳入回归测试。 ## 风险检查 - 不涉及数据库迁移、生产配置、数据修复或权限变更。 - 仅调整连接方式判定与页面默认列。 Reviewed-on: https://git.1080p.hk/WuYongJie/CaiWuXiTong/pulls/1577 --- .../Controllers/Business/FinanceLedger.php | 11 +++++++++- .../FinanceLedgerBankDirectAccounts.php | 4 ++-- .../FinanceLedgerFlowSummaryDataSource.php | 15 ++++++++++--- .../FinanceLedgerFlowSummaryEditor.php | 2 +- .../View/NonStoreAccountMonitorPageData.php | 5 +++-- .../Business/FinanceLedgerManualEditTest.php | 22 +++++++++++++++++++ .../Business/NonStoreAccountMonitorTest.php | 1 + 7 files changed, 51 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Business/FinanceLedger.php b/app/Http/Controllers/Business/FinanceLedger.php index 8156241d..f856e610 100644 --- a/app/Http/Controllers/Business/FinanceLedger.php +++ b/app/Http/Controllers/Business/FinanceLedger.php @@ -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']); diff --git a/app/Utilities/FinanceLedgerBankDirectAccounts.php b/app/Utilities/FinanceLedgerBankDirectAccounts.php index 738e0a36..526909bc 100644 --- a/app/Utilities/FinanceLedgerBankDirectAccounts.php +++ b/app/Utilities/FinanceLedgerBankDirectAccounts.php @@ -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; } diff --git a/app/Utilities/FinanceLedgerFlowSummaryDataSource.php b/app/Utilities/FinanceLedgerFlowSummaryDataSource.php index fa7c1582..a30b0250 100644 --- a/app/Utilities/FinanceLedgerFlowSummaryDataSource.php +++ b/app/Utilities/FinanceLedgerFlowSummaryDataSource.php @@ -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, }; } diff --git a/modules/EcommerceFinance/Services/FinanceLedgerFlowSummaryEditor.php b/modules/EcommerceFinance/Services/FinanceLedgerFlowSummaryEditor.php index da3322d0..54d773dc 100644 --- a/modules/EcommerceFinance/Services/FinanceLedgerFlowSummaryEditor.php +++ b/modules/EcommerceFinance/Services/FinanceLedgerFlowSummaryEditor.php @@ -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' => '数据来源只能选择“手动”或“银企直连”。', ]); diff --git a/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php b/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php index b97f7155..be3374e1 100644 --- a/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php +++ b/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php @@ -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; diff --git a/tests/Feature/Business/FinanceLedgerManualEditTest.php b/tests/Feature/Business/FinanceLedgerManualEditTest.php index 7d45875a..4d760f1d 100644 --- a/tests/Feature/Business/FinanceLedgerManualEditTest.php +++ b/tests/Feature/Business/FinanceLedgerManualEditTest.php @@ -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')) diff --git a/tests/Feature/Business/NonStoreAccountMonitorTest.php b/tests/Feature/Business/NonStoreAccountMonitorTest.php index 74729952..ed80f2b6 100644 --- a/tests/Feature/Business/NonStoreAccountMonitorTest.php +++ b/tests/Feature/Business/NonStoreAccountMonitorTest.php @@ -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' => '测试'],