fix(platform): 平台订单创建页透传 lead_id 以维持线索联动

This commit is contained in:
萝卜
2026-03-14 04:17:14 +00:00
parent e2169d99a9
commit 19abd26dd9
3 changed files with 71 additions and 0 deletions

View File

@@ -40,6 +40,8 @@ class PlatformOrderController extends Controller
'remark' => (string) $request->query('remark', ''),
// back用于创建成功后回到来源页例如订阅详情
'back' => (string) $request->query('back', ''),
// 线索联动:用于从开通线索进入下单页,需透传到 form hidden input
'lead_id' => (int) $request->query('lead_id', 0),
];
// back 安全阀:必须为站内相对路径,并拒绝引号/尖括号。

View File

@@ -30,6 +30,8 @@
<input type="hidden" name="site_subscription_id" value="{{ old('site_subscription_id', $defaults['site_subscription_id'] ?? '') }}">
<input type="hidden" name="lead_id" value="{{ old('lead_id', $defaults['lead_id'] ?? '') }}">
@php
$backVal = (string) old('back', $defaults['back'] ?? '');
@endphp

View File

@@ -0,0 +1,67 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformLead;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlatformOrderCreateShouldKeepLeadIdTest 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_create_should_render_hidden_lead_id_input_when_present_in_query(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'lead_id_create_order_plan',
'name' => '下单页lead_id透传测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$lead = PlatformLead::query()->create([
'name' => 'lead_id线索',
'mobile' => '13800000005',
'email' => 'lead5@example.com',
'company' => 'lead_id公司',
'source' => 'test',
'status' => 'new',
'plan_id' => $plan->id,
'meta' => ['merchant_id' => $merchant->id],
]);
$url = '/admin/platform-orders/create?' . Arr::query([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'lead_id' => $lead->id,
'back' => '/admin/platform-leads',
]);
$res = $this->get($url);
$res->assertOk();
$res->assertSee('name="lead_id"', false);
$res->assertSee('value="' . $lead->id . '"', false);
}
}