架构设计:分层与微服务双模驱动
本系统采用分层架构+微服务的混合设计模式,核心模块通过Spring Boot 2.7.10构建后端服务,前端使用Vue+ElementUI实现响应式界面。架构分为四层:
- 源码及演示:c.xsymz.icu
- 表现层:Uniapp跨端框架支持H5/小程序/APP三端同步,通过RESTful API与后端交互
- 业务逻辑层:基于Spring Security实现RBAC权限控制,集成Kettle+Spark实现ETL数据处理
- 数据访问层:MyBatis-Plus 3.5.3.1操作MySQL 8.0数据库,Redis 6.2实现热点数据缓存
- 集成层:Kong网关统一对接ERP、OA等第三方系统,支持API鉴权与流量管控
微服务架构采用典型四域模型:
graph LR
A[客户端] --> B[SLB负载均衡]
B --> C[Web服务器1]
B --> D[Web服务器2]
C --> E[Redis哨兵集群]
D --> E
E --> F[MySQL主从集群]
F --> G[OSS对象存储]
数据库模型设计:核心表结构详解
客户表(customer)
CREATE TABLE customer (
customer_id BIGINT PRIMARY KEY AUTO_INCREMENT,
customer_name VARCHAR(255) NOT NULL COMMENT '客户全称',
industry VARCHAR(50) COMMENT '所属行业',
contact_person VARCHAR(100) COMMENT '主要联系人',
phone VARCHAR(20) UNIQUE COMMENT '联系电话',
email VARCHAR(255) COMMENT '电子邮箱',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
status TINYINT DEFAULT 1 COMMENT '0-失效 1-有效'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
销售机会表(opportunity)
@Data
@TableName("opportunity")
public class Opportunity {
@TableId(type = IdType.AUTO)
private Long id;
private Long customerId;
private String opportunityName;
private Double amount;
private Integer stage; // 0-初步接触 1-需求确认 2-方案报价 3-成交
private String probability;
private String responsiblePerson;
private Date expectedClosingDate;
private Date createTime;
}
核心模块源码解析
客户管理模块
后端实现(Spring Boot)
@RestController
@RequestMapping("/api/customers")
public class CustomerController {
@Autowired
private CustomerService customerService;
@GetMapping("/{id}")
public Customer getCustomerById(@PathVariable Long id) {
return customerService.findById(id);
}
@PostMapping
public ResponseEntity<Customer> saveCustomer(@RequestBody Customer customer) {
customer.setCreateTime(new Date());
return ResponseEntity.ok(customerService.save(customer));
}
}
前端实现(Vue)
<template>
<el-form :model="customerForm" label-width="120px">
<el-form-item label="客户名称" prop="customerName">
<el-input v-model="customerForm.customerName" />
</el-form-item>
<el-form-item label="行业" prop="industry">
<el-select v-model="customerForm.industry">
<el-option label="制造业" value="manufacturing" />
<el-option label="IT行业" value="it" />
<el-option label="金融业" value="finance" />
</el-select>
</el-form-item>
<el-button type="primary" @click="submitForm">保存</el-button>
</el-form>
</template>
<script>
export default {
data() {
return {
customerForm: {
customerName: '',
industry: ''
}
}
},
methods: {
async submitForm() {
await this.$http.post('/api/customers', this.customerForm);
this.$message.success('保存成功');
}
}
}
</script>
销售漏斗分析模块
# 基于机器学习的客户分配算法
from sklearn.cluster import KMeans
import pandas as pd
def assign_customer():
df = pd.read_sql("SELECT * FROM customer_features", con=db)
features = df[['potential_value', 'region', 'industry']]
kmeans = KMeans(n_clusters=5).fit(features)
df['group'] = kmeans.labels_
return optimize_assignment(df) # 结合销售代表能力矩阵优化分配
部署落地全流程
环境准备
| 组件 | 版本要求 | 配置建议 |
|---|---|---|
| 操作系统 | CentOS 7.9+ | 4核CPU/8GB内存/100GB SSD |
| Web服务器 | Nginx 1.20+ | 开启HTTP/2与Brotli压缩 |
| PHP | 8.0+ | 安装OPcache扩展 |
| MySQL | 8.0+ | 配置InnoDB缓冲池 |
| Redis | 6.2+ | 持久化策略AOF |
部署七步法
# 1. 获取源码
wget https://www.bangqishop.com/download/crm-pro-5.2.tar.gz
tar -zxvf crm-pro-5.2.tar.gz -C /var/www/
# 2. 安装依赖
cd /var/www/crm
composer install --no-dev
npm install --production
# 3. 数据库初始化
mysql -u root -p -e "CREATE DATABASE crm DEFAULT CHARSET utf8mb4"
mysql -u root -p crm < install/crm_schema.sql
# 4. 环境配置
cp .env.example .env
vim .env # 修改数据库连接参数
# 5. 权限设置
chown -R www-data:www-data /var/www/crm
chmod -R 755 storage bootstrap/cache
# 6. Nginx配置
vim /etc/nginx/conf.d/crm.conf # 添加server配置块
nginx -t && systemctl reload nginx
# 7. 定时任务设置
crontab -e
* * * * * cd /var/www/crm && php artisan schedule:run >> /dev/null 2>&1
性能优化与安全加固
数据库优化
-- 慢查询优化示例
ALTER TABLE orders ADD INDEX idx_created(create_time);
SELECT id, order_no FROM orders
WHERE create_time > '2025-01-01'
USE INDEX (idx_created);
缓存策略
// Redis多级缓存实现
$data = $redis->get('customer_123');
if (!$data) {
$data = $db->query("SELECT * FROM customers WHERE id=123");
$redis->setex('customer_123', 3600, json_encode($data));
}
安全防护体系
- SQL注入防护:预处理语句+ORM防护
- XSS攻击防护:HTMLPurifier过滤
- CSRF防护:SameSite Cookie+Token验证
- 数据加密:AES-256加密敏感字段
定制化开发实战
模块化拆分方案
src/
├── core/ # 核心基础库
├── modules/ # 功能模块
│ ├── sales/ # 销售管理
│ ├── marketing/ # 营销自动化
│ └── service/ # 客户服务
└── plugins/ # 插件系统
插件开发示例
// 客户定位插件
export default {
methods: {
getLocation() {
uni.getLocation({
type: 'gcj02',
success: res => {
this.$store.commit('UPDATE_LOCATION', res)
}
})
}
}
}
本系统通过严谨的架构设计、规范的源码实现、完善的部署方案,可支持从数十人到数千人规模企业的客户关系管理需求。通过模块化设计和微服务架构,系统具备良好的可扩展性,可轻松集成企业现有的ERP、OA等系统,实现真正的数字化客户管理转型。