前端项目:基于Nodejs+vue开发实现酒店管理系统
Posted 编程指南针
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了前端项目:基于Nodejs+vue开发实现酒店管理系统相关的知识,希望对你有一定的参考价值。
作者主页:编程指南针
作者简介:Java领域优质创作者、CSDN博客专家 、掘金特邀作者、多年架构师设计经验、腾讯课堂常驻讲师
主要内容:Java项目、毕业设计、简历模板、学习资料、面试题库、技术互助
文末获取源码
项目编号:BS-QD-KS-002
一,项目简介
本项目使用纯前端技术开发实现一个酒店管理系统,前端采用VUE开发实现,后台通过NODEJS作为服务器开发实现,主要实现了酒店管理系统中的:房型管理、房间管理、顾客管理、订单管理等,用户可以注册并登陆后进行相应的管理操作。主要说明
- 前后端分离技术
- 前端使用vuejs,ElementUI,axios前后端通信,图标使用了ElementUI自带的图标还有font-awesome.css的图标库, 阿里的iconfont图标库也不错,这里没用。
- 后端使用了nodejs,nodejs采用了Express框架,orm采用的是Sequelize操作数据库(效率极高),restful风格的Api, 跨域是由后端解决的,采用的是nodejs的cors模块(比较方便)。
- 数据库采用了mysql5.2(建议大家换成最新的mysql版本)
- 使用jsonwebtoken验证用户调用api的权限,增加接口的安全性,防止恶意攻击接口,串改数据。
- 主要界面里面的图片主要使用的是网上的图片,免费而且美观。
二,环境介绍
语言环境:nodejs
数据库: mysql5.7
应用服务器:nodejs
开发工具:IDEA或vscode
开发技术:nodejs+vue+elementUI
三,系统展示
用户注册
用户登陆
房间管理
房型管理
订单管理
订单管理
四,核心代码展示
const Op = require('sequelize')//nodejs的sequelize模块
const express = require('express')//express框架
const admin = require('../crud/table/admin.js')//引入管理员信息表
const token = require('../comment/token.js')//引入token模块
const adminRouter = express.Router()//express路由
adminRouter.post('/register',(req,res) =>//管理员注册
const adminId, adminName, adminPassword = req.body;
admin.findOne(
where:
adminId:adminId
)
.then(data =>
if(data)
res.status(200).json(
msg:'该用户已经注册',
success:false
)
return new Promise(() =>)
else
return admin.create(
adminId, adminName, adminPassword
)
)
.then(data =>
res.status(200).json(
success:true,
msg:'管理员注册成功!',
admin:data.get()
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'内部服务器错误!'
)
)
)
adminRouter.get('/login',(req,res) =>//登录
const adminId, adminPassword = req.query;
let adminInfo;
admin.findOne(
where:
adminId
)
.then(data =>
if(data)
if(data.get().adminPassword==adminPassword)
adminInfo = data.get();
return token.setToken(data.get())
else
res.status(200).json(
success:false,
msg:'用户密码错误!'
);
return new Promise(() =>)
else
res.status(200).json(
success:false,
msg:'该用户还未注册!'
)
return new Promise(() =>)
)
.then(data =>
res.status(200).json(
success:true,
admin:adminInfo,
token:data,
msg:'登录成功!'
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'内部服务器出错!'
)
)
)
adminRouter.put('/update',(req,res) =>//修改管理员信息
const adminId, adminName, adminPassword, adminSex, adminAge = req.body;
admin.findOne(
where:
adminId,adminPassword
)
.then(data =>
if(data)
return admin.update(
adminName,adminSex,adminAge
,
where:
adminId,adminPassword
)
else
res.status(200).json(
success:false,
msg:'管理员账号或者密码错误!'
)
return new Promise(() =>)
)
.then(data =>
return admin.findOne(
where:
adminId,adminPassword
)
)
.then(data =>
res.status(200).json(
success:true,
msg:'管理员信息修改成功!',
admin:data.get()
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
adminRouter.delete('/del',(req,res) =>
const adminId = req.body || req.query;
admin.destroy(
where:
adminId
)
.then(data =>
res.status(200).json(
success:true,
msg:'删除成功!'
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'删除失败!'
)
)
)
module.exports = adminRouter;
const Op = require('sequelize')//nodejs的sequelize模块
const express = require('express')//express框架
const customer = require('../crud/table/customer.js')//引入用户表
const customerRouter = express.Router()//express路由
customerRouter.post('/add',(req,res) =>//用户注册
const customerIdCard, customerName, customerSex, customerPhoneNumber = req.body;
customer.findOne(
where:
customerIdCard
)
.then(data =>
if(data)
res.status(200).json(
success:false,
msg:'该用户已经注册!'
)
return new Promise(() =>)
else
return customer.create(
customerIdCard, customerName, customerSex, customerPhoneNumber
)
)
.then(data =>
res.status(200).json(
success:true,
msg:'用户信息录入成功!',
customer:data.get()
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'内部服务器错误!'
)
)
)
// customerRouter.get('/login',(req,res) =>//用户登录
// const customerIdCard, cust
// )
customerRouter.put('/update',(req,res) =>//用户基本信息修改
const customerIdCard, customerName, customerSex, customerPhoneNumber = req.body;
customer.findOne(
where:
customerIdCard:
[Op.eq]:customerIdCard
)
.then(data =>
if(data)
return customer.update(
customerName, customerSex, customerPhoneNumber
,
where:
customerIdCard:
[Op.eq]:customerIdCard
)
else
res.status(200).json(
success:false,
msg:'该用户还未注册!'
)
return new Promise(() =>)
)
.then(data =>
res.status(200).json(
success:true,
msg:'用户信息修改成功!',
customer:data.get()
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器出错!'
)
)
)
customerRouter.delete('/del',(req,res) =>//删除用户
const customerIdCard = req.body;
customer.destroy(
where:
customerIdCard
)
.then(data =>
res.status(200).json(
success:true,
msg:'用户删除成功!'
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
customerRouter.put('/updatevip',(req,res) =>//购买会员
const customerIdCard, level = req.body;
customer.findOne(
where:
customerIdCard
)
.then(data =>
if(data)
return customer.update(
level
,
where:
customerIdCard
)
else
res.status(200).json(
success:false,
msg:'该用户未注册!'
)
return new Promise(() =>)
)
.then(data =>
return customer.findOne(
where:
customerIdCard
)
)
.then(data =>
res.status(200).json(
success:true,
msg:'vip更改成功!',
customer:data.get()
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
customerRouter.put('/updatemoney',(req,res) =>//修改用户总消费金额
const customerIdCard, money = req.body;
customer.findOne(
where:
customerIdCard
)
.then(data =>
if(data)
let oldMoney = data.get().totalAmount;
let newMoney = oldMoney + money;
return customer.update(
totalAmount: newMoney
,
where:
customerIdCard
)
else
res.status(200).json(
success:false,
msg:'该用户为注册!'
)
)
.then(data =>
return customer.findOne(
where:
customerIdCard
)
)
.then(data =>
res.status(200).json(
success:true,
msg:'用户消费金额修改成功!'
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
customerRouter.get('/getAllCustomer',(req,res) =>//查询所有顾客
customer.findAndCountAll()
.then(data =>
res.status(200).json(
success:true,
msg:'顾客信息查询成功!',
customerList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器出错!'
)
)
)
customerRouter.get('/queryCustomer',(req,res) =>//模糊查询顾客信息
const queryName = req.query;
customer.findAndCountAll(
where:
customerName:
[Op.like]:'%'+queryName+'%'
)
.then(data =>
res.status(200).json(
success:true,
msg:'顾客信息查询成功!',
customerList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
.then(err =>
res.status(200).json(
success:false,
msg:'服务器出错!'
)
)
)
module.exports = customerRouter;
const express = require('express')//express框架
const Op = require('sequelize')//nodejs的sequelize模块
const order = require('../crud/table/myorder.js')//引入订单信息表
const customer = require('../crud/table/customer.js')//引入顾客信息表
const room = require('../crud/table/room.js')//引入房间信息表
order.hasOne(customer, sourceKey:'customerIdCard', foreignKey:'customerIdCard' )
order.hasOne(room, sourceKey:'roomNumber', foreignKey:'roomNumber' )
const orderRouter = express.Router()
orderRouter.post('/add',(req,res) =>//创建订单
console.log(req.body)
const orderNumber, orderStatus,customerIdCard,roomNumber,
checkInTime,checkOutTime,totalMoney,remarks
= req.body;
order.findOne(
where:
orderNumber
)
.then(data =>
if(data)
res.status(200).json(
success:false,
msg:'该订单已经存在!'
)
return new Promise(() =>)
else
return customer.findOne(
where:
customerIdCard
)
)
.then(data =>
if(data)
return room.update(
roomStatus:'已入住'
,
where:
roomNumber
)
else
res.status(200).json(
success:false,
msg:'该用户还未注册!'
);
return new Promise(() =>);
)
.then(data =>
return order.create(
orderNumber, orderStatus,customerIdCard,roomNumber,
checkInTime,checkOutTime,totalMoney,remarks
)
)
.then(data =>
res.status(200).json(
success:'true',
msg:'订单创建成功!'
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'内部服务器出错!'
)
)
)
orderRouter.delete('/del',(req,res) =>//删除订单
const orderNumber = req.body;
order.findOne(
where:
orderNumber
)
.then(data =>
if(data)
return order.destroy(
where:
orderNumber
)
else
res.status(200).json(
success:false,
msg:'该订单不存在!'
)
return new Promise(() =>)
)
.then(data =>
res.status(200).json(
success:true,
msg:'删除成功!'
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
orderRouter.put('/update',(req,res) =>//修改订单状态
const orderStatus, orderNumber,totalMoney,roomNumber = req.body;
order.findOne(
where:
orderNumber
)
.then(data =>
if(data)
return room.update(
roomStatus:'未入住'
,
where:
roomNumber
)
else
res.status(200).json(
success:false,
msg:'该订单不存在!'
)
return new Promise(() =>)
)
.then(data =>
return order.update(
orderStatus,totalMoney
,
where:
orderNumber
)
)
.then(data =>
return order.findOne(
where:
orderNumber
)
)
.then(data =>
res.status(200).json(
success:true,
msg:'订单修改成功!',
order:data.get()
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
orderRouter.get('/getAllOrder',(req,res) =>//查询所有订单
const pageSize, offset = req.query;
order.findAndCountAll(
limit:pageSize,
offset:offset,
include:[
model:customer,
foreignKey:'customerIdCard',
attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
,
model:room,
foreignKey:'roomNumber',
attributes:['type','remarks']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'所有订单查询成功!',
orderList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
orderRouter.get('/getAllNotPayOrder',(req,res) =>//查询所有未支付的订单
const pageSize, offset = req.query;
order.findAndCountAll(
limit:pageSize,
offset:offset,
where:
orderStatus:
[Op.eq]:'未支付'
,
include:[
model:customer,
foreignKey:'customerIdCard',
attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
,
model:room,
foreignKey:'roomNumber',
attributes:['type']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'未支付订单查询成功!',
orderList:data.rows.map(item =>
return item.get()
),
count:data.count,
pageSize:pageSize,
offset:offset
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
orderRouter.get('/getAllPayOrder',(req,res) =>//查询所有已支付的订单
const pageSize, offset = req.query;
order.findAndCountAll(
limit:pageSize,
offset:offset,
where:
orderStatus:
[Op.eq]:'已支付'
,
include:[
model:customer,
foreignKey:'customerIdCard',
attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
,
model:room,
foreignKey:'roomNumber',
attributes:['type']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'未支付订单查询成功!',
orderList:data.rows.map(item =>
return item.get()
),
count:data.count,
pageSize:pageSize,
offset:offset
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
orderRouter.get('/getStatusOrder',(req,res) =>//查询所有该状态的订单
const pageSize, offset, orderStatus = req.query;
order.findAndCountAll(
limit:pageSize,
offset:offset,
where:
orderStatus:
[Op.eq]:orderStatus
,
include:[
model:customer,
foreignKey:'customerIdCard',
attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
,
model:room,
foreignKey:'roomNumber',
attributes:['type']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'状态订单查询成功!',
orderList:data.rows.map(item =>
return item.get()
),
count:data.count,
pageSize:pageSize,
offset:offset
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
module.exports = orderRouter;
const express = require('express')//express框架
const Op = require('sequelize')//nodejs的sequelize模块
const room = require('../crud/table/room.js')//引入放假信息表
const roomType = require('../crud/table/roomType.js')//引入所有房间类型表
room.hasOne(roomType, sourceKey:'type',foreignKey:'type')//每个房间都有一个房间类型
const roomRouter = express.Router()
roomRouter.post('/add',(req,res) =>//添加房间
const roomNumber, type, roomStatus, remarks = req.body;
room.findOne(
where:
roomNumber
)
.then(data =>
if(data)
res.status(200).json(
success:false,
msg:'该房间已经存在!'
)
return new Promise(() =>)
else
return room.create(
roomNumber, type, roomStatus, remarks
)
)
.then(data =>
return room.findOne(
where:
roomNumber
,
include:[
model:roomType,
foreignKey:'type',
attributes:['price','url']
]
)
)
.then(data =>
res.status(200).json(
success:true,
msg:'房间添加成功!',
room:data.get()
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
roomRouter.delete('/del',(req,res) =>
const roomNumber = req.body;
room.findOne(
where:
roomNumber
)
.then(data =>
if(data)
return room.destroy(
where:
roomNumber
)
else
res.status(200).json(
success:false,
msg:'房间删除失败!'
)
return new Promise(() =>)
)
.then(data =>
res.status(200).json(
success:true,
msg:'该房间删除成功!'
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
roomRouter.put('/update',(req,res) =>//修改房间信息
const roomNumber, type, roomStatus,remarks = req.body;
room.findOne(
where:
roomNumber
)
.then(data =>
if(data)
return room.update(
type, roomStatus,remarks
,
where:
roomNumber
)
else
res.status(200).json(
success:false,
msg:'该房间不存在!'
)
return new Promise(() =>)
)
.then(data =>
return room.findOne(
where:
roomNumber
)
)
.then(data =>
res.status(200).json(
success:true,
msg:'房间信息修改成功!',
room:data.get()
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误'
)
)
)
roomRouter.get('/getAllRoom',(req,res) =>//获取所有房间信息
const pageSize, offset = req.query;
room.findAndCountAll(
limit:pageSize,
offset:offset
)
.then(data =>
let roomList = data.rows.map(item =>
return item.get()
)
res.status(200).json(
success:true,
msg:'房间信息查询成功!',
roomList:roomList,
count:data.count
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
roomRouter.get('/getOneRoom',(req,res) =>//获取某个房间号的房间信息
const roomNumber = req.query;
room.findOne(
where:
roomNumber
)
.then(data =>
if(data)
res.status(200).json(
success:true,
msg:'房间查询成功!',
room:data.get()
)
else
res.status(200).json(
success:false,
msg:'未查询到该房间信息'
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
roomRouter.get('/getNotInRoom',(req,res) =>//获取未入住房间信息
const pageSize, offset = req.query;
room.findAndCountAll(
limit:pageSize,
offset:offset,
where:
roomStatus:
[Op.eq]:'未入住'
)
.then(data =>
res.status(200).json(
success:true,
msg:'未入住房间查询成功!',
roomList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
roomRouter.get('/getInRoom',(req,res) =>//查询已入住房间信息
const pageSize, offset = req.query;
room.findAndCountAll(
limit:pageSize,
offset:offset,
where:
roomStatus:
[Op.eq]:'已入住'
)
.then(data =>
res.status(200).json(
success:true,
msg:'已入住房间查询成功!',
roomList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
roomRouter.get('/getAllRoomPrice',(req,res) =>//查询所有的房间以及价格
const pageSize, offset = req.query;
room.findAndCountAll(
limit:pageSize,
offset:offset,
include:[
model:roomType,
foreignKey:'type',
attributes:['price','url']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'房间信息查询成功!',
roomList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器内部错误!'
)
)
)
roomRouter.get('/getAllNotINRoomPrice',(req,res) =>//获取所有未入住的房间信息
const pageSize, offset = req.query;
room.findAndCountAll(
limit:pageSize,
offset:offset,
where:
roomStatus:
[Op.eq]:'未入住'
,
include:[
model:roomType,
foreignKey:'type',
attributes:['price','url']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'房间信息查询成功!',
roomList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
)
roomRouter.get('/getAllINRoomPrice',(req,res) =>//获取所有已入住的房间信息
const pageSize, offset = req.query;
room.findAndCountAll(
limit:pageSize,
offset:offset,
where:
roomStatus:
[Op.eq]:'已入住'
,
include:[
model:roomType,
foreignKey:'type',
attributes:['price','url']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'房间信息查询成功!',
roomList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
)
roomRouter.get('/getAllRoomTypePrice',(req,res) =>
const pageSize, offset, type = req.query;
room.findAndCountAll(
where:
type:
[Op.eq]:type
,
include:[
model:roomType,
foreignKey:'type',
attributes:['price','url']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'房型查询成功!',
roomList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
.catch(err =>
res.status(200).json(
success:false,
msg:'服务器出错!'
)
)
)
roomRouter.get('/getAllStatusRoom',(req,res) =>//获取所有该状态的房间信息
const pageSize, offset, roomStatus = req.query;
room.findAndCountAll(
limit:pageSize,
offset:offset,
where:
roomStatus:
[Op.eq]:roomStatus
,
include:[
model:roomType,
foreignKey:'type',
attributes:['price','url']
]
)
.then(data =>
res.status(200).json(
success:true,
msg:'房间信息查询成功!',
roomList:data.rows.map(item =>
return item.get()
),
count:data.count
)
)
)
module.exports = roomRouter
五,项目总结
以上是关于前端项目:基于Nodejs+vue开发实现酒店管理系统的主要内容,如果未能解决你的问题,请参考以下文章
基于nodejs电影售票后台管理的设计和实现.zip(论文+源码+ppt文档+视频录制)