From e3867968e0d95bec026297b8573bd9d2ce7a245f Mon Sep 17 00:00:00 2001 From: chenxi Date: Mon, 26 Oct 2026 16:19:35 +0800 Subject: [PATCH 01/12] =?UTF-8?q?fix:=20=E4=BA=BA=E5=B7=A5=E8=B4=B9?= =?UTF-8?q?=E7=94=A8=E9=80=9F=E7=AE=97=E6=89=A3=E9=99=A4=E6=95=B0=E6=8C=89?= =?UTF-8?q?=E7=A8=8E=E6=B3=95=E6=A1=A3=E4=BD=8D=E8=87=AA=E5=8A=A8=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=20(#606)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 月度 L/U/AH 速算扣除数改为税法七档公式,年度 Y/AL/BD 档位同步核验。 --- config/labor_expense_table.php | 6 +-- .../labor-expenses.blade.php | 31 +++++++------ .../Business/LaborExpensePageAccessTest.php | 45 +++++++++++++++++-- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/config/labor_expense_table.php b/config/labor_expense_table.php index b621ca25..7ce0498c 100644 --- a/config/labor_expense_table.php +++ b/config/labor_expense_table.php @@ -22,7 +22,7 @@ return [ ['key' => 'I', 'label' => '扣除额', 'group' => 'original', 'kind' => 'number'], ['key' => 'J', 'label' => '原需报个税基数', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=F#-G#-H#-I#'], ['key' => 'K', 'label' => '原个税比列', 'group' => 'original', 'kind' => 'formula_percent', 'formula' => '=IF(J#<=0,"",IF(J#<=3000,0.03,IF(J#<=12000,0.1,IF(J#<=25000,0.2,IF(J#<=35000,0.25,IF(J#<=55000,0.3,IF(J#<=80000,0.35,0.45)))))))'], - ['key' => 'L', 'label' => '原速算扣除数', 'group' => 'original', 'kind' => 'number'], + ['key' => 'L', 'label' => '原速算扣除数', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=IF(J#<=0,"",IF(J#<=3000,0,IF(J#<=12000,210,IF(J#<=25000,1410,IF(J#<=35000,2660,IF(J#<=55000,4410,IF(J#<=80000,7160,15160)))))))'], ['key' => 'M', 'label' => '原需交个税金额', 'group' => 'original', 'kind' => 'number'], ['key' => 'N', 'label' => '原需年交个税金额', 'group' => 'original', 'kind' => 'formula_number', 'formula' => '=M#*12'], ['key' => 'O', 'label' => '新公积金缴存基数', 'group' => 'fund', 'kind' => 'number'], @@ -31,7 +31,7 @@ return [ ['key' => 'R', 'label' => '超额代扣缴', 'group' => 'fund', 'kind' => 'number'], ['key' => 'S', 'label' => '新月度应纳税所得额', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=F#-G#-I#-P#-R#'], ['key' => 'T', 'label' => '新月度个税比列', 'group' => 'fund', 'kind' => 'formula_percent', 'formula' => '=IF(S#<=0,"",IF(S#<=3000,0.03,IF(S#<=12000,0.1,IF(S#<=25000,0.2,IF(S#<=35000,0.25,IF(S#<=55000,0.3,IF(S#<=80000,0.35,0.45)))))))'], - ['key' => 'U', 'label' => '新月度新速算扣除数', 'group' => 'fund', 'kind' => 'number'], + ['key' => 'U', 'label' => '新月度新速算扣除数', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=IF(S#<=0,"",IF(S#<=3000,0,IF(S#<=12000,210,IF(S#<=25000,1410,IF(S#<=35000,2660,IF(S#<=55000,4410,IF(S#<=80000,7160,15160)))))))'], ['key' => 'V', 'label' => '新月度个税金额', 'group' => 'fund', 'kind' => 'number'], ['key' => 'W', 'label' => '全年应纳税所得额', 'group' => 'fund', 'kind' => 'formula_number', 'formula' => '=S#*12'], ['key' => 'X', 'label' => '年度税率', 'group' => 'fund', 'kind' => 'formula_percent', 'formula' => '=IF(S#=0,"",IF(W#<=0,0,IF(W#<=36000,0.03,IF(W#<=144000,0.1,IF(W#<=300000,0.2,IF(W#<=420000,0.25,IF(W#<=660000,0.3,IF(W#<=960000,0.35,0.45))))))))'], @@ -44,7 +44,7 @@ return [ ['key' => 'AE', 'label' => '新8月工资应发', 'group' => 'salary_parttime', 'kind' => 'formula_number', 'formula' => '=F#-AD#'], ['key' => 'AF', 'label' => '新月度应纳税所得额', 'group' => 'salary_parttime', 'kind' => 'formula_number', 'formula' => '=AE#-G#-I#-P#-R#'], ['key' => 'AG', 'label' => '新月度个税比列', 'group' => 'salary_parttime', 'kind' => 'formula_percent', 'formula' => '=IF(AF#<=0,"",IF(AF#<=3000,0.03,IF(AF#<=12000,0.1,IF(AF#<=25000,0.2,IF(AF#<=35000,0.25,IF(AF#<=55000,0.3,IF(AF#<=80000,0.35,0.45)))))))'], - ['key' => 'AH', 'label' => '新月度新速算扣除数', 'group' => 'salary_parttime', 'kind' => 'number'], + ['key' => 'AH', 'label' => '新月度新速算扣除数', 'group' => 'salary_parttime', 'kind' => 'formula_number', 'formula' => '=IF(AF#<=0,"",IF(AF#<=3000,0,IF(AF#<=12000,210,IF(AF#<=25000,1410,IF(AF#<=35000,2660,IF(AF#<=55000,4410,IF(AF#<=80000,7160,15160)))))))'], ['key' => 'AI', 'label' => '新月度个税金额', 'group' => 'salary_parttime', 'kind' => 'number'], ['key' => 'AJ', 'label' => '全年应纳税所得额', 'group' => 'salary_parttime', 'kind' => 'formula_number', 'formula' => '=AF#*12'], ['key' => 'AK', 'label' => '年度税率', 'group' => 'salary_parttime', 'kind' => 'formula_percent', 'formula' => '=IF(AJ#=0,"",IF(AJ#<=0,0,IF(AJ#<=36000,0.03,IF(AJ#<=144000,0.1,IF(AJ#<=300000,0.2,IF(AJ#<=420000,0.25,IF(AJ#<=660000,0.3,IF(AJ#<=960000,0.35,0.45))))))))'], diff --git a/resources/views/business/pages/financial-operations/labor-expenses.blade.php b/resources/views/business/pages/financial-operations/labor-expenses.blade.php index fda814df..83e3fdfa 100644 --- a/resources/views/business/pages/financial-operations/labor-expenses.blade.php +++ b/resources/views/business/pages/financial-operations/labor-expenses.blade.php @@ -377,7 +377,7 @@
人工费用测算表 -

表头与公式依据 {{ $laborExpenseTable['source_label'] ?? '工资表' }}。黄色字段用于录入,浅金列按公式实时计算;月度工资税率按月度应纳税所得额、年度税率按全年应纳税所得额匹配税法档位,公式中的 # 表示当前行。

+

表头与公式依据 {{ $laborExpenseTable['source_label'] ?? '工资表' }}。黄色字段用于录入,浅金列按公式实时计算;月度、年度税率及速算扣除数按对应应纳税所得额匹配税法档位,公式中的 # 表示当前行。

{{ count($laborFields) }} 个业务列 · {{ $laborFormulaCount }} 个公式
@@ -506,13 +506,13 @@ const monthlyWageBracket = (income) => { if (income <= 0) return null; - if (income <= 3000) return 0.03; - if (income <= 12000) return 0.1; - if (income <= 25000) return 0.2; - if (income <= 35000) return 0.25; - if (income <= 55000) return 0.3; - if (income <= 80000) return 0.35; - return 0.45; + if (income <= 3000) return { rate: 0.03, deduction: 0 }; + if (income <= 12000) return { rate: 0.1, deduction: 210 }; + if (income <= 25000) return { rate: 0.2, deduction: 1410 }; + if (income <= 35000) return { rate: 0.25, deduction: 2660 }; + if (income <= 55000) return { rate: 0.3, deduction: 4410 }; + if (income <= 80000) return { rate: 0.35, deduction: 7160 }; + return { rate: 0.45, deduction: 15160 }; }; const annualBracket = (income) => { @@ -549,12 +549,12 @@ const originalAnnualTaxAmount = originalRate === null || originalDeduction === null ? null : newAnnualTaxable * originalRate - originalDeduction; - const originalMonthlyRate = monthlyWageBracket(originalTaxable); + const originalMonthlyBracket = monthlyWageBracket(originalTaxable); const parttimeSalary = v('AB') + v('AC'); const newSalary = v('F') - parttimeSalary; const salaryTaxable = newSalary - v('G') - v('I') - v('P') - v('R'); - const newMonthlyRate = monthlyWageBracket(newMonthlyTaxable); - const salaryMonthlyRate = monthlyWageBracket(salaryTaxable); + const newMonthlyBracket = monthlyWageBracket(newMonthlyTaxable); + const salaryMonthlyBracket = monthlyWageBracket(salaryTaxable); const salaryAnnualTaxable = salaryTaxable * 12; const salaryBracket = annualBracket(salaryAnnualTaxable); const salaryRate = salaryAnnualTaxable === 0 ? null : salaryBracket.rate; @@ -607,12 +607,15 @@ X: originalRate, Y: originalDeduction, Z: originalAnnualTaxAmount, - K: originalMonthlyRate, - T: newMonthlyRate, + K: originalMonthlyBracket?.rate ?? null, + L: originalMonthlyBracket?.deduction ?? null, + T: newMonthlyBracket?.rate ?? null, + U: newMonthlyBracket?.deduction ?? null, AD: parttimeSalary, AE: newSalary, AF: salaryTaxable, - AG: salaryMonthlyRate, + AG: salaryMonthlyBracket?.rate ?? null, + AH: salaryMonthlyBracket?.deduction ?? null, AJ: salaryAnnualTaxable, AK: salaryRate, AL: salaryDeduction, diff --git a/tests/Feature/Business/LaborExpensePageAccessTest.php b/tests/Feature/Business/LaborExpensePageAccessTest.php index 2120476c..3b62f4b1 100644 --- a/tests/Feature/Business/LaborExpensePageAccessTest.php +++ b/tests/Feature/Business/LaborExpensePageAccessTest.php @@ -69,7 +69,7 @@ class LaborExpensePageAccessTest extends FeatureTestCase ); $this->assertCount(61, $fields); - $this->assertCount(37, $formulaFields); + $this->assertCount(40, $formulaFields); $response = $this->loginAs($chenxi)->get(route('business.pages.show', [ 'section' => 'financial-operations', @@ -85,12 +85,39 @@ class LaborExpensePageAccessTest extends FeatureTestCase ->assertSee('data-labor-expense-table', false) ->assertSee('=F#-G#-H#-I#', false) ->assertSee('=IF(AN#<=0,0,IF(AN#<=4000,800,AN#*0.2))', false) - ->assertSee('=IF(J#<=0,"",IF(J#<=3000,0.03', false) + ->assertSee('=IF(J#<=0,"",IF(J#<=3000,0.03', false) + ->assertSee('=IF(J#<=0,"",IF(J#<=3000,0,IF(J#<=12000,210', false) ->assertDontSee('data-labor-row="0"', false); $html = $response->getContent(); $this->assertSame(61, substr_count($html, 'data-labor-header="')); - $this->assertSame(37, substr_count($html, 'class="labor-expense-formula"')); + $this->assertSame(40, substr_count($html, 'class="labor-expense-formula"')); + } + + public function test_monthly_and_annual_tax_quick_deductions_are_formula_driven(): void + { + $fields = collect(config('labor_expense_table.fields'))->keyBy('key'); + + foreach (['L', 'U', 'AH', 'Y', 'AL', 'BD'] as $key) { + $this->assertNotEmpty($fields[$key]['formula'] ?? null, "{$key} 应配置速算扣除数公式"); + } + + foreach (['L' => 'J', 'U' => 'S', 'AH' => 'AF'] as $key => $taxableKey) { + $this->assertSame('formula_number', $fields[$key]['kind']); + $this->assertStringStartsWith("=IF({$taxableKey}#<=0,\"\"", $fields[$key]['formula']); + $this->assertSame( + [0, 210, 1410, 2660, 4410, 7160, 15160], + $this->quickDeductions($fields[$key]['formula']) + ); + } + + foreach (['Y' => 'W', 'AL' => 'AJ', 'BD' => 'BB'] as $key => $taxableKey) { + $this->assertStringStartsWith("=IF({$taxableKey}#", $fields[$key]['formula']); + $this->assertSame( + [0, 2520, 16920, 31920, 52920, 85920, 181920], + $this->quickDeductions($fields[$key]['formula']) + ); + } } private function pageIsVisible(User $user): bool @@ -119,4 +146,16 @@ class LaborExpensePageAccessTest extends FeatureTestCase return $user; } + + private function quickDeductions(string $formula): array + { + preg_match_all('/IF\([A-Z]+#<=\d+,(\d+)/', $formula, $matches); + $deductions = array_values(array_unique(array_map('intval', $matches[1]))); + + if (preg_match('/,(\d+)\)+\s*$/', $formula, $fallback)) { + $deductions[] = (int) $fallback[1]; + } + + return $deductions; + } } From fa86be7bc5e548b1660431165458210ec43bcc7a Mon Sep 17 00:00:00 2001 From: qiuxiang <394405259@qq.com> Date: Mon, 26 Oct 2026 16:19:42 +0800 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20=E5=AE=89=E8=A3=85=E8=B4=B9?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E6=94=B9=E4=B8=BA=E6=95=B4=E8=A1=8C=E5=B8=83?= =?UTF-8?q?=E5=B1=80=20(#607)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 安装费卡片改为整行宽度、128px 高和 40px 元金额展示。 --- .../installation-fee-summary.blade.php | 46 ++++++++++--------- tests/Feature/Business/ManagementCrudTest.php | 4 +- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/resources/views/business/pages/partials/installation-fee-summary.blade.php b/resources/views/business/pages/partials/installation-fee-summary.blade.php index b236ce43..e2b29237 100644 --- a/resources/views/business/pages/partials/installation-fee-summary.blade.php +++ b/resources/views/business/pages/partials/installation-fee-summary.blade.php @@ -5,10 +5,13 @@ .installation-fee-card { position: relative; - display: block; - width: min(100%, 52rem); - min-height: 9.25rem; - padding: 0.95rem 1.15rem 0.8rem 1.25rem; + display: flex; + width: 100%; + height: 8rem; + min-height: 0; + flex-direction: column; + box-sizing: border-box; + padding: 0.7rem 1rem 0 1.15rem; border: 1px solid #d8d2c7; border-left: 3px solid #006395; border-radius: 0.75rem; @@ -34,7 +37,7 @@ .installation-fee-card__top { display: flex; - align-items: flex-start; + align-items: center; justify-content: space-between; gap: 1rem; } @@ -64,14 +67,14 @@ align-items: baseline; gap: 0.35rem; min-width: 0; - margin: 0.35rem 0 0.58rem; + margin: 0.2rem 0 0.3rem; } .installation-fee-card__value { color: #171717; - font-size: 2.625rem; + font-size: 2.5rem; font-weight: 700; - line-height: 1.1; + line-height: 1; letter-spacing: -0.035em; font-variant-numeric: tabular-nums; } @@ -109,7 +112,8 @@ align-items: center; gap: 0.45rem; flex-wrap: wrap; - padding-top: 0.55rem; + margin: auto -1rem 0 -1.15rem; + padding: 0.43rem 1rem 0.48rem 1.15rem; border-top: 1px solid #e5e0d7; color: #171717; font-size: 0.75rem; @@ -134,8 +138,9 @@ @media (max-width: 720px) { .installation-fee-card { - min-height: 0; - padding: 0.9rem 0.95rem 0.8rem 1rem; + height: auto; + min-height: 8rem; + padding: 0.7rem 0.85rem 0 0.95rem; } .installation-fee-card__top { flex-direction: column; @@ -149,7 +154,13 @@ flex-wrap: wrap; } .installation-fee-card__value { - font-size: 2.625rem; + font-size: 2.5rem; + } + .installation-fee-card__split { + margin-right: -0.85rem; + margin-left: -0.95rem; + padding-right: 0.85rem; + padding-left: 0.95rem; } } @@ -365,7 +376,7 @@ 0.00 - 万元 + 元 — 较上月 @@ -486,13 +497,6 @@ }); } - function wan(value) { - return (Number(value || 0) / 10000).toLocaleString('zh-CN', { - minimumFractionDigits: 2, - maximumFractionDigits: 2 - }); - } - function amount(value) { return Number(value || 0).toLocaleString('zh-CN', { minimumFractionDigits: 2, @@ -544,7 +548,7 @@ var packageRate = total > 0 ? Math.round((packageTotal / total) * 100) : 0; var nonPackageRate = total > 0 ? 100 - packageRate : 0; - cardTotal.textContent = wan(total); + cardTotal.textContent = amount(total); packageAmount.textContent = amount(packageTotal); nonPackageAmount.textContent = amount(nonPackageTotal); packagePercent.textContent = '(' + packageRate + '%)'; diff --git a/tests/Feature/Business/ManagementCrudTest.php b/tests/Feature/Business/ManagementCrudTest.php index 9b7f581e..5c66f3d7 100644 --- a/tests/Feature/Business/ManagementCrudTest.php +++ b/tests/Feature/Business/ManagementCrudTest.php @@ -286,7 +286,9 @@ class ManagementCrudTest extends FeatureTestCase ->assertSee('data-installation-fee-package', false) ->assertSee('data-installation-fee-non-package', false) ->assertSee('border-left: 3px solid #006395', false) - ->assertSee('font-size: 2.625rem', false) + ->assertSee('height: 8rem', false) + ->assertSee('font-size: 2.5rem', false) + ->assertSee('元', false) ->assertSee('function captionRange(value)', false) ->assertSee('function setCardValue(total, rows, value, data)', false) ->assertSeeText('平台') From deae0c3e21244d3d2596f8c825fe7f86cdc130ad Mon Sep 17 00:00:00 2001 From: yueyang <2495544247@qq.com> Date: Mon, 26 Oct 2026 16:31:03 +0800 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20=E8=B4=A2=E5=8A=A1=E7=BB=8F?= =?UTF-8?q?=E8=90=A5=E6=8A=A5=E8=A1=A8=E6=96=B0=E5=A2=9E=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E9=A1=B5=E9=9D=A2=20(#608)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Commands/ImportDingProcessDetails.php | 43 ++ app/Utilities/BusinessNavigation.php | 23 + .../business_navigation_page_extensions.php | 19 + ...eate_ding_process_detail_mirror_tables.php | 68 +++ .../Http/Controllers/ProcessDetails.php | 139 ++++++ .../DingProcessDetailMirrorRepository.php | 222 +++++++++ modules/EcommerceFinance/Routes/admin.php | 18 + .../DingProcessDetailMirrorImporter.php | 282 +++++++++++ .../process-details.blade.php | 452 ++++++++++++++++++ .../Business/ProcessDetailsPageTest.php | 133 ++++++ .../Console/ImportDingProcessDetailsTest.php | 271 +++++++++++ .../Fixtures/ding_process_details_sample.csv | 5 + .../DingProcessDetailMirrorRepositoryTest.php | 233 +++++++++ 13 files changed, 1908 insertions(+) create mode 100644 app/Console/Commands/ImportDingProcessDetails.php create mode 100644 config/business_navigation_page_extensions.php create mode 100644 database/migrations/2026_10_26_150000_create_ding_process_detail_mirror_tables.php create mode 100644 modules/EcommerceFinance/Http/Controllers/ProcessDetails.php create mode 100644 modules/EcommerceFinance/Repositories/DingProcessDetailMirrorRepository.php create mode 100644 modules/EcommerceFinance/Services/DingProcessDetailMirrorImporter.php create mode 100644 resources/views/business/pages/financial-operations/process-details.blade.php create mode 100644 tests/Feature/Business/ProcessDetailsPageTest.php create mode 100644 tests/Feature/Console/ImportDingProcessDetailsTest.php create mode 100644 tests/Fixtures/ding_process_details_sample.csv create mode 100644 tests/Unit/EcommerceFinance/DingProcessDetailMirrorRepositoryTest.php diff --git a/app/Console/Commands/ImportDingProcessDetails.php b/app/Console/Commands/ImportDingProcessDetails.php new file mode 100644 index 00000000..c9e4639c --- /dev/null +++ b/app/Console/Commands/ImportDingProcessDetails.php @@ -0,0 +1,43 @@ +import( + (string) $this->argument('file'), + (string) $this->option('scope'), + (bool) $this->option('replace'), + ); + } catch (Throwable $exception) { + $this->error('导入失败:' . $exception->getMessage()); + + return self::FAILURE; + } + + $this->info(sprintf( + '导入完成:%d 行,跳过占位 %d 行,跳过无效 %d 行,重复 %d 行,范围 %s。', + $result['rows'], + $result['placeholders'], + $result['invalid'], + $result['duplicates'], + $result['scope'], + )); + + return self::SUCCESS; + } +} diff --git a/app/Utilities/BusinessNavigation.php b/app/Utilities/BusinessNavigation.php index 6aca5455..556b645b 100644 --- a/app/Utilities/BusinessNavigation.php +++ b/app/Utilities/BusinessNavigation.php @@ -10,6 +10,29 @@ class BusinessNavigation public static function all(): array { $navigation = config('business_navigation', []); + $pageExtensions = (array) config('business_navigation_page_extensions', []); + + foreach ($navigation as &$section) { + $sectionSlug = (string) ($section['slug'] ?? ''); + + foreach ((array) ($pageExtensions[$sectionSlug] ?? []) as $extension) { + $extensionSlug = trim((string) ($extension['slug'] ?? '')); + + if ($extensionSlug === '') { + continue; + } + + $exists = collect($section['pages'] ?? [])->contains( + static fn (array $page): bool => (string) ($page['slug'] ?? '') === $extensionSlug + ); + + if (! $exists) { + $section['pages'][] = $extension; + } + } + } + unset($section); + $titles = (array) setting('navigation.titles', []); $sectionTitles = (array) ($titles['sections'] ?? []); $pageTitles = (array) ($titles['pages'] ?? []); diff --git a/config/business_navigation_page_extensions.php b/config/business_navigation_page_extensions.php new file mode 100644 index 00000000..981e6a08 --- /dev/null +++ b/config/business_navigation_page_extensions.php @@ -0,0 +1,19 @@ + [ + [ + 'slug' => 'process-details', + 'title' => '流程明细', + ], + ], +]; diff --git a/database/migrations/2026_10_26_150000_create_ding_process_detail_mirror_tables.php b/database/migrations/2026_10_26_150000_create_ding_process_detail_mirror_tables.php new file mode 100644 index 00000000..f239f079 --- /dev/null +++ b/database/migrations/2026_10_26_150000_create_ding_process_detail_mirror_tables.php @@ -0,0 +1,68 @@ +environment('testing') + || (string) config('system_database.mode', 'bootstrap') === 'bootstrap') { + return; + } + + $schema = Schema::connection($this->connection()); + + if ($schema->hasTable('ding_process_detail_mirror')) { + return; + } + + $schema->create('ding_process_detail_mirror', function (Blueprint $table): void { + $table->bigIncrements('id'); + $table->string('business_id', 32); + $table->unsignedInteger('line_no'); + $table->string('business_month', 6)->index(); + $table->string('originator_name', 100)->nullable()->index(); + $table->string('status', 20)->nullable()->index(); + $table->string('document_type', 100)->nullable()->index(); + $table->text('purpose')->nullable(); + $table->string('account_code', 64)->nullable(); + $table->string('account_name', 255)->nullable(); + $table->decimal('amount', 18, 2)->nullable(); + $table->string('bank_account_code', 255)->nullable(); + $table->string('bank_account_name', 255)->nullable(); + $table->decimal('bank_amount', 18, 2)->nullable(); + $table->string('payment_method', 50)->nullable(); + $table->string('paid_at', 50)->nullable(); + $table->string('source_scope', 40)->default('personal_permission')->index(); + $table->dateTime('synced_at', 6); + $table->timestamps(); + + $table->unique( + ['business_id', 'line_no'], + 'ding_process_detail_business_line_unique', + ); + $table->index( + ['business_month', 'document_type'], + 'ding_process_detail_month_type_index', + ); + }); + } + + public function down(): void + { + if (app()->environment('testing') + || (string) config('system_database.mode', 'bootstrap') === 'bootstrap') { + return; + } + + Schema::connection($this->connection())->dropIfExists('ding_process_detail_mirror'); + } +}; diff --git a/modules/EcommerceFinance/Http/Controllers/ProcessDetails.php b/modules/EcommerceFinance/Http/Controllers/ProcessDetails.php new file mode 100644 index 00000000..73f52b29 --- /dev/null +++ b/modules/EcommerceFinance/Http/Controllers/ProcessDetails.php @@ -0,0 +1,139 @@ +filters($request); + $page = max((int) $request->query('page', 1), 1); + $perPage = 50; + + try { + $result = $this->repository->paginate($filters, $page, $perPage); + $options = $this->repository->filterOptions(); + + return view('business.pages.financial-operations.process-details', [ + 'section' => ['slug' => 'financial-operations', 'title' => '财务经营报表'], + 'page' => ['slug' => 'process-details', 'title' => '流程明细'], + 'rows' => new LengthAwarePaginator( + $result['data'], + $result['total'], + $perPage, + $page, + ['path' => $request->url(), 'query' => $request->except('page')], + ), + 'filters' => $filters, + 'summary' => $result['summary'], + 'months' => $options['months'], + 'documentTypes' => $options['document_types'], + 'statuses' => $options['statuses'], + 'mirrorStatus' => $result['status'], + 'mirrorSyncedAt' => $result['last_synced_at'], + 'scope' => $result['scope'], + 'error' => null, + ]); + } catch (Throwable $exception) { + report($exception); + + return view('business.pages.financial-operations.process-details', [ + 'section' => ['slug' => 'financial-operations', 'title' => '财务经营报表'], + 'page' => ['slug' => 'process-details', 'title' => '流程明细'], + 'rows' => new LengthAwarePaginator([], 0, $perPage, $page, [ + 'path' => $request->url(), + 'query' => $request->except('page'), + ]), + 'filters' => $filters, + 'summary' => [ + 'rows' => 0, + 'approvals' => 0, + 'amount_total' => 0.0, + 'bank_amount_total' => 0.0, + ], + 'months' => [], + 'documentTypes' => [], + 'statuses' => [], + 'mirrorStatus' => 'unavailable', + 'mirrorSyncedAt' => null, + 'scope' => $this->repository->scope(), + 'error' => '流程明细镜像尚未完成导入,请稍后重试。', + ]); + } + } + + public function export(Request $request): StreamedResponse|RedirectResponse + { + if (! $this->repository->ready()) { + return redirect() + ->route('business.pages.show', [ + 'section' => 'financial-operations', + 'page' => 'process-details', + ]) + ->withErrors(['export' => '流程明细镜像尚未完成导入,暂时不能导出。']); + } + + $filters = $this->filters($request); + + return response()->streamDownload(function () use ($filters): void { + $stream = fopen('php://output', 'wb'); + fwrite($stream, "\xEF\xBB\xBF"); + fputcsv($stream, DingProcessDetailMirrorImporter::HEADERS); + + $number = 0; + foreach ($this->repository->exportRows($filters) as $row) { + $number++; + fputcsv($stream, [ + $number, + (string) ($row['business_id'] ?? ''), + (string) ($row['originator_name'] ?? ''), + (string) ($row['status'] ?? ''), + (string) ($row['document_type'] ?? ''), + (string) ($row['purpose'] ?? ''), + (int) ($row['line_no'] ?? 0), + (string) ($row['account_code'] ?? ''), + (string) ($row['account_name'] ?? ''), + $row['amount'] ?? '', + (string) ($row['bank_account_code'] ?? ''), + (string) ($row['bank_account_name'] ?? ''), + $row['bank_amount'] ?? '', + (string) ($row['payment_method'] ?? ''), + (string) ($row['paid_at'] ?? ''), + ]); + } + + fclose($stream); + }, '流程明细_' . now()->format('Ymd_His') . '.csv', [ + 'Content-Type' => 'text/csv; charset=UTF-8', + ]); + } + + /** @return array */ + private function filters(Request $request): array + { + $month = trim((string) $request->query('month', '')); + $status = trim((string) $request->query('status', '')); + + return [ + 'month' => preg_match('/^\d{4}-\d{2}$/', $month) === 1 ? $month : '', + 'document_type' => mb_substr(trim((string) $request->query('document_type', '')), 0, 100), + 'status' => mb_substr($status, 0, 20), + 'business_id' => mb_substr(trim((string) $request->query('business_id', '')), 0, 32), + 'originator_name' => mb_substr(trim((string) $request->query('originator_name', '')), 0, 100), + 'keyword' => mb_substr(trim((string) $request->query('keyword', '')), 0, 100), + ]; + } +} diff --git a/modules/EcommerceFinance/Repositories/DingProcessDetailMirrorRepository.php b/modules/EcommerceFinance/Repositories/DingProcessDetailMirrorRepository.php new file mode 100644 index 00000000..689e0835 --- /dev/null +++ b/modules/EcommerceFinance/Repositories/DingProcessDetailMirrorRepository.php @@ -0,0 +1,222 @@ +connection = $database->connection( + (string) config('upstream_mirrors.connection', 'business_mirror') + ); + } + + public function scope(): string + { + $scope = trim((string) config( + 'upstream_mirrors.ding_process_details.scope', + self::DEFAULT_SCOPE, + )); + + return $scope !== '' ? $scope : self::DEFAULT_SCOPE; + } + + public function datasetKey(): string + { + return self::DATASET_PREFIX . $this->scope(); + } + + public function ready(): bool + { + $schema = Schema::connection($this->connection->getName()); + + if (! $schema->hasTable('ding_process_detail_mirror') + || ! $schema->hasTable('business_mirror_table_states')) { + return false; + } + + $state = $this->state(); + + return $state !== null && ($state['initial_completed_at'] ?? null) !== null; + } + + /** @return array|null */ + public function state(): ?array + { + if (! Schema::connection($this->connection->getName())->hasTable('business_mirror_table_states')) { + return null; + } + + $row = $this->connection->table('business_mirror_table_states') + ->where('dataset_key', $this->datasetKey()) + ->first(); + + return $row === null ? null : (array) $row; + } + + /** + * @param array $filters + * @return array{ + * data:list, + * total:int, + * summary:array{rows:int,approvals:int,amount_total:float,bank_amount_total:float}, + * status:string, + * last_synced_at:?string, + * scope:string + * } + */ + public function paginate(array $filters, int $page, int $perPage): array + { + if (! $this->ready()) { + throw new RuntimeException('ding_process_detail_mirror_not_ready'); + } + + $page = max($page, 1); + $perPage = min(max($perPage, 1), 100); + $query = $this->filteredQuery($filters); + + $total = (clone $query)->count(); + $summary = [ + 'rows' => $total, + 'approvals' => (clone $query)->distinct()->count('business_id'), + 'amount_total' => (float) ((clone $query)->sum('amount') ?? 0), + 'bank_amount_total' => (float) ((clone $query)->sum('bank_amount') ?? 0), + ]; + $data = $query + ->orderByDesc('business_month') + ->orderByDesc('business_id') + ->orderBy('line_no') + ->forPage($page, $perPage) + ->get() + ->all(); + $state = $this->state(); + + return [ + 'data' => $data, + 'total' => $total, + 'summary' => $summary, + 'status' => (string) ($state['status'] ?? 'unknown'), + 'last_synced_at' => isset($state['last_succeeded_at']) + ? (string) $state['last_succeeded_at'] + : null, + 'scope' => $this->scope(), + ]; + } + + /** @return array{months:list,document_types:list,statuses:list} */ + public function filterOptions(): array + { + if (! Schema::connection($this->connection->getName())->hasTable('ding_process_detail_mirror')) { + return ['months' => [], 'document_types' => [], 'statuses' => []]; + } + + $base = $this->connection->table('ding_process_detail_mirror') + ->where('source_scope', $this->scope()); + + return [ + 'months' => (clone $base) + ->whereNotNull('business_month') + ->where('business_month', '!=', '') + ->distinct() + ->orderByDesc('business_month') + ->pluck('business_month') + ->map(static function (mixed $value): string { + $month = (string) $value; + + return preg_match('/^\d{6}$/', $month) === 1 + ? substr($month, 0, 4) . '-' . substr($month, 4, 2) + : $month; + }) + ->all(), + 'document_types' => (clone $base) + ->whereNotNull('document_type') + ->where('document_type', '!=', '') + ->distinct() + ->orderBy('document_type') + ->pluck('document_type') + ->map(static fn (mixed $value): string => (string) $value) + ->all(), + 'statuses' => (clone $base) + ->whereNotNull('status') + ->where('status', '!=', '') + ->distinct() + ->orderBy('status') + ->pluck('status') + ->map(static fn (mixed $value): string => (string) $value) + ->all(), + ]; + } + + /** @param array $filters */ + public function exportCount(array $filters): int + { + if (! Schema::connection($this->connection->getName())->hasTable('ding_process_detail_mirror')) { + return 0; + } + + return (int) $this->filteredQuery($filters)->count(); + } + + /** + * @param array $filters + * @return \Generator> + */ + public function exportRows(array $filters): \Generator + { + $query = $this->filteredQuery($filters) + ->orderByDesc('business_month') + ->orderByDesc('business_id') + ->orderBy('line_no'); + + foreach ($query->cursor() as $row) { + yield (array) $row; + } + } + + /** @param array $filters */ + private function filteredQuery(array $filters): Builder + { + $query = $this->connection->table('ding_process_detail_mirror') + ->where('source_scope', $this->scope()); + + $month = trim((string) ($filters['month'] ?? '')); + if (preg_match('/^\d{4}-\d{2}$/', $month) === 1) { + $query->where('business_month', str_replace('-', '', $month)); + } + + foreach ([ + 'document_type' => 'document_type', + 'status' => 'status', + ] as $filter => $column) { + $value = trim((string) ($filters[$filter] ?? '')); + if ($value !== '') { + $query->where($column, $value); + } + } + + foreach ([ + 'business_id' => 'business_id', + 'originator_name' => 'originator_name', + 'keyword' => 'purpose', + ] as $filter => $column) { + $value = mb_substr(trim((string) ($filters[$filter] ?? '')), 0, 100); + if ($value !== '') { + $query->where($column, 'like', '%' . $value . '%'); + } + } + + return $query; + } +} diff --git a/modules/EcommerceFinance/Routes/admin.php b/modules/EcommerceFinance/Routes/admin.php index 5a08c09f..d128dda9 100644 --- a/modules/EcommerceFinance/Routes/admin.php +++ b/modules/EcommerceFinance/Routes/admin.php @@ -1,7 +1,25 @@ name('index'); }); + +// 通用 workspace/{section}/{page} 路由在 App\Providers\Route::boot() 中注册; +// 模块路由在 register 阶段先注册,因此这里的精确路由会优先命中。沿用 +// business.pages.show 名称,侧边栏仍能生成与通用页面一致的可访问 URL。 +Route::admin('ecommerce-finance', function (): void { + Route::get('workspace/financial-operations/process-details', [ProcessDetails::class, 'show']) + ->middleware('business.page.viewer') + ->defaults('section', 'financial-operations') + ->defaults('page', 'process-details') + ->name('business.pages.show'); + + Route::get('workspace/financial-operations/process-details/export', [ProcessDetails::class, 'export']) + ->middleware('business.page.viewer') + ->defaults('section', 'financial-operations') + ->defaults('page', 'process-details') + ->name('business.process-details.export'); +}, ['prefix' => '', 'as' => '']); diff --git a/modules/EcommerceFinance/Services/DingProcessDetailMirrorImporter.php b/modules/EcommerceFinance/Services/DingProcessDetailMirrorImporter.php new file mode 100644 index 00000000..34e3b434 --- /dev/null +++ b/modules/EcommerceFinance/Services/DingProcessDetailMirrorImporter.php @@ -0,0 +1,282 @@ +connection = $database->connection( + (string) config('upstream_mirrors.connection', 'business_mirror') + ); + } + + /** + * @return array{status:string,rows:int,invalid:int,placeholders:int,duplicates:int,scope:string,dataset_key:string} + */ + public function import( + string $path, + string $scope = self::DEFAULT_SCOPE, + bool $replace = false, + ): array { + $scope = trim($scope) !== '' ? trim($scope) : self::DEFAULT_SCOPE; + + if (! is_file($path)) { + throw new RuntimeException('流程明细 CSV 文件不存在:' . $path); + } + + [$rows, $invalid, $placeholders, $duplicates] = $this->readCsv($path, $scope); + + if ($rows === []) { + throw new RuntimeException('流程明细 CSV 没有可导入的数据。'); + } + + $now = now(); + $datasetKey = self::DATASET_PREFIX . $scope; + $generation = (string) Str::uuid(); + $upserted = 0; + + $this->connection->transaction(function () use ( + $rows, + $replace, + $scope, + $now, + $generation, + &$upserted, + ): void { + if ($replace) { + $this->connection->table('ding_process_detail_mirror') + ->where('source_scope', $scope) + ->delete(); + } + + foreach (array_chunk($rows, 500) as $chunk) { + $this->connection->table('ding_process_detail_mirror')->upsert( + $chunk, + ['business_id', 'line_no'], + [ + 'business_month', + 'originator_name', + 'status', + 'document_type', + 'purpose', + 'account_code', + 'account_name', + 'amount', + 'bank_account_code', + 'bank_account_name', + 'bank_amount', + 'payment_method', + 'paid_at', + 'source_scope', + 'synced_at', + 'updated_at', + ], + ); + $upserted += count($chunk); + } + }); + + $rowCount = (int) $this->connection->table('ding_process_detail_mirror') + ->where('source_scope', $scope) + ->count(); + $values = [ + 'source_key' => 'dingtalk_oa', + 'source_object' => $scope === self::DEFAULT_SCOPE + ? 'oa approval detail (personal permission scope)' + : 'oa approval detail (' . $scope . ')', + 'target_table' => 'ding_process_detail_mirror', + 'status' => 'succeeded', + 'run_mode' => 'full', + 'generation' => $generation, + 'cursor' => null, + 'high_watermark' => null, + 'window_started_at' => null, + 'window_ends_at' => null, + 'initial_completed_at' => $now, + 'last_full_succeeded_at' => $now, + 'last_attempted_at' => $now, + 'last_succeeded_at' => $now, + 'last_upserted_rows' => $upserted, + 'mirror_row_count' => $rowCount, + 'last_error_code' => null, + 'updated_at' => $now, + ]; + + $this->connection->table('business_mirror_table_states')->updateOrInsert( + ['dataset_key' => $datasetKey], + $values + ['created_at' => $now], + ); + + return [ + 'status' => 'succeeded', + 'rows' => $upserted, + 'invalid' => $invalid, + 'placeholders' => $placeholders, + 'duplicates' => $duplicates, + 'scope' => $scope, + 'dataset_key' => $datasetKey, + ]; + } + + /** + * @return array{0:list>,1:int,2:int,3:int} + */ + private function readCsv(string $path, string $scope): array + { + $handle = fopen($path, 'rb'); + + if ($handle === false) { + throw new RuntimeException('流程明细 CSV 无法打开:' . $path); + } + + try { + $header = fgetcsv($handle); + + if ($header === false) { + throw new RuntimeException('流程明细 CSV 缺少表头。'); + } + + $header[0] = preg_replace('/^\xEF\xBB\xBF/', '', (string) $header[0]); + $header = array_map(static fn (mixed $value): string => trim((string) $value), $header); + $missing = array_values(array_diff(self::HEADERS, $header)); + + if ($missing !== []) { + throw new RuntimeException('流程明细 CSV 缺少列:' . implode('、', $missing)); + } + + $index = array_flip($header); + $rows = []; + $qualities = []; + $invalid = 0; + $placeholders = 0; + $duplicates = 0; + $now = now(); + + while (($data = fgetcsv($handle)) !== false) { + if ($data === [null] || count(array_filter( + $data, + static fn (mixed $value): bool => trim((string) $value) !== '', + )) === 0) { + continue; + } + + $businessId = trim((string) ($data[$index['审批编号']] ?? '')); + $lineNo = trim((string) ($data[$index['单据内行号']] ?? '')); + + if ($businessId === '' || preg_match('/^\d+$/', $lineNo) !== 1) { + $invalid++; + continue; + } + + $accountCode = trim((string) ($data[$index['科目编码']] ?? '')); + $accountName = trim((string) ($data[$index['科目名称']] ?? '')); + $amountRaw = trim((string) ($data[$index['金额(元)']] ?? '')); + + // 历史导入遗留的占位行:用途/科目/银行字段全部是 251,金额为空。 + if ($accountCode === '251' && $accountName === '251' && $amountRaw === '') { + $placeholders++; + continue; + } + + $key = $businessId . '|' . (int) $lineNo; + $candidate = [ + 'business_id' => mb_substr($businessId, 0, 32), + 'line_no' => (int) $lineNo, + 'business_month' => preg_match('/^\d{6}/', $businessId) === 1 + ? substr($businessId, 0, 6) + : '', + 'originator_name' => mb_substr(trim((string) ($data[$index['发起人']] ?? '')), 0, 100), + 'status' => mb_substr(trim((string) ($data[$index['状态']] ?? '')), 0, 20), + 'document_type' => mb_substr(trim((string) ($data[$index['单据类型']] ?? '')), 0, 100), + 'purpose' => trim((string) ($data[$index['用途/摘要']] ?? '')), + 'account_code' => mb_substr($accountCode, 0, 64), + 'account_name' => mb_substr($accountName, 0, 255), + 'amount' => $this->decimal($data[$index['金额(元)']] ?? null), + 'bank_account_code' => mb_substr(trim((string) ($data[$index['银行科目编码']] ?? '')), 0, 255), + 'bank_account_name' => mb_substr(trim((string) ($data[$index['银行科目名称']] ?? '')), 0, 255), + 'bank_amount' => $this->decimal($data[$index['银行付款金额']] ?? null), + 'payment_method' => mb_substr(trim((string) ($data[$index['付款方式']] ?? '')), 0, 50), + 'paid_at' => mb_substr(trim((string) ($data[$index['打款时间']] ?? '')), 0, 50), + 'source_scope' => $scope, + 'synced_at' => $now, + 'created_at' => $now, + 'updated_at' => $now, + ]; + $quality = $this->quality($candidate); + + if (isset($qualities[$key])) { + $duplicates++; + if ($quality < $qualities[$key]) { + continue; + } + } + + $rows[$key] = $candidate; + $qualities[$key] = $quality; + } + + return [array_values($rows), $invalid, $placeholders, $duplicates]; + } finally { + fclose($handle); + } + } + + private function decimal(mixed $value): ?string + { + $value = trim((string) $value); + + if ($value === '' || ! is_numeric($value)) { + return null; + } + + return number_format((float) $value, 2, '.', ''); + } + + /** @param array $row */ + private function quality(array $row): int + { + $score = 0; + $score += trim((string) ($row['purpose'] ?? '')) !== '' + && trim((string) ($row['purpose'] ?? '')) !== '251' ? 1 : 0; + $score += trim((string) ($row['account_name'] ?? '')) !== '' + && trim((string) ($row['account_name'] ?? '')) !== '251' ? 1 : 0; + $score += is_numeric($row['amount'] ?? null) && (float) $row['amount'] !== 0.0 ? 4 : 0; + $score += trim((string) ($row['bank_account_code'] ?? '')) !== '' + && trim((string) ($row['bank_account_code'] ?? '')) !== '251' ? 2 : 0; + $score += is_numeric($row['bank_amount'] ?? null) && (float) $row['bank_amount'] !== 0.0 ? 2 : 0; + $score += trim((string) ($row['paid_at'] ?? '')) !== '' + && trim((string) ($row['paid_at'] ?? '')) !== '251' ? 1 : 0; + + return $score; + } +} diff --git a/resources/views/business/pages/financial-operations/process-details.blade.php b/resources/views/business/pages/financial-operations/process-details.blade.php new file mode 100644 index 00000000..2d743d7b --- /dev/null +++ b/resources/views/business/pages/financial-operations/process-details.blade.php @@ -0,0 +1,452 @@ +@php + $rows = $rows ?? null; + $filters = $filters ?? []; + $summary = $summary ?? []; + $months = $months ?? []; + $documentTypes = $documentTypes ?? []; + $statuses = $statuses ?? []; + $error = $error ?? null; + $scope = $scope ?? 'personal_permission'; + $scopeLabel = $scope === 'personal_permission' ? '当前账号权限范围' : $scope; + $money = static fn (mixed $value): string => $value === null || $value === '' + ? '-' + : number_format((float) $value, 2); + $text = static fn (mixed $value): string => $value === null || trim((string) $value) === '' + ? '-' + : (string) $value; + $statusClass = static fn (string $status): string => match ($status) { + '已完成' => 'is-success', + '审批中' => 'is-warning', + '已终止', '已撤销' => 'is-danger', + default => 'is-neutral', + }; + $pageUrl = route('business.pages.show', [ + 'section' => 'financial-operations', + 'page' => 'process-details', + ]); + $exportUrl = route('business.process-details.export', array_filter( + $filters, + static fn (mixed $value): bool => $value !== '' && $value !== null, + )); +@endphp + + + + 流程明细 + + + + + +
+
+ 数据范围:{{ $scopeLabel }} + 镜像状态:{{ $mirrorStatus ?? 'unknown' }} + @if (! empty($mirrorSyncedAt)) + 最近同步:{{ $mirrorSyncedAt }} + @endif +
+ + @if ($error) + + @endif + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
明细行数{{ number_format((int) ($summary['rows'] ?? 0)) }}
+
审批单数{{ number_format((int) ($summary['approvals'] ?? 0)) }}
+
金额合计{{ $money($summary['amount_total'] ?? null) }}
+
银行付款合计{{ $money($summary['bank_amount_total'] ?? null) }}
+
+ +

+ 当前展示的是当前账号权限范围内可读取的钉钉审批流程明细;审批中的金额和行项目仍可能随流程变化。 + 企业级全量数据待领导开通 OA 权限后切换。 +

+ +
+ + + + + + + + + + + + + + + + + + + + + + @forelse ($rows as $row) + + + + + + + + + + + + + + + + + + @empty + + + + @endforelse + +
序号审批编号发起人状态单据类型用途/摘要单据内行号科目编码科目名称金额(元)银行科目编码银行科目名称银行付款金额付款方式打款时间
{{ ($rows->currentPage() - 1) * $rows->perPage() + $loop->iteration }}{{ $row->business_id }}{{ $text($row->originator_name) }} + {{ $text($row->status) }} + {{ $text($row->document_type) }}{{ $text($row->purpose) }}{{ $row->line_no }}{{ $text($row->account_code) }}{{ $text($row->account_name) }}{{ $money($row->amount) }}{{ $text($row->bank_account_code) }}{{ $text($row->bank_account_name) }}{{ $money($row->bank_amount) }}{{ $text($row->payment_method) }}{{ $text($row->paid_at) }}
+ 当前筛选条件没有流程明细。可以调整月份、单据类型、状态或关键词后重试。 +
+
+ + +
+
+
diff --git a/tests/Feature/Business/ProcessDetailsPageTest.php b/tests/Feature/Business/ProcessDetailsPageTest.php new file mode 100644 index 00000000..3877a7a7 --- /dev/null +++ b/tests/Feature/Business/ProcessDetailsPageTest.php @@ -0,0 +1,133 @@ +user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); + + $repository = Mockery::mock(DingProcessDetailMirrorRepository::class); + $repository->shouldReceive('paginate')->once()->andReturn([ + 'data' => [ + (object) [ + 'business_id' => '202601011200000000001', + 'line_no' => 1, + 'originator_name' => '张三', + 'status' => '已完成', + 'document_type' => '公摊日常报销', + 'purpose' => '办公用品采购', + 'account_code' => '5602.04', + 'account_name' => '管理费用_办公费', + 'amount' => 100.00, + 'bank_account_code' => '1002.01.001', + 'bank_account_name' => '华夏银行-测试', + 'bank_amount' => 100.00, + 'payment_method' => '银行卡', + 'paid_at' => '2026-01-02 00:00', + ], + ], + 'total' => 1, + 'summary' => [ + 'rows' => 1, + 'approvals' => 1, + 'amount_total' => 100.0, + 'bank_amount_total' => 100.0, + ], + 'status' => 'succeeded', + 'last_synced_at' => '2026-10-26 15:00:00', + 'scope' => 'personal_permission', + ]); + $repository->shouldReceive('filterOptions')->once()->andReturn([ + 'months' => ['2026-01'], + 'document_types' => ['公摊日常报销'], + 'statuses' => ['已完成'], + ]); + $this->app->instance(DingProcessDetailMirrorRepository::class, $repository); + + $financeSection = collect(\App\Utilities\BusinessNavigation::all()) + ->firstWhere('slug', 'financial-operations'); + $this->assertContains( + 'process-details', + array_column($financeSection['pages'] ?? [], 'slug'), + ); + + $this->loginAs()->get(route('business.pages.show', [ + 'section' => 'financial-operations', + 'page' => 'process-details', + ]))->assertOk() + ->assertSee('流程明细') + ->assertSee('审批编号') + ->assertSee('发起人') + ->assertSee('单据类型') + ->assertSee('银行付款金额') + ->assertSee('202601011200000000001') + ->assertSee('张三') + ->assertSee('管理费用_办公费') + ->assertSee('100.00') + ->assertSee('当前账号权限范围') + ->assertSee('导出'); + } + + public function test_page_stays_readable_when_mirror_is_not_ready(): void + { + $this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); + + $repository = Mockery::mock(DingProcessDetailMirrorRepository::class); + $repository->shouldReceive('paginate')->once()->andThrow(new RuntimeException('not ready')); + $repository->shouldReceive('scope')->once()->andReturn('personal_permission'); + $this->app->instance(DingProcessDetailMirrorRepository::class, $repository); + + $this->loginAs()->get(route('business.pages.show', [ + 'section' => 'financial-operations', + 'page' => 'process-details', + ]))->assertOk() + ->assertSee('流程明细镜像尚未完成导入') + ->assertSee('当前账号权限范围'); + } + + public function test_export_streams_filtered_csv(): void + { + $this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail()); + + $repository = Mockery::mock(DingProcessDetailMirrorRepository::class); + $repository->shouldReceive('ready')->once()->andReturn(true); + $repository->shouldReceive('exportRows')->once()->andReturnUsing(function (): \Generator { + yield [ + 'business_id' => '202601011200000000001', + 'originator_name' => '张三', + 'status' => '已完成', + 'document_type' => '公摊日常报销', + 'purpose' => '办公用品采购', + 'line_no' => 1, + 'account_code' => '5602.04', + 'account_name' => '管理费用_办公费', + 'amount' => '100.00', + 'bank_account_code' => '1002.01.001', + 'bank_account_name' => '华夏银行-测试', + 'bank_amount' => '100.00', + 'payment_method' => '银行卡', + 'paid_at' => '2026-01-02 00:00', + ]; + }); + $this->app->instance(DingProcessDetailMirrorRepository::class, $repository); + + $response = $this->loginAs()->get(route('business.process-details.export', [ + 'status' => '已完成', + ])); + + $response->assertOk(); + $content = $response->streamedContent(); + $this->assertStringContainsString('审批编号', $content); + $this->assertStringContainsString('202601011200000000001', $content); + $this->assertStringContainsString('张三', $content); + $this->assertStringContainsString('管理费用_办公费', $content); + } +} diff --git a/tests/Feature/Console/ImportDingProcessDetailsTest.php b/tests/Feature/Console/ImportDingProcessDetailsTest.php new file mode 100644 index 00000000..c3b036ba --- /dev/null +++ b/tests/Feature/Console/ImportDingProcessDetailsTest.php @@ -0,0 +1,271 @@ + */ + private array $tempFiles = []; + + protected function setUp(): void + { + parent::setUp(); + + config([ + 'database.connections.business_mirror' => [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ], + 'upstream_mirrors.connection' => 'business_mirror', + 'upstream_mirrors.ding_process_details.scope' => 'personal_permission', + ]); + DB::purge('business_mirror'); + $this->createMirrorTables(); + + $this->fixture = base_path('tests/Fixtures/ding_process_details_sample.csv'); + } + + protected function tearDown(): void + { + foreach ($this->tempFiles as $file) { + if (is_file($file)) { + unlink($file); + } + } + + parent::tearDown(); + } + + public function test_imports_csv_and_publishes_mirror_state(): void + { + $result = app(DingProcessDetailMirrorImporter::class) + ->import($this->fixture, 'personal_permission', true); + + $this->assertSame('succeeded', $result['status']); + $this->assertSame(4, $result['rows']); + $this->assertSame(0, $result['invalid']); + $this->assertSame(0, $result['placeholders']); + $this->assertSame(4, DB::connection('business_mirror') + ->table('ding_process_detail_mirror')->count()); + + $row = DB::connection('business_mirror') + ->table('ding_process_detail_mirror') + ->where('business_id', '202601011200000000001') + ->where('line_no', 1) + ->first(); + + $this->assertNotNull($row); + $this->assertSame('张三', $row->originator_name); + $this->assertSame('已完成', $row->status); + $this->assertSame('公摊日常报销', $row->document_type); + $this->assertSame('5602.04', $row->account_code); + $this->assertSame('管理费用_办公费', $row->account_name); + $this->assertEqualsWithDelta(100.0, (float) $row->amount, 0.001); + $this->assertSame('202601', $row->business_month); + $this->assertSame('personal_permission', $row->source_scope); + + $state = DB::connection('business_mirror') + ->table('business_mirror_table_states') + ->where('dataset_key', 'ding.process_details.personal_permission') + ->first(); + + $this->assertNotNull($state); + $this->assertSame('succeeded', $state->status); + $this->assertSame('ding_process_detail_mirror', $state->target_table); + $this->assertNotNull($state->initial_completed_at); + $this->assertSame(4, (int) $state->mirror_row_count); + } + + public function test_import_is_idempotent_by_business_id_and_line_number(): void + { + $importer = app(DingProcessDetailMirrorImporter::class); + $importer->import($this->fixture, 'personal_permission', true); + $importer->import($this->fixture, 'personal_permission', false); + + $this->assertSame(4, DB::connection('business_mirror') + ->table('ding_process_detail_mirror')->count()); + } + + public function test_replace_removes_rows_that_are_not_in_the_new_file(): void + { + $importer = app(DingProcessDetailMirrorImporter::class); + $importer->import($this->fixture, 'personal_permission', true); + + $replacement = $this->makeCsv([[ + '1', + '202603011200000000003', + '王五', + '已完成', + '店铺日常报销', + '替换后的流程', + '1', + '5601.01', + '销售费用', + '10.00', + '1002.01.003', + '银行-测试3', + '10.00', + '银行卡', + '2026-03-02 00:00', + ]]); + + $importer->import($replacement, 'personal_permission', true); + + $this->assertSame(1, DB::connection('business_mirror') + ->table('ding_process_detail_mirror')->count()); + $this->assertSame( + '202603011200000000003', + (string) DB::connection('business_mirror') + ->table('ding_process_detail_mirror') + ->value('business_id'), + ); + } + + public function test_missing_headers_does_not_delete_existing_rows(): void + { + $importer = app(DingProcessDetailMirrorImporter::class); + $importer->import($this->fixture, 'personal_permission', true); + + $path = tempnam(sys_get_temp_dir(), 'ding-process-bad-'); + file_put_contents($path, "序号,审批编号\n1,202603011200000000003\n"); + $this->tempFiles[] = $path; + + try { + $importer->import($path, 'personal_permission', true); + $this->fail('缺少表头时应抛出异常。'); + } catch (RuntimeException $exception) { + $this->assertStringContainsString('缺少列', $exception->getMessage()); + } + + $this->assertSame(4, DB::connection('business_mirror') + ->table('ding_process_detail_mirror')->count()); + } + + public function test_placeholder_rows_are_skipped_and_the_better_duplicate_wins(): void + { + $path = $this->makeCsv([ + [ + '1', '202604011200000000004', '赵六', '已完成', '公摊日常报销', '真实费用', + '1', '5602.04', '管理费用_办公费', '100.00', '1002.01.001', '华夏银行-测试', + '100.00', '银行卡', '2026-04-02 00:00', + ], + [ + '2', '202604011200000000004', '赵六', '已完成', '公摊日常报销', '251', + '1', '251', '251', '', '251', '251', '251', '251', '251', + ], + [ + '3', '202604011200000000004', '赵六', '已完成', '公摊日常报销', '251', + '1', '1221.05', '251', '0.00', '1002.01.001', '华夏银行-测试', + '100.00', '银行卡', '2026-04-02 00:00', + ], + [ + '4', '202604021200000000005', '钱七', '已完成', '店铺日常报销', '251', + '1', '251', '251', '', '251', '251', '251', '251', '251', + ], + ]); + + $result = app(DingProcessDetailMirrorImporter::class) + ->import($path, 'personal_permission', true); + + $this->assertSame(1, $result['rows']); + $this->assertSame(2, $result['placeholders']); + $this->assertSame(1, $result['duplicates']); + $row = DB::connection('business_mirror') + ->table('ding_process_detail_mirror') + ->first(); + $this->assertSame('5602.04', $row->account_code); + $this->assertSame('管理费用_办公费', $row->account_name); + $this->assertEqualsWithDelta(100.0, (float) $row->amount, 0.001); + } + + public function test_artisan_command_imports_the_file(): void + { + $this->artisan('ding:import-process-details', [ + 'file' => $this->fixture, + '--scope' => 'personal_permission', + '--replace' => true, + ])->assertSuccessful(); + + $this->assertSame(4, DB::connection('business_mirror') + ->table('ding_process_detail_mirror')->count()); + } + + private function createMirrorTables(): void + { + Schema::connection('business_mirror')->create( + 'business_mirror_table_states', + function (Blueprint $table): void { + $table->string('dataset_key')->primary(); + $table->string('source_key'); + $table->string('source_object'); + $table->string('target_table'); + $table->string('status')->default('pending'); + $table->string('run_mode')->nullable(); + $table->string('generation')->nullable(); + $table->json('cursor')->nullable(); + $table->json('high_watermark')->nullable(); + $table->dateTime('window_started_at')->nullable(); + $table->dateTime('window_ends_at')->nullable(); + $table->dateTime('initial_completed_at')->nullable(); + $table->dateTime('last_full_succeeded_at')->nullable(); + $table->dateTime('last_attempted_at')->nullable(); + $table->dateTime('last_succeeded_at')->nullable(); + $table->unsignedBigInteger('last_upserted_rows')->default(0); + $table->unsignedBigInteger('mirror_row_count')->default(0); + $table->string('last_error_code')->nullable(); + $table->timestamps(); + }, + ); + + Schema::connection('business_mirror')->create( + 'ding_process_detail_mirror', + function (Blueprint $table): void { + $table->bigIncrements('id'); + $table->string('business_id', 32); + $table->unsignedInteger('line_no'); + $table->string('business_month', 6)->index(); + $table->string('originator_name', 100)->nullable()->index(); + $table->string('status', 20)->nullable()->index(); + $table->string('document_type', 100)->nullable()->index(); + $table->text('purpose')->nullable(); + $table->string('account_code', 64)->nullable(); + $table->string('account_name', 255)->nullable(); + $table->decimal('amount', 18, 2)->nullable(); + $table->string('bank_account_code', 255)->nullable(); + $table->string('bank_account_name', 255)->nullable(); + $table->decimal('bank_amount', 18, 2)->nullable(); + $table->string('payment_method', 50)->nullable(); + $table->string('paid_at', 50)->nullable(); + $table->string('source_scope', 40)->default('personal_permission')->index(); + $table->dateTime('synced_at', 6); + $table->timestamps(); + $table->unique(['business_id', 'line_no']); + }, + ); + } + + /** @param list> $rows */ + private function makeCsv(array $rows): string + { + $path = tempnam(sys_get_temp_dir(), 'ding-process-'); + $handle = fopen($path, 'wb'); + fputcsv($handle, DingProcessDetailMirrorImporter::HEADERS); + foreach ($rows as $row) { + fputcsv($handle, $row); + } + fclose($handle); + $this->tempFiles[] = $path; + + return $path; + } +} diff --git a/tests/Fixtures/ding_process_details_sample.csv b/tests/Fixtures/ding_process_details_sample.csv new file mode 100644 index 00000000..64f7a2e4 --- /dev/null +++ b/tests/Fixtures/ding_process_details_sample.csv @@ -0,0 +1,5 @@ +序号,审批编号,发起人,状态,单据类型,用途/摘要,单据内行号,科目编码,科目名称,金额(元),银行科目编码,银行科目名称,银行付款金额,付款方式,打款时间 +1,202601011200000000001,张三,已完成,公摊日常报销,办公用品采购,1,5602.04,管理费用_办公费,100.00,1002.01.001,华夏银行-测试,100.00,银行卡,2026-01-02 00:00 +2,202601011200000000001,张三,已完成,公摊日常报销,交通费,2,5602.06,管理费用_交通费,50.50,1002.01.001,华夏银行-测试,50.50,银行卡,2026-01-02 00:00 +3,202602031200000000002,李四,审批中,应付申请流程,供应商货款,1,,,200.00,1002.01.002,银行-测试2,200.00,银行卡, +4,202602031200000000002,李四,审批中,应付申请流程,供应商货款,2,,,300.00,1002.01.002,银行-测试2,300.00,银行卡, diff --git a/tests/Unit/EcommerceFinance/DingProcessDetailMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/DingProcessDetailMirrorRepositoryTest.php new file mode 100644 index 00000000..45746aa2 --- /dev/null +++ b/tests/Unit/EcommerceFinance/DingProcessDetailMirrorRepositoryTest.php @@ -0,0 +1,233 @@ + [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'prefix' => '', + ], + 'upstream_mirrors.connection' => 'business_mirror', + 'upstream_mirrors.ding_process_details.scope' => 'personal_permission', + ]); + DB::purge('business_mirror'); + $this->createMirrorTables(); + $this->seedRows(); + + $this->repository = app(DingProcessDetailMirrorRepository::class); + } + + public function test_paginate_returns_rows_summary_and_filter_options(): void + { + $result = $this->repository->paginate([], 1, 50); + + $this->assertSame(4, $result['total']); + $this->assertCount(4, $result['data']); + $this->assertSame(4, $result['summary']['rows']); + $this->assertSame(2, $result['summary']['approvals']); + $this->assertEqualsWithDelta(650.5, $result['summary']['amount_total'], 0.001); + $this->assertEqualsWithDelta(650.5, $result['summary']['bank_amount_total'], 0.001); + $this->assertSame('personal_permission', $result['scope']); + + $options = $this->repository->filterOptions(); + $this->assertSame(['2026-02', '2026-01'], $options['months']); + $this->assertContains('公摊日常报销', $options['document_types']); + $this->assertContains('应付申请流程', $options['document_types']); + $this->assertContains('已完成', $options['statuses']); + $this->assertContains('审批中', $options['statuses']); + } + + public function test_paginate_applies_month_status_and_keyword_filters(): void + { + $this->assertSame( + 2, + $this->repository->paginate(['month' => '2026-01'], 1, 50)['total'], + ); + $this->assertSame( + 2, + $this->repository->paginate(['status' => '审批中'], 1, 50)['total'], + ); + $this->assertSame( + 1, + $this->repository->paginate(['keyword' => '办公'], 1, 50)['total'], + ); + } + + public function test_paginate_applies_document_type_originator_and_business_id_filters(): void + { + $this->assertSame( + 2, + $this->repository->paginate([ + 'document_type' => '应付申请流程', + 'originator_name' => '李四', + ], 1, 50)['total'], + ); + $this->assertSame( + 2, + $this->repository->paginate(['business_id' => '0002'], 1, 50)['total'], + ); + } + + public function test_export_rows_returns_every_filtered_row(): void + { + $rows = iterator_to_array($this->repository->exportRows(['status' => '已完成'])); + + $this->assertCount(2, $rows); + $this->assertSame('202601011200000000001', (string) $rows[0]['business_id']); + } + + public function test_not_ready_when_state_is_missing(): void + { + DB::connection('business_mirror') + ->table('business_mirror_table_states') + ->where('dataset_key', 'ding.process_details.personal_permission') + ->delete(); + + $this->assertFalse($this->repository->ready()); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('ding_process_detail_mirror_not_ready'); + $this->repository->paginate([], 1, 50); + } + + private function seedRows(): void + { + $now = now(); + $rows = [ + $this->row('202601011200000000001', 1, '202601', '张三', '已完成', '公摊日常报销', '办公用品采购', 100.00), + $this->row('202601011200000000001', 2, '202601', '张三', '已完成', '公摊日常报销', '交通费', 50.50), + $this->row('202602031200000000002', 1, '202602', '李四', '审批中', '应付申请流程', '供应商货款', 200.00), + $this->row('202602031200000000002', 2, '202602', '李四', '审批中', '应付申请流程', '供应商货款', 300.00), + ]; + + DB::connection('business_mirror') + ->table('ding_process_detail_mirror') + ->insert($rows); + + DB::connection('business_mirror') + ->table('business_mirror_table_states') + ->insert([ + 'dataset_key' => 'ding.process_details.personal_permission', + 'source_key' => 'dingtalk_oa', + 'source_object' => 'oa approval detail (personal permission scope)', + 'target_table' => 'ding_process_detail_mirror', + 'status' => 'succeeded', + 'run_mode' => 'full', + 'generation' => '00000000-0000-0000-0000-000000000001', + 'initial_completed_at' => $now, + 'last_full_succeeded_at' => $now, + 'last_attempted_at' => $now, + 'last_succeeded_at' => $now, + 'last_upserted_rows' => 4, + 'mirror_row_count' => 4, + 'created_at' => $now, + 'updated_at' => $now, + ]); + } + + /** @return array */ + private function row( + string $businessId, + int $lineNo, + string $month, + string $originator, + string $status, + string $documentType, + string $purpose, + float $amount, + ): array { + $now = now(); + + return [ + 'business_id' => $businessId, + 'line_no' => $lineNo, + 'business_month' => $month, + 'originator_name' => $originator, + 'status' => $status, + 'document_type' => $documentType, + 'purpose' => $purpose, + 'account_code' => '5602.04', + 'account_name' => '管理费用_办公费', + 'amount' => $amount, + 'bank_account_code' => '1002.01.001', + 'bank_account_name' => '华夏银行-测试', + 'bank_amount' => $amount, + 'payment_method' => '银行卡', + 'paid_at' => '2026-01-02 00:00', + 'source_scope' => 'personal_permission', + 'synced_at' => $now, + 'created_at' => $now, + 'updated_at' => $now, + ]; + } + + private function createMirrorTables(): void + { + Schema::connection('business_mirror')->create( + 'business_mirror_table_states', + function (Blueprint $table): void { + $table->string('dataset_key')->primary(); + $table->string('source_key'); + $table->string('source_object'); + $table->string('target_table'); + $table->string('status')->default('pending'); + $table->string('run_mode')->nullable(); + $table->string('generation')->nullable(); + $table->json('cursor')->nullable(); + $table->json('high_watermark')->nullable(); + $table->dateTime('window_started_at')->nullable(); + $table->dateTime('window_ends_at')->nullable(); + $table->dateTime('initial_completed_at')->nullable(); + $table->dateTime('last_full_succeeded_at')->nullable(); + $table->dateTime('last_attempted_at')->nullable(); + $table->dateTime('last_succeeded_at')->nullable(); + $table->unsignedBigInteger('last_upserted_rows')->default(0); + $table->unsignedBigInteger('mirror_row_count')->default(0); + $table->string('last_error_code')->nullable(); + $table->timestamps(); + }, + ); + + Schema::connection('business_mirror')->create( + 'ding_process_detail_mirror', + function (Blueprint $table): void { + $table->bigIncrements('id'); + $table->string('business_id', 32); + $table->unsignedInteger('line_no'); + $table->string('business_month', 6)->index(); + $table->string('originator_name', 100)->nullable()->index(); + $table->string('status', 20)->nullable()->index(); + $table->string('document_type', 100)->nullable()->index(); + $table->text('purpose')->nullable(); + $table->string('account_code', 64)->nullable(); + $table->string('account_name', 255)->nullable(); + $table->decimal('amount', 18, 2)->nullable(); + $table->string('bank_account_code', 255)->nullable(); + $table->string('bank_account_name', 255)->nullable(); + $table->decimal('bank_amount', 18, 2)->nullable(); + $table->string('payment_method', 50)->nullable(); + $table->string('paid_at', 50)->nullable(); + $table->string('source_scope', 40)->default('personal_permission')->index(); + $table->dateTime('synced_at', 6); + $table->timestamps(); + $table->unique(['business_id', 'line_no']); + }, + ); + } +} From dfc3dcd0d0916709a6a5ad619153f2e89c9fff1b Mon Sep 17 00:00:00 2001 From: DoDo <1060330844@qq.com> Date: Mon, 26 Oct 2026 16:32:29 +0800 Subject: [PATCH 04/12] =?UTF-8?q?fix:=20=E9=BB=98=E8=AE=A4=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E6=97=A0=E6=95=B0=E6=8D=AE=E7=9A=84=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=E6=9C=88=E4=BB=BD=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 报表初始只显示有数据的月份列,空列可在筛选字段中手动打开。 --- app/Business/UpstreamBusinessInformation.php | 42 +++++++++++++++++++ .../pages/partials/directory-table.blade.php | 5 ++- tests/Feature/Business/PrototypePageTest.php | 34 ++++++++++----- .../StoreReportRepositoryTest.php | 5 ++- .../UpstreamBusinessInformationTest.php | 5 ++- 5 files changed, 76 insertions(+), 15 deletions(-) diff --git a/app/Business/UpstreamBusinessInformation.php b/app/Business/UpstreamBusinessInformation.php index 67b39aa1..62702f52 100644 --- a/app/Business/UpstreamBusinessInformation.php +++ b/app/Business/UpstreamBusinessInformation.php @@ -319,6 +319,12 @@ SQL); $filters = StoreReportRepository::requestFilters(); $rows = $this->storeReportRows($filters); + // 整列为 0 的月份视为没有销量,默认隐藏;仍可从「筛选字段」手动打开。 + request()->attributes->set( + 'store-report.default_hidden_columns', + $this->columnsWithoutData($rows, 'sales_', zeroCountsAsData: false), + ); + $offset = ($page - 1) * $perPage; return [ @@ -550,6 +556,12 @@ SQL); } unset($row); + // 整列为空的月份默认隐藏;金额 0 仍视为有账单,不隐藏。 + request()->attributes->set( + 'subject-operating-report.default_hidden_columns', + $this->columnsWithoutData($rows, 'income_', zeroCountsAsData: true), + ); + $rows = array_values(array_filter($rows, fn (array $row): bool => $this->subjectMatchesFilters($row, $filters))); $summary = $this->subjectSummary($rows, $companyStatusReady); $this->sortSubjectRows($rows, $filters); @@ -641,6 +653,36 @@ SQL); }; } + /** + * 返回整列都没有数据的月份列;这类列只默认隐藏,字段和数据不会被删除。 + * + * @param list> $rows + * @return list + */ + private function columnsWithoutData(array $rows, string $prefix, bool $zeroCountsAsData): array + { + $columns = []; + + for ($month = 1; $month <= 12; $month++) { + $key = sprintf('%s%02d', $prefix, $month); + foreach ($rows as $row) { + $value = $row[$key] ?? null; + if ($value === null || $value === '') { + continue; + } + if (! $zeroCountsAsData && (float) $value === 0.0) { + continue; + } + + continue 2; + } + + $columns[] = $key; + } + + return $columns; + } + /** @param array $row @param array $filters */ private function subjectMatchesFilters(array $row, array $filters): bool { diff --git a/resources/views/business/pages/partials/directory-table.blade.php b/resources/views/business/pages/partials/directory-table.blade.php index 304c64d7..2bba0d1c 100644 --- a/resources/views/business/pages/partials/directory-table.blade.php +++ b/resources/views/business/pages/partials/directory-table.blade.php @@ -1418,6 +1418,7 @@ data-directory-user="{{ auth()->id() ?? 'guest' }}" data-directory-section="{{ $section['slug'] ?? '' }}" data-directory-tab="{{ $activeTab['slug'] ?? '' }}" + data-directory-column-preference-version="{{ in_array($directoryPageKey, ['company-management/subject-operating-report', 'store-management/store-report'], true) ? 'empty-month-columns-v1' : '' }}" aria-label="{{ $page['title'] ?? $section['title'] }}" > @if ($directoryUsesFieldQuery) @@ -3662,12 +3663,14 @@ const tableKey = tableScope?.dataset.directoryTableKey || section?.dataset.directoryTab || 'table'; const sourceUrl = tableScope?.dataset.directorySourceUrl || window.location.href; const lastPage = Number(tableScope?.dataset.directoryLastPage || section?.dataset.directoryLastPage || 1); + const preferenceVersion = section.dataset.directoryColumnPreferenceVersion || ''; const storageKey = [ 'directory-fields', section.dataset.directoryUser || 'guest', section.dataset.directorySection || 'section', section.dataset.directoryPage || 'page', tableKey, + ...(preferenceVersion ? [preferenceVersion] : []), ].join(':'); const defaultOrder = checks.map((check) => check.value); const orderedChecks = () => [...(picker?.querySelectorAll('[data-directory-field-option]') || [])] @@ -3841,7 +3844,7 @@ const options = [...picker.querySelectorAll('[data-directory-field-option]')]; const byKey = new Map(options.map((option) => [option.querySelector('[data-directory-field-check]').value, option])); defaultOrder.forEach((key) => picker.querySelector('.directory-field-picker__panel').appendChild(byKey.get(key))); - checks.forEach((check) => { check.checked = !['sales_01', 'sales_02', 'sales_03', 'sales_04', 'sales_05', 'sales_06'].includes(check.value); }); + checks.forEach((check) => { check.checked = check.defaultChecked; }); applyColumns(); }; const resetButton = tools.querySelector('[data-directory-reset]'); diff --git a/tests/Feature/Business/PrototypePageTest.php b/tests/Feature/Business/PrototypePageTest.php index 9eabc4b6..7beebb9a 100644 --- a/tests/Feature/Business/PrototypePageTest.php +++ b/tests/Feature/Business/PrototypePageTest.php @@ -227,11 +227,16 @@ class PrototypePageTest extends FeatureTestCase ->assertSeeTextInOrder(['最近12个月累计收入', '1月收入', '12月收入']); } - public function testSubjectOperatingReportShowsAllMonthsByDefaultAndStillSupportsColumnSelection(): void + public function testSubjectOperatingReportHidesMonthsWithoutDataAndKeepsThemSelectable(): void { $service = Mockery::mock(UpstreamBusinessInformation::class); $service->shouldReceive('paginate')->with('company-management', 'subject-operating-report', 50) ->andReturnUsing(function (): LengthAwarePaginator { + request()->attributes->set( + 'subject-operating-report.default_hidden_columns', + ['income_01', 'income_02'], + ); + return new LengthAwarePaginator([(object) [ 'entity' => '测试主体', 'city' => '常州市', @@ -255,13 +260,15 @@ class PrototypePageTest extends FeatureTestCase $response->assertOk(); $html = $response->getContent(); - // 所有原始月份表头默认显示,避免新增汇总卡后缩减原表字段。 - $this->assertDoesNotMatchRegularExpression('/]*data-column-key="income_01"[^>]*is-column-hidden/', $html); - $this->assertDoesNotMatchRegularExpression('/]*data-column-key="income_02"[^>]*is-column-hidden/', $html); + // 没有数据的月份默认隐藏,但表头和「筛选字段」勾选项仍在页面中。 + $this->assertMatchesRegularExpression('/]*data-column-key="income_01"[^>]*is-column-hidden/', $html); + $this->assertMatchesRegularExpression('/]*data-column-key="income_02"[^>]*is-column-hidden/', $html); $this->assertDoesNotMatchRegularExpression('/]*data-column-key="income_03"[^>]*is-column-hidden/', $html); $this->assertStringContainsString('value="income_01" data-directory-query-column', $html); - $this->assertStringContainsString('value="income_01" data-directory-query-column checked', $html); + $this->assertStringNotContainsString('value="income_01" data-directory-query-column checked', $html); $this->assertStringContainsString('value="income_03" data-directory-query-column checked', $html); + $this->assertStringContainsString('筛选字段 19/21', $html); + $this->assertStringContainsString('data-directory-column-preference-version="empty-month-columns-v1"', $html); // 手动勾选(columns 参数)后,对应月份列恢复显示。 $restored = $this->get(route('business.pages.show', [ @@ -277,11 +284,16 @@ class PrototypePageTest extends FeatureTestCase $this->assertMatchesRegularExpression('/]*data-column-key="income_04"[^>]*is-column-hidden/', $restoredHtml); } - public function testStoreReportShowsAllMonthsByDefaultAndStillSupportsColumnSelection(): void + public function testStoreReportHidesSalesMonthsWithoutDataAndKeepsThemSelectable(): void { $service = Mockery::mock(UpstreamBusinessInformation::class); $service->shouldReceive('paginate')->with('store-management', 'store-report', 50) ->andReturnUsing(function (): LengthAwarePaginator { + request()->attributes->set( + 'store-report.default_hidden_columns', + ['sales_01', 'sales_08'], + ); + return new LengthAwarePaginator([(object) [ 'erp_store_name' => 'ERP测试店铺', 'store_name' => '前台测试店铺', @@ -305,13 +317,15 @@ class PrototypePageTest extends FeatureTestCase $response->assertOk(); $html = $response->getContent(); - // 所有原始月份表头默认显示,避免新增汇总卡后缩减原表字段。 - $this->assertDoesNotMatchRegularExpression('/]*data-column-key="sales_01"[^>]*is-column-hidden/', $html); - $this->assertDoesNotMatchRegularExpression('/]*data-column-key="sales_08"[^>]*is-column-hidden/', $html); + // 没有业绩的月份默认隐藏,但表头和「筛选字段」勾选项仍在页面中。 + $this->assertMatchesRegularExpression('/]*data-column-key="sales_01"[^>]*is-column-hidden/', $html); + $this->assertMatchesRegularExpression('/]*data-column-key="sales_08"[^>]*is-column-hidden/', $html); $this->assertDoesNotMatchRegularExpression('/]*data-column-key="sales_07"[^>]*is-column-hidden/', $html); $this->assertStringContainsString('value="sales_01" data-directory-query-column', $html); - $this->assertStringContainsString('value="sales_01" data-directory-query-column checked', $html); + $this->assertStringNotContainsString('value="sales_01" data-directory-query-column checked', $html); $this->assertStringContainsString('value="sales_07" data-directory-query-column checked', $html); + $this->assertStringContainsString('筛选字段 24/26', $html); + $this->assertStringContainsString('data-directory-column-preference-version="empty-month-columns-v1"', $html); // 手动勾选(columns 参数)后,对应月份列恢复显示。 $restored = $this->get(route('business.pages.show', [ diff --git a/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php b/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php index 9652f8cf..37fb8088 100644 --- a/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/StoreReportRepositoryTest.php @@ -295,7 +295,7 @@ class StoreReportRepositoryTest extends TestCase $this->assertSame(1, $summaryCards['当月(7月)有销量店铺']['value']); } - public function test_store_report_keeps_all_sales_months_visible_by_default(): void + public function test_store_report_hides_sales_months_without_data_by_default(): void { Carbon::setTestNow('2026-09-15 10:00:00'); $this->insertBill('店铺A', '2026-07-05', 60); @@ -315,7 +315,8 @@ class StoreReportRepositoryTest extends TestCase $paginator = $service->paginate('store-management', 'store-report', 50); - $this->assertNull( + $this->assertSame( + ['sales_01', 'sales_02', 'sales_03', 'sales_04', 'sales_05', 'sales_06', 'sales_08', 'sales_09', 'sales_10', 'sales_11', 'sales_12'], $this->app['request']->attributes->get('store-report.default_hidden_columns'), ); $this->assertSame(1, $paginator->total()); diff --git a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php index 444fa866..d8a44988 100644 --- a/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php +++ b/tests/Unit/EcommerceFinance/UpstreamBusinessInformationTest.php @@ -219,7 +219,7 @@ class UpstreamBusinessInformationTest extends TestCase ->paginate('store-management', 'basic-information'); } - public function test_subject_operating_report_keeps_all_income_months_visible_by_default(): void + public function test_subject_operating_report_hides_income_months_without_data_by_default(): void { $mirror = Mockery::mock(BusinessInformationMirrorRepository::class); $mirror->shouldReceive('ready')->with('store-information.read')->andReturnTrue(); @@ -258,7 +258,8 @@ class UpstreamBusinessInformationTest extends TestCase $paginator = $information->paginate('company-management', 'subject-operating-report', 50); - $this->assertNull( + $this->assertSame( + ['income_01', 'income_04', 'income_05', 'income_06', 'income_07', 'income_08', 'income_09', 'income_10', 'income_11', 'income_12'], $this->app['request']->attributes->get('subject-operating-report.default_hidden_columns'), ); $this->assertSame(1, $paginator->total()); From 4d5b6ee7180fb0a8c862254f18d8d0527c1c633b Mon Sep 17 00:00:00 2001 From: qiuxiang <394405259@qq.com> Date: Mon, 26 Oct 2026 16:37:39 +0800 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E8=B4=B9=E5=8D=A1=E7=89=87=E4=B8=87=E5=85=83=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=92=8C=E6=98=8E=E7=BB=86=E5=85=A5=E5=8F=A3=20(#610)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 安装费卡片统一数字字体,切换万元展示,并增加右下角明细按钮。 --- .../installation-fee-summary.blade.php | 129 ++++++++++++------ tests/Feature/Business/ManagementCrudTest.php | 6 +- 2 files changed, 95 insertions(+), 40 deletions(-) diff --git a/resources/views/business/pages/partials/installation-fee-summary.blade.php b/resources/views/business/pages/partials/installation-fee-summary.blade.php index e2b29237..383db060 100644 --- a/resources/views/business/pages/partials/installation-fee-summary.blade.php +++ b/resources/views/business/pages/partials/installation-fee-summary.blade.php @@ -18,21 +18,8 @@ background: #ffffff; color: #171717; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04); - font: inherit; + font-family: "JetBrains Mono", "Microsoft YaHei", "PingFang SC", monospace; text-align: left; - cursor: pointer; - } - - .installation-fee-card:hover, - .installation-fee-card:focus-visible { - border-color: #b9954f; - border-left-color: #006395; - background: #fffdf8; - outline: none; - } - - .installation-fee-card:focus-visible { - box-shadow: 0 0 0 3px rgba(133, 102, 50, 0.2); } .installation-fee-card__top { @@ -75,7 +62,7 @@ font-size: 2.5rem; font-weight: 700; line-height: 1; - letter-spacing: -0.035em; + letter-spacing: 0; font-variant-numeric: tabular-nums; } @@ -110,6 +97,7 @@ .installation-fee-card__split { display: flex; align-items: center; + justify-content: space-between; gap: 0.45rem; flex-wrap: wrap; margin: auto -1rem 0 -1.15rem; @@ -121,6 +109,14 @@ font-variant-numeric: tabular-nums; } + .installation-fee-card__split-summary { + display: flex; + min-width: 0; + align-items: center; + gap: 0.45rem; + flex-wrap: wrap; + } + .installation-fee-card__split strong { font-weight: 600; } @@ -136,6 +132,35 @@ font-weight: 400; } + .installation-fee-card__detail-button { + display: inline-flex; + min-height: 1.55rem; + align-items: center; + justify-content: center; + gap: 0.25rem; + margin-left: auto; + padding: 0 0.45rem; + border: 0; + border-radius: 0.3rem; + background: transparent; + color: #006395; + cursor: pointer; + font: inherit; + font-size: 0.75rem; + font-weight: 600; + white-space: nowrap; + } + + .installation-fee-card__detail-button:hover { + background: #eef6fa; + } + + .installation-fee-card__detail-button:focus-visible { + background: #eef6fa; + box-shadow: 0 0 0 3px rgba(0, 99, 149, 0.16); + outline: none; + } + @media (max-width: 720px) { .installation-fee-card { height: auto; @@ -162,6 +187,10 @@ padding-right: 0.85rem; padding-left: 0.95rem; } + .installation-fee-card__detail-button { + width: 100%; + justify-content: flex-end; + } } .installation-fee-dialog { @@ -362,13 +391,9 @@
- - +
@@ -462,9 +496,10 @@