268 lines
10 KiB
PHP
268 lines
10 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use App\Http\Controllers\Business\Pages;
|
|
use Illuminate\Support\Facades\DB;
|
|
use ReflectionMethod;
|
|
use Tests\TestCase;
|
|
|
|
class PerformanceDifferenceRemarkTest extends TestCase
|
|
{
|
|
private function remarkLabels(): array
|
|
{
|
|
return (new ReflectionMethod(Pages::class, 'receiptDifferenceRemarkLabels'))->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,
|
|
'cross_month_balanced' => 0,
|
|
'planting_amount' => null,
|
|
'remark' => null,
|
|
], $attributes);
|
|
|
|
return (new ReflectionMethod(Pages::class, 'receiptDifferenceRemark'))->invoke(null, $row);
|
|
}
|
|
|
|
private function comparablePaid(array $attributes): float
|
|
{
|
|
$row = (object) array_merge([
|
|
'income_amount' => 0,
|
|
'discount_amount' => 0,
|
|
'offset_amount' => 0,
|
|
'default_compensation_amount' => 0,
|
|
'paid_amount' => 0,
|
|
'remark' => null,
|
|
], $attributes);
|
|
|
|
return (new ReflectionMethod(Pages::class, 'receiptComparablePaidAmount'))->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_cross_month_balanced_rule_is_first_and_only_marks_reconciled_rows(): void
|
|
{
|
|
$rules = $this->baseRules();
|
|
$label = '差额=跨月收款(合并已对平)';
|
|
|
|
$this->assertSame($label, array_key_first($rules));
|
|
$this->assertSame('cross_month_balanced = 1', $rules[$label]);
|
|
$this->assertSame($label, $this->remark([
|
|
'platform' => '淘系支付宝',
|
|
'income_amount' => 2713.20,
|
|
'paid_amount' => 3488.40,
|
|
'difference' => -775.20,
|
|
'cross_month_balanced' => 1,
|
|
]));
|
|
$this->assertSame('差额待核实', $this->remark([
|
|
'platform' => '淘系支付宝',
|
|
'income_amount' => 2713.20,
|
|
'paid_amount' => 3488.40,
|
|
'difference' => -775.20,
|
|
'cross_month_balanced' => 0,
|
|
]));
|
|
}
|
|
|
|
public function test_cross_month_filters_use_direct_columns_without_recomputing_reason_case(): void
|
|
{
|
|
$controller = app(Pages::class);
|
|
$query = DB::connection('business_mirror')->table('store_receipt_order_match_rows');
|
|
|
|
$remarkFilter = new ReflectionMethod(Pages::class, 'applyReceiptRemarkFilter');
|
|
$remarkFilter->setAccessible(true);
|
|
$remarkFilter->invoke($controller, $query, ['差额=跨月收款(合并已对平)']);
|
|
|
|
$this->assertStringContainsString('cross_month_balanced', $query->toSql());
|
|
$this->assertStringNotContainsString('CASE WHEN', $query->toSql());
|
|
|
|
$differenceFilter = new ReflectionMethod(Pages::class, 'applyReceiptDifferenceStateFilter');
|
|
$differenceFilter->setAccessible(true);
|
|
$differenceFilter->invoke($controller, $query, ['有差额'], true);
|
|
|
|
$this->assertStringNotContainsString('CASE WHEN', $query->toSql());
|
|
}
|
|
|
|
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_basis_matched_rows_display_the_amount_used_for_comparison(): void
|
|
{
|
|
$this->assertSame(10.0, $this->comparablePaid([
|
|
'income_amount' => 10.00,
|
|
'paid_amount' => 13079.80,
|
|
'remark' => '订单实付按应付/已付核对',
|
|
]));
|
|
$this->assertSame(90.0, $this->comparablePaid([
|
|
'income_amount' => 100.00,
|
|
'discount_amount' => -10.00,
|
|
'paid_amount' => 150.00,
|
|
'remark' => '订单实付按卖家实收核对',
|
|
]));
|
|
$this->assertSame(123.45, $this->comparablePaid([
|
|
'income_amount' => 100.00,
|
|
'paid_amount' => 123.45,
|
|
'remark' => null,
|
|
]));
|
|
}
|
|
|
|
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,
|
|
]));
|
|
}
|
|
}
|