项目简介
本项目是基于 Node.js 构建的在线点餐系统,采用经典的 MVC(模型 - 视图 - 控制器)架构,结合 MySQL 数据库,具备用户管理、门店管理、菜品管理、订单管理、优惠券管理以及微信支付等功能,为用户提供便捷的点餐体验,为商家提供高效的管理工具。
项目的主要特性和功能
- 用户管理:提供用户注册、登录等功能,方便用户使用系统进行点餐操作。
- 门店管理:可对门店信息进行管理,如门店的基本信息维护等。
- 菜品管理:支持菜品的添加、查询等操作,商家可灵活管理菜品信息。
- 订单管理:用户能够创建订单,根据用户 ID 和订单状态查询订单及详情;后厨可根据订单状态查询所有用户订单及详情,并且用户和后厨均可修改订单状态。
- 优惠券管理:实现优惠券的发放和管理,用户可使用优惠券进行支付。
- 微信支付:集成微信支付功能,用户点击支付按钮后,系统按流程完成支付操作,支付完成后微信支付服务器会异步回调通知系统。
安装使用步骤
1. 数据库配置
- 安装
dotenv
包:在项目根目录下,通过命令npm install dotenv
进行安装。 - 创建
.env
文件:在项目根目录创建该文件,并添加数据库配置信息,示例如下:DB_NAME=your_database_name DB_USER=your_database_username DB_PASSWORD=your_database_password DB_HOST=your_database_host
- 修改
dbConfig.js
:修改该文件以使用dotenv
加载.env
文件中的环境变量。
2. Nginx 反代理配置
- 找到配置文件位置
/www/server/nginx/conf/nginx.conf
进行编辑。 - 配置 SSL 证书(HTTPS),示例配置如下: ```conf server { listen 80 ; server_name forestlamb.online www.forestlamb.online; # 或使用 localhost return 301 https://$server_name$request_uri; }
server { listen 443 ssl; server_name forestlamb.online www.forestlamb.online; # 或使用 localhost
root /home/www/forestlamb; # 指向网站的根目录
index index.html index.htm index.php;
ssl_certificate cert/forestlamb.online.pem; # 证书的文件名。
ssl_certificate_key cert/forestlamb.online.key; # 证书的密钥文件名。
ssl_session_timeout 5m;
ssl_ciphers
ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 使用该协议进行配置。
ssl_prefer_server_ciphers on;
……
}
- 配置反向代理,示例配置如下:
conf
location /public/ {
alias /home/www/public/;
}
location /restaurant { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }
location / { root /home/www/forestlamb; # 指定默认页面的根目录 index index.html; # 指定默认页面的文件名 try_files $uri $uri/ /index.html; # 优先尝试查找静态文件,否则返回默认页面 }
location ~ /.(?!well-known) {
deny all;
}
``
- 测试 Nginx 配置文件:在命令行运行
nginx -t检查配置文件语法。
- 重新加载 Nginx 配置:确认无误后,运行
sudo nginx -s reload` 使配置生效。
3. Redis 配置
- 添加 EPEL 仓库:运行
sudo yum install epel-release
。 - 安装 Redis:运行
sudo yum install redis
。 - 启动 Redis 服务:运行
sudo systemctl start redis
。 - 验证 Redis 是否正在运行:运行
redis-cli ping
,若返回PONG
则表示运行正常。 - 设置 Redis 开机自启:运行
sudo systemctl enable redis
。 - 可选:配置 Redis 安全设置,编辑
/etc/redis.conf
文件,设置密码后重启服务。
4. 项目运行
- 运行 Node.js 程序:打开终端,进入项目目录
cd /home/www/restaurant/
,运行node app.js &
。 - 若想让项目持续运行,可使用
pm2
管理: - 安装
pm2
:运行npm install pm2 -g
。 - 启动项目:运行
pm2 start app.js
。 - 查看运行的应用列表:运行
pm2 list
。 - 停止应用:运行
pm2 stop <app_name_or_id>
。 - 设置开机自启:运行
pm2 startup
。 - 查看应用日志:运行
pm2 logs
。
下载地址
点击下载 【提取码: 4003】【解压密码: www.makuang.net】