From abdc7f76605c26a43fcc851dd6f2097354714c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E6=9C=A8?= <594326199@qq.com> Date: Wed, 4 Nov 2026 13:49:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=82=E5=AE=B6=E9=80=80=E8=B4=A7?= =?UTF-8?q?=E5=87=80=E6=89=A3=E5=87=8F=E4=B8=8D=E8=AE=A1=E9=A2=84=E4=BC=B0?= =?UTF-8?q?=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/SupplierReturnAccounting.php | 5 +-- .../SupplierReturnAccountingTest.php | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/modules/EcommerceFinance/Services/SupplierReturnAccounting.php b/modules/EcommerceFinance/Services/SupplierReturnAccounting.php index a0749be6..c58145c3 100644 --- a/modules/EcommerceFinance/Services/SupplierReturnAccounting.php +++ b/modules/EcommerceFinance/Services/SupplierReturnAccounting.php @@ -35,8 +35,9 @@ class SupplierReturnAccounting } $qty = $this->number($row['qty'] ?? 0); - $unitPrice = $this->number($row['unit_price'] ?? $row['guess_unit_price'] ?? 0); - $amount = $this->number($row['amount'] ?? $row['guess_amount'] ?? 0); + // 厂家净扣减只按实际单价/金额计算,不能用预估单价或预估金额兜底。 + $unitPrice = $this->number($row['unit_price'] ?? 0); + $amount = $this->number($row['amount'] ?? 0); if ($amount === 0.0 && $qty !== 0.0) { $amount = $qty * $unitPrice; } diff --git a/tests/Unit/EcommerceFinance/SupplierReturnAccountingTest.php b/tests/Unit/EcommerceFinance/SupplierReturnAccountingTest.php index ff175c38..40b507d1 100644 --- a/tests/Unit/EcommerceFinance/SupplierReturnAccountingTest.php +++ b/tests/Unit/EcommerceFinance/SupplierReturnAccountingTest.php @@ -78,4 +78,38 @@ class SupplierReturnAccountingTest extends TestCase $this->assertSame(3.0, $row['_supplier_qty']); $this->assertSame(750.0, $row['_supplier_amount']); } + + public function test_supplier_net_amount_never_uses_estimated_price_or_amount(): void + { + $accounting = new SupplierReturnAccounting(); + $rows = [ + [ + 'qty' => '2', + 'unit_price' => '50', + 'amount' => '100', + 'guess_unit_price' => '999', + 'guess_amount' => '999', + ], + [ + 'qty' => '5', + 'unit_price' => '0', + 'amount' => '0', + 'guess_unit_price' => '30', + 'guess_amount' => '150', + ], + [ + 'qty' => '3', + 'unit_price' => '20', + 'amount' => '0', + 'guess_amount' => '999', + ], + ]; + + $unpriced = $accounting->enrich($rows[1]); + $summary = $accounting->summarize($rows); + + $this->assertSame(0.0, $unpriced['_supplier_amount']); + $this->assertSame(10.0, $summary['supplier_qty']); + $this->assertSame(160.0, $summary['supplier_amount']); + } } -- 2.47.2