From ea3d4282624caac26ad476b160f8f6da43c10dcc Mon Sep 17 00:00:00 2001 From: yueyang <2495544247@qq.com> Date: Thu, 3 Dec 2026 15:41:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B4=B9=E7=94=A8=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E6=8C=89=E5=8F=91=E7=94=9F=E6=97=B6=E9=97=B4=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E4=B8=BB=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PerformanceDetailSubjectMatcher.php | 10 ++- .../View/BillingDetailsPageData.php | 6 +- .../BillingDetailsExpenseFilterTest.php | 87 +++++++++++++++++-- 3 files changed, 87 insertions(+), 16 deletions(-) diff --git a/modules/EcommerceFinance/Services/PerformanceDetailSubjectMatcher.php b/modules/EcommerceFinance/Services/PerformanceDetailSubjectMatcher.php index ae1f40d53..3746e5020 100644 --- a/modules/EcommerceFinance/Services/PerformanceDetailSubjectMatcher.php +++ b/modules/EcommerceFinance/Services/PerformanceDetailSubjectMatcher.php @@ -298,12 +298,14 @@ final class PerformanceDetailSubjectMatcher private function rowDate(object $row): string { - $date = trim((string) ($row->occurred_date ?? '')); - if ($date !== '') { - return substr($date, 0, 10); + foreach (['occurred_date', 'occurred_at', 'report_month'] as $property) { + $date = trim((string) ($row->{$property} ?? '')); + if ($date !== '') { + return substr($date, 0, 10); + } } - return substr(trim((string) ($row->report_month ?? '')), 0, 10); + return ''; } private function normalize(mixed $value): string diff --git a/modules/EcommerceFinance/View/BillingDetailsPageData.php b/modules/EcommerceFinance/View/BillingDetailsPageData.php index 725d50e49..3f157d2db 100644 --- a/modules/EcommerceFinance/View/BillingDetailsPageData.php +++ b/modules/EcommerceFinance/View/BillingDetailsPageData.php @@ -113,7 +113,7 @@ class BillingDetailsPageData 'remark' => ['备注', 'text'], ]; - /** 费用明细精简列:平台、店铺、当前主体资料、线上单号、账单费用、收支净额。 */ + /** 费用明细精简列:平台、店铺、按发生时间命中的主体资料、线上单号、账单费用、收支净额。 */ public const EXPENSE_COLUMNS = [ 'platform' => ['平台', 'text'], 'store_name' => ['店铺', 'text'], @@ -248,7 +248,7 @@ class BillingDetailsPageData if (isset($want['custom_remark'])) { $add('custom_remark', $has('custom_remark') ? 'custom_remark' : null); } if (isset($want['remark'])) { $add('remark', $has('remark') ? 'remark' : null); } if (isset($want['type_text'])) { $add('type_text', $pick(is_string($meta['type']) ? (string) $meta['type'] : null)); } - if (isset($want['occurred_at'])) { $add('occurred_at', (string) $meta['date']); } + if (isset($want['occurred_at']) || $subject) { $add('occurred_at', (string) $meta['date']); } if (isset($want['income']) || isset($want['amount'])) { $add('income', (string) $meta['income']); } if (isset($want['expense']) || isset($want['amount'])) { $add('expense', (string) $meta['expense']); } @@ -1476,7 +1476,7 @@ class BillingDetailsPageData $this->subjectMatcher ??= app(PerformanceDetailSubjectMatcher::class); - return $this->subjectMatcher->applyArrayCurrent($row, $subjectMap); + return $this->subjectMatcher->applyArray($row, $subjectMap); } /** @param list $storeNames */ diff --git a/tests/Unit/EcommerceFinance/BillingDetailsExpenseFilterTest.php b/tests/Unit/EcommerceFinance/BillingDetailsExpenseFilterTest.php index 9e1856f2f..8c68a7e69 100644 --- a/tests/Unit/EcommerceFinance/BillingDetailsExpenseFilterTest.php +++ b/tests/Unit/EcommerceFinance/BillingDetailsExpenseFilterTest.php @@ -31,7 +31,7 @@ class BillingDetailsExpenseFilterTest extends TestCase $this->assertSame('账单费用', BillingDetailsPageData::EXPENSE_COLUMNS['finance_remark'][0]); } - public function test_expense_rows_include_current_company_and_taxpayer_type(): void + public function test_expense_rows_use_the_company_period_matching_occurred_at(): void { $data = app(BillingDetailsPageData::class); $apply = new ReflectionMethod(BillingDetailsPageData::class, 'applySubjectRow'); @@ -40,16 +40,29 @@ class BillingDetailsExpenseFilterTest extends TestCase $row = $apply->invoke($data, [ 'store_name' => '天猫-亿家达旗舰店', 'online_order_no' => '512789121088013442', + 'occurred_at' => '2026-09-15 12:00:00', ], [ 'periods' => [ - '天猫-亿家达旗舰店' => [[ - 'company_name' => '常州市测试家居有限公司', - 'effective_at' => '2026-07-01', - 'expires_at' => null, - 'source' => 'initial', - ]], + '天猫-亿家达旗舰店' => [ + [ + 'company_name' => '旧测试家居有限公司', + 'effective_at' => '2026-07-01', + 'expires_at' => '2026-09-30', + 'source' => 'initial', + ], + [ + 'company_name' => '常州市测试家居有限公司', + 'effective_at' => '2026-10-01', + 'expires_at' => null, + 'source' => 'initial', + ], + ], ], 'plans' => [ + '旧测试家居有限公司' => [ + 'company_name' => '旧测试家居有限公司', + 'taxpayer_type' => '小规模纳税人', + ], '常州市测试家居有限公司' => [ 'company_name' => '常州市测试家居有限公司', 'taxpayer_type' => '一般纳税人', @@ -58,8 +71,64 @@ class BillingDetailsExpenseFilterTest extends TestCase 'company_plan_shops' => [], ]); - $this->assertSame('一般纳税人', $row['taxpayer_type']); - $this->assertSame('常州市测试家居有限公司', $row['company_name']); + $this->assertSame('小规模纳税人', $row['taxpayer_type']); + $this->assertSame('旧测试家居有限公司', $row['company_name']); + + $newPeriod = $apply->invoke($data, [ + 'store_name' => '天猫-亿家达旗舰店', + 'online_order_no' => '512789121088013443', + 'occurred_at' => '2026-10-01 00:00:00', + ], [ + 'periods' => [ + '天猫-亿家达旗舰店' => [ + [ + 'company_name' => '旧测试家居有限公司', + 'effective_at' => '2026-07-01', + 'expires_at' => '2026-09-30', + 'source' => 'initial', + ], + [ + 'company_name' => '常州市测试家居有限公司', + 'effective_at' => '2026-10-01', + 'expires_at' => null, + 'source' => 'initial', + ], + ], + ], + 'plans' => [ + '旧测试家居有限公司' => [ + 'company_name' => '旧测试家居有限公司', + 'taxpayer_type' => '小规模纳税人', + ], + '常州市测试家居有限公司' => [ + 'company_name' => '常州市测试家居有限公司', + 'taxpayer_type' => '一般纳税人', + ], + ], + 'company_plan_shops' => [], + ]); + + $this->assertSame('一般纳税人', $newPeriod['taxpayer_type']); + $this->assertSame('常州市测试家居有限公司', $newPeriod['company_name']); + } + + public function test_expense_export_selects_occurred_at_for_period_matching(): void + { + $data = app(BillingDetailsPageData::class); + $select = new ReflectionMethod(BillingDetailsPageData::class, 'exportSelectList'); + $select->setAccessible(true); + + $sql = $select->invoke($data, [ + 'table' => 'taobao_alipay_bill_rows', + 'date' => 'occurred_at', + 'income' => 'income_amount', + 'expense' => 'expense_amount', + 'online_order' => 'online_order_no', + 'merchant_order' => 'merchant_order_no', + 'type' => null, + ], BillingDetailsPageData::EXPENSE_COLUMNS); + + $this->assertContains('occurred_at', explode(', ', $sql)); } public function test_ledger_memo_totals_split_invoice_buckets(): void