feat(platform): 线索可查看关联订单(platform_orders 按 lead_id 筛选)
This commit is contained in:
@@ -205,6 +205,8 @@ class PlatformOrderController extends Controller
|
||||
'refund_status' => trim((string) $request->query('refund_status', '')),
|
||||
// 退款数据不一致(可治理):基于 refund_summary.total_amount 与 paid_amount 对比
|
||||
'refund_inconsistent' => (string) $request->query('refund_inconsistent', ''),
|
||||
// 线索联动:用于从开通线索跳转查看关联订单
|
||||
'lead_id' => trim((string) $request->query('lead_id', '')),
|
||||
];
|
||||
|
||||
|
||||
@@ -1054,6 +1056,8 @@ class PlatformOrderController extends Controller
|
||||
'refund_status' => trim((string) $request->query('refund_status', '')),
|
||||
// 退款数据不一致(可治理):基于 refund_summary.total_amount 与 paid_amount 对比
|
||||
'refund_inconsistent' => (string) $request->query('refund_inconsistent', ''),
|
||||
// 线索联动:用于从开通线索跳转查看关联订单
|
||||
'lead_id' => trim((string) $request->query('lead_id', '')),
|
||||
];
|
||||
|
||||
|
||||
@@ -2067,6 +2071,20 @@ class PlatformOrderController extends Controller
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
->when(($filters['lead_id'] ?? '') !== '', function (Builder $builder) use ($filters) {
|
||||
// 线索联动:仅看指定线索关联的订单(meta.platform_lead_id = lead_id)
|
||||
$leadId = (int) ($filters['lead_id'] ?? 0);
|
||||
if ($leadId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$driver = $builder->getQuery()->getConnection()->getDriverName();
|
||||
if ($driver === 'sqlite') {
|
||||
$builder->whereRaw("JSON_EXTRACT(meta, '$.platform_lead_id') = ?", [$leadId]);
|
||||
} else {
|
||||
$builder->whereRaw("CAST(JSON_UNQUOTE(JSON_EXTRACT(meta, '$.platform_lead_id')) AS UNSIGNED) = ?", [$leadId]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,17 @@
|
||||
<td>{{ $l->source }}</td>
|
||||
<td>{{ optional($l->created_at)->format('Y-m-d H:i:s') }}</td>
|
||||
<td>
|
||||
<a class="btn btn-sm" href="{!! $buildCreatePlatformOrderUrl($l) !!}">创建订单</a>
|
||||
<div class="actions">
|
||||
<a class="btn btn-sm" href="{!! $buildCreatePlatformOrderUrl($l) !!}">创建订单</a>
|
||||
|
||||
@php
|
||||
$viewOrdersUrl = '/admin/platform-orders?' . \Illuminate\Support\Arr::query([
|
||||
'lead_id' => $l->id,
|
||||
'back' => $selfWithoutBack,
|
||||
]);
|
||||
@endphp
|
||||
<a class="btn-secondary btn-sm" href="{!! $viewOrdersUrl !!}">查看订单</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
|
||||
110
tests/Feature/AdminPlatformLeadIndexViewOrdersLinkTest.php
Normal file
110
tests/Feature/AdminPlatformLeadIndexViewOrdersLinkTest.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Merchant;
|
||||
use App\Models\Plan;
|
||||
use App\Models\PlatformLead;
|
||||
use App\Models\PlatformOrder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Arr;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminPlatformLeadIndexViewOrdersLinkTest 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_lead_index_should_render_view_orders_link_and_platform_orders_can_filter_by_lead_id(): void
|
||||
{
|
||||
$this->loginAsPlatformAdmin();
|
||||
|
||||
$merchant = Merchant::query()->firstOrFail();
|
||||
|
||||
$plan = Plan::query()->create([
|
||||
'code' => 'lead_view_orders_plan',
|
||||
'name' => '线索查看订单测试套餐',
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 10,
|
||||
'list_price' => 10,
|
||||
'status' => 'active',
|
||||
'sort' => 10,
|
||||
'published_at' => now(),
|
||||
]);
|
||||
|
||||
$lead = PlatformLead::query()->create([
|
||||
'name' => '查看订单线索',
|
||||
'mobile' => '13800000004',
|
||||
'email' => 'lead4@example.com',
|
||||
'company' => '查看订单公司',
|
||||
'source' => 'test',
|
||||
'status' => 'new',
|
||||
'plan_id' => $plan->id,
|
||||
'meta' => ['from' => 'test'],
|
||||
]);
|
||||
|
||||
// 关联订单(通过 meta.platform_lead_id)
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'site_subscription_id' => null,
|
||||
'created_by_admin_id' => 1,
|
||||
'order_no' => 'PO_LEAD_VIEW_0001',
|
||||
'order_type' => 'new_purchase',
|
||||
'status' => 'pending',
|
||||
'payment_status' => 'unpaid',
|
||||
'payment_channel' => null,
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'list_amount' => 10,
|
||||
'discount_amount' => 0,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 0,
|
||||
'placed_at' => now(),
|
||||
'plan_snapshot' => ['plan_id' => $plan->id],
|
||||
'meta' => ['platform_lead_id' => $lead->id],
|
||||
'remark' => 'from lead',
|
||||
]);
|
||||
|
||||
$res = $this->get('/admin/platform-leads?' . Arr::query(['status' => 'new']));
|
||||
$res->assertOk();
|
||||
|
||||
$selfWithoutBack = '/admin/platform-leads?' . Arr::query(['status' => 'new']);
|
||||
|
||||
$html = $res->getContent();
|
||||
preg_match_all('/href="([^"]+)"/', $html, $matches);
|
||||
$hrefs = $matches[1] ?? [];
|
||||
|
||||
$viewUrls = array_values(array_filter($hrefs, fn ($u) => str_contains($u, '/admin/platform-orders?')));
|
||||
$this->assertNotEmpty($viewUrls, '未找到查看订单链接');
|
||||
|
||||
$found = false;
|
||||
foreach ($viewUrls as $u) {
|
||||
$parts = parse_url($u);
|
||||
parse_str($parts['query'] ?? '', $q);
|
||||
|
||||
if ((string) ($q['lead_id'] ?? '') === (string) $lead->id
|
||||
&& (string) ($q['back'] ?? '') === $selfWithoutBack) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertTrue($found, '未找到包含 lead_id/back 的查看订单链接');
|
||||
|
||||
// 平台订单列表支持按 lead_id 过滤,并能看到对应订单号
|
||||
$ordersPage = $this->get('/admin/platform-orders?' . Arr::query(['lead_id' => $lead->id]));
|
||||
$ordersPage->assertOk();
|
||||
$ordersPage->assertSee('PO_LEAD_VIEW_0001');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user