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' => '测试'],