invoke(null); } private function baseRules(): array { return (new ReflectionMethod(Pages::class, 'receiptDifferenceRemarkBaseRules'))->invoke(null); } private function remark(array $attributes): ?string { $row = (object) array_merge([ 'platform' => '拼多多', 'match_status' => '已匹配', 'income_amount' => 0, 'discount_amount' => 0, 'offset_amount' => 0, 'default_compensation_amount' => 0, 'refund_amount' => 0, 'product_amount' => 0, 'paid_amount' => 0, 'difference' => 0, 'planting_amount' => null, 'remark' => null, ], $attributes); return (new ReflectionMethod(Pages::class, 'receiptDifferenceRemark'))->invoke(null, $row); } public function test_pinduoduo_full_refund_wins_before_other_difference_rules(): void { $this->assertSame('订单实付含已退款部分', $this->remark([ 'income_amount' => 7.00, 'discount_amount' => 17.00, 'refund_amount' => -7.00, 'product_amount' => 42.00, 'paid_amount' => 6.99, 'difference' => 17.01, ])); } public function test_pinduoduo_partial_refund_marks_platform_payment_discount(): void { $this->assertSame('差额=平台支付立减', $this->remark([ 'income_amount' => 896.00, 'refund_amount' => -552.36, 'product_amount' => 936.00, 'paid_amount' => 894.21, 'difference' => 1.79, ])); $this->assertSame('差额=平台支付立减', $this->remark([ 'income_amount' => 16.43, 'refund_amount' => -12.00, 'product_amount' => 21.90, 'paid_amount' => 16.42, 'difference' => 0.01, ])); } public function test_large_unexplained_pinduoduo_difference_stays_pending(): void { $this->assertSame('差额待核实', $this->remark([ 'income_amount' => 130.00, 'refund_amount' => -50.00, 'product_amount' => 150.00, 'paid_amount' => 100.00, 'difference' => 30.00, ])); } public function test_combination_rules_reuse_existing_labels(): void { $labels = $this->remarkLabels(); $rules = $this->baseRules(); $this->assertContains('订单实付含已退款部分', $labels); $this->assertContains('订单实付未减优惠和冲减', $labels); $this->assertStringContainsString('refund_amount', $rules['订单实付含已退款部分']); $this->assertStringContainsString('discount_amount', $rules['订单实付未减优惠和冲减']); $this->assertStringContainsString('offset_amount', $rules['订单实付未减优惠和冲减']); $this->assertStringContainsString('default_compensation_amount', $rules['订单实付未减优惠和冲减']); $this->assertArrayNotHasKey('差额含已退款部分', $rules); $this->assertArrayNotHasKey('差额含优惠/冲减项', $rules); $this->assertArrayNotHasKey('差额=退款金额(金额对平)', $rules); $this->assertArrayNotHasKey('差额=优惠+冲减(金额对平)', $rules); $this->assertArrayNotHasKey('订单实付含已退款部分(金额对平)', $rules); $this->assertArrayNotHasKey('订单实付未减优惠和冲减(金额对平)', $rules); $this->assertArrayNotHasKey('订单实付含退款、优惠和冲减(金额对平)', $rules); $this->assertArrayNotHasKey('订单实付含种菜收入(金额对平)', $rules); $this->assertArrayNotHasKey('差额=小额尾差', $rules); } public function test_planting_income_does_not_create_a_new_difference_remark(): void { $this->assertSame('差额待核实', $this->remark([ 'platform' => '得物', 'income_amount' => 458.80, 'planting_amount' => 458.80, 'product_amount' => 220.00, 'paid_amount' => 120.80, 'difference' => 338.00, ])); } public function test_refund_difference_requires_the_refund_amount_to_reconcile(): void { $this->assertSame('订单实付含已退款部分', $this->remark([ 'platform' => '京东账单', 'store_name' => '京东-普通旗舰店', 'income_amount' => 100.00, 'refund_amount' => -19.00, 'product_amount' => 119.00, 'paid_amount' => 119.00, 'difference' => -19.00, ])); } public function test_discount_or_offset_difference_requires_the_amounts_to_reconcile(): void { $this->assertSame('订单实付未减优惠和冲减', $this->remark([ 'platform' => '得物', 'income_amount' => 100.00, 'discount_amount' => -10.00, 'offset_amount' => -29.00, 'product_amount' => 150.00, 'paid_amount' => 129.00, 'difference' => -39.00, ])); } public function test_refund_discount_combination_requires_all_amounts_to_reconcile(): void { $this->assertSame('订单实付含已退款部分', $this->remark([ 'platform' => '得物', 'income_amount' => 100.00, 'discount_amount' => -10.00, 'refund_amount' => -19.00, 'product_amount' => 129.00, 'paid_amount' => 129.00, 'difference' => -29.00, ])); } public function test_default_compensation_is_counted_once_as_a_separate_adjustment(): void { $this->assertSame('订单实付未减优惠和冲减', $this->remark([ 'platform' => '得物', 'income_amount' => 100.00, 'offset_amount' => -14.00, 'default_compensation_amount' => -25.00, 'product_amount' => 100.00, 'paid_amount' => 100.00, 'difference' => -39.00, ])); } public function test_refund_or_discount_cooccurrence_alone_stays_pending(): void { $this->assertSame('差额待核实', $this->remark([ 'platform' => '得物', 'income_amount' => 100.00, 'discount_amount' => -10.00, 'refund_amount' => -19.00, 'product_amount' => 150.00, 'paid_amount' => 129.00, 'difference' => -39.00, ])); $this->assertSame('差额待核实', $this->remark([ 'platform' => '得物', 'income_amount' => 99.50, 'product_amount' => 100.00, 'paid_amount' => 100.00, 'difference' => -0.50, ])); } }