“ 以下是基于 CRM 核心功能设计的 MySQL 数据库表结构,涵盖线索、客户、销售、营销、服务等全流程,每个表包含字段定义、索引设计和业务说明:”
一、基础配置表(系统支撑)
1. 系统用户表(sys_user)
CREATE TABLE `sys_user` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '用户ID',`username` varchar(50) NOT NULL COMMENT '登录账号',`full_name` varchar(50) NOT NULL COMMENT '姓名',`dept_id` bigint NOT NULL COMMENT '所属部门ID',`role_ids` varchar(255) COMMENT '角色ID,逗号分隔',`phone` varchar(20) COMMENT '手机号',`email` varchar(100) COMMENT '邮箱',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0-禁用,1-启用',`last_login_time` datetime COMMENT '最后登录时间',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_username` (`username`),KEY `idx_dept` (`dept_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '系统用户(销售/客服等)';
2. 部门表(sys_dept)
CREATE TABLE `sys_dept` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '部门ID',`dept_name` varchar(100) NOT NULL COMMENT '部门名称',`parent_id` bigint COMMENT '上级部门ID',`sort` int DEFAULT 0 COMMENT '排序',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_parent` (`parent_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '部门(销售一部/客服部等)';
二、线索管理模块
3. 线索表(crm_lead)
CREATE TABLE `crm_lead` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '线索ID',`lead_name` varchar(100) NOT NULL COMMENT '线索名称(个人/企业名)',`phone` varchar(20) COMMENT '联系电话',`company` varchar(200) COMMENT '公司名称',`position` varchar(100) COMMENT '职位',`source` varchar(50) COMMENT '来源渠道(官网/展会/转介绍)',`intent_product` varchar(200) COMMENT '意向产品',`intent_level` tinyint COMMENT '意向度:1-低,2-中,3-高',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-新增,2-跟进中,3-已转化,4-失效',`remark` text COMMENT '备注',`owner_id` bigint COMMENT '负责人ID(未分配为NULL)',`pool_id` bigint NOT NULL COMMENT '所属线索池ID',`created_by` bigint NOT NULL COMMENT '创建人ID',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_phone` (`phone`) COMMENT '避免重复线索',KEY `idx_owner` (`owner_id`),KEY `idx_pool_status` (`pool_id`,`status`),KEY `idx_source` (`source`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '线索信息';
4. 线索池表(crm_lead_pool)
CREATE TABLE `crm_lead_pool` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '线索池ID',`pool_name` varchar(100) NOT NULL COMMENT '线索池名称(公共池/市场部池)',`description` text COMMENT '描述',`is_public` tinyint NOT NULL DEFAULT 1 COMMENT '是否公共池:0-私有,1-公共',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_pool_name` (`pool_name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '线索池(线索的容器)';
三、客户管理模块
5. 客户表(crm_customer)
CREATE TABLE `crm_customer` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '客户ID',`customer_name` varchar(200) NOT NULL COMMENT '客户名称',`customer_type` tinyint NOT NULL COMMENT '类型:1-个人,2-企业',`industry` varchar(50) COMMENT '所属行业(企业客户)',`scale` varchar(50) COMMENT '企业规模(企业客户)',`address` varchar(500) COMMENT '地址',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-潜在,2-成交,3-流失',`level` tinyint COMMENT '客户等级:1-A,2-B,3-C',`source_lead_id` bigint COMMENT '来源线索ID(从线索转化时关联)',`owner_id` bigint NOT NULL COMMENT '负责人ID',`is_in_sea` tinyint NOT NULL DEFAULT 0 COMMENT '是否在公海:0-否,1-是',`sea_time` datetime COMMENT '进入公海时间',`created_by` bigint NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_owner` (`owner_id`),KEY `idx_status_level` (`status`,`level`),KEY `idx_sea` (`is_in_sea`,`sea_time`),KEY `idx_source_lead` (`source_lead_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '客户信息(线索转化后生成)';
6. 联系人表(crm_contact)
CREATE TABLE `crm_contact` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '联系人ID',`customer_id` bigint NOT NULL COMMENT '所属客户ID',`contact_name` varchar(100) NOT NULL COMMENT '姓名',`position` varchar(100) COMMENT '职位',`phone` varchar(20) NOT NULL COMMENT '手机号',`email` varchar(100) COMMENT '邮箱',`is_key` tinyint NOT NULL DEFAULT 0 COMMENT '是否关键决策人:0-否,1-是',`communication_preference` varchar(50) COMMENT '沟通偏好(电话/微信)',`birthday` date COMMENT '生日',`remark` text COMMENT '备注',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_customer_phone` (`customer_id`,`phone`) COMMENT '同一客户手机号唯一',KEY `idx_customer` (`customer_id`),KEY `idx_is_key` (`is_key`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '客户联系人(一个客户可多个联系人)';
四、客户互动模块
7. 客户会话表(crm_customer_session)
CREATE TABLE `crm_customer_session` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '会话ID',`customer_id` bigint NOT NULL COMMENT '客户ID',`contact_id` bigint COMMENT '关联联系人ID(可为空)',`session_type` varchar(20) NOT NULL COMMENT '会话类型(电话/微信/邮件)',`session_time` datetime NOT NULL COMMENT '会话时间',`content` text COMMENT '会话内容',`tag` varchar(50) COMMENT '会话标签(需求沟通/报价讨论)',`created_by` bigint NOT NULL COMMENT '记录人ID',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_customer` (`customer_id`),KEY `idx_session_time` (`session_time`),KEY `idx_contact` (`contact_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '客户会话记录';
8. 跟进记录表(crm_follow_up)
CREATE TABLE `crm_follow_up` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '跟进ID',`relation_type` varchar(20) NOT NULL COMMENT '关联类型(lead-线索/customer-客户)',`relation_id` bigint NOT NULL COMMENT '关联ID(线索ID/客户ID)',`follow_type` varchar(20) NOT NULL COMMENT '跟进方式(电话/面谈/微信)',`content` text NOT NULL COMMENT '跟进内容',`next_follow_time` datetime COMMENT '下次跟进时间',`next_content` varchar(500) COMMENT '下次跟进内容',`created_by` bigint NOT NULL COMMENT '跟进人ID',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_relation` (`relation_type`,`relation_id`),KEY `idx_next_follow` (`next_follow_time`),KEY `idx_creator` (`created_by`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '线索/客户跟进记录';
9. 拜访计划表(crm_visit_plan)
CREATE TABLE `crm_visit_plan` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '拜访ID',`customer_id` bigint NOT NULL COMMENT '客户ID',`visit_purpose` varchar(500) NOT NULL COMMENT '拜访目的',`visit_time` datetime NOT NULL COMMENT '计划拜访时间',`address` varchar(500) COMMENT '拜访地点',`participants` varchar(500) COMMENT '参与人(内部员工)',`materials` varchar(500) COMMENT '携带资料',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-计划中,2-已完成,3-已取消',`summary` text COMMENT '拜访总结(完成后填写)',`created_by` bigint NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_customer` (`customer_id`),KEY `idx_visit_time` (`visit_time`),KEY `idx_status` (`status`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '客户拜访计划';
10. 回访计划表(crm_return_visit)
CREATE TABLE `crm_return_visit` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '回访ID',`customer_id` bigint NOT NULL COMMENT '客户ID',`contract_id` bigint COMMENT '关联合同ID(可为空)',`visit_type` varchar(20) NOT NULL COMMENT '回访方式(电话/上门/问卷)',`plan_time` datetime NOT NULL COMMENT '计划回访时间',`actual_time` datetime COMMENT '实际回访时间',`content` text COMMENT '回访内容',`feedback` text COMMENT '客户反馈',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-待执行,2-已完成,3-已取消',`created_by` bigint NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_customer` (`customer_id`),KEY `idx_plan_time` (`plan_time`),KEY `idx_contract` (`contract_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '客户回访计划';
五、销售管理模块
11. 产品表(crm_product)
CREATE TABLE `crm_product` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '产品ID',`product_name` varchar(200) NOT NULL COMMENT '产品名称',`category_id` bigint NOT NULL COMMENT '产品分类ID',`specification` varchar(500) COMMENT '规格型号',`unit` varchar(20) COMMENT '单位',`price` decimal(18,4) NOT NULL COMMENT '标准售价',`cost_price` decimal(18,4) COMMENT '成本价',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0-下架,1-上架',`description` text COMMENT '产品描述',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_category` (`category_id`),KEY `idx_status` (`status`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '产品信息';
12. 产品分类表(crm_product_category)
CREATE TABLE `crm_product_category` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '分类ID',`category_name` varchar(100) NOT NULL COMMENT '分类名称',`parent_id` bigint COMMENT '上级分类ID',`sort` int DEFAULT 0 COMMENT '排序',PRIMARY KEY (`id`),KEY `idx_parent` (`parent_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '产品分类';
13. 商机表(crm_opportunity)
CREATE TABLE `crm_opportunity` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '商机ID',`customer_id` bigint NOT NULL COMMENT '客户ID',`opportunity_name` varchar(200) NOT NULL COMMENT '商机名称',`product_ids` varchar(255) COMMENT '意向产品ID,逗号分隔',`estimated_amount` decimal(18,2) NOT NULL COMMENT '预估金额',`win_probability` int COMMENT '赢单概率(%)',`stage` varchar(50) NOT NULL COMMENT '阶段(初步接触/需求分析/商务谈判)',`expected_close_time` date COMMENT '预计成交时间',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-进行中,2-已赢单,3-已输单',`lose_reason` text COMMENT '输单原因(状态为3时填写)',`owner_id` bigint NOT NULL COMMENT '负责人ID',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_customer` (`customer_id`),KEY `idx_owner_stage` (`owner_id`,`stage`),KEY `idx_status` (`status`),KEY `idx_expected_close` (`expected_close_time`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '销售商机';
14. 报价单表(crm_quotation)
CREATE TABLE `crm_quotation` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '报价单ID',`quotation_no` varchar(50) NOT NULL COMMENT '报价单号(自动生成)',`opportunity_id` bigint NOT NULL COMMENT '关联商机ID',`customer_id` bigint NOT NULL COMMENT '客户ID',`total_amount` decimal(18,2) NOT NULL COMMENT '总金额',`valid_until` date COMMENT '报价有效期',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-草稿,2-已发送,3-已接受,4-已拒绝',`remark` text COMMENT '备注',`created_by` bigint NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_quotation_no` (`quotation_no`),KEY `idx_opportunity` (`opportunity_id`),KEY `idx_customer` (`customer_id`),KEY `idx_status` (`status`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '报价单';
15. 报价单明细表(crm_quotation_item)
CREATE TABLE `crm_quotation_item` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '明细ID',`quotation_id` bigint NOT NULL COMMENT '报价单ID',`product_id` bigint NOT NULL COMMENT '产品ID',`specification` varchar(500) COMMENT '规格型号',`quantity` decimal(18,4) NOT NULL COMMENT '数量',`unit` varchar(20) NOT NULL COMMENT '单位',`unit_price` decimal(18,4) NOT NULL COMMENT '单价',`discount` decimal(10,2) DEFAULT 100 COMMENT '折扣(%)',`amount` decimal(18,2) NOT NULL COMMENT '金额(数量*单价*折扣)',PRIMARY KEY (`id`),KEY `idx_quotation` (`quotation_id`),KEY `idx_product` (`product_id`),CONSTRAINT `fk_quotation_item_quotation` FOREIGN KEY (`quotation_id`) REFERENCES `crm_quotation` (`id`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '报价单明细';
16. 合同表(crm_contract)
CREATE TABLE `crm_contract` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '合同ID',`contract_no` varchar(50) NOT NULL COMMENT '合同编号',`customer_id` bigint NOT NULL COMMENT '客户ID',`opportunity_id` bigint COMMENT '关联商机ID',`quotation_id` bigint COMMENT '关联报价单ID',`contract_name` varchar(200) NOT NULL COMMENT '合同名称',`sign_date` date NOT NULL COMMENT '签约日期',`start_date` date COMMENT '生效日期',`end_date` date COMMENT '到期日期',`total_amount` decimal(18,2) NOT NULL COMMENT '合同总金额',`status` tinyint NOT NULL COMMENT '状态:1-草稿,2-已审核,3-已签约,4-已终止',`file_url` varchar(500) COMMENT '合同文件URL',`remark` text COMMENT '备注',`created_by` bigint NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_contract_no` (`contract_no`),KEY `idx_customer` (`customer_id`),KEY `idx_opportunity` (`opportunity_id`),KEY `idx_status` (`status`),KEY `idx_sign_date` (`sign_date`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '销售合同';
17. 合同明细表(crm_contract_item)
CREATE TABLE `crm_contract_item` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '明细ID',`contract_id` bigint NOT NULL COMMENT '合同ID',`product_id` bigint NOT NULL COMMENT '产品ID',`specification` varchar(500) COMMENT '规格',`quantity` decimal(18,4) NOT NULL COMMENT '数量',`unit` varchar(20) NOT NULL COMMENT '单位',`unit_price` decimal(18,4) NOT NULL COMMENT '单价',`amount` decimal(18,2) NOT NULL COMMENT '金额',PRIMARY KEY (`id`),KEY `idx_contract` (`contract_id`),CONSTRAINT `fk_contract_item_contract` FOREIGN KEY (`contract_id`) REFERENCES `crm_contract` (`id`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '合同明细';
六、回款管理模块
18. 回款计划表(crm_payment_plan)
CREATE TABLE `crm_payment_plan` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '计划ID',`contract_id` bigint NOT NULL COMMENT '合同ID',`plan_amount` decimal(18,2) NOT NULL COMMENT '计划回款金额',`plan_date` date NOT NULL COMMENT '计划回款日期',`payment_term` varchar(100) COMMENT '付款条件(首付/尾款)',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-未回款,2-部分回款,3-全部回款',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_contract` (`contract_id`),KEY `idx_plan_date` (`plan_date`),KEY `idx_status` (`status`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '回款计划';
19. 回款记录表(crm_payment_record)
CREATE TABLE `crm_payment_record` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '回款ID',`contract_id` bigint NOT NULL COMMENT '合同ID',`plan_id` bigint COMMENT '关联回款计划ID',`payment_no` varchar(50) NOT NULL COMMENT '回款单号',`payment_amount` decimal(18,2) NOT NULL COMMENT '回款金额',`payment_date` date NOT NULL COMMENT '回款日期',`payment_method` varchar(50) COMMENT '回款方式(转账/现金)',`bank_flow` varchar(500) COMMENT '银行流水凭证URL',`remark` text COMMENT '备注',`created_by` bigint NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_payment_no` (`payment_no`),KEY `idx_contract` (`contract_id`),KEY `idx_plan` (`plan_id`),KEY `idx_payment_date` (`payment_date`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '回款记录';
20. 发票表(crm_invoice)
CREATE TABLE `crm_invoice` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '发票ID',`invoice_no` varchar(50) NOT NULL COMMENT '发票号码',`contract_id` bigint NOT NULL COMMENT '合同ID',`payment_id` bigint COMMENT '关联回款记录ID',`invoice_type` varchar(20) NOT NULL COMMENT '类型(专票/普票)',`amount` decimal(18,2) NOT NULL COMMENT '发票金额',`issue_date` date NOT NULL COMMENT '开票日期',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-已开票,2-已寄达,3-已认证',`file_url` varchar(500) COMMENT '发票扫描件URL',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_invoice_no` (`invoice_no`),KEY `idx_contract` (`contract_id`),KEY `idx_status` (`status`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '发票管理';
七、营销管理模块
21. 市场活动表(crm_marketing_activity)
CREATE TABLE `crm_marketing_activity` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '活动ID',`activity_name` varchar(200) NOT NULL COMMENT '活动名称',`activity_type` varchar(50) NOT NULL COMMENT '类型(展会/直播/促销)',`start_time` datetime NOT NULL COMMENT '开始时间',`end_time` datetime NOT NULL COMMENT '结束时间',`budget` decimal(18,2) COMMENT '预算金额',`actual_cost` decimal(18,2) COMMENT '实际成本',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-策划中,2-进行中,3-已结束',`description` text COMMENT '活动描述',`created_by` bigint NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_time_status` (`start_time`,`end_time`,`status`),KEY `idx_type` (`activity_type`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '市场活动';
22. 短信营销表(crm_sms_marketing)
CREATE TABLE `crm_sms_marketing` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '短信ID',`template_id` bigint NOT NULL COMMENT '短信模板ID',`activity_id` bigint COMMENT '关联市场活动ID',`send_time` datetime NOT NULL COMMENT '发送时间',`target_tag` varchar(255) COMMENT '目标客户标签(如“沉睡客户”)',`total_count` int NOT NULL COMMENT '总发送条数',`success_count` int COMMENT '成功条数',`fail_count` int COMMENT '失败条数',`created_by` bigint NOT NULL,`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_activity` (`activity_id`),KEY `idx_send_time` (`send_time`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '短信营销记录';
23. 短信模板表(crm_sms_template)
CREATE TABLE `crm_sms_template` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '模板ID',`template_name` varchar(100) NOT NULL COMMENT '模板名称',`content` text NOT NULL COMMENT '短信内容(含变量${name})',`template_type` varchar(50) COMMENT '类型(营销/通知)',`is_enabled` tinyint NOT NULL DEFAULT 1 COMMENT '是否启用:0-否,1-是',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (`id`),KEY `idx_type_enabled` (`template_type`,`is_enabled`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '短信模板';
八、服务支持模块
24. 工单表(crm_work_order)
CREATE TABLE `crm_work_order` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT '工单ID',`order_no` varchar(50) NOT NULL COMMENT '工单号',`customer_id` bigint NOT NULL COMMENT '客户ID',`contact_id` bigint COMMENT '联系人ID',`contract_id` bigint COMMENT '关联合同ID',`order_type` varchar(50) NOT NULL COMMENT '类型(售后问题/产品咨询/投诉)',`title` varchar(200) NOT NULL COMMENT '工单标题',`content` text NOT NULL COMMENT '问题描述',`priority` tinyint NOT NULL DEFAULT 2 COMMENT '优先级:1-紧急,2-普通,3-低',`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:1-待处理,2-处理中,3-已解决,4-已关闭',`assignee_id` bigint COMMENT '处理人ID',`solution` text COMMENT '解决方案(处理后填写)',`satisfaction` tinyint COMMENT '满意度:1-5分',`created_by` bigint NOT NULL COMMENT '创建人(客户/员工)',`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,PRIMARY KEY (`id`),UNIQUE KEY `uk_order_no` (`order_no`),KEY `idx_customer` (`customer_id`),KEY `idx_assignee_status` (`assignee_id`,`status`),KEY `idx_priority` (`priority`),KEY `idx_create_time` (`created_at`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '服务工单';
设计说明
- 关联关系:
通过customer_id/opportunity_id等字段实现表间关联,如 “客户 - 联系人” 为一对多,“合同 - 回款计划” 为一对多。 - 索引策略:
对高频查询字段(如负责人 ID、状态、时间)创建索引,避免全表扫描。 - 业务追踪:
所有表包含 created_by和时间字段,支持数据溯源和操作审计。 - 扩展性:
预留 remark字段存储额外信息,通过status字段支持业务状态流转。
开源代码:
git clone https://gitee.com/zhiops/xecrm.git

关于【黄哥开源】
聚焦开源整合前沿技术,覆盖企业,教育,物联网,园区、工地智慧城市建设等核心领域。
提供更多前沿技术、高可用的开源项目。
商务合作/项目开发/联系微信:mingyu17173

