From 3b48f3a572d21c2eb2f881fdcfb33fc6acb54898 Mon Sep 17 00:00:00 2001 From: yueyang <2495544247@qq.com> Date: Mon, 2 Nov 2026 17:37:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A1=A5=E9=BD=90OA=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E7=A7=9F=E8=B5=81=E7=A7=91=E7=9B=AE=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._210000_refresh_oa_other_lease_mapping.php | 74 +++++++++++++++++++ .../data/oa_process_account_mapping.json | 10 +++ .../ManagementExpensesPageDataTest.php | 9 ++- 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2026_11_02_210000_refresh_oa_other_lease_mapping.php diff --git a/database/migrations/2026_11_02_210000_refresh_oa_other_lease_mapping.php b/database/migrations/2026_11_02_210000_refresh_oa_other_lease_mapping.php new file mode 100644 index 00000000..98300dc3 --- /dev/null +++ b/database/migrations/2026_11_02_210000_refresh_oa_other_lease_mapping.php @@ -0,0 +1,74 @@ +environment('testing') + || (string) config('system_database.mode', 'bootstrap') === 'bootstrap') { + return; + } + + $schema = Schema::connection($this->connection()); + if (! $schema->hasTable('oa_process_account_mapping')) { + return; + } + + $mapping = json_decode( + (string) file_get_contents(base_path('resources/data/oa_process_account_mapping.json')), + true, + 512, + JSON_THROW_ON_ERROR, + ); + $codes = array_column($mapping, 'account_code'); + if ($mapping === [] || count($codes) !== count(array_unique($codes))) { + throw new \RuntimeException('流程科目映射快照为空或科目编码重复。'); + } + + $database = $schema->getConnection(); + $now = now(); + foreach (array_chunk($mapping, 100) as $chunk) { + $database->table('oa_process_account_mapping')->upsert( + array_map(static fn (array $row): array => [ + 'account_code' => (string) $row['account_code'], + 'account_name' => (string) $row['account_name'], + 'expense_category' => (string) $row['expense_category'], + 'second_level' => $row['second_level'] + ?? ((string) $row['expense_category'] . '(未细分)'), + 'third_level' => $row['third_level'] ?? '未细分', + 'in_fee_ratio' => (bool) $row['in_fee_ratio'], + 'allocation' => $row['allocation'] ?? null, + 'created_at' => $now, + 'updated_at' => $now, + ], $chunk), + ['account_code'], + [ + 'account_name', + 'expense_category', + 'second_level', + 'third_level', + 'in_fee_ratio', + 'allocation', + 'updated_at', + ], + ); + } + + $database->table('oa_process_account_mapping') + ->whereNotIn('account_code', $codes) + ->delete(); + } + + public function down(): void + { + // 已确认的业务映射在回滚时保留。 + } +}; diff --git a/resources/data/oa_process_account_mapping.json b/resources/data/oa_process_account_mapping.json index 5d936c03..020b9ebd 100644 --- a/resources/data/oa_process_account_mapping.json +++ b/resources/data/oa_process_account_mapping.json @@ -1948,5 +1948,15 @@ "in_fee_ratio": false, "allocation": "分摊", "source_row": 196 + }, + { + "account_code": "1123.09.99", + "account_name": "预付账款_租赁费_其他租赁", + "expense_category": "摊销", + "second_level": "摊销", + "third_level": "租赁", + "in_fee_ratio": false, + "allocation": "分摊", + "source_row": 197 } ] diff --git a/tests/Unit/EcommerceFinance/ManagementExpensesPageDataTest.php b/tests/Unit/EcommerceFinance/ManagementExpensesPageDataTest.php index 6a372678..82961b38 100644 --- a/tests/Unit/EcommerceFinance/ManagementExpensesPageDataTest.php +++ b/tests/Unit/EcommerceFinance/ManagementExpensesPageDataTest.php @@ -233,10 +233,10 @@ class ManagementExpensesPageDataTest extends TestCase JSON_THROW_ON_ERROR, ); - $this->assertCount(195, $mapping); - $this->assertCount(195, array_unique(array_column($mapping, 'account_code'))); + $this->assertCount(196, $mapping); + $this->assertCount(196, array_unique(array_column($mapping, 'account_code'))); $this->assertSame(37, count(array_filter($mapping, static fn (array $row): bool => $row['in_fee_ratio']))); - $this->assertSame(127, count(array_filter($mapping, static fn (array $row): bool => $row['allocation'] !== null))); + $this->assertSame(128, count(array_filter($mapping, static fn (array $row): bool => $row['allocation'] !== null))); $mappingByCode = array_column($mapping, null, 'account_code'); $this->assertSame('往来', $mappingByCode['2202.01']['expense_category']); $this->assertSame('往来', $mappingByCode['2202.01']['second_level']); @@ -248,6 +248,9 @@ class ManagementExpensesPageDataTest extends TestCase $this->assertTrue($mappingByCode['5601.11.01']['in_fee_ratio']); $this->assertSame('销售费用', $mappingByCode['1221.07']['expense_category']); $this->assertSame('推广费用', $mappingByCode['1221.07']['second_level']); + $this->assertSame('摊销', $mappingByCode['1123.09.99']['expense_category']); + $this->assertSame('摊销', $mappingByCode['1123.09.99']['second_level']); + $this->assertSame('租赁', $mappingByCode['1123.09.99']['third_level']); $this->assertSame('空包费', $mappingByCode['1221.07']['third_level']); $this->assertTrue($mappingByCode['1221.07']['in_fee_ratio']); $this->assertSame('管理费用', $mappingByCode['5602.11.03.19']['expense_category']); -- 2.47.2