一、满减活动核心逻辑设计
1. 活动类型分类
- 单档满减:满100减20(适合简单促销)
- 多档满减:满100减15/满200减40/满300减70(提升客单价)
- 阶梯满减:首单满50减10,复购满80减15(精准营销)
2. 关键参数配置
```python
示例配置结构(可转换为JSON/YAML)
activity_rules = [
{
"id": 1,
"name": "生鲜狂欢",
"start_time": "2023-11-01 00:00:00",
"end_time": "2023-11-30 23:59:59",
"thresholds": [100, 200, 300], 满减门槛
"discounts": [20, 45, 80], 对应减免金额
"exclude_categories": ["海鲜礼盒"], 排除品类
"max_discount": 100, 单笔最高减免
"user_limit": 3 每人限用次数
}
]
```
二、万象源码部署实现步骤
1. 环境准备
- 基础环境:Nginx + MySQL 5.7 + PHP 7.4(确保符合源码要求)
- 快速部署:使用宝塔面板一键安装环境
2. 源码修改要点
- 路由修改:在`/application/route.php`中添加活动接口
```php
Route::post(api/promotion/check, api/Promotion/checkDiscount);
```
- 核心逻辑:修改`/application/api/controller/Promotion.php`
```php
public function checkDiscount() {
$cartTotal = input(post.total);
$rules = config(promotion_rules); // 从配置文件读取规则
foreach ($rules as $rule) {
if ($cartTotal >= max($rule[thresholds])) {
$discount = $rule[discounts][array_search(
max($rule[thresholds]),
$rule[thresholds]
)];
break;
}
}
return json([discount => $discount ?? 0]);
}
```
3. 数据库设计
```sql
CREATE TABLE `promotion_rules` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`start_time` datetime NOT NULL,
`end_time` datetime NOT NULL,
`rules` json NOT NULL COMMENT 存储JSON格式的门槛和折扣,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```
三、前端集成方案
1. 购物车页面改造
- 在结算栏添加满减提示组件:
```html
满{{activeRule.threshold}}减{{activeRule.discount}}
```
2. Vue.js实现逻辑
```javascript
data() {
return {
cartTotal: 0,
discountRules: [],
activeRule: null
}
},
methods: {
checkDiscount() {
axios.post(/api/promotion/check, {total: this.cartTotal})
.then(res => {
if (res.data.discount > 0) {
// 查找匹配的规则(需后端返回完整规则或前端预加载)
this.activeRule = this.discountRules.find(r =>
this.cartTotal >= Math.max(...r.thresholds)
);
}
});
}
}
```
四、运营配置建议
1. 可视化配置界面(需二次开发)
- 添加表单字段:
- 活动名称(输入框)
- 时间范围(日期选择器)
- 满减规则(动态表单,可添加多档)
- 适用商品(多选框/分类选择)
2. 推荐配置方案
- 早市特惠:06:00-09:00 满50减8(针对上班族)
- 家庭套餐:周末满150减30(提升大额订单)
- 清仓促销:每日20:00后 满80减25(减少损耗)
五、常见问题解决方案
1. 规则冲突处理
- 优先级设置:在规则表中添加`priority`字段,数值越大优先级越高
- 互斥规则:通过`exclude_activity_ids`字段标记互斥活动
2. 性能优化
- 缓存策略:使用Redis缓存活动规则(有效期与活动时间同步)
- 数据库优化:为`start_time`和`end_time`字段添加索引
3. 测试用例
```javascript
// 边界值测试
const testCases = [
{total: 99.99, expect: 0}, // 不足最低门槛
{total: 100, expect: 20}, // 刚好满足第一档
{total: 199.99, expect: 20}, // 不足第二档
{total: 200, expect: 45}, // 满足第二档
{total: 350, expect: 80} // 满足最高档
];
```
六、部署注意事项
1. 源码部署步骤
- 上传源码至服务器 `/var/www/fresh_mall`
- 设置Nginx虚拟主机:
```nginx
server {
listen 80;
server_name mall.example.com;
root /var/www/fresh_mall/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
```
- 执行数据库迁移:`php think migrate:run`
2. 定时任务设置
```bash
每天0点检查过期活动(crontab -e)
0 0 * * * curl -s http://mall.example.com/api/promotion/cleanup
```
七、扩展功能建议
1. 会员差异化:VIP用户满减门槛降低20%
2. 地域定制:根据收货地址显示不同满减规则
3. 组合优惠:满减+赠品(如满128送葱姜蒜套装)
通过以上方案,即使没有深厚的技术背景,也能通过配置化方式快速搭建生鲜商城的满减活动系统。建议先在测试环境验证规则逻辑,再逐步推广到生产环境。