From 5803d2b9bd1189a2dc4353d3ab1c1b71d950b7ae Mon Sep 17 00:00:00 2001 From: DoDo <1060330844@qq.com> Date: Mon, 9 Nov 2026 16:32:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=AC=E5=8F=B8=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=B3=A8=E5=86=8C=E6=97=B6=E9=97=B4=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=B1=95=E7=A4=BA=20(#1016)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 已注销及无效/2000 年前注册时间统一显示 /,合法日期保持原值。 --- app/Business/UpstreamBusinessInformation.php | 41 ++++++++++++++++--- .../UpstreamBusinessInformationTest.php | 31 ++++++++++++++ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/app/Business/UpstreamBusinessInformation.php b/app/Business/UpstreamBusinessInformation.php index 898742ff..d93e7880 100644 --- a/app/Business/UpstreamBusinessInformation.php +++ b/app/Business/UpstreamBusinessInformation.php @@ -16,6 +16,7 @@ use Throwable; class UpstreamBusinessInformation { private const SOURCE = 'operations_replica'; + private const COMPANY_ESTABLISHMENT_YEAR_FLOOR = 2000; public function __construct( private readonly UpstreamQueryCacheFactory $caches, @@ -1066,14 +1067,18 @@ SQL); private function mapCompany(array $row): array { $row = $this->toUtf8($row); - $row['establishment_date'] = $this->date($row['establishment_date'] ?? null); + $companyStatus = trim((string) ($row['company_status'] ?? '')); + $row['company_status'] = match ($companyStatus) { + '0', '正常' => '正常', + '1', '注销', '已注销' => '已注销', + default => $companyStatus !== '' ? $companyStatus : null, + }; + $row['establishment_date'] = $this->companyEstablishmentDate( + $row['establishment_date'] ?? null, + $row['company_status'] === '已注销', + ); $row['subscribed_at'] = $this->date($row['subscribed_at'] ?? null); $row['city'] = RegisteredAddressCity::parse($row['registered_address'] ?? null); - $row['company_status'] = match ((string) ($row['company_status'] ?? '')) { - '0' => '正常', - '1' => '已注销', - default => $row['company_status'] ?? null, - }; $businessType = trim((string) ($row['business_registration_type'] ?? '')); $row['business_registration_type'] = in_array($businessType, ['核定', '个人独资企业'], true) ? $businessType @@ -1082,6 +1087,30 @@ SQL); return $row; } + private function companyEstablishmentDate(mixed $value, bool $deregistered): ?string + { + if ($deregistered) { + return '/'; + } + + if ($value === null || trim((string) $value) === '') { + return null; + } + + // 上游用 1900-01-01 表示未知成立日期;公司资料不展示 2000 年前或非法日期。 + $date = substr(trim((string) $value), 0, 10); + if (! preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $date, $parts)) { + return '/'; + } + + [, $year, $month, $day] = array_map('intval', $parts); + if ($year < self::COMPANY_ESTABLISHMENT_YEAR_FLOOR || ! checkdate($month, $day, $year)) { + return '/'; + } + + return $date; + } + private function mapStore(array $row): array { $row = $this->toUtf8($row); diff --git a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php index d8a44988..3673f476 100644 --- a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php +++ b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php @@ -206,6 +206,37 @@ class UpstreamBusinessInformationTest extends TestCase $this->assertSame([], $trademarkCards->all()); } + public function test_company_registration_date_is_hidden_for_deregistered_and_invalid_pre_2000_values(): void + { + $mirror = Mockery::mock(BusinessInformationMirrorRepository::class); + $mirror->shouldReceive('ready')->once()->with('company-information.read')->andReturnTrue(); + $mirror->shouldReceive('paginate')->once()->with('company-information.read', 1, 50, [])->andReturn([ + 'data' => [ + ['id' => 1, 'company_status' => '1', 'establishment_date' => '2024-04-28'], + ['id' => 2, 'company_status' => '已注销', 'establishment_date' => null], + ['id' => 3, 'company_status' => '0', 'establishment_date' => '1900-01-01'], + ['id' => 4, 'company_status' => '正常', 'establishment_date' => '1999-12-31'], + ['id' => 5, 'company_status' => '0', 'establishment_date' => '2000-01-01'], + ['id' => 6, 'company_status' => null, 'establishment_date' => null], + ], + 'total' => 6, + ]); + + $items = (new UpstreamBusinessInformation( + Mockery::mock(UpstreamQueryCacheFactory::class), + $mirror, + null, + ))->paginate('company-management', 'basic-information', 50)->items(); + + $this->assertSame('已注销', $items[0]->company_status); + $this->assertSame('/', $items[0]->establishment_date); + $this->assertSame('/', $items[1]->establishment_date); + $this->assertSame('/', $items[2]->establishment_date); + $this->assertSame('/', $items[3]->establishment_date); + $this->assertSame('2000-01-01', $items[4]->establishment_date); + $this->assertNull($items[5]->establishment_date); + } + public function test_bootstrap_without_mirror_explains_shared_connection_instead_of_requesting_upstream_credentials(): void { config(['system_database.mode' => 'bootstrap', 'upstreams.local_configuration.enabled' => false]);