diff --git a/app/Business/UpstreamBusinessInformation.php b/app/Business/UpstreamBusinessInformation.php index 779efd62..bd5dc633 100644 --- a/app/Business/UpstreamBusinessInformation.php +++ b/app/Business/UpstreamBusinessInformation.php @@ -529,7 +529,7 @@ SQL); } /** - * 店铺基础信息页每次读取时把负责人字段覆盖为店铺账号镜像中的值。 + * 店铺基础信息页从店铺账号镜像关联负责人;部门负责人不使用旧档案兜底。 * 账号店铺名与 ERP 店铺名只差下划线/空格,因此统一归一后关联。 * * @param list> $rows @@ -542,16 +542,16 @@ SQL); $key = StoreAccountMirrorRepository::storeNameKey($row['erp_store_name'] ?? ''); $match = $ownership[$key] ?? null; if ($match === null) { + // 部门负责人只认店铺账号密码镜像,不能沿用可能属于其他口径的旧档案值。 + $row['department_manager'] = null; continue; } - foreach ([ - 'store_manager' => $match['operation_owner'], - 'department_manager' => $match['operation_department_head'], - ] as $field => $value) { - if ($value !== '') { - $row[$field] = $value; - } + + if ($match['operation_owner'] !== '') { + $row['store_manager'] = $match['operation_owner']; } + $departmentManager = trim((string) $match['operation_department_head']); + $row['department_manager'] = $departmentManager !== '' ? $departmentManager : null; } unset($row); diff --git a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php index bb05bf3b..127c041d 100644 --- a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php +++ b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php @@ -165,6 +165,46 @@ class UpstreamBusinessInformationTest extends TestCase $this->assertSame([], $summaryCards->all()); } + public function test_store_basic_information_does_not_fall_back_to_stale_department_manager(): void + { + $mirror = Mockery::mock(BusinessInformationMirrorRepository::class); + $mirror->shouldReceive('ready')->once()->with('store-information.read')->andReturnTrue(); + $mirror->shouldReceive('allStores')->once()->with([])->andReturn([ + [ + 'id' => 7, + 'erp_store_name' => '拼多多-无账号店铺', + 'store_manager' => '旧店铺负责人', + 'department_manager' => '错误的旧部门负责人', + ], + [ + 'id' => 8, + 'erp_store_name' => '拼多多-账号无部门店铺', + 'store_manager' => '旧店铺负责人', + 'department_manager' => '另一个错误的旧部门负责人', + ], + ]); + $accounts = Mockery::mock(StoreAccountMirrorRepository::class); + $accounts->shouldReceive('ownershipByStoreName')->once()->andReturn([ + StoreAccountMirrorRepository::storeNameKey('拼多多-账号无部门店铺') => [ + 'operation_owner' => '账号店铺负责人', + 'operation_department_head' => '', + 'operation_director' => '运营总监', + 'profit_center' => '运营中心A', + ], + ]); + + $paginator = (new UpstreamBusinessInformation( + Mockery::mock(UpstreamQueryCacheFactory::class), + $mirror, + null, + $accounts, + ))->paginate('store-management', 'basic-information', 50); + + $rows = collect($paginator->items())->keyBy('erp_store_name'); + $this->assertNull($rows['拼多多-无账号店铺']->department_manager); + $this->assertNull($rows['拼多多-账号无部门店铺']->department_manager); + } + public function test_trademark_classification_is_normalized_to_digits_only(): void { $mirror = Mockery::mock(BusinessInformationMirrorRepository::class);