feat(round-15): 跨境多币种发票税额/线索自动化阶段跃升/名片私密访问锁/芯片激光标刻排版 (P1/P2功能达成)
这个提交包含在:
@@ -0,0 +1,122 @@
|
||||
import { Provide } from '@midwayjs/core';
|
||||
import { BaseService } from '@cool-midway/core';
|
||||
|
||||
export type LeadStage = 'new' | 'contacted' | 'qualified' | 'proposal' | 'closed_won' | 'closed_lost';
|
||||
|
||||
export interface LeadBehaviorTrigger {
|
||||
action: 'PAGE_VIEW' | 'AI_CHAT_INTERACT' | 'FORM_SUBMITTED' | 'MEETING_SCHEDULED' | 'PAYMENT_SUCCESS';
|
||||
staySeconds?: number;
|
||||
radarScore?: number;
|
||||
metadata?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface PromotionEvaluation {
|
||||
promoted: boolean;
|
||||
targetStage: LeadStage;
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface StageTransitionResult {
|
||||
leadId: number;
|
||||
previousStage: LeadStage;
|
||||
currentStage: LeadStage;
|
||||
changed: boolean;
|
||||
historyLog: string;
|
||||
}
|
||||
|
||||
const STAGE_RANKS: Record<LeadStage, number> = {
|
||||
new: 1,
|
||||
contacted: 2,
|
||||
qualified: 3,
|
||||
proposal: 4,
|
||||
closed_won: 5,
|
||||
closed_lost: 0,
|
||||
};
|
||||
|
||||
/**
|
||||
* 判定线索行为是否满足自动推进条件
|
||||
*/
|
||||
export function evaluateLeadStagePromotion(
|
||||
currentStage: LeadStage,
|
||||
trigger: LeadBehaviorTrigger
|
||||
): PromotionEvaluation {
|
||||
const currentRank = STAGE_RANKS[currentStage] || 0;
|
||||
|
||||
// 1. 支付成功直接达成 closed_won
|
||||
if (trigger.action === 'PAYMENT_SUCCESS') {
|
||||
return {
|
||||
promoted: currentStage !== 'closed_won',
|
||||
targetStage: 'closed_won',
|
||||
reason: '客户完成国际订单支付,自动转入成交状态',
|
||||
};
|
||||
}
|
||||
|
||||
// 2. 成功预约会议直接推进到 proposal
|
||||
if (trigger.action === 'MEETING_SCHEDULED') {
|
||||
if (currentRank < STAGE_RANKS.proposal) {
|
||||
return {
|
||||
promoted: true,
|
||||
targetStage: 'proposal',
|
||||
reason: '客户已完成日程预约,自动流转至方案洽谈阶段',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 留资提交或雷达评分 >= 80 推进到 qualified
|
||||
if (trigger.action === 'FORM_SUBMITTED' || (trigger.radarScore != null && trigger.radarScore >= 80)) {
|
||||
if (currentRank < STAGE_RANKS.qualified) {
|
||||
return {
|
||||
promoted: true,
|
||||
targetStage: 'qualified',
|
||||
reason: '客户提交名片/留资表单或意向评分达到高潜线索阈值',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 4. AI 对话交互或停留超过 120 秒推进到 contacted
|
||||
if (
|
||||
trigger.action === 'AI_CHAT_INTERACT' ||
|
||||
(trigger.staySeconds != null && trigger.staySeconds >= 120)
|
||||
) {
|
||||
if (currentRank < STAGE_RANKS.contacted) {
|
||||
return {
|
||||
promoted: true,
|
||||
targetStage: 'contacted',
|
||||
reason: '客户与 AI 数字人顾问深度交互或停留超过 120 秒,已成功建联',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 未满足晋级条件或已有更高阶段,保持原阶段
|
||||
return {
|
||||
promoted: false,
|
||||
targetStage: currentStage,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 出海潜客线索自动化阶段流转服务
|
||||
*/
|
||||
@Provide()
|
||||
export class LeadStageAutomationService extends BaseService {
|
||||
async processBehaviorEvent(
|
||||
lead: { id: number; stage: LeadStage; name: string },
|
||||
trigger: LeadBehaviorTrigger
|
||||
): Promise<StageTransitionResult> {
|
||||
const evalResult = evaluateLeadStagePromotion(lead.stage, trigger);
|
||||
|
||||
const changed = evalResult.promoted;
|
||||
const currentStage = evalResult.targetStage;
|
||||
const historyLog = changed
|
||||
? `[${new Date().toISOString()}] 阶段由 ${lead.stage} 自动跃升为 ${currentStage}: ${evalResult.reason}`
|
||||
: `[${new Date().toISOString()}] 阶段保持 ${currentStage}`;
|
||||
|
||||
return {
|
||||
leadId: lead.id,
|
||||
previousStage: lead.stage,
|
||||
currentStage,
|
||||
changed,
|
||||
historyLog,
|
||||
};
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户