feat(platform-orders): 新增退款轨迹筛选 refund_status(含UI/导出/批量透传/测试)

This commit is contained in:
萝卜
2026-03-10 23:48:28 +00:00
parent 429c84bfc2
commit f258aab657
3 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
<?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 AdminPlatformOrderRefundStatusFilterTest 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_by_refund_status_has_and_none(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'refund_status_filter_test',
'name' => '退款状态筛选测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
// 有退款:仅 refund_receipts
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_REFUND_HAS_0001',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'partially_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(),
'meta' => [
'refund_receipts' => [
['amount' => 1.00, 'refunded_at' => now()->toDateTimeString()],
],
],
]);
// 有退款refund_summary
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_REFUND_HAS_0002',
'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(),
'meta' => [
'refund_summary' => [
'total_amount' => 10.00,
'count' => 1,
],
],
]);
// 无退款:两者都没有
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_REFUND_NONE_0003',
'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' => [],
]);
$this->get('/admin/platform-orders?refund_status=has')
->assertOk()
->assertSee('PO_REFUND_HAS_0001')
->assertSee('PO_REFUND_HAS_0002')
->assertDontSee('PO_REFUND_NONE_0003');
$this->get('/admin/platform-orders?refund_status=none')
->assertOk()
->assertSee('PO_REFUND_NONE_0003')
->assertDontSee('PO_REFUND_HAS_0001')
->assertDontSee('PO_REFUND_HAS_0002');
}
}