Skip to content

企业级 CRM 自动化系统 - 客户管理流程实战

客户关系管理(CRM)是企业的核心业务流程之一。本文将展示如何使用 n8n 构建一个完整的 CRM 自动化系统,涵盖客户获取、培育、转化和维护的全流程。

系统架构设计

整体架构

mermaid
graph TB
    A[潜在客户获取] --> B[客户信息验证]
    B --> C[客户分级评分]
    C --> D[自动分配销售]
    D --> E[客户培育流程]
    E --> F[销售跟进提醒]
    F --> G[成交后服务]
    G --> H[客户满意度调查]
    H --> I[续约提醒]

数据模型设计

javascript
// 客户数据模型
const customerSchema = {
  id: 'string',
  personalInfo: {
    name: 'string',
    email: 'string',
    phone: 'string',
    company: 'string',
    position: 'string'
  },
  source: 'string', // 来源渠道
  score: 'number',  // 客户评分
  stage: 'string',  // 销售阶段
  assignedSales: 'string', // 分配的销售
  tags: ['string'], // 标签
  interactions: [{
    type: 'string',
    date: 'date',
    content: 'string',
    result: 'string'
  }],
  createdAt: 'date',
  updatedAt: 'date'
};

客户获取自动化

多渠道客户获取

javascript
// 网站表单提交处理
async function processWebFormSubmission(formData) {
  // 数据验证和清洗
  const cleanedData = {
    name: formData.name?.trim(),
    email: formData.email?.toLowerCase().trim(),
    phone: formData.phone?.replace(/\D/g, ''),
    company: formData.company?.trim(),
    source: 'website_form',
    submittedAt: new Date().toISOString()
  };
  
  // 邮箱验证
  const emailValidation = await validateEmail(cleanedData.email);
  if (!emailValidation.isValid) {
    return { success: false, error: 'Invalid email address' };
  }
  
  // 重复检查
  const existingCustomer = await checkExistingCustomer(cleanedData.email);
  if (existingCustomer) {
    await updateCustomerInteraction(existingCustomer.id, {
      type: 'form_submission',
      date: new Date(),
      content: 'Repeated form submission',
      source: 'website'
    });
    return { success: true, action: 'updated_existing' };
  }
  
  // 创建新客户
  const customer = await createNewCustomer(cleanedData);
  
  // 触发欢迎邮件
  await triggerWelcomeEmail(customer);
  
  // 客户评分
  const score = await calculateCustomerScore(customer);
  await updateCustomerScore(customer.id, score);
  
  return { success: true, action: 'created_new', customer };
}

// 社交媒体监控
async function monitorSocialMediaMentions() {
  const mentions = await searchSocialMentions('@yourcompany OR "your company"');
  
  for (const mention of mentions) {
    const sentiment = analyzeSentiment(mention.text);
    
    if (sentiment.score > 0.5) { // 正面提及
      const contact = await extractContactInfo(mention);
      if (contact.email || contact.profile) {
        await createLeadFromSocialMention({
          ...contact,
          source: 'social_media',
          platform: mention.platform,
          sentiment: sentiment,
          originalPost: mention.text
        });
      }
    }
  }
}

客户信息丰富化

javascript
// 客户信息丰富化
async function enrichCustomerData(customer) {
  const enrichedData = { ...customer };
  
  // 公司信息查询
  if (customer.company) {
    const companyInfo = await lookupCompanyInfo(customer.company);
    enrichedData.companyDetails = {
      industry: companyInfo.industry,
      size: companyInfo.employeeCount,
      revenue: companyInfo.annualRevenue,
      website: companyInfo.website
    };
  }
  
  // 社交媒体档案
  if (customer.email) {
    const socialProfiles = await findSocialProfiles(customer.email);
    enrichedData.socialProfiles = socialProfiles;
  }
  
  // 技术栈分析(针对技术公司)
  if (customer.companyDetails?.website) {
    const techStack = await analyzeTechStack(customer.companyDetails.website);
    enrichedData.techStack = techStack;
  }
  
  return enrichedData;
}

// 客户评分算法
function calculateCustomerScore(customer) {
  let score = 0;
  
  // 公司规模评分
  if (customer.companyDetails?.size) {
    if (customer.companyDetails.size > 1000) score += 30;
    else if (customer.companyDetails.size > 100) score += 20;
    else if (customer.companyDetails.size > 10) score += 10;
  }
  
  // 行业评分
  const highValueIndustries = ['technology', 'finance', 'healthcare'];
  if (highValueIndustries.includes(customer.companyDetails?.industry)) {
    score += 20;
  }
  
  // 职位评分
  const decisionMakerTitles = ['ceo', 'cto', 'director', 'manager', 'head'];
  const position = customer.position?.toLowerCase() || '';
  if (decisionMakerTitles.some(title => position.includes(title))) {
    score += 25;
  }
  
  // 互动评分
  const recentInteractions = customer.interactions?.filter(
    i => new Date(i.date) > new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
  ) || [];
  score += Math.min(recentInteractions.length * 5, 25);
  
  return Math.min(score, 100);
}

销售分配自动化

智能销售分配

javascript
// 销售团队管理
class SalesTeamManager {
  constructor() {
    this.salesReps = [];
    this.loadSalesTeam();
  }
  
  async loadSalesTeam() {
    this.salesReps = await getSalesTeamData();
  }
  
  assignCustomerToSales(customer) {
    // 基于地理位置分配
    const geographicMatch = this.findGeographicMatch(customer);
    if (geographicMatch) return geographicMatch;
    
    // 基于行业专长分配
    const industryMatch = this.findIndustryExpert(customer);
    if (industryMatch) return industryMatch;
    
    // 基于工作负载平衡分配
    return this.findLeastBusySalesRep();
  }
  
  findGeographicMatch(customer) {
    return this.salesReps.find(rep => 
      rep.territories.includes(customer.location?.country) ||
      rep.territories.includes(customer.location?.region)
    );
  }
  
  findIndustryExpert(customer) {
    if (!customer.companyDetails?.industry) return null;
    
    return this.salesReps.find(rep =>
      rep.specialties.includes(customer.companyDetails.industry)
    );
  }
  
  findLeastBusySalesRep() {
    return this.salesReps.reduce((least, current) => 
      current.activeLeads < least.activeLeads ? current : least
    );
  }
}

// 分配通知
async function notifySalesAssignment(customer, salesRep) {
  // 发送邮件通知
  await sendEmail({
    to: salesRep.email,
    subject: `新客户分配:${customer.name} - ${customer.company}`,
    template: 'sales_assignment',
    data: {
      salesRep: salesRep.name,
      customer: customer,
      score: customer.score,
      nextActions: generateNextActions(customer)
    }
  });
  
  // Slack 通知
  await sendSlackMessage({
    channel: salesRep.slackChannel,
    text: `🎯 新客户分配`,
    attachments: [{
      color: customer.score > 70 ? 'good' : 'warning',
      fields: [
        { title: '客户', value: `${customer.name} (${customer.company})`, short: true },
        { title: '评分', value: `${customer.score}/100`, short: true },
        { title: '来源', value: customer.source, short: true },
        { title: '行业', value: customer.companyDetails?.industry || 'Unknown', short: true }
      ]
    }]
  });
  
  // CRM 系统更新
  await updateCRMRecord(customer.id, {
    assignedSales: salesRep.id,
    stage: 'assigned',
    assignedAt: new Date().toISOString()
  });
}

客户培育自动化

邮件营销自动化

javascript
// 客户培育邮件序列
class CustomerNurturingCampaign {
  constructor() {
    this.emailSequences = {
      new_lead: [
        { delay: 0, template: 'welcome', subject: '欢迎了解我们的解决方案' },
        { delay: 2, template: 'case_study', subject: '客户成功案例分享' },
        { delay: 5, template: 'product_demo', subject: '免费产品演示邀请' },
        { delay: 10, template: 'social_proof', subject: '看看其他客户怎么说' },
        { delay: 15, template: 'limited_offer', subject: '限时优惠,不要错过' }
      ],
      demo_requested: [
        { delay: 0, template: 'demo_confirmation', subject: '演示确认 - 期待与您见面' },
        { delay: 1, template: 'demo_preparation', subject: '演示准备 - 让我们更了解您的需求' },
        { delay: 7, template: 'demo_followup', subject: '演示后续 - 有什么问题吗?' }
      ],
      proposal_sent: [
        { delay: 3, template: 'proposal_followup', subject: '关于我们的提案,您有什么想法?' },
        { delay: 7, template: 'proposal_reminder', subject: '提案提醒 - 我们随时为您解答' },
        { delay: 14, template: 'proposal_final', subject: '最后机会 - 让我们谈谈' }
      ]
    };
  }
  
  async startNurturingSequence(customer, sequenceType) {
    const sequence = this.emailSequences[sequenceType];
    if (!sequence) return;
    
    for (const email of sequence) {
      await this.scheduleEmail(customer, email, sequenceType);
    }
  }
  
  async scheduleEmail(customer, emailConfig, sequenceType) {
    const sendDate = new Date();
    sendDate.setDate(sendDate.getDate() + emailConfig.delay);
    
    await scheduleTask({
      type: 'send_nurturing_email',
      executeAt: sendDate,
      data: {
        customerId: customer.id,
        template: emailConfig.template,
        subject: emailConfig.subject,
        sequenceType: sequenceType
      }
    });
  }
  
  async sendNurturingEmail(customerId, template, subject) {
    const customer = await getCustomer(customerId);
    
    // 检查客户状态,如果已转化则停止发送
    if (customer.stage === 'customer' || customer.stage === 'closed_lost') {
      return { skipped: true, reason: 'Customer status changed' };
    }
    
    const emailContent = await generateEmailContent(template, customer);
    
    await sendEmail({
      to: customer.email,
      subject: subject,
      html: emailContent,
      trackOpens: true,
      trackClicks: true
    });
    
    // 记录互动
    await recordCustomerInteraction(customerId, {
      type: 'email_sent',
      template: template,
      date: new Date(),
      content: subject
    });
  }
}

行为触发自动化

javascript
// 客户行为监控
class CustomerBehaviorTracker {
  constructor() {
    this.behaviorRules = [
      {
        trigger: 'email_opened',
        condition: { count: 3, timeframe: '7d' },
        action: 'increase_score',
        value: 10
      },
      {
        trigger: 'website_visit',
        condition: { pages: ['pricing', 'features'], timeframe: '1d' },
        action: 'notify_sales',
        priority: 'high'
      },
      {
        trigger: 'demo_video_watched',
        condition: { percentage: 80 },
        action: 'schedule_call',
        delay: '1d'
      }
    ];
  }
  
  async processBehaviorEvent(customerId, event) {
    const customer = await getCustomer(customerId);
    
    for (const rule of this.behaviorRules) {
      if (this.matchesTrigger(event, rule.trigger)) {
        const conditionMet = await this.checkCondition(customerId, rule.condition);
        
        if (conditionMet) {
          await this.executeAction(customer, rule.action, rule);
        }
      }
    }
  }
  
  matchesTrigger(event, trigger) {
    return event.type === trigger;
  }
  
  async checkCondition(customerId, condition) {
    if (condition.count) {
      const recentEvents = await getRecentEvents(customerId, condition.timeframe);
      return recentEvents.length >= condition.count;
    }
    
    if (condition.pages) {
      const recentPageViews = await getRecentPageViews(customerId, condition.timeframe);
      return condition.pages.some(page => 
        recentPageViews.some(view => view.page.includes(page))
      );
    }
    
    if (condition.percentage) {
      return event.data.watchPercentage >= condition.percentage;
    }
    
    return true;
  }
  
  async executeAction(customer, action, rule) {
    switch (action) {
      case 'increase_score':
        await updateCustomerScore(customer.id, customer.score + rule.value);
        break;
        
      case 'notify_sales':
        await notifySalesOfHotLead(customer, rule.priority);
        break;
        
      case 'schedule_call':
        await scheduleFollowUpCall(customer, rule.delay);
        break;
    }
  }
}

销售流程自动化

销售阶段管理

javascript
// 销售流程管理
class SalesProcessManager {
  constructor() {
    this.stages = [
      { name: 'lead', duration: 7, nextActions: ['qualify', 'disqualify'] },
      { name: 'qualified', duration: 14, nextActions: ['demo', 'nurture'] },
      { name: 'demo_completed', duration: 7, nextActions: ['proposal', 'follow_up'] },
      { name: 'proposal_sent', duration: 14, nextActions: ['negotiate', 'close_lost'] },
      { name: 'negotiation', duration: 7, nextActions: ['close_won', 'close_lost'] },
      { name: 'close_won', duration: 0, nextActions: ['onboarding'] },
      { name: 'close_lost', duration: 0, nextActions: ['nurture_long_term'] }
    ];
  }
  
  async moveToNextStage(customerId, newStage, salesRepId) {
    const customer = await getCustomer(customerId);
    const currentStage = this.stages.find(s => s.name === customer.stage);
    const nextStage = this.stages.find(s => s.name === newStage);
    
    // 验证阶段转换是否有效
    if (!currentStage.nextActions.includes(newStage)) {
      throw new Error(`Invalid stage transition from ${customer.stage} to ${newStage}`);
    }
    
    // 更新客户阶段
    await updateCustomer(customerId, {
      stage: newStage,
      stageUpdatedAt: new Date(),
      stageUpdatedBy: salesRepId
    });
    
    // 记录阶段变更
    await recordStageChange(customerId, customer.stage, newStage, salesRepId);
    
    // 触发阶段相关的自动化
    await this.triggerStageAutomation(customerId, newStage);
    
    // 设置下一阶段的提醒
    if (nextStage.duration > 0) {
      await this.scheduleStageReminder(customerId, newStage, nextStage.duration);
    }
  }
  
  async triggerStageAutomation(customerId, stage) {
    const customer = await getCustomer(customerId);
    
    switch (stage) {
      case 'qualified':
        await this.scheduleQualificationCall(customer);
        break;
        
      case 'demo_completed':
        await this.sendDemoFollowUp(customer);
        break;
        
      case 'proposal_sent':
        await this.startProposalFollowUpSequence(customer);
        break;
        
      case 'close_won':
        await this.initiateOnboarding(customer);
        break;
        
      case 'close_lost':
        await this.addToLongTermNurturing(customer);
        break;
    }
  }
  
  async scheduleStageReminder(customerId, stage, daysFromNow) {
    const reminderDate = new Date();
    reminderDate.setDate(reminderDate.getDate() + daysFromNow);
    
    await scheduleTask({
      type: 'stage_reminder',
      executeAt: reminderDate,
      data: {
        customerId,
        stage,
        message: `Customer has been in ${stage} stage for ${daysFromNow} days`
      }
    });
  }
}

客户成功自动化

成交后流程

javascript
// 客户成功管理
class CustomerSuccessManager {
  async initiateOnboarding(customer) {
    // 创建客户成功记录
    const csRecord = await createCustomerSuccessRecord({
      customerId: customer.id,
      stage: 'onboarding',
      startDate: new Date(),
      assignedCSM: await assignCustomerSuccessManager(customer)
    });
    
    // 发送欢迎邮件
    await sendOnboardingWelcomeEmail(customer);
    
    // 创建入职任务清单
    await createOnboardingTasks(customer.id);
    
    // 安排入职会议
    await scheduleOnboardingMeeting(customer, csRecord.assignedCSM);
    
    // 设置健康度监控
    await setupCustomerHealthMonitoring(customer.id);
  }
  
  async createOnboardingTasks(customerId) {
    const tasks = [
      { name: '账户设置', dueDate: 1, responsible: 'customer' },
      { name: '初始配置', dueDate: 3, responsible: 'csm' },
      { name: '数据导入', dueDate: 7, responsible: 'technical' },
      { name: '培训会议', dueDate: 10, responsible: 'csm' },
      { name: '首次使用检查', dueDate: 14, responsible: 'csm' }
    ];
    
    for (const task of tasks) {
      const dueDate = new Date();
      dueDate.setDate(dueDate.getDate() + task.dueDate);
      
      await createTask({
        customerId,
        name: task.name,
        dueDate,
        responsible: task.responsible,
        status: 'pending'
      });
    }
  }
  
  async monitorCustomerHealth(customerId) {
    const customer = await getCustomer(customerId);
    const usage = await getCustomerUsageData(customerId);
    const support = await getCustomerSupportData(customerId);
    
    let healthScore = 100;
    const issues = [];
    
    // 使用频率检查
    if (usage.dailyActiveUsers < usage.expectedUsers * 0.5) {
      healthScore -= 20;
      issues.push('Low user adoption');
    }
    
    // 功能使用检查
    if (usage.featuresUsed < usage.availableFeatures * 0.3) {
      healthScore -= 15;
      issues.push('Limited feature utilization');
    }
    
    // 支持票据检查
    if (support.openTickets > 5) {
      healthScore -= 25;
      issues.push('High number of support tickets');
    }
    
    // 更新健康度分数
    await updateCustomerHealth(customerId, {
      score: healthScore,
      issues: issues,
      lastChecked: new Date()
    });
    
    // 如果健康度低,触发干预
    if (healthScore < 70) {
      await triggerCustomerSuccessIntervention(customerId, healthScore, issues);
    }
  }
}

报告和分析

销售漏斗分析

javascript
// 销售漏斗分析
async function generateSalesFunnelReport(dateRange) {
  const stages = ['lead', 'qualified', 'demo_completed', 'proposal_sent', 'close_won'];
  const funnelData = {};
  
  for (const stage of stages) {
    const count = await getCustomerCountByStage(stage, dateRange);
    const value = await getTotalValueByStage(stage, dateRange);
    
    funnelData[stage] = {
      count,
      value,
      conversionRate: stage === 'lead' ? 100 : 
        (count / funnelData[stages[stages.indexOf(stage) - 1]].count * 100)
    };
  }
  
  return {
    dateRange,
    funnel: funnelData,
    summary: {
      totalLeads: funnelData.lead.count,
      totalWon: funnelData.close_won.count,
      overallConversionRate: (funnelData.close_won.count / funnelData.lead.count * 100),
      totalRevenue: funnelData.close_won.value
    }
  };
}

// 销售团队绩效分析
async function generateSalesPerformanceReport(dateRange) {
  const salesReps = await getSalesTeam();
  const performance = [];
  
  for (const rep of salesReps) {
    const metrics = await getSalesRepMetrics(rep.id, dateRange);
    
    performance.push({
      name: rep.name,
      leadsAssigned: metrics.leadsAssigned,
      dealsWon: metrics.dealsWon,
      revenue: metrics.revenue,
      conversionRate: (metrics.dealsWon / metrics.leadsAssigned * 100),
      avgDealSize: metrics.revenue / metrics.dealsWon,
      avgSalesCycle: metrics.avgSalesCycle
    });
  }
  
  return {
    dateRange,
    teamPerformance: performance,
    teamSummary: {
      totalRevenue: performance.reduce((sum, rep) => sum + rep.revenue, 0),
      avgConversionRate: performance.reduce((sum, rep) => sum + rep.conversionRate, 0) / performance.length,
      topPerformer: performance.reduce((top, rep) => rep.revenue > top.revenue ? rep : top)
    }
  };
}

小结

通过本文的 CRM 自动化系统实战,我们学会了:

  1. 系统架构设计:构建完整的客户管理流程
  2. 客户获取自动化:多渠道客户获取和信息丰富化
  3. 智能分配系统:基于规则的销售分配
  4. 客户培育流程:自动化的邮件营销和行为触发
  5. 销售流程管理:阶段化的销售过程控制
  6. 客户成功管理:成交后的客户维护和健康监控

下一篇文章将学习电商订单处理系统,了解如何自动化完整的电商业务流程。