From f71fa8f669d18fb2c578f7872dcb19a1bde88fea Mon Sep 17 00:00:00 2001 From: yueyang <2495544247@qq.com> Date: Fri, 13 Nov 2026 13:23:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B7=B2=E4=BB=98=E6=B8=85=E5=AE=A1?= =?UTF-8?q?=E6=89=B9=E6=8C=89=E4=BB=98=E6=AC=BE=E5=90=88=E8=AE=A1=E6=8E=92?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DingProcessDetailMirrorRepository.php | 55 +++++++++++++++++++ .../DingProcessDetailMirrorRepositoryTest.php | 5 ++ 2 files changed, 60 insertions(+) diff --git a/modules/EcommerceFinance/Repositories/DingProcessDetailMirrorRepository.php b/modules/EcommerceFinance/Repositories/DingProcessDetailMirrorRepository.php index 32357246..6627d0be 100644 --- a/modules/EcommerceFinance/Repositories/DingProcessDetailMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/DingProcessDetailMirrorRepository.php @@ -525,6 +525,61 @@ class DingProcessDetailMirrorRepository ) ->where('paid_approval.cashier_status', 'completed'); }); + if ($this->structuredPaymentsEnabled()) { + $query->whereNotExists(function (Builder $fullyPaidApproval): void { + $fullyPaidApproval + ->select('payment_fully_paid.business_id') + ->from('ding_process_payment_mirror as payment_fully_paid') + ->whereColumn( + 'payment_fully_paid.business_id', + 'ding_process_detail_mirror.business_id', + ) + ->whereColumn( + 'payment_fully_paid.source_scope', + 'ding_process_detail_mirror.source_scope', + ) + ->groupBy( + 'payment_fully_paid.business_id', + 'payment_fully_paid.source_scope', + ) + ->havingRaw( + 'SUM(COALESCE(payment_fully_paid.amount, 0)) > 0', + ) + ->havingRaw( + 'SUM(COALESCE(payment_fully_paid.amount, 0)) + 0.01 >= (' + . 'SELECT SUM(COALESCE(detail_fully_paid.amount, 0)) ' + . 'FROM ding_process_detail_mirror AS detail_fully_paid ' + . 'WHERE detail_fully_paid.business_id = ding_process_detail_mirror.business_id ' + . 'AND detail_fully_paid.source_scope = ding_process_detail_mirror.source_scope' + . ')', + ); + }); + } else { + $query->whereNotExists(function (Builder $fullyPaidApproval): void { + $fullyPaidApproval + ->select('fully_paid_approval.business_id') + ->from('ding_process_detail_mirror as fully_paid_approval') + ->whereColumn( + 'fully_paid_approval.business_id', + 'ding_process_detail_mirror.business_id', + ) + ->whereColumn( + 'fully_paid_approval.source_scope', + 'ding_process_detail_mirror.source_scope', + ) + ->groupBy( + 'fully_paid_approval.business_id', + 'fully_paid_approval.source_scope', + ) + ->havingRaw( + 'SUM(COALESCE(fully_paid_approval.bank_amount, 0)) > 0', + ) + ->havingRaw( + 'SUM(COALESCE(fully_paid_approval.bank_amount, 0)) + 0.01 ' + . '>= SUM(COALESCE(fully_paid_approval.amount, 0))', + ); + }); + } } $paidStart = $this->filterDate($filters['paid_start'] ?? ''); diff --git a/tests/Unit/EcommerceFinance/DingProcessDetailMirrorRepositoryTest.php b/tests/Unit/EcommerceFinance/DingProcessDetailMirrorRepositoryTest.php index 4cb1d651..0f5e90c7 100644 --- a/tests/Unit/EcommerceFinance/DingProcessDetailMirrorRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/DingProcessDetailMirrorRepositoryTest.php @@ -128,6 +128,11 @@ class DingProcessDetailMirrorRepositoryTest extends TestCase public function test_paid_approvals_are_excluded_unless_explicitly_included(): void { + DB::connection('business_mirror') + ->table('ding_process_detail_mirror') + ->where('business_id', '202601011200000000001') + ->update(['cashier_status' => 'pending']); + $pending = $this->repository->paginate([ 'include_paid' => '', ], 1, 50);