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']); + } }