superlishunqin 364b7acbb7 END
2025-10-10 23:22:52 +08:00
END
2025-10-10 23:22:52 +08:00
END
2025-10-10 23:22:52 +08:00
2025-09-25 05:52:22 +08:00
END
2025-10-10 23:22:52 +08:00
2025-09-25 05:52:22 +08:00
END
2025-10-10 23:22:52 +08:00
2025-09-25 06:14:49 +08:00

🌱 SunnyFarm | 农产品直销平台

现代化农产品电商解决方案 - 连接农户与消费者的桥梁

Spring Boot Vue.js MySQL License Build Status

🚀 快速开始📖 文档🎯 演示🤝 贡献


📖 项目介绍

SunnyFarm 是一个基于现代技术栈开发的农产品电商平台,致力于为农户和消费者搭建直接沟通的桥梁。平台采用微服务架构,支持多角色权限管理,提供完整的电商业务流程,让新鲜农产品直达餐桌。

🎯 核心优势

💎 技术先进 🔐 安全可靠 📱 响应式设计 高性能
Spring Boot + Vue3 JWT + Spring Security 多端适配 Redis缓存优化

功能亮点

🛒 用户端功能

🔍 智能商品搜索 - 分类筛选、价格排序

🛍️ 购物车管理 - 实时更新、批量操作

💳 多种支付方式 - 支付宝、微信支付

📍 地址管理 - 多地址管理、默认地址

商品评价 - 图文评价、评分系统

💬 在线客服 - 实时聊天、问题解答

🏪 商家端功能

📦 商品管理 - 批量上传、库存预警

📊 销售统计 - 实时数据、图表分析

🚚 订单处理 - 状态跟踪、物流管理

💰 收益分析 - 财务报表、提现管理

🎨 店铺装修 - 个性化展示

📈 营销工具 - 优惠券、促销活动

🔧 管理员功能

👥 用户管理 - 用户审核、权限分配、行为监控

🏢 商家管理 - 商家入驻审核、资质验证、经营监管

📋 平台配置 - 系统参数、业务规则、功能开关

📊 数据分析 - 运营报表、用户画像、商业洞察


🏗️ 技术架构

graph TB
    A[用户端 Vue3] --> B[Nginx]
    C[商家端 Vue3] --> B
    D[管理端 Vue3] --> B
    B --> E[Spring Boot API Gateway]
    E --> F[用户服务]
    E --> G[商品服务]
    E --> H[订单服务]
    E --> I[支付服务]
    F --> J[(MySQL)]
    G --> J
    H --> J
    I --> J
    E --> K[(Redis)]
    E --> L[腾讯云COS]
    I --> M[支付宝API]

🛠️ 技术栈详情

分层 技术选型 版本 说明
后端 Spring Boot 2.7.14 核心框架
Spring Security - 安全认证
MyBatis Plus - 数据访问
MySQL 8.0+ 主数据库
Redis 6.0+ 缓存/会话
腾讯云COS - 文件存储
前端 Vue 3 3.0+ 前端框架
Element Plus - UI组件库
Pinia - 状态管理
Vue Router 4.0+ 路由管理
Axios - HTTP客户端
ECharts - 数据可视化
运维 Docker - 容器化部署
Nginx - 反向代理
Docker Compose - 服务编排

📋 环境要求

环境 开发环境 生产环境
操作系统 Windows/macOS/Linux Linux (推荐 Ubuntu 20.04+)
Java JDK 8+ JDK 8+
Node.js 16.0+ 16.0+
数据库 MySQL 8.0+ MySQL 8.0+
缓存 Redis 6.0+ Redis 6.0+
内存 4GB+ 8GB+
存储 10GB+ 50GB+

🚀 快速开始

📥 1. 项目克隆

# 克隆项目
git clone https://git.sq0715.com/qin/SunnyFarm.git

# 进入项目目录
cd SunnyFarm

⚙️ 2. 环境配置

🎯 后端配置

# 复制配置模板
cp backend/src/main/resources/application-dev.yml.example \
   backend/src/main/resources/application-dev.yml

# 编辑配置文件
vim backend/src/main/resources/application-dev.yml

🔧 关键配置项

📊 数据库配置
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/sunnyfarm?useSSL=false&serverTimezone=Asia/Shanghai
    username: your_username
    password: your_password
    driver-class-name: com.mysql.cj.jdbc.Driver
🔴 Redis配置
spring:
  redis:
    host: localhost
    port: 6379
    password: your_redis_password
    timeout: 5000ms
    lettuce:
      pool:
        max-active: 8
        max-wait: -1ms
        max-idle: 8
        min-idle: 0
📧 邮件服务配置
spring:
  mail:
    host: smtp.qq.com
    port: 465
    username: your_email@qq.com
    password: your_email_auth_code
    protocol: smtp
    properties:
      mail.smtp.auth: true
      mail.smtp.ssl.enable: true
☁️ 腾讯云COS配置
tencent:
  cos:
    secret-id: your_secret_id
    secret-key: your_secret_key
    region: ap-guangzhou
    bucket: your_bucket_name
    base-url: https://your-bucket.cos.ap-guangzhou.myqcloud.com
💳 支付宝配置
alipay:
  app-id: your_app_id
  app-private-key: your_private_key
  alipay-public-key: alipay_public_key
  notify-url: https://your-domain.com/api/payment/alipay/notify
  return-url: https://your-domain.com/orders?payment=success
  gateway-url: https://openapi.alipaydev.com/gateway.do  # 沙箱环境

🗄️ 3. 数据库初始化

# 创建数据库
mysql -u root -p -e "CREATE DATABASE sunnyfarm CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"

# 导入数据库结构
mysql -u root -p sunnyfarm < sql/sunnyfarm.sql

# 导入初始化数据
mysql -u root -p sunnyfarm < sql/init_inventory.sql

🔥 4. 启动服务

🖥️ 后端服务

cd backend

# 安装依赖并启动
mvn clean install
mvn spring-boot:run

# 或者使用jar包启动
java -jar target/sunnyfarm-backend-1.0.0.jar

🌐 前端服务

cd frontend

# 安装依赖
npm install

# 启动开发服务器
npm run dev

# 构建生产版本
npm run build

🎯 5. 访问应用

服务 地址 说明
🖥️ 前端应用 http://localhost:3000 用户界面
🔧 后端API http://localhost:8080 API服务
📊 健康检查 http://localhost:8080/api/init/status 服务状态

🐳 容器化部署

🚀 一键部署

# 使用 Docker Compose 一键启动所有服务
docker-compose up -d

# 查看服务状态
docker-compose ps

# 查看实时日志
docker-compose logs -f

🔧 手动部署

点击展开详细部署步骤
# 1. 构建后端镜像
cd backend
docker build -t sunnyfarm-backend:latest .

# 2. 构建前端镜像
cd ../frontend
docker build -t sunnyfarm-frontend:latest .

# 3. 创建网络
docker network create sunnyfarm-network

# 4. 启动数据库
docker run -d \
  --name sunnyfarm-mysql \
  --network sunnyfarm-network \
  -e MYSQL_ROOT_PASSWORD=root123 \
  -e MYSQL_DATABASE=sunnyfarm \
  -p 3306:3306 \
  mysql:8.0

# 5. 启动Redis
docker run -d \
  --name sunnyfarm-redis \
  --network sunnyfarm-network \
  -p 6379:6379 \
  redis:6-alpine

# 6. 启动后端服务
docker run -d \
  --name sunnyfarm-backend \
  --network sunnyfarm-network \
  -p 8080:8080 \
  sunnyfarm-backend:latest

# 7. 启动前端服务
docker run -d \
  --name sunnyfarm-frontend \
  --network sunnyfarm-network \
  -p 3000:3000 \
  sunnyfarm-frontend:latest

🌍 生产环境部署

🏗️ 服务器准备

# 更新系统
sudo apt update && sudo apt upgrade -y

# 安装必要软件
sudo apt install -y docker.io docker-compose nginx ufw

# 启动Docker服务
sudo systemctl start docker
sudo systemctl enable docker

# 配置防火墙
sudo ufw allow 22
sudo ufw allow 80
sudo ufw allow 443
sudo ufw --force enable

🔧 Nginx配置

Nginx反向代理配置
server {
    listen 80;
    server_name your-domain.com;
    
    # 前端静态文件
    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    
    # 后端API
    location /api/ {
        proxy_pass http://localhost:8080/api/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    
    # 文件上传大小限制
    client_max_body_size 10M;
}

📚 API接口文档

🔐 认证模块

方法 路径 描述 权限
POST /api/user/register 用户注册 公开
POST /api/user/login 用户登录 公开
POST /api/merchant/login 商家登录 公开
POST /api/admin/login 管理员登录 公开
POST /api/auth/logout 退出登录 登录用户

🛍️ 商品模块

方法 路径 描述 权限
GET /api/product/list 商品列表 公开
GET /api/product/{id} 商品详情 公开
POST /api/product/create 创建商品 商家
PUT /api/product/{id} 更新商品 商家
DELETE /api/product/{id} 删除商品 商家

📦 订单模块

方法 路径 描述 权限
POST /api/order/create 创建订单 用户
GET /api/order/list 订单列表 用户/商家
GET /api/order/{id} 订单详情 用户/商家
POST /api/order/{id}/pay 订单支付 用户
PUT /api/order/{id}/status 更新订单状态 商家

🎯 测试账号

🔑 默认账号信息

角色 用户名 密码 权限说明
🔧 管理员 admin admin123 系统管理、用户管理、数据统计
🏪 商家 merchant merchant123 商品管理、订单处理、销售统计
👤 用户 user user123 购物下单、个人中心、订单管理

⚠️ 安全提醒: 生产环境请立即修改默认密码!


📁 项目结构

SunnyFarm/
├── 📁 backend/                    # 🖥️ 后端Spring Boot项目
│   ├── 📁 src/main/java/         # ☕ Java源码
│   │   ├── 📁 controller/        # 🌐 控制器层
│   │   ├── 📁 service/           # 🔧 业务逻辑层
│   │   ├── 📁 mapper/            # 🗄️ 数据访问层
│   │   ├── 📁 model/             # 📋 数据模型
│   │   └── 📁 config/            # ⚙️ 配置类
│   ├── 📁 src/main/resources/    # 📄 配置文件
│   │   ├── 📄 application.yml    # 主配置文件
│   │   ├── 📄 application-dev.yml # 开发环境配置
│   │   └── 📄 application-prod.yml # 生产环境配置
│   └── 📄 pom.xml                # Maven依赖配置
├── 📁 frontend/                   # 🌐 前端Vue项目
│   ├── 📁 src/                   # Vue源码
│   │   ├── 📁 components/        # 🧩 组件库
│   │   ├── 📁 views/             # 📱 页面视图
│   │   ├── 📁 router/            # 🗺️ 路由配置
│   │   ├── 📁 store/             # 💾 状态管理
│   │   └── 📁 utils/             # 🔧 工具函数
│   ├── 📁 public/                # 🖼️ 静态资源
│   └── 📄 package.json           # NPM依赖配置
├── 📁 sql/                       # 🗄️ 数据库脚本
│   ├── 📄 sunnyfarm.sql          # 数据库结构
│   └── 📄 init_inventory.sql     # 初始化数据
├── 📁 docker/                    # 🐳 Docker配置
├── 📄 docker-compose.yml         # 容器编排配置
├── 📄 nginx.conf                 # Nginx配置
└── 📄 README.md                  # 项目说明文档

🔄 开发流程

🌿 Git工作流

gitgraph
    commit id: "Initial"
    branch develop
    checkout develop
    commit id: "Feature A"
    commit id: "Feature B"
    branch feature/user-auth
    checkout feature/user-auth
    commit id: "Add login"
    commit id: "Add register"
    checkout develop
    merge feature/user-auth
    checkout main
    merge develop
    commit id: "Release v1.0"

📝 提交规范

# 功能开发
git commit -m "feat: 添加用户登录功能"

# 问题修复
git commit -m "fix: 修复商品搜索bug"

# 文档更新
git commit -m "docs: 更新API文档"

# 样式调整
git commit -m "style: 调整商品卡片样式"

# 重构代码
git commit -m "refactor: 优化订单查询逻辑"

🔍 常见问题

启动时数据库连接失败

解决方案:

  1. 检查MySQL服务是否启动
  2. 验证数据库连接配置是否正确
  3. 确认数据库用户权限
  4. 检查防火墙设置
# 检查MySQL服务状态
sudo systemctl status mysql

# 测试数据库连接
mysql -h localhost -u username -p
支付回调接收失败

解决方案:

  1. 确保回调URL是公网可访问的
  2. 检查支付宝配置是否正确
  3. 验证SSL证书配置
  4. 查看支付宝开发者后台日志
# 测试回调URL可访问性
curl -X POST https://your-domain.com/api/payment/alipay/notify
文件上传失败

解决方案:

  1. 检查腾讯云COS配置
  2. 验证存储桶权限设置
  3. 确认文件大小限制
  4. 检查网络连接
# 增加文件上传大小限制
spring:
  servlet:
    multipart:
      max-file-size: 10MB
      max-request-size: 50MB

🚀 性能优化建议

🔧 后端优化

// Redis缓存优化
@Cacheable(value = "products", key = "#categoryId")
public List<Product> getProductsByCategory(Long categoryId) {
    return productMapper.selectByCategory(categoryId);
}

// 数据库连接池优化
spring:
  datasource:
    hikari:
      maximum-pool-size: 20
      minimum-idle: 5
      connection-timeout: 30000

🌐 前端优化

// 路由懒加载
const routes = [
  {
    path: '/products',
    component: () => import('@/views/Products.vue')
  }
]

// 组件缓存
<keep-alive include="ProductList,UserProfile">
  <router-view />
</keep-alive>

🤝 贡献指南

我们欢迎所有形式的贡献!🎉

🌟 贡献方式

  • 🐛 问题反馈: 发现bug请提交Issue
  • 💡 功能建议: 有好想法请告诉我们
  • 📖 文档改进: 帮助完善文档
  • 🔧 代码贡献: 提交Pull Request

📋 贡献流程

  1. 🍴 Fork项目 - 点击右上角Fork按钮
  2. 🌿 创建分支 - git checkout -b feature/amazing-feature
  3. 💻 编写代码 - 遵循项目编码规范
  4. 测试验证 - 确保功能正常工作
  5. 📝 提交更改 - git commit -m 'feat: add amazing feature'
  6. 🚀 推送分支 - git push origin feature/amazing-feature
  7. 🔄 提交PR - 创建Pull Request

📏 编码规范

  • Java: 遵循阿里巴巴Java开发规范
  • Vue: 遵循Vue官方风格指南
  • 数据库: 遵循MySQL命名规范
  • 接口: 遵循RESTful API设计原则

📄 许可证

本项目基于 MIT License 开源协议。

MIT License

Copyright (c) 2024 SunnyFarm Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

📞 联系我们

项目地址 邮箱联系 手机号码

🙏 特别感谢

感谢所有为本项目做出贡献的开发者们!


如果这个项目对你有帮助,请给我们一个星标!

让新鲜农产品直达每个家庭 🌱


🌱 Built with ❤️ by SunnyFarm Team • 源码地址回到顶部
Description
No description provided
Readme 568 KiB
Languages
Vue 50.2%
Java 31.2%
PLpgSQL 8.4%
HTML 7.6%
JavaScript 2.4%
Other 0.2%