From 93b9657e6f846730a9f55d266d7fa11328a3af94 Mon Sep 17 00:00:00 2001 From: 92451 <924518135@qq.com> Date: Mon, 26 Oct 2026 21:52:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E7=94=A8=E5=90=8C=E5=9B=9E=E6=AC=BE?= =?UTF-8?q?=E8=B4=A6=E6=88=B7=E7=9A=84=E7=A1=AE=E8=AE=A4=E7=AE=80=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/FinanceLedgerShopDirectory.php | 41 ++++++++++- .../FinanceLedgerShopDirectoryTest.php | 69 ++++++++++++++++--- 2 files changed, 101 insertions(+), 9 deletions(-) diff --git a/modules/EcommerceFinance/Services/FinanceLedgerShopDirectory.php b/modules/EcommerceFinance/Services/FinanceLedgerShopDirectory.php index d7c3a496..2b8513ba 100644 --- a/modules/EcommerceFinance/Services/FinanceLedgerShopDirectory.php +++ b/modules/EcommerceFinance/Services/FinanceLedgerShopDirectory.php @@ -111,7 +111,7 @@ class FinanceLedgerShopDirectory ]; } - return $rows; + return $this->propagateAccountShorts($rows); } /** @return array{exact:array,normalized:array} */ @@ -218,6 +218,45 @@ class FinanceLedgerShopDirectory return preg_replace('/[^a-z0-9]+/i', '', mb_strtolower(trim((string) $value))) ?? ''; } + /** + * 同一回款账号已在其他店铺匹配到唯一简称时,可安全复用到同账号店铺。 + * 同账号出现多个简称时视为歧义,不传播。 + * + * @param list> $rows + * @return list> + */ + private function propagateAccountShorts(array $rows): array + { + $knownGroups = []; + foreach ($rows as $row) { + $payoutKey = $this->normalizeAccountValue($row['payout_account'] ?? null); + $accountShort = trim((string) ($row['account_short'] ?? '')); + if ($payoutKey !== '' && $accountShort !== '') { + $knownGroups[$payoutKey][] = $accountShort; + } + } + $knownShorts = []; + foreach ($knownGroups as $payoutKey => $shorts) { + $uniqueShorts = array_values(array_unique($shorts)); + if (count($uniqueShorts) === 1) { + $knownShorts[$payoutKey] = $uniqueShorts[0]; + } + } + + foreach ($rows as &$row) { + if (trim((string) ($row['account_short'] ?? '')) !== '') { + continue; + } + $payoutKey = $this->normalizeAccountValue($row['payout_account'] ?? null); + if ($payoutKey !== '' && isset($knownShorts[$payoutKey])) { + $row['account_short'] = $knownShorts[$payoutKey]; + } + } + unset($row); + + return $rows; + } + private function nullableString(mixed $value): ?string { $value = trim((string) $value); diff --git a/tests/Feature/Business/FinanceLedgerShopDirectoryTest.php b/tests/Feature/Business/FinanceLedgerShopDirectoryTest.php index 49abbe0e..7372f443 100644 --- a/tests/Feature/Business/FinanceLedgerShopDirectoryTest.php +++ b/tests/Feature/Business/FinanceLedgerShopDirectoryTest.php @@ -49,14 +49,35 @@ class FinanceLedgerShopDirectoryTest extends FeatureTestCase 'created_at' => now(), 'updated_at' => now(), ], + [ + 'company_name' => '测试公司', + 'account_short' => '专属账户', + 'account_no' => 'MASTER-OTHER', + 'account_type' => '个人卡', + 'bank_name' => null, + 'created_at' => now(), + 'updated_at' => now(), + ], ]); DB::connection('business_mirror')->table('fin_shops')->insert([ - 'shop_name' => '报表测试店', - 'platform' => '天猫', - 'shop_balance' => 123.45, - 'shop_balance_date' => '2026-10-25', - 'created_at' => now(), - 'updated_at' => now(), + [ + 'shop_name' => '报表测试店', + 'platform' => '天猫', + 'account_short' => null, + 'shop_balance' => 123.45, + 'shop_balance_date' => '2026-10-25', + 'created_at' => now(), + 'updated_at' => now(), + ], + [ + 'shop_name' => '同账户甲', + 'platform' => '天猫', + 'account_short' => '专属账户', + 'shop_balance' => 0, + 'shop_balance_date' => null, + 'created_at' => now(), + 'updated_at' => now(), + ], ]); $openStore = [ @@ -91,15 +112,44 @@ class FinanceLedgerShopDirectoryTest extends FeatureTestCase 'store_status' => '0', 'withdrawal_account' => 'NET-7777', ]; + $openStoreWithKnownSharedPayout = [ + 'id' => 905, + 'platform' => '天猫', + 'erp_store_name' => '天猫-同账户甲', + 'company_name' => null, + 'store_status' => '0', + 'withdrawal_account' => 'LEGACY-5555', + ]; + $openStoreWithUnknownSharedPayout = [ + 'id' => 906, + 'platform' => '淘宝', + 'erp_store_name' => '淘宝-同账户乙', + 'company_name' => null, + 'store_status' => '0', + 'withdrawal_account' => 'LEGACY5555', + ]; $this->mock(BusinessInformationMirrorRepository::class) ->shouldReceive('allStores') ->once() - ->andReturn([$openStore, $closedStore, $openStoreWithoutSubject, $openStoreWithExcludedBank]); + ->andReturn([ + $openStore, + $closedStore, + $openStoreWithoutSubject, + $openStoreWithExcludedBank, + $openStoreWithKnownSharedPayout, + $openStoreWithUnknownSharedPayout, + ]); $this->mock(StoreReportPeriodBuilder::class) ->shouldReceive('build') ->once() - ->with([$openStore, $openStoreWithoutSubject, $openStoreWithExcludedBank]) + ->with([ + $openStore, + $openStoreWithoutSubject, + $openStoreWithExcludedBank, + $openStoreWithKnownSharedPayout, + $openStoreWithUnknownSharedPayout, + ]) ->andReturn([ '天猫-报表测试店' => [ [ @@ -129,9 +179,12 @@ class FinanceLedgerShopDirectoryTest extends FeatureTestCase $this->assertStringContainsString('当前存续主体', $shopHtml); $this->assertStringContainsString('淘宝-无主体店', $shopHtml); $this->assertStringContainsString('拼多多-网商店', $shopHtml); + $this->assertStringContainsString('天猫-同账户甲', $shopHtml); + $this->assertStringContainsString('淘宝-同账户乙', $shopHtml); $this->assertStringContainsString('在营', $shopHtml); $this->assertStringContainsString('公户账户', $shopHtml); $this->assertStringContainsString('123.45', $shopHtml); + $this->assertGreaterThanOrEqual(2, substr_count($shopHtml, '>专属账户')); $this->assertStringNotContainsString('京东-已关店', $shopHtml); $this->assertStringNotContainsString('历史主体', $shopHtml); $this->assertStringNotContainsString('支付宝账户', $shopHtml); -- 2.47.2