feat: add PlatformOrder isReconcileMismatch and reuse in subscription summary

This commit is contained in:
萝卜
2026-03-11 06:57:25 +00:00
parent 5597a16ccc
commit a1ae7caf88
3 changed files with 110 additions and 4 deletions

View File

@@ -0,0 +1,100 @@
<?php
namespace Tests\Unit;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PlatformOrderReconcileMismatchTest extends TestCase
{
use RefreshDatabase;
public function test_is_reconcile_mismatch_returns_true_when_receipt_total_differs_from_paid_amount(): void
{
$merchant = Merchant::query()->create([
'name' => '单测站点_reconcile',
'slug' => 'unit-test-merchant-reconcile',
'status' => 'active',
]);
$plan = Plan::query()->create([
'code' => 'unit_test_plan_reconcile_mismatch',
'name' => '单测套餐_reconcile',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_UNIT_RECONCILE_MISMATCH_0001',
'order_type' => 'subscription',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => 'Unit Test Plan',
'billing_cycle' => 'monthly',
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'meta' => [
'payment_summary' => [
'total_amount' => 9.99,
],
],
]);
$this->assertTrue($order->isReconcileMismatch());
}
public function test_is_reconcile_mismatch_returns_false_when_receipt_total_equals_paid_amount(): void
{
$merchant = Merchant::query()->create([
'name' => '单测站点_reconcile_2',
'slug' => 'unit-test-merchant-reconcile-2',
'status' => 'active',
]);
$plan = Plan::query()->create([
'code' => 'unit_test_plan_reconcile_match',
'name' => '单测套餐_reconcile_2',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_UNIT_RECONCILE_MATCH_0001',
'order_type' => 'subscription',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => 'Unit Test Plan',
'billing_cycle' => 'monthly',
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'meta' => [
'payment_summary' => [
'total_amount' => 10.00,
],
],
]);
$this->assertFalse($order->isReconcileMismatch());
}
}