feat(admin): 线索页补齐创建续费订单入口(require_subscription)

This commit is contained in:
萝卜
2026-03-15 08:16:31 +00:00
parent d28885db50
commit 2f05f6df47
2 changed files with 86 additions and 0 deletions

View File

@@ -48,6 +48,29 @@
return '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query($q);
};
// 从线索直达“创建续费订单”入口:本质是 require_subscription 治理链路。
// 线索自身通常没有订阅ID因此这里不直接传 site_subscription_id而是引导先去订阅管理选择订阅再返回。
$buildCreateRenewalOrderUrl = function (\App\Models\PlatformLead $l) use ($selfWithoutBack) {
$q = [];
if ((int) $l->plan_id > 0) {
$q['plan_id'] = (int) $l->plan_id;
}
$meta = is_array($l->meta) ? $l->meta : [];
$merchantId = (int) ($meta['merchant_id'] ?? 0);
if ($merchantId > 0) {
$q['merchant_id'] = $merchantId;
}
// require_subscription用于“续费必须先选订阅”的治理 UI 口径
$q['require_subscription'] = '1';
$q['lead_id'] = (int) $l->id;
$q['back'] = $selfWithoutBack;
return '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query($q);
};
@endphp
<div class="card mb-20">
@@ -155,6 +178,7 @@
<td>
<div class="actions">
<a class="btn btn-sm" href="{!! $buildCreatePlatformOrderUrl($l) !!}">创建订单</a>
<a class="btn btn-secondary btn-sm" href="{!! $buildCreateRenewalOrderUrl($l) !!}">创建续费订单</a>
@php
$viewOrdersUrl = '/admin/platform-orders?' . \Illuminate\Support\Arr::query([

View File

@@ -0,0 +1,62 @@
<?php
namespace Tests\Feature;
use App\Models\Plan;
use App\Models\PlatformLead;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformLeadIndexCreateRenewalOrderLinkTest 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_lead_index_should_include_create_renewal_order_link(): void
{
$this->loginAsPlatformAdmin();
$plan = Plan::query()->create([
'code' => 'lead_index_create_renewal_plan',
'name' => '线索页创建续费订单入口测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$lead = PlatformLead::query()->create([
'status' => 'new',
'name' => '张三',
'mobile' => '13800000000',
'email' => 'zs@example.com',
'company' => '测试公司',
'plan_id' => $plan->id,
'source' => 'test',
'meta' => [],
]);
$res = $this->get('/admin/platform-leads');
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString('创建续费订单', $html);
$this->assertStringContainsString('/admin/platform-orders/create?', $html);
$this->assertStringContainsString('require_subscription=1', $html);
$this->assertStringContainsString('lead_id=' . $lead->id, $html);
$this->assertStringContainsString('plan_id=' . $plan->id, $html);
$this->assertStringContainsString('back=' . urlencode('/admin/platform-leads'), $html);
}
}