平台订单:新增退款不一致 refund_inconsistent 筛选与摘要卡

This commit is contained in:
萝卜
2026-03-11 04:29:52 +00:00
parent 9de9a44318
commit 35ab780f8c
3 changed files with 205 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
<?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 AdminPlatformOrderRefundInconsistentFilterTest 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_platform_orders_page_can_filter_refund_inconsistent(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'refund_inconsistent_test',
'name' => '退款不一致筛选测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// 1) 不一致:状态=refunded但退款总额不足
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_REFUND_INCONSISTENT_0001',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'refunded',
'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(),
'refunded_at' => now(),
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 9.98,
'last_at' => now()->toDateTimeString(),
'last_amount' => 9.99,
'last_channel' => 'bank',
],
],
]);
// 2) 不一致:状态!=refunded但退款总额已达到/超过已付金额
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_REFUND_INCONSISTENT_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' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'last_at' => now()->toDateTimeString(),
'last_amount' => 10.00,
'last_channel' => 'bank',
],
],
]);
// 3) 一致refunded 且退款总额=已付金额
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_REFUND_CONSISTENT_0003',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'refunded',
'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(),
'refunded_at' => now(),
'meta' => [
'refund_summary' => [
'count' => 1,
'total_amount' => 10.00,
'last_at' => now()->toDateTimeString(),
'last_amount' => 10.00,
'last_channel' => 'bank',
],
],
]);
$this->get('/admin/platform-orders?refund_inconsistent=1')
->assertOk()
->assertSee('PO_REFUND_INCONSISTENT_0001')
->assertSee('PO_REFUND_INCONSISTENT_0002')
->assertDontSee('PO_REFUND_CONSISTENT_0003');
}
}