feat(platform): 从开通线索创建订单时自动回写线索为已转化
This commit is contained in:
@@ -82,6 +82,8 @@ class PlatformOrderController extends Controller
|
||||
'payment_channel' => ['nullable', 'string', 'max:30'],
|
||||
'remark' => ['nullable', 'string', 'max:2000'],
|
||||
'back' => ['nullable', 'string', 'max:2000'],
|
||||
// 可选:从开通线索进入下单(用于轻量闭环联动)
|
||||
'lead_id' => ['nullable', 'integer', 'exists:platform_leads,id'],
|
||||
]);
|
||||
|
||||
$plan = Plan::query()->findOrFail((int) $data['plan_id']);
|
||||
@@ -131,10 +133,23 @@ class PlatformOrderController extends Controller
|
||||
],
|
||||
'meta' => [
|
||||
'created_from' => 'manual_form',
|
||||
// 轻量联动:从开通线索创建订单时记录 lead_id(用于后续转化漏斗与追溯)
|
||||
'platform_lead_id' => (int) ($data['lead_id'] ?? 0) ?: null,
|
||||
],
|
||||
'remark' => $data['remark'] ?? null,
|
||||
]);
|
||||
|
||||
// 轻量闭环:从线索创建订单后,自动把线索标记为 converted。
|
||||
// 注意:只做“前进”流转,避免误把已关闭/已确认需求的线索回写。
|
||||
$leadId = (int) ($data['lead_id'] ?? 0);
|
||||
if ($leadId > 0) {
|
||||
$lead = \App\Models\PlatformLead::query()->find($leadId);
|
||||
if ($lead && !in_array((string) $lead->status, ['converted', 'closed'], true)) {
|
||||
$lead->status = 'converted';
|
||||
$lead->save();
|
||||
}
|
||||
}
|
||||
|
||||
$back = (string) ($data['back'] ?? '');
|
||||
// back 需为站内相对路径,并拒绝引号/尖括号,避免在后续页面以 `{!! !!}` 原样输出时引入 XSS 风险。
|
||||
$safeBack = (str_starts_with($back, '/')
|
||||
|
||||
Reference in New Issue
Block a user