From b5688d88669c52f8cd97d4b760996dbdb8625a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sat, 14 Mar 2026 03:36:38 +0000 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E7=BA=BF=E7=B4=A2=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E8=AE=A2=E5=8D=95=E9=93=BE=E6=8E=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=A2=84=E5=A1=AB=E7=AB=99=E7=82=B9=20merchant=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/platform_leads/index.blade.php | 7 ++ ...exCreateOrderLinkPrefillMerchantIdTest.php | 84 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/Feature/AdminPlatformLeadIndexCreateOrderLinkPrefillMerchantIdTest.php diff --git a/resources/views/admin/platform_leads/index.blade.php b/resources/views/admin/platform_leads/index.blade.php index 5dbd65a..e15977c 100644 --- a/resources/views/admin/platform_leads/index.blade.php +++ b/resources/views/admin/platform_leads/index.blade.php @@ -14,6 +14,7 @@ } // 从线索直达“创建平台订单”入口:预填 plan_id/remark,并带 back 回到当前线索列表(保留筛选) + // 备注:如果线索 meta 中包含 merchant_id,也会一并预填(用于“已存在站点,但需补单/续费”的场景) $buildCreatePlatformOrderUrl = function (\App\Models\PlatformLead $l) use ($selfWithoutBack) { $remarkParts = array_filter([ '线索#' . $l->id, @@ -33,6 +34,12 @@ $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); }; @endphp diff --git a/tests/Feature/AdminPlatformLeadIndexCreateOrderLinkPrefillMerchantIdTest.php b/tests/Feature/AdminPlatformLeadIndexCreateOrderLinkPrefillMerchantIdTest.php new file mode 100644 index 0000000..82eac0a --- /dev/null +++ b/tests/Feature/AdminPlatformLeadIndexCreateOrderLinkPrefillMerchantIdTest.php @@ -0,0 +1,84 @@ +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 预填的创建订单链接'); + } +}