复用同回款账户的确认简称 (#660)
Co-authored-by: 92451 <924518135@qq.com> Co-committed-by: 92451 <924518135@qq.com>
This commit is contained in:
parent
32e8811f71
commit
f593cd5bb0
@ -111,7 +111,7 @@ class FinanceLedgerShopDirectory
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
return $this->propagateAccountShorts($rows);
|
||||
}
|
||||
|
||||
/** @return array{exact:array<string,object>,normalized:array<string,object>} */
|
||||
@ -218,6 +218,45 @@ class FinanceLedgerShopDirectory
|
||||
return preg_replace('/[^a-z0-9]+/i', '', mb_strtolower(trim((string) $value))) ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 同一回款账号已在其他店铺匹配到唯一简称时,可安全复用到同账号店铺。
|
||||
* 同账号出现多个简称时视为歧义,不传播。
|
||||
*
|
||||
* @param list<array<string,mixed>> $rows
|
||||
* @return list<array<string,mixed>>
|
||||
*/
|
||||
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);
|
||||
|
||||
@ -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, '>专属账户</td>'));
|
||||
$this->assertStringNotContainsString('京东-已关店', $shopHtml);
|
||||
$this->assertStringNotContainsString('历史主体', $shopHtml);
|
||||
$this->assertStringNotContainsString('支付宝账户', $shopHtml);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user