From b0cd721e0b2d41ae300e477aff16d5c36abd39e5 Mon Sep 17 00:00:00 2001 From: shanshi <3316401569@qq.com> Date: Wed, 21 Oct 2026 11:58:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A2=E5=8A=A1=E5=8F=B0=E8=B4=A6=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B4=A6=E6=88=B7=E6=98=AF=E5=90=A6=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FinanceLedgerAccountShouldKeep.php | 45 +++++ ...dd_account_should_keep_to_fin_accounts.php | 35 ++++ .../Services/FinanceLedgerAccountTemplate.php | 27 ++- .../Services/FinanceLedgerBaseImporter.php | 70 +++++--- .../View/FinanceLedgerPageData.php | 5 + .../pages/financial-ledger/ledger.blade.php | 7 +- .../FinanceLedgerAccountStatusTest.php | 17 ++ .../FinanceLedgerAccountTemplateTest.php | 11 +- .../FinanceLedgerBaseImporterTest.php | 159 ++++++++++++++++++ 9 files changed, 338 insertions(+), 38 deletions(-) create mode 100644 app/Utilities/FinanceLedgerAccountShouldKeep.php create mode 100644 database/migrations/2026_10_21_120000_add_account_should_keep_to_fin_accounts.php create mode 100644 tests/Unit/EcommerceFinance/FinanceLedgerBaseImporterTest.php diff --git a/app/Utilities/FinanceLedgerAccountShouldKeep.php b/app/Utilities/FinanceLedgerAccountShouldKeep.php new file mode 100644 index 00000000..bf928203 --- /dev/null +++ b/app/Utilities/FinanceLedgerAccountShouldKeep.php @@ -0,0 +1,45 @@ +connection()); + if (! $schema->hasTable('fin_accounts') || $schema->hasColumn('fin_accounts', 'account_should_keep')) { + return; + } + + $schema->table('fin_accounts', function (Blueprint $table): void { + $table->string('account_should_keep', 20)->nullable()->after('company_plan'); + }); + } + + public function down(): void + { + $schema = Schema::connection($this->connection()); + if ($schema->hasTable('fin_accounts') && $schema->hasColumn('fin_accounts', 'account_should_keep')) { + $schema->table('fin_accounts', function (Blueprint $table): void { + $table->dropColumn('account_should_keep'); + }); + } + } +}; diff --git a/modules/EcommerceFinance/Services/FinanceLedgerAccountTemplate.php b/modules/EcommerceFinance/Services/FinanceLedgerAccountTemplate.php index 3b059c2e..f5658433 100644 --- a/modules/EcommerceFinance/Services/FinanceLedgerAccountTemplate.php +++ b/modules/EcommerceFinance/Services/FinanceLedgerAccountTemplate.php @@ -3,6 +3,7 @@ namespace Modules\EcommerceFinance\Services; use App\Utilities\FinanceLedgerAccountStatus; +use App\Utilities\FinanceLedgerAccountShouldKeep; use App\Utilities\FinanceLedgerAccountType; use Illuminate\Support\Facades\DB; use PhpOffice\PhpSpreadsheet\Cell\Coordinate; @@ -33,6 +34,7 @@ class FinanceLedgerAccountTemplate '开户行', '开户城市/网点', '公司规划', + '账户是否保留', '后4位', '单笔限额', '日限额', @@ -98,29 +100,35 @@ class FinanceLedgerAccountTemplate $sheet->getStyle("A1:{$lastColumn}{$lastRow}")->getBorders()->getAllBorders() ->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FFD8D2C7'); - $sheet->getStyle("A2:N{$lastRow}")->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); - $sheet->getStyle("O2:Q{$lastRow}")->getNumberFormat()->setFormatCode('#,##0.00'); - $sheet->getStyle("R2:R{$lastRow}")->getNumberFormat()->setFormatCode('0.00'); - $sheet->getStyle("S2:Y{$lastRow}")->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); + $sheet->getStyle("A2:O{$lastRow}")->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); + $sheet->getStyle("P2:R{$lastRow}")->getNumberFormat()->setFormatCode('#,##0.00'); + $sheet->getStyle("S2:S{$lastRow}")->getNumberFormat()->setFormatCode('0.00'); + $sheet->getStyle("T2:Z{$lastRow}")->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT); $options = $spreadsheet->createSheet(); $options->setTitle('选项'); $options->setCellValue('A1', '账户状态'); $options->setCellValue('B1', '账户类型'); + $options->setCellValue('C1', '账户是否保留'); $statuses = array_values(FinanceLedgerAccountStatus::OPTIONS); $types = $this->accountTypes(); + $keepOptions = FinanceLedgerAccountShouldKeep::OPTIONS; foreach ($statuses as $index => $status) { $options->setCellValue('A' . ($index + 2), $status); } foreach ($types as $index => $type) { $options->setCellValue('B' . ($index + 2), $type); } + foreach ($keepOptions as $index => $option) { + $options->setCellValue('C' . ($index + 2), $option); + } $options->setSheetState(Worksheet::SHEETSTATE_HIDDEN); $this->applyListValidation($sheet, 'D', '\'选项\'!$A$2:$A$' . (count($statuses) + 1), '请选择账户状态'); if ($types !== []) { $this->applyListValidation($sheet, 'C', '\'选项\'!$B$2:$B$' . (count($types) + 1), '请选择账户类型'); } + $this->applyListValidation($sheet, 'J', '\'选项\'!$C$2:$C$' . (count($keepOptions) + 1), '请选择账户是否保留'); $notes = $spreadsheet->createSheet(); $notes->setTitle('填写说明'); @@ -130,6 +138,7 @@ class FinanceLedgerAccountTemplate ['必填', '公司名称、账户简称。'], ['账户状态', implode(' / ', $statuses)], ['账户类型', $types !== [] ? implode(' / ', $types) : '留空或按实际填写'], + ['账户是否保留', implode(' / ', $keepOptions)], ['金额', '可用金额、不可用金额、每日可出按数字填写;限额列保留原有组合写法。'], ['提交前', '请核对账户数、余额合计和期初合计,再导入系统。'], ], null, 'A1'); @@ -139,8 +148,8 @@ class FinanceLedgerAccountTemplate $notes->getStyle('A1:B1')->getFill() ->setFillType(Fill::FILL_SOLID) ->getStartColor()->setARGB('FF856632'); - $notes->getStyle('A1:B7')->getAlignment()->setVertical(Alignment::VERTICAL_TOP)->setWrapText(true); - $notes->getStyle('A1:B7')->getBorders()->getAllBorders() + $notes->getStyle('A1:B8')->getAlignment()->setVertical(Alignment::VERTICAL_TOP)->setWrapText(true); + $notes->getStyle('A1:B8')->getBorders()->getAllBorders() ->setBorderStyle(Border::BORDER_THIN)->getColor()->setARGB('FFD8D2C7'); $notes->getRowDimension(1)->setRowHeight(26); @@ -189,9 +198,9 @@ class FinanceLedgerAccountTemplate { return match ($index) { 0, 6 => 30, - 1, 5, 7, 23 => 22, - 2, 3, 4, 8, 17 => 13, - 14, 15, 16 => 16, + 1, 5, 7, 24 => 22, + 2, 3, 4, 8, 9, 18 => 13, + 15, 16, 17 => 16, default => 18, }; } diff --git a/modules/EcommerceFinance/Services/FinanceLedgerBaseImporter.php b/modules/EcommerceFinance/Services/FinanceLedgerBaseImporter.php index e3790ac8..447d57ee 100644 --- a/modules/EcommerceFinance/Services/FinanceLedgerBaseImporter.php +++ b/modules/EcommerceFinance/Services/FinanceLedgerBaseImporter.php @@ -2,7 +2,9 @@ namespace Modules\EcommerceFinance\Services; +use App\Utilities\FinanceLedgerAccountShouldKeep; use Illuminate\Support\Facades\DB; +use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use RuntimeException; @@ -90,45 +92,63 @@ class FinanceLedgerBaseImporter ]; } - private function accounts(?Worksheet $sheet): array + protected function accounts(?Worksheet $sheet): array { if (! $sheet) { throw new RuntimeException('缺少「账户总表」工作表。'); } + $lastColumn = Coordinate::columnIndexFromString($sheet->getHighestDataColumn()); + $headers = $sheet->rangeToArray('A1:' . Coordinate::stringFromColumnIndex($lastColumn) . '1')[0] ?? []; + $headerIndexes = []; + foreach ($headers as $index => $header) { + $key = (string) preg_replace('/\s+/u', '', trim((string) $header)); + if ($key !== '') { + $headerIndexes[$key] = $index; + } + } + $rows = []; - foreach ($this->rows($sheet, 2, 23) as $row) { - $company = $this->text($row[0] ?? null); - $short = $this->text($row[1] ?? null); + foreach ($this->rows($sheet, 2, $lastColumn) as $row) { + $value = static function (string $header, int $legacyIndex) use ($row, $headerIndexes): mixed { + return $row[$headerIndexes[$header] ?? $legacyIndex] ?? null; + }; + + $company = $this->text($value('公司名称', 0)); + $short = $this->text($value('账户简称', 1)); if ($company === '' || $short === '') { continue; } + $keepIndex = $headerIndexes['账户是否保留'] ?? null; $rows[] = [ 'company_name' => $company, 'account_short' => $short, 'region' => null, - 'account_no' => $this->text($row[2] ?? null), - 'bank_name' => $this->text($row[3] ?? null), - 'bank_city_branch' => $this->text($row[4] ?? null), - 'account_type' => $this->text($row[5] ?? null), - 'company_plan' => $this->text($row[6] ?? null), - 'account_last4' => $this->text($row[7] ?? null), - 'single_limit' => $this->text($row[8] ?? null), - 'daily_limit' => $this->text($row[9] ?? null), - 'monthly_limit' => $this->text($row[10] ?? null), - 'yearly_limit' => $this->text($row[11] ?? null), - 'current_balance' => $this->number($row[12] ?? null), - 'blocked_amount' => $this->number($row[13] ?? null), - 'daily_available' => $this->number($row[14] ?? null), - 'clearing_days' => $this->nullableNumber($row[15] ?? null), - 'raise_target' => $this->text($row[16] ?? null), - 'raise_status' => $this->text($row[17] ?? null), - 'raise_actions' => $this->text($row[18] ?? null), - 'done_actions' => $this->text($row[19] ?? null), - 'next_action' => $this->text($row[20] ?? null), - 'remark' => $this->text($row[21] ?? null), - 'owner' => $this->text($row[22] ?? null), + 'account_no' => $this->text($value('账号', 2)), + 'bank_name' => $this->text($value('开户行', 3)), + 'bank_city_branch' => $this->text($value('开户城市/网点', 4)), + 'account_type' => $this->text($value('账户类型', 5)), + 'company_plan' => $this->text($value('公司规划', 6)), + 'account_should_keep' => FinanceLedgerAccountShouldKeep::normalize( + $keepIndex === null ? null : $this->text($row[$keepIndex] ?? null), + ), + 'account_last4' => $this->text($value('后4位', 7)), + 'single_limit' => $this->text($value('单笔限额', 8)), + 'daily_limit' => $this->text($value('日限额', 9)), + 'monthly_limit' => $this->text($value('月限额', 10)), + 'yearly_limit' => $this->text($value('年限额', 11)), + 'current_balance' => $this->number($value('可用金额', 12)), + 'blocked_amount' => $this->number($value('不可用金额', 13)), + 'daily_available' => $this->number($value('每日可出', 14)), + 'clearing_days' => $this->nullableNumber($value('预计出清天数', 15)), + 'raise_target' => $this->text($value('提额目标', 16)), + 'raise_status' => $this->text($value('提额状态', 17)), + 'raise_actions' => $this->text($value('提额动作', 18)), + 'done_actions' => $this->text($value('已做动作', 19)), + 'next_action' => $this->text($value('下一步', 20)), + 'remark' => $this->text($value('备注', 21)), + 'owner' => $this->text($value('责任人', 22)), ]; } diff --git a/modules/EcommerceFinance/View/FinanceLedgerPageData.php b/modules/EcommerceFinance/View/FinanceLedgerPageData.php index e027325b..1d5a9951 100644 --- a/modules/EcommerceFinance/View/FinanceLedgerPageData.php +++ b/modules/EcommerceFinance/View/FinanceLedgerPageData.php @@ -3,6 +3,7 @@ namespace Modules\EcommerceFinance\View; use App\Utilities\FinanceLedgerAccountStatus; +use App\Utilities\FinanceLedgerAccountShouldKeep; use App\Utilities\FinanceLedgerAccountType; use App\Utilities\FinanceLedgerAccess; use Illuminate\Contracts\Pagination\LengthAwarePaginator; @@ -173,6 +174,10 @@ class FinanceLedgerPageData if ($typeOverrides->has($row->account_short)) { $row->account_type = (string) ($typeOverrides->get($row->account_short) ?? ''); } + $row->account_should_keep = FinanceLedgerAccountShouldKeep::display( + $row->account_should_keep ?? null, + $row->company_plan ?? null, + ); return $row; }); diff --git a/resources/views/business/pages/financial-ledger/ledger.blade.php b/resources/views/business/pages/financial-ledger/ledger.blade.php index e1d42910..f85c14e6 100644 --- a/resources/views/business/pages/financial-ledger/ledger.blade.php +++ b/resources/views/business/pages/financial-ledger/ledger.blade.php @@ -88,6 +88,7 @@ .ledger-accounts-table thead th.num { text-align:center; } .ledger-accounts-table { min-width:max-content; } .ledger-accounts-table .is-column-hidden { display:none !important; } + .ledger-keep-column { width:6.5rem; min-width:6.5rem; text-align:center; } .ledger-table td.wrap { white-space:normal; min-width:14rem; max-width:22rem; line-height:1.5; } .ledger-table .muted { color:var(--vip-content-muted, #595959); } .ledger-table .danger { color:var(--vip-danger, #B80000); } @@ -196,7 +197,7 @@
- + @forelse ($ledgerAccounts as $row) @@ -226,10 +227,10 @@ @endif - + @empty - + @endforelse
公司名称账户简称账户类型账户状态地区账号开户行开户城市/网点公司规划后4位单笔限额日限额月限额年限额可用金额不可用金额每日可出预计出清天数提额目标提额状态提额动作已做动作下一步备注责任人
公司名称账户简称账户类型账户状态地区账号开户行开户城市/网点公司规划账户是否保留后4位单笔限额日限额月限额年限额可用金额不可用金额每日可出预计出清天数提额目标提额状态提额动作已做动作下一步备注责任人
{{ $row->region }}{{ $row->account_no }}{{ $row->bank_name }}{{ $row->bank_city_branch }}{{ $row->company_plan }}{{ $row->account_last4 }}{{ $row->single_limit }}{{ $row->daily_limit }}{{ $row->monthly_limit }}{{ $row->yearly_limit }}{{ $money($row->current_balance) }}{{ $money($row->blocked_amount) }}{{ $money($row->daily_available) }}{{ $row->clearing_days !== null ? number_format((float) $row->clearing_days, 2) : '' }}{{ $row->raise_target }}{{ $row->raise_status }}{{ $row->raise_actions }}{{ $row->done_actions }}{{ $row->next_action }}{{ $row->remark }}{{ $row->owner }}{{ $row->company_plan }}{{ $row->account_should_keep }}{{ $row->account_last4 }}{{ $row->single_limit }}{{ $row->daily_limit }}{{ $row->monthly_limit }}{{ $row->yearly_limit }}{{ $money($row->current_balance) }}{{ $money($row->blocked_amount) }}{{ $money($row->daily_available) }}{{ $row->clearing_days !== null ? number_format((float) $row->clearing_days, 2) : '' }}{{ $row->raise_target }}{{ $row->raise_status }}{{ $row->raise_actions }}{{ $row->done_actions }}{{ $row->next_action }}{{ $row->remark }}{{ $row->owner }}
没有匹配的账户数据。
没有匹配的账户数据。
diff --git a/tests/Feature/Business/FinanceLedgerAccountStatusTest.php b/tests/Feature/Business/FinanceLedgerAccountStatusTest.php index 7de58a29..7e9c7a85 100644 --- a/tests/Feature/Business/FinanceLedgerAccountStatusTest.php +++ b/tests/Feature/Business/FinanceLedgerAccountStatusTest.php @@ -21,6 +21,7 @@ class FinanceLedgerAccountStatusTest extends FeatureTestCase 'account_short' => '测试账户', 'account_no' => '6222000000000001', 'bank_name' => '测试银行', + 'company_plan' => '保留', ]); } @@ -68,6 +69,8 @@ class FinanceLedgerAccountStatusTest extends FeatureTestCase ->assertSee('data-account-template-download', false) ->assertSee('data-account-template-download-status', false) ->assertSee('账户简称账户类型账户状态', false) + ->assertSee('公司规划账户是否保留后4位', false) + ->assertSee('data-account-short="测试账户" data-account-should-keep="是"', false) ->assertSee('网商银行') ->assertSee('ledger-accounts-table-wrap', false) ->assertSee('ledger-pagination__controls', false) @@ -97,6 +100,20 @@ class FinanceLedgerAccountStatusTest extends FeatureTestCase } } + public function test_explicit_account_keep_value_takes_precedence_over_company_plan(): void + { + DB::connection('business_mirror')->table('fin_accounts')->insert([ + 'company_name' => '保留判断测试公司', + 'account_short' => '显式不保留账户', + 'company_plan' => '保留', + 'account_should_keep' => '否', + ]); + + $this->loginAs()->get($this->pageUrl()) + ->assertOk() + ->assertSee('data-account-short="显式不保留账户" data-account-should-keep="否"', false); + } + public function test_account_pagination_lists_page_urls_with_current_filter(): void { $rows = []; diff --git a/tests/Feature/Business/FinanceLedgerAccountTemplateTest.php b/tests/Feature/Business/FinanceLedgerAccountTemplateTest.php index bfecef65..9344b53b 100644 --- a/tests/Feature/Business/FinanceLedgerAccountTemplateTest.php +++ b/tests/Feature/Business/FinanceLedgerAccountTemplateTest.php @@ -53,6 +53,7 @@ class FinanceLedgerAccountTemplateTest extends FeatureTestCase '开户行', '开户城市/网点', '公司规划', + '账户是否保留', '后4位', '单笔限额', '日限额', @@ -69,16 +70,24 @@ class FinanceLedgerAccountTemplateTest extends FeatureTestCase '下一步', '备注', '责任人', - ], $sheet->rangeToArray('A1:Y1')[0]); + ], $sheet->rangeToArray('A1:Z1')[0]); $this->assertNull($sheet->getCell('A2')->getValue()); $this->assertSame(DataValidation::TYPE_LIST, $sheet->getCell('C2')->getDataValidation()->getType()); $this->assertSame(DataValidation::TYPE_LIST, $sheet->getCell('D2')->getDataValidation()->getType()); + $this->assertSame(DataValidation::TYPE_LIST, $sheet->getCell('J2')->getDataValidation()->getType()); $this->assertSame(Worksheet::SHEETSTATE_HIDDEN, $spreadsheet->getSheetByName('选项')->getSheetState()); $typeOptions = array_map( static fn (array $row): string => (string) ($row[0] ?? ''), $spreadsheet->getSheetByName('选项')->rangeToArray('B2:B20'), ); $this->assertContains('网商银行', $typeOptions); + $this->assertSame( + ['是', '否'], + array_map( + static fn (array $row): string => (string) ($row[0] ?? ''), + $spreadsheet->getSheetByName('选项')->rangeToArray('C2:C3'), + ), + ); $this->assertNotNull($spreadsheet->getSheetByName('填写说明')); $spreadsheet->disconnectWorksheets(); } finally { diff --git a/tests/Unit/EcommerceFinance/FinanceLedgerBaseImporterTest.php b/tests/Unit/EcommerceFinance/FinanceLedgerBaseImporterTest.php new file mode 100644 index 00000000..81fea8e3 --- /dev/null +++ b/tests/Unit/EcommerceFinance/FinanceLedgerBaseImporterTest.php @@ -0,0 +1,159 @@ +sheet([ + '公司名称', + '账户简称', + '账号', + '开户行', + '开户城市/网点', + '账户类型', + '公司规划', + '账户是否保留', + '后4位', + '单笔限额', + '日限额', + '月限额', + '年限额', + '可用金额', + '不可用金额', + '每日可出', + '预计出清天数', + '提额目标', + '提额状态', + '提额动作', + '已做动作', + '下一步', + '备注', + '责任人', + ], [ + '新格式公司', + '新格式账户', + '62220001', + '测试银行', + '上海 / 测试支行', + '公户', + '保留', + '是', + '0001', + '10000', + '20000', + '30000', + '40000', + 123.45, + 6.78, + 116.67, + 2.5, + '目标', + '进行中', + '动作', + '已做', + '下一步', + '备注', + '责任人', + ]); + + $rows = $this->importer()->parseAccounts($sheet); + + $this->assertCount(1, $rows); + $this->assertSame('是', $rows[0]['account_should_keep']); + $this->assertSame('0001', $rows[0]['account_last4']); + $this->assertSame('10000', $rows[0]['single_limit']); + $this->assertEqualsWithDelta(123.45, $rows[0]['current_balance'], 0.001); + $this->assertSame('责任人', $rows[0]['owner']); + } + + public function test_account_headers_keep_legacy_layout_compatible(): void + { + $sheet = $this->sheet([ + '公司名称', + '账户简称', + '账号', + '开户行', + '开户城市/网点', + '账户类型', + '公司规划', + '后4位', + '单笔限额', + '日限额', + '月限额', + '年限额', + '可用金额', + '不可用金额', + '每日可出', + '预计出清天数', + '提额目标', + '提额状态', + '提额动作', + '已做动作', + '下一步', + '备注', + '责任人', + ], [ + '旧格式公司', + '旧格式账户', + '62220002', + '测试银行', + '杭州 / 测试支行', + '个人卡', + '待注销', + '0002', + '1000', + '2000', + '3000', + '4000', + 12.34, + 0, + 12.34, + null, + '', + '', + '', + '', + '', + '', + '旧格式责任人', + ]); + + $rows = $this->importer()->parseAccounts($sheet); + + $this->assertCount(1, $rows); + $this->assertSame('', $rows[0]['account_should_keep']); + $this->assertSame('0002', $rows[0]['account_last4']); + $this->assertSame('1000', $rows[0]['single_limit']); + $this->assertEqualsWithDelta(12.34, $rows[0]['current_balance'], 0.001); + $this->assertSame('旧格式责任人', $rows[0]['owner']); + } + + private function importer(): FinanceLedgerBaseImporterForTest + { + return new FinanceLedgerBaseImporterForTest(); + } + + private function sheet(array $headers, array $values): Worksheet + { + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $sheet->fromArray([$headers, $values], null, 'A1'); + + return $sheet; + } +} + +final class FinanceLedgerBaseImporterForTest extends FinanceLedgerBaseImporter +{ + public function parseAccounts(Worksheet $sheet): array + { + return $this->accounts($sheet); + } +} -- 2.47.2