feat(platform-orders): 对账不一致筛选支持回退汇总 payment_receipts

This commit is contained in:
萝卜
2026-03-10 22:38:26 +00:00
parent 83c20ccae5
commit 4d41313f8f
2 changed files with 114 additions and 5 deletions

View File

@@ -0,0 +1,108 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderReconcileMismatchFallbackToReceiptsTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_reconcile_mismatch_filter_falls_back_to_payment_receipts_when_no_payment_summary(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'reconcile_mismatch_receipts_fallback',
'name' => '对账不一致回退回执汇总测试',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// 不一致paid_amount=10但 payment_receipts 合计=9.99(且没有 payment_summary
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_RECON_FALLBACK_MISMATCH_0001',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'paid_at' => now(),
'activated_at' => now(),
'meta' => [
'payment_receipts' => [
[
'type' => 'bank_transfer',
'channel' => 'bank',
'amount' => 9.99,
'paid_at' => now()->toDateTimeString(),
'created_at' => now()->toDateTimeString(),
'admin_id' => 1,
],
],
],
]);
// 一致paid_amount=10payment_receipts 合计=10且没有 payment_summary
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_RECON_FALLBACK_MATCH_0002',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'paid_at' => now(),
'activated_at' => now(),
'meta' => [
'payment_receipts' => [
[
'type' => 'bank_transfer',
'channel' => 'bank',
'amount' => 10.00,
'paid_at' => now()->toDateTimeString(),
'created_at' => now()->toDateTimeString(),
'admin_id' => 1,
],
],
],
]);
$this->get('/admin/platform-orders?reconcile_mismatch=1')
->assertOk()
->assertSee('PO_RECON_FALLBACK_MISMATCH_0001')
->assertDontSee('PO_RECON_FALLBACK_MATCH_0002');
}
}