diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index a6b16fe..8e82da1 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1081,6 +1081,7 @@ class PlatformOrderController extends Controller $headers = [ 'ID', '订单号', + '线索ID', '站点', '套餐', '订单类型', @@ -1149,6 +1150,7 @@ class PlatformOrderController extends Controller $row = [ $order->id, $order->order_no, + (int) (data_get($order->meta, 'platform_lead_id') ?? 0), $order->merchant?->name ?? '', $order->plan_name ?: ($order->plan?->name ?? ''), $order->order_type, diff --git a/tests/Feature/AdminPlatformOrderExportTest.php b/tests/Feature/AdminPlatformOrderExportTest.php index 96d0cc9..c553d18 100644 --- a/tests/Feature/AdminPlatformOrderExportTest.php +++ b/tests/Feature/AdminPlatformOrderExportTest.php @@ -211,5 +211,57 @@ class AdminPlatformOrderExportTest extends TestCase $this->get('/admin/platform-orders/export') ->assertRedirect('/admin/login'); - } +} + + public function test_platform_admin_can_export_platform_orders_csv_with_lead_id_column(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'export_order_lead_id_test', + 'name' => '导出线索ID测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $lead = \App\Models\PlatformLead::query()->create([ + 'name' => 'Lead Export', + 'mobile' => '13800000999', + 'company' => 'Export Inc', + 'status' => 'new', + ]); + + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_EXPORT_LEAD_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' => [ + 'platform_lead_id' => $lead->id, + ], + ]); + + $res = $this->get('/admin/platform-orders/export?download=1&lead_id=' . $lead->id); + $res->assertOk(); + + $content = $res->streamedContent(); + $this->assertStringContainsString('线索ID', $content); + $this->assertStringContainsString('PO_EXPORT_LEAD_0001', $content); + $this->assertStringContainsString((string) $lead->id, $content); + } + }