feat(admin): 线索列表增加创建平台订单入口 + 护栏

This commit is contained in:
萝卜
2026-03-14 03:30:51 +00:00
parent e9fba11785
commit 23ff6d7d5d
2 changed files with 132 additions and 2 deletions

View File

@@ -4,6 +4,39 @@
@section('page_title', '开通线索')
@section('content')
@php
// back 参数用于“返回上一页(保留上下文)”,但 back 本身不应再包含 back避免无限嵌套导致 URL 膨胀)
$currentQuery = request()->query();
unset($currentQuery['back']);
$selfWithoutBack = '/' . ltrim(request()->path(), '/');
if (count($currentQuery) > 0) {
$selfWithoutBack .= '?' . \Illuminate\Support\Arr::query($currentQuery);
}
// 从线索直达“创建平台订单”入口:预填 plan_id/remark并带 back 回到当前线索列表(保留筛选)
$buildCreatePlatformOrderUrl = function (\App\Models\PlatformLead $l) use ($selfWithoutBack) {
$remarkParts = array_filter([
'线索#' . $l->id,
$l->name,
$l->mobile,
$l->company,
$l->email,
], fn ($v) => (string) $v !== '');
$q = [
'order_type' => 'new_purchase',
'back' => $selfWithoutBack,
'remark' => mb_substr(implode(' / ', $remarkParts), 0, 180),
];
if ((int) $l->plan_id > 0) {
$q['plan_id'] = (int) $l->plan_id;
}
return '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query($q);
};
@endphp
<div class="card mb-20">
<p class="muted muted-tight">对外平台(/platform收集的开通意向线索用于前期 A站点开通型人工运营承接。</p>
<p class="muted">后续会在此处逐步接入:一键生成站点/订阅/平台订单、跟进记录、转化漏斗与治理提示。</p>
@@ -27,7 +60,7 @@
<div class="card">
<h3>线索列表</h3>
<div class="muted mb-10">当前阶段仅提供查询与筛选;后续补“状态流转/转化为站点/生成订单”等操作闭环</div>
<div class="muted mb-10">当前阶段仅提供查询与筛选;已补“从线索创建订单”入口,先把收费闭环跑起来</div>
<table class="table">
<thead>
@@ -41,6 +74,7 @@
<th>套餐ID</th>
<th>来源</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
@@ -55,10 +89,13 @@
<td>{{ $l->plan_id ?: '-' }}</td>
<td>{{ $l->source }}</td>
<td>{{ optional($l->created_at)->format('Y-m-d H:i:s') }}</td>
<td>
<a class="muted" href="{!! $buildCreatePlatformOrderUrl($l) !!}">创建订单</a>
</td>
</tr>
@empty
<tr>
<td colspan="9" class="muted">暂无线索</td>
<td colspan="10" class="muted">暂无线索</td>
</tr>
@endforelse
</tbody>

View File

@@ -0,0 +1,93 @@
<?php
namespace Tests\Feature;
use App\Models\Plan;
use App\Models\PlatformLead;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlatformLeadIndexCreateOrderLinkTest 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_index_should_render_create_order_link_with_safe_back_and_prefills(): void
{
$this->loginAsPlatformAdmin();
$plan = Plan::query()->create([
'code' => 'lead_order_plan',
'name' => '线索转订单测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$lead = PlatformLead::query()->create([
'name' => '张三',
'mobile' => '13800000000',
'email' => 'zs@example.com',
'company' => '示例公司',
'source' => 'platform_plans',
'status' => 'new',
'plan_id' => $plan->id,
'meta' => ['from' => 'test'],
]);
$currentUrl = '/admin/platform-leads?' . Arr::query([
'status' => 'new',
'keyword' => '张',
]);
$res = $this->get($currentUrl);
$res->assertOk();
$selfWithoutBack = '/admin/platform-leads?' . Arr::query([
'status' => 'new',
'keyword' => '张',
]);
$html = $res->getContent();
preg_match_all('/href="([^"]+)"/', $html, $matches);
$hrefs = $matches[1] ?? [];
$createUrls = array_values(array_filter($hrefs, fn ($u) => str_contains($u, '/admin/platform-orders/create?')));
$this->assertNotEmpty($createUrls, '未找到从线索创建订单的链接');
$found = false;
foreach ($createUrls as $u) {
$parts = parse_url($u);
parse_str($parts['query'] ?? '', $q);
if (($q['order_type'] ?? '') === 'new_purchase'
&& (string) ($q['plan_id'] ?? '') === (string) $plan->id
&& (string) ($q['back'] ?? '') === $selfWithoutBack
&& str_contains((string) ($q['remark'] ?? ''), '线索#' . $lead->id)
&& str_contains((string) ($q['remark'] ?? ''), '张三')) {
$found = true;
break;
}
}
$this->assertTrue($found, '未找到包含 plan_id/back/remark 预填的创建订单链接');
$res->assertSee('创建订单', false);
// 防 back 嵌套URL 不应出现 back%3D
$res->assertDontSee('back%3D', false);
}
}