From 8df3c3ec369ee794fcde6d21f5a8089f08bbc236 Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Thu, 26 Nov 2026 20:47:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BE=9B=E5=BA=94=E5=95=86=E5=BA=94?= =?UTF-8?q?=E4=BB=98):=20=E7=BB=88=E7=89=88=E8=B4=A7=E6=AC=BE=E5=AF=B9?= =?UTF-8?q?=E8=B4=A6=E6=8C=89=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=86=E9=A1=B5?= =?UTF-8?q?=20(#1489)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Business/Pages.php | 75 +++++++++++-------- .../Services/SupplierPayableOverrideStore.php | 39 ++++++++++ .../SupplierPayableFinalPagesTest.php | 48 ++++++++++++ 3 files changed, 129 insertions(+), 33 deletions(-) diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 26c60fe6..a316db98 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -4699,29 +4699,15 @@ class Pages extends Controller } $keyword = trim((string) request('keyword', '')); - $rows = $this->supplierPayableOverrides->listRows( - PayablesFinalActions::DATASET_PREFIX - . ($sectionSlug === PayablesFinalRegistry::SECTION_COURIER ? 'courier:' : 'supplier:') - . $dataset, - (int) (company_id() ?: 1), - ); - - if ($keyword !== '') { - $needle = mb_strtolower($keyword); - $rows = array_values(array_filter($rows, static function (array $row) use ($needle): bool { - foreach ($row as $key => $value) { - if ($key === '_action_key' || $value === null) { - continue; - } - if (str_contains(mb_strtolower((string) $value), $needle)) { - return true; - } - } - - return false; - })); - } - + $storeDataset = PayablesFinalActions::DATASET_PREFIX + . ($sectionSlug === PayablesFinalRegistry::SECTION_COURIER ? 'courier:' : 'supplier:') + . $dataset; + $perPage = in_array($dataset, [ + 'payment-reconciliation', + 'return-reconciliation', + 'supplier-payables-report', + ], true) ? 15 : 50; + $currentPage = max((int) request('page', 1), 1); $unpricedSummaryFields = match ($dataset) { 'delivery-unpriced' => ['qty', 'guessAmount'], 'return-unpriced' => ['qty', 'guess_amount'], @@ -4729,6 +4715,25 @@ class Pages extends Controller }; $unpricedSummary = null; if ($unpricedSummaryFields !== null) { + $rows = $this->supplierPayableOverrides->listRows( + $storeDataset, + (int) (company_id() ?: 1), + ); + if ($keyword !== '') { + $needle = mb_strtolower($keyword); + $rows = array_values(array_filter($rows, static function (array $row) use ($needle): bool { + foreach ($row as $key => $value) { + if ($key === '_action_key' || $value === null) { + continue; + } + if (str_contains(mb_strtolower((string) $value), $needle)) { + return true; + } + } + + return false; + })); + } $quantity = 0.0; $estimatedAmount = 0.0; [$quantityField, $amountField] = $unpricedSummaryFields; @@ -4744,16 +4749,20 @@ class Pages extends Controller 'quantity' => $quantity, 'estimated_amount' => $estimatedAmount, ]; + $pagedRows = array_slice($rows, ($currentPage - 1) * $perPage, $perPage); + $totalRows = count($rows); + } else { + $paged = $this->supplierPayableOverrides->paginateRows( + $storeDataset, + (int) (company_id() ?: 1), + $perPage, + $currentPage, + $keyword, + ); + $pagedRows = $paged['rows']; + $totalRows = $paged['total']; } - // 宽表固定每页 15 行,减少纵向滚动并保持横向核对区稳定。 - $perPage = in_array($dataset, [ - 'payment-reconciliation', - 'return-reconciliation', - 'supplier-payables-report', - ], true) ? 15 : 50; - $currentPage = max((int) request('page', 1), 1); - return [ 'dataset' => $dataset, 'fields' => collect($registry->fields($sectionSlug, $dataset)) @@ -4761,8 +4770,8 @@ class Pages extends Controller ->values() ->all(), 'rows' => new LengthAwarePaginator( - array_slice($rows, ($currentPage - 1) * $perPage, $perPage), - count($rows), + $pagedRows, + $totalRows, $perPage, $currentPage, ['path' => request()->url(), 'query' => request()->query()], diff --git a/modules/EcommerceFinance/Services/SupplierPayableOverrideStore.php b/modules/EcommerceFinance/Services/SupplierPayableOverrideStore.php index f0c550f6..37558022 100644 --- a/modules/EcommerceFinance/Services/SupplierPayableOverrideStore.php +++ b/modules/EcommerceFinance/Services/SupplierPayableOverrideStore.php @@ -321,6 +321,45 @@ class SupplierPayableOverrideStore ->all(); } + /** + * 按数据库分页读取终版明细,避免宽表在历史数据较多时整表解码。 + * + * @return array{rows:list>,total:int} + */ + public function paginateRows( + string $dataset, + int $companyId, + int $perPage, + int $page, + string $keyword = '', + ): array { + $perPage = max(1, min($perPage, 200)); + $page = max(1, $page); + $query = $this->connection()->table('supplier_payable_overrides') + ->where('company_id', $companyId) + ->where('dataset', $dataset); + + $keyword = trim($keyword); + if ($keyword !== '') { + $query->where('values', 'like', '%' . $keyword . '%'); + } + + $total = (int) (clone $query)->count(); + $rows = $query + ->orderBy('id') + ->forPage($page, $perPage) + ->get() + ->map(static function (object $record): array { + $values = json_decode((string) $record->values, true) ?: []; + $values['_action_key'] = (string) $record->record_key; + + return $values; + }) + ->all(); + + return ['rows' => $rows, 'total' => $total]; + } + /** * 按记录键读取一条本地业务记录,找不到时返回 null。 * diff --git a/tests/Feature/Business/SupplierPayableFinalPagesTest.php b/tests/Feature/Business/SupplierPayableFinalPagesTest.php index 8fe6555d..1a7a33d7 100644 --- a/tests/Feature/Business/SupplierPayableFinalPagesTest.php +++ b/tests/Feature/Business/SupplierPayableFinalPagesTest.php @@ -312,6 +312,54 @@ class SupplierPayableFinalPagesTest extends FeatureTestCase $this->assertStringContainsString('快递单号,未发出,对账人', $export->streamedContent()); } + public function test_final_payment_reconciliation_page_reads_one_database_page(): void + { + $records = []; + for ($index = 1; $index <= 31; $index++) { + $records[sprintf('payment:%02d', $index)] = [ + 'summary_month' => '2026-09', + 'stockNo' => sprintf('RK-%02d', $index), + 'purchaseNo' => sprintf('CG-%02d', $index), + 'date' => '2026-09-08', + 'supplier' => sprintf('供应商%02d', $index), + 'skuCode' => sprintf('SKU-%02d', $index), + 'productCode' => sprintf('BAR-%02d', $index), + 'skuName' => sprintf('规格%02d', $index), + 'qty' => '2', + 'unitPrice' => '10', + 'amount' => '20', + ]; + } + app(SupplierPayableOverrideStore::class)->saveBatch( + 'final:supplier:payment-reconciliation', + $records, + (int) $this->company->id, + (int) $this->user->id, + ); + + $baseUrl = route('business.pages.show', [ + 'company_id' => (int) $this->company->id, + 'section' => 'supplier-payables-final', + 'page' => 'payment-reconciliation', + ]); + + $this->loginAs() + ->get($baseUrl . '?page=2') + ->assertOk() + ->assertSeeText('第 2 页 / 共 3 页') + ->assertSeeText('RK-16') + ->assertSeeText('RK-30') + ->assertDontSeeText('RK-01') + ->assertDontSeeText('RK-31'); + + $this->loginAs() + ->get($baseUrl . '?keyword=' . urlencode('供应商31')) + ->assertOk() + ->assertSeeText('共 1 条') + ->assertSeeText('RK-31') + ->assertDontSeeText('RK-01'); + } + public function test_final_return_reconciliation_template_adds_wms_and_creator_columns(): void { $response = $this->loginAs()