平台订单:单笔对账明细CSV导出(支付回执+退款记录)

This commit is contained in:
萝卜
2026-03-13 20:47:12 +00:00
parent 9f89536933
commit 470f8fe2f5
4 changed files with 200 additions and 1 deletions

View File

@@ -0,0 +1,136 @@
<?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 AdminPlatformOrderExportLedgerTest 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_export_ledger_should_download_csv_with_bom_and_headers(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_export_ledger_plan',
'name' => '平台订单导出对账明细测试套餐',
'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_EXPORT_LEDGER_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [
'payment_receipts' => [
[
'type' => 'bank_transfer',
'channel' => 'offline',
'amount' => 10,
'paid_at' => now()->toDateTimeString(),
'note' => 'test-pay',
'created_at' => now()->toDateTimeString(),
'admin_id' => 1,
],
],
'refund_receipts' => [
[
'type' => 'refund',
'channel' => 'offline',
'amount' => 1,
'refunded_at' => now()->toDateTimeString(),
'note' => 'test-refund',
'created_at' => now()->toDateTimeString(),
'admin_id' => 1,
],
],
],
]);
$res = $this->get('/admin/platform-orders/' . $order->id . '/export-ledger');
$res->assertOk();
$content = $res->streamedContent();
// UTF-8 BOM
$this->assertStringStartsWith("\xEF\xBB\xBF", $content);
// 核心表头
$this->assertStringContainsString('record_type,channel,amount,biz_time,created_at,admin_id,note', $content);
// 至少包含一条 payment 与一条 refund 行
$this->assertStringContainsString('payment,offline,10', $content);
$this->assertStringContainsString('refund,offline,1', $content);
}
public function test_show_page_should_render_export_ledger_link(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_export_ledger_link_plan',
'name' => '平台订单详情导出对账明细链接测试套餐',
'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_EXPORT_LEDGER_LINK_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [],
]);
$res = $this->get('/admin/platform-orders/' . $order->id);
$res->assertOk();
$res->assertSee('/admin/platform-orders/' . $order->id . '/export-ledger', false);
$res->assertSee('导出对账明细CSV', false);
}
}