feat(admin): 线索创建订单链接支持预填站点 merchant_id
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 从线索直达“创建平台订单”入口:预填 plan_id/remark,并带 back 回到当前线索列表(保留筛选)
|
// 从线索直达“创建平台订单”入口:预填 plan_id/remark,并带 back 回到当前线索列表(保留筛选)
|
||||||
|
// 备注:如果线索 meta 中包含 merchant_id,也会一并预填(用于“已存在站点,但需补单/续费”的场景)
|
||||||
$buildCreatePlatformOrderUrl = function (\App\Models\PlatformLead $l) use ($selfWithoutBack) {
|
$buildCreatePlatformOrderUrl = function (\App\Models\PlatformLead $l) use ($selfWithoutBack) {
|
||||||
$remarkParts = array_filter([
|
$remarkParts = array_filter([
|
||||||
'线索#' . $l->id,
|
'线索#' . $l->id,
|
||||||
@@ -33,6 +34,12 @@
|
|||||||
$q['plan_id'] = (int) $l->plan_id;
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
return '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query($q);
|
return '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query($q);
|
||||||
};
|
};
|
||||||
@endphp
|
@endphp
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?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 AdminPlatformLeadIndexCreateOrderLinkPrefillMerchantIdTest 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_create_order_link_should_prefill_merchant_id_when_lead_meta_has_merchant_id(): void
|
||||||
|
{
|
||||||
|
$this->loginAsPlatformAdmin();
|
||||||
|
|
||||||
|
$merchant = Merchant::query()->firstOrFail();
|
||||||
|
|
||||||
|
$plan = Plan::query()->create([
|
||||||
|
'code' => 'lead_order_plan_merchant',
|
||||||
|
'name' => '线索转订单预填站点测试套餐',
|
||||||
|
'billing_cycle' => 'monthly',
|
||||||
|
'price' => 10,
|
||||||
|
'list_price' => 10,
|
||||||
|
'status' => 'active',
|
||||||
|
'sort' => 10,
|
||||||
|
'published_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
PlatformLead::query()->create([
|
||||||
|
'name' => '李四',
|
||||||
|
'mobile' => '13900000000',
|
||||||
|
'email' => 'ls@example.com',
|
||||||
|
'company' => '示例公司2',
|
||||||
|
'source' => 'platform_plans',
|
||||||
|
'status' => 'new',
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'meta' => ['merchant_id' => $merchant->id],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$currentUrl = '/admin/platform-leads?' . Arr::query([
|
||||||
|
'status' => 'new',
|
||||||
|
'keyword' => '李',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$res = $this->get($currentUrl);
|
||||||
|
$res->assertOk();
|
||||||
|
|
||||||
|
$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 ((string) ($q['merchant_id'] ?? '') === (string) $merchant->id
|
||||||
|
&& (string) ($q['plan_id'] ?? '') === (string) $plan->id) {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertTrue($found, '未找到包含 merchant_id 预填的创建订单链接');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user