• 基于Nodejs+vue开发实现酒店管理系统


    作者主页:编程千纸鹤

    作者简介:Java、前端、Pythone开发多年,做过高程,项目经理,架构师

    主要内容:Java项目开发、毕业设计开发、面试技术整理、最新技术分享

    项目编号:BS-QD-KS-002

    一,项目简介

    本项目使用纯前端技术开发实现一个酒店管理系统,前端采用VUE开发实现,后台通过NODEJS作为服务器开发实现,主要实现了酒店管理系统中的:房型管理、房间管理、顾客管理、订单管理等,用户可以注册并登陆后进行相应的管理操作。主要说明

    1. 前后端分离技术
    2. 前端使用vuejs,ElementUI,axios前后端通信,图标使用了ElementUI自带的图标还有font-awesome.css的图标库, 阿里的iconfont图标库也不错,这里没用。
    3. 后端使用了nodejs,nodejs采用了Express框架,orm采用的是Sequelize操作数据库(效率极高),restful风格的Api, 跨域是由后端解决的,采用的是nodejs的cors模块(比较方便)。
    4. 数据库采用了mysql5.2(建议大家换成最新的mysql版本)
    5. 使用jsonwebtoken验证用户调用api的权限,增加接口的安全性,防止恶意攻击接口,串改数据。
    6. 主要界面里面的图片主要使用的是网上的图片,免费而且美观。

    二,环境介绍

    语言环境:nodejs

    数据库: mysql5.7

    应用服务器:nodejs

    开发工具:IDEA或vscode

    开发技术:nodejs+vue+elementUI

    三,系统展示

    用户注册

    用户登陆

    房间管理

    房型管理

    订单管理

    订单管理

    四,核心代码展示

    1. const { Op } = require('sequelize')//nodejs的sequelize模块
    2. const express = require('express')//express框架
    3. const admin = require('../crud/table/admin.js')//引入管理员信息表
    4. const token = require('../comment/token.js')//引入token模块
    5. const adminRouter = express.Router()//express路由
    6. adminRouter.post('/register',(req,res) =>{//管理员注册
    7. const { adminId, adminName, adminPassword } = req.body;
    8. admin.findOne({
    9. where:{
    10. adminId:adminId
    11. }
    12. })
    13. .then(data =>{
    14. if(data){
    15. res.status(200).json({
    16. msg:'该用户已经注册',
    17. success:false
    18. })
    19. return new Promise(() =>{})
    20. }else{
    21. return admin.create({
    22. adminId, adminName, adminPassword
    23. })
    24. }
    25. })
    26. .then(data =>{
    27. res.status(200).json({
    28. success:true,
    29. msg:'管理员注册成功!',
    30. admin:data.get()
    31. })
    32. })
    33. .catch(err =>{
    34. res.status(200).json({
    35. success:false,
    36. msg:'内部服务器错误!'
    37. })
    38. })
    39. })
    40. adminRouter.get('/login',(req,res) =>{//登录
    41. const { adminId, adminPassword } = req.query;
    42. let adminInfo;
    43. admin.findOne({
    44. where:{
    45. adminId
    46. }
    47. })
    48. .then(data =>{
    49. if(data){
    50. if(data.get().adminPassword==adminPassword){
    51. adminInfo = data.get();
    52. return token.setToken(data.get())
    53. }else{
    54. res.status(200).json({
    55. success:false,
    56. msg:'用户密码错误!'
    57. });
    58. return new Promise(() =>{})
    59. }
    60. }else{
    61. res.status(200).json({
    62. success:false,
    63. msg:'该用户还未注册!'
    64. })
    65. return new Promise(() =>{})
    66. }
    67. })
    68. .then(data =>{
    69. res.status(200).json({
    70. success:true,
    71. admin:adminInfo,
    72. token:data,
    73. msg:'登录成功!'
    74. })
    75. })
    76. .catch(err =>{
    77. res.status(200).json({
    78. success:false,
    79. msg:'内部服务器出错!'
    80. })
    81. })
    82. })
    83. adminRouter.put('/update',(req,res) =>{//修改管理员信息
    84. const { adminId, adminName, adminPassword, adminSex, adminAge } = req.body;
    85. admin.findOne({
    86. where:{
    87. adminId,adminPassword
    88. }
    89. })
    90. .then(data =>{
    91. if(data){
    92. return admin.update({
    93. adminName,adminSex,adminAge
    94. },{
    95. where:{
    96. adminId,adminPassword
    97. }
    98. })
    99. }else{
    100. res.status(200).json({
    101. success:false,
    102. msg:'管理员账号或者密码错误!'
    103. })
    104. return new Promise(() =>{})
    105. }
    106. })
    107. .then(data =>{
    108. return admin.findOne({
    109. where:{
    110. adminId,adminPassword
    111. }
    112. })
    113. })
    114. .then(data =>{
    115. res.status(200).json({
    116. success:true,
    117. msg:'管理员信息修改成功!',
    118. admin:data.get()
    119. })
    120. })
    121. .catch(err =>{
    122. res.status(200).json({
    123. success:false,
    124. msg:'服务器内部错误!'
    125. })
    126. })
    127. })
    128. adminRouter.delete('/del',(req,res) =>{
    129. const { adminId } = req.body || req.query;
    130. admin.destroy({
    131. where:{
    132. adminId
    133. }
    134. })
    135. .then(data =>{
    136. res.status(200).json({
    137. success:true,
    138. msg:'删除成功!'
    139. })
    140. })
    141. .catch(err =>{
    142. res.status(200).json({
    143. success:false,
    144. msg:'删除失败!'
    145. })
    146. })
    147. })
    148. module.exports = adminRouter;

    1. const { Op } = require('sequelize')//nodejs的sequelize模块
    2. const express = require('express')//express框架
    3. const customer = require('../crud/table/customer.js')//引入用户表
    4. const customerRouter = express.Router()//express路由
    5. customerRouter.post('/add',(req,res) =>{//用户注册
    6. const { customerIdCard, customerName, customerSex, customerPhoneNumber } = req.body;
    7. customer.findOne({
    8. where:{
    9. customerIdCard
    10. }
    11. })
    12. .then(data =>{
    13. if(data){
    14. res.status(200).json({
    15. success:false,
    16. msg:'该用户已经注册!'
    17. })
    18. return new Promise(() =>{})
    19. }else{
    20. return customer.create({
    21. customerIdCard, customerName, customerSex, customerPhoneNumber
    22. })
    23. }
    24. })
    25. .then(data =>{
    26. res.status(200).json({
    27. success:true,
    28. msg:'用户信息录入成功!',
    29. customer:data.get()
    30. })
    31. })
    32. .catch(err =>{
    33. res.status(200).json({
    34. success:false,
    35. msg:'内部服务器错误!'
    36. })
    37. })
    38. })
    39. // customerRouter.get('/login',(req,res) =>{//用户登录
    40. // const { customerIdCard, cust}
    41. // })
    42. customerRouter.put('/update',(req,res) =>{//用户基本信息修改
    43. const { customerIdCard, customerName, customerSex, customerPhoneNumber } = req.body;
    44. customer.findOne({
    45. where:{
    46. customerIdCard:{
    47. [Op.eq]:customerIdCard
    48. }
    49. }
    50. })
    51. .then(data =>{
    52. if(data){
    53. return customer.update({
    54. customerName, customerSex, customerPhoneNumber
    55. },{
    56. where:{
    57. customerIdCard:{
    58. [Op.eq]:customerIdCard
    59. }
    60. }
    61. })
    62. }else{
    63. res.status(200).json({
    64. success:false,
    65. msg:'该用户还未注册!'
    66. })
    67. return new Promise(() =>{})
    68. }
    69. })
    70. .then(data =>{
    71. res.status(200).json({
    72. success:true,
    73. msg:'用户信息修改成功!',
    74. customer:data.get()
    75. })
    76. })
    77. .catch(err =>{
    78. res.status(200).json({
    79. success:false,
    80. msg:'服务器出错!'
    81. })
    82. })
    83. })
    84. customerRouter.delete('/del',(req,res) =>{//删除用户
    85. const { customerIdCard } = req.body;
    86. customer.destroy({
    87. where:{
    88. customerIdCard
    89. }
    90. })
    91. .then(data =>{
    92. res.status(200).json({
    93. success:true,
    94. msg:'用户删除成功!'
    95. })
    96. })
    97. .catch(err =>{
    98. res.status(200).json({
    99. success:false,
    100. msg:'服务器内部错误!'
    101. })
    102. })
    103. })
    104. customerRouter.put('/updatevip',(req,res) =>{//购买会员
    105. const { customerIdCard, level } = req.body;
    106. customer.findOne({
    107. where:{
    108. customerIdCard
    109. }
    110. })
    111. .then(data =>{
    112. if(data){
    113. return customer.update({
    114. level
    115. },{
    116. where:{
    117. customerIdCard
    118. }
    119. })
    120. }else{
    121. res.status(200).json({
    122. success:false,
    123. msg:'该用户未注册!'
    124. })
    125. return new Promise(() =>{})
    126. }
    127. })
    128. .then(data =>{
    129. return customer.findOne({
    130. where:{
    131. customerIdCard
    132. }
    133. })
    134. })
    135. .then(data =>{
    136. res.status(200).json({
    137. success:true,
    138. msg:'vip更改成功!',
    139. customer:data.get()
    140. })
    141. })
    142. .catch(err =>{
    143. res.status(200).json({
    144. success:false,
    145. msg:'服务器内部错误!'
    146. })
    147. })
    148. })
    149. customerRouter.put('/updatemoney',(req,res) =>{//修改用户总消费金额
    150. const { customerIdCard, money} = req.body;
    151. customer.findOne({
    152. where:{
    153. customerIdCard
    154. }
    155. })
    156. .then(data =>{
    157. if(data){
    158. let oldMoney = data.get().totalAmount;
    159. let newMoney = oldMoney + money;
    160. return customer.update({
    161. totalAmount: newMoney
    162. },{
    163. where:{
    164. customerIdCard
    165. }
    166. })
    167. }else{
    168. res.status(200).json({
    169. success:false,
    170. msg:'该用户为注册!'
    171. })
    172. }
    173. })
    174. .then(data =>{
    175. return customer.findOne({
    176. where:{
    177. customerIdCard
    178. }
    179. })
    180. })
    181. .then(data =>{
    182. res.status(200).json({
    183. success:true,
    184. msg:'用户消费金额修改成功!'
    185. })
    186. })
    187. .catch(err =>{
    188. res.status(200).json({
    189. success:false,
    190. msg:'服务器内部错误!'
    191. })
    192. })
    193. })
    194. customerRouter.get('/getAllCustomer',(req,res) =>{//查询所有顾客
    195. customer.findAndCountAll()
    196. .then(data =>{
    197. res.status(200).json({
    198. success:true,
    199. msg:'顾客信息查询成功!',
    200. customerList:data.rows.map(item =>{
    201. return item.get()
    202. }),
    203. count:data.count
    204. })
    205. })
    206. .catch(err =>{
    207. res.status(200).json({
    208. success:false,
    209. msg:'服务器出错!'
    210. })
    211. })
    212. })
    213. customerRouter.get('/queryCustomer',(req,res) =>{//模糊查询顾客信息
    214. const { queryName } = req.query;
    215. customer.findAndCountAll({
    216. where:{
    217. customerName:{
    218. [Op.like]:'%'+queryName+'%'
    219. }
    220. }
    221. })
    222. .then(data =>{
    223. res.status(200).json({
    224. success:true,
    225. msg:'顾客信息查询成功!',
    226. customerList:data.rows.map(item =>{
    227. return item.get()
    228. }),
    229. count:data.count
    230. })
    231. })
    232. .then(err =>{
    233. res.status(200).json({
    234. success:false,
    235. msg:'服务器出错!'
    236. })
    237. })
    238. })
    239. module.exports = customerRouter;
    1. const express = require('express')//express框架
    2. const { Op } = require('sequelize')//nodejs的sequelize模块
    3. const order = require('../crud/table/myorder.js')//引入订单信息表
    4. const customer = require('../crud/table/customer.js')//引入顾客信息表
    5. const room = require('../crud/table/room.js')//引入房间信息表
    6. order.hasOne(customer,{ sourceKey:'customerIdCard', foreignKey:'customerIdCard' })
    7. order.hasOne(room,{ sourceKey:'roomNumber', foreignKey:'roomNumber' })
    8. const orderRouter = express.Router()
    9. orderRouter.post('/add',(req,res) =>{//创建订单
    10. console.log(req.body)
    11. const { orderNumber, orderStatus,customerIdCard,roomNumber,
    12. checkInTime,checkOutTime,totalMoney,remarks
    13. } = req.body;
    14. order.findOne({
    15. where:{
    16. orderNumber
    17. }
    18. })
    19. .then(data =>{
    20. if(data){
    21. res.status(200).json({
    22. success:false,
    23. msg:'该订单已经存在!'
    24. })
    25. return new Promise(() =>{})
    26. }else{
    27. return customer.findOne({
    28. where:{
    29. customerIdCard
    30. }
    31. })
    32. }
    33. })
    34. .then(data =>{
    35. if(data){
    36. return room.update({
    37. roomStatus:'已入住'
    38. },{
    39. where:{
    40. roomNumber
    41. }
    42. })
    43. }else{
    44. res.status(200).json({
    45. success:false,
    46. msg:'该用户还未注册!'
    47. });
    48. return new Promise(() =>{});
    49. }
    50. })
    51. .then(data =>{
    52. return order.create({
    53. orderNumber, orderStatus,customerIdCard,roomNumber,
    54. checkInTime,checkOutTime,totalMoney,remarks
    55. })
    56. })
    57. .then(data =>{
    58. res.status(200).json({
    59. success:'true',
    60. msg:'订单创建成功!'
    61. })
    62. })
    63. .catch(err =>{
    64. res.status(200).json({
    65. success:false,
    66. msg:'内部服务器出错!'
    67. })
    68. })
    69. })
    70. orderRouter.delete('/del',(req,res) =>{//删除订单
    71. const { orderNumber } = req.body;
    72. order.findOne({
    73. where:{
    74. orderNumber
    75. }
    76. })
    77. .then(data =>{
    78. if(data){
    79. return order.destroy({
    80. where:{
    81. orderNumber
    82. }
    83. })
    84. }else{
    85. res.status(200).json({
    86. success:false,
    87. msg:'该订单不存在!'
    88. })
    89. return new Promise(() =>{})
    90. }
    91. })
    92. .then(data =>{
    93. res.status(200).json({
    94. success:true,
    95. msg:'删除成功!'
    96. })
    97. })
    98. .catch(err =>{
    99. res.status(200).json({
    100. success:false,
    101. msg:'服务器内部错误!'
    102. })
    103. })
    104. })
    105. orderRouter.put('/update',(req,res) =>{//修改订单状态
    106. const { orderStatus, orderNumber,totalMoney,roomNumber } = req.body;
    107. order.findOne({
    108. where:{
    109. orderNumber
    110. }
    111. })
    112. .then(data =>{
    113. if(data){
    114. return room.update({
    115. roomStatus:'未入住'
    116. },{
    117. where:{
    118. roomNumber
    119. }
    120. })
    121. }else{
    122. res.status(200).json({
    123. success:false,
    124. msg:'该订单不存在!'
    125. })
    126. return new Promise(() =>{})
    127. }
    128. })
    129. .then(data =>{
    130. return order.update({
    131. orderStatus,totalMoney
    132. },{
    133. where:{
    134. orderNumber
    135. }
    136. })
    137. })
    138. .then(data =>{
    139. return order.findOne({
    140. where:{
    141. orderNumber
    142. }
    143. })
    144. })
    145. .then(data =>{
    146. res.status(200).json({
    147. success:true,
    148. msg:'订单修改成功!',
    149. order:data.get()
    150. })
    151. })
    152. .catch(err =>{
    153. res.status(200).json({
    154. success:false,
    155. msg:'服务器内部错误!'
    156. })
    157. })
    158. })
    159. orderRouter.get('/getAllOrder',(req,res) =>{//查询所有订单
    160. const { pageSize, offset } = req.query;
    161. order.findAndCountAll({
    162. limit:pageSize,
    163. offset:offset,
    164. include:[
    165. {
    166. model:customer,
    167. foreignKey:'customerIdCard',
    168. attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
    169. },
    170. {
    171. model:room,
    172. foreignKey:'roomNumber',
    173. attributes:['type','remarks']
    174. }
    175. ]
    176. })
    177. .then(data =>{
    178. res.status(200).json({
    179. success:true,
    180. msg:'所有订单查询成功!',
    181. orderList:data.rows.map(item =>{
    182. return item.get()
    183. }),
    184. count:data.count
    185. })
    186. })
    187. .catch(err =>{
    188. res.status(200).json({
    189. success:false,
    190. msg:'服务器内部错误!'
    191. })
    192. })
    193. })
    194. orderRouter.get('/getAllNotPayOrder',(req,res) =>{//查询所有未支付的订单
    195. const { pageSize, offset } = req.query;
    196. order.findAndCountAll({
    197. limit:pageSize,
    198. offset:offset,
    199. where:{
    200. orderStatus:{
    201. [Op.eq]:'未支付'
    202. }
    203. },
    204. include:[
    205. {
    206. model:customer,
    207. foreignKey:'customerIdCard',
    208. attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
    209. },
    210. {
    211. model:room,
    212. foreignKey:'roomNumber',
    213. attributes:['type']
    214. }
    215. ]
    216. })
    217. .then(data =>{
    218. res.status(200).json({
    219. success:true,
    220. msg:'未支付订单查询成功!',
    221. orderList:data.rows.map(item =>{
    222. return item.get()
    223. }),
    224. count:data.count,
    225. pageSize:pageSize,
    226. offset:offset
    227. })
    228. })
    229. .catch(err =>{
    230. res.status(200).json({
    231. success:false,
    232. msg:'服务器内部错误!'
    233. })
    234. })
    235. })
    236. orderRouter.get('/getAllPayOrder',(req,res) =>{//查询所有已支付的订单
    237. const { pageSize, offset } = req.query;
    238. order.findAndCountAll({
    239. limit:pageSize,
    240. offset:offset,
    241. where:{
    242. orderStatus:{
    243. [Op.eq]:'已支付'
    244. }
    245. },
    246. include:[
    247. {
    248. model:customer,
    249. foreignKey:'customerIdCard',
    250. attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
    251. },
    252. {
    253. model:room,
    254. foreignKey:'roomNumber',
    255. attributes:['type']
    256. }
    257. ]
    258. })
    259. .then(data =>{
    260. res.status(200).json({
    261. success:true,
    262. msg:'未支付订单查询成功!',
    263. orderList:data.rows.map(item =>{
    264. return item.get()
    265. }),
    266. count:data.count,
    267. pageSize:pageSize,
    268. offset:offset
    269. })
    270. })
    271. .catch(err =>{
    272. res.status(200).json({
    273. success:false,
    274. msg:'服务器内部错误!'
    275. })
    276. })
    277. })
    278. orderRouter.get('/getStatusOrder',(req,res) =>{//查询所有该状态的订单
    279. const { pageSize, offset, orderStatus } = req.query;
    280. order.findAndCountAll({
    281. limit:pageSize,
    282. offset:offset,
    283. where:{
    284. orderStatus:{
    285. [Op.eq]:orderStatus
    286. }
    287. },
    288. include:[
    289. {
    290. model:customer,
    291. foreignKey:'customerIdCard',
    292. attributes:['customerName','customerSex','customerVipLevel','customerPhoneNumber','totalAmount']
    293. },
    294. {
    295. model:room,
    296. foreignKey:'roomNumber',
    297. attributes:['type']
    298. }
    299. ]
    300. })
    301. .then(data =>{
    302. res.status(200).json({
    303. success:true,
    304. msg:'状态订单查询成功!',
    305. orderList:data.rows.map(item =>{
    306. return item.get()
    307. }),
    308. count:data.count,
    309. pageSize:pageSize,
    310. offset:offset
    311. })
    312. })
    313. .catch(err =>{
    314. res.status(200).json({
    315. success:false,
    316. msg:'服务器内部错误!'
    317. })
    318. })
    319. })
    320. module.exports = orderRouter;
    1. const express = require('express')//express框架
    2. const { Op } = require('sequelize')//nodejs的sequelize模块
    3. const room = require('../crud/table/room.js')//引入放假信息表
    4. const roomType = require('../crud/table/roomType.js')//引入所有房间类型表
    5. room.hasOne(roomType,{ sourceKey:'type',foreignKey:'type'})//每个房间都有一个房间类型
    6. const roomRouter = express.Router()
    7. roomRouter.post('/add',(req,res) =>{//添加房间
    8. const { roomNumber, type, roomStatus, remarks } = req.body;
    9. room.findOne({
    10. where:{
    11. roomNumber
    12. }
    13. })
    14. .then(data =>{
    15. if(data){
    16. res.status(200).json({
    17. success:false,
    18. msg:'该房间已经存在!'
    19. })
    20. return new Promise(() =>{})
    21. }else{
    22. return room.create({
    23. roomNumber, type, roomStatus, remarks
    24. })
    25. }
    26. })
    27. .then(data =>{
    28. return room.findOne({
    29. where:{
    30. roomNumber
    31. },
    32. include:[{
    33. model:roomType,
    34. foreignKey:'type',
    35. attributes:['price','url']
    36. }]
    37. })
    38. })
    39. .then(data =>{
    40. res.status(200).json({
    41. success:true,
    42. msg:'房间添加成功!',
    43. room:data.get()
    44. })
    45. })
    46. .catch(err =>{
    47. res.status(200).json({
    48. success:false,
    49. msg:'服务器内部错误!'
    50. })
    51. })
    52. })
    53. roomRouter.delete('/del',(req,res) =>{
    54. const { roomNumber } = req.body;
    55. room.findOne({
    56. where:{
    57. roomNumber
    58. }
    59. })
    60. .then(data =>{
    61. if(data){
    62. return room.destroy({
    63. where:{
    64. roomNumber
    65. }
    66. })
    67. }else{
    68. res.status(200).json({
    69. success:false,
    70. msg:'房间删除失败!'
    71. })
    72. return new Promise(() =>{})
    73. }
    74. })
    75. .then(data =>{
    76. res.status(200).json({
    77. success:true,
    78. msg:'该房间删除成功!'
    79. })
    80. })
    81. .catch(err =>{
    82. res.status(200).json({
    83. success:false,
    84. msg:'服务器内部错误!'
    85. })
    86. })
    87. })
    88. roomRouter.put('/update',(req,res) =>{//修改房间信息
    89. const { roomNumber, type, roomStatus,remarks } = req.body;
    90. room.findOne({
    91. where:{
    92. roomNumber
    93. }
    94. })
    95. .then(data =>{
    96. if(data){
    97. return room.update({
    98. type, roomStatus,remarks
    99. },{
    100. where:{
    101. roomNumber
    102. }
    103. })
    104. }else{
    105. res.status(200).json({
    106. success:false,
    107. msg:'该房间不存在!'
    108. })
    109. return new Promise(() =>{})
    110. }
    111. })
    112. .then(data =>{
    113. return room.findOne({
    114. where:{
    115. roomNumber
    116. }
    117. })
    118. })
    119. .then(data =>{
    120. res.status(200).json({
    121. success:true,
    122. msg:'房间信息修改成功!',
    123. room:data.get()
    124. })
    125. })
    126. .catch(err =>{
    127. res.status(200).json({
    128. success:false,
    129. msg:'服务器内部错误'
    130. })
    131. })
    132. })
    133. roomRouter.get('/getAllRoom',(req,res) =>{//获取所有房间信息
    134. const { pageSize, offset } = req.query;
    135. room.findAndCountAll({
    136. limit:pageSize,
    137. offset:offset
    138. })
    139. .then(data =>{
    140. let roomList = data.rows.map(item =>{
    141. return item.get()
    142. })
    143. res.status(200).json({
    144. success:true,
    145. msg:'房间信息查询成功!',
    146. roomList:roomList,
    147. count:data.count
    148. })
    149. })
    150. .catch(err =>{
    151. res.status(200).json({
    152. success:false,
    153. msg:'服务器内部错误!'
    154. })
    155. })
    156. })
    157. roomRouter.get('/getOneRoom',(req,res) =>{//获取某个房间号的房间信息
    158. const { roomNumber } = req.query;
    159. room.findOne({
    160. where:{
    161. roomNumber
    162. }
    163. })
    164. .then(data =>{
    165. if(data){
    166. res.status(200).json({
    167. success:true,
    168. msg:'房间查询成功!',
    169. room:data.get()
    170. })
    171. }else{
    172. res.status(200).json({
    173. success:false,
    174. msg:'未查询到该房间信息'
    175. })
    176. }
    177. })
    178. .catch(err =>{
    179. res.status(200).json({
    180. success:false,
    181. msg:'服务器内部错误!'
    182. })
    183. })
    184. })
    185. roomRouter.get('/getNotInRoom',(req,res) =>{//获取未入住房间信息
    186. const { pageSize, offset } = req.query;
    187. room.findAndCountAll({
    188. limit:pageSize,
    189. offset:offset,
    190. where:{
    191. roomStatus:{
    192. [Op.eq]:'未入住'
    193. }
    194. }
    195. })
    196. .then(data =>{
    197. res.status(200).json({
    198. success:true,
    199. msg:'未入住房间查询成功!',
    200. roomList:data.rows.map(item =>{
    201. return item.get()
    202. }),
    203. count:data.count
    204. })
    205. })
    206. .catch(err =>{
    207. res.status(200).json({
    208. success:false,
    209. msg:'服务器内部错误!'
    210. })
    211. })
    212. })
    213. roomRouter.get('/getInRoom',(req,res) =>{//查询已入住房间信息
    214. const { pageSize, offset } = req.query;
    215. room.findAndCountAll({
    216. limit:pageSize,
    217. offset:offset,
    218. where:{
    219. roomStatus:{
    220. [Op.eq]:'已入住'
    221. }
    222. }
    223. })
    224. .then(data =>{
    225. res.status(200).json({
    226. success:true,
    227. msg:'已入住房间查询成功!',
    228. roomList:data.rows.map(item =>{
    229. return item.get()
    230. }),
    231. count:data.count
    232. })
    233. })
    234. .catch(err =>{
    235. res.status(200).json({
    236. success:false,
    237. msg:'服务器内部错误!'
    238. })
    239. })
    240. })
    241. roomRouter.get('/getAllRoomPrice',(req,res) =>{//查询所有的房间以及价格
    242. const { pageSize, offset } = req.query;
    243. room.findAndCountAll({
    244. limit:pageSize,
    245. offset:offset,
    246. include:[{
    247. model:roomType,
    248. foreignKey:'type',
    249. attributes:['price','url']
    250. }]
    251. })
    252. .then(data =>{
    253. res.status(200).json({
    254. success:true,
    255. msg:'房间信息查询成功!',
    256. roomList:data.rows.map(item =>{
    257. return item.get()
    258. }),
    259. count:data.count
    260. })
    261. })
    262. .catch(err =>{
    263. res.status(200).json({
    264. success:false,
    265. msg:'服务器内部错误!'
    266. })
    267. })
    268. })
    269. roomRouter.get('/getAllNotINRoomPrice',(req,res) =>{//获取所有未入住的房间信息
    270. const { pageSize, offset } = req.query;
    271. room.findAndCountAll({
    272. limit:pageSize,
    273. offset:offset,
    274. where:{
    275. roomStatus:{
    276. [Op.eq]:'未入住'
    277. }
    278. },
    279. include:[{
    280. model:roomType,
    281. foreignKey:'type',
    282. attributes:['price','url']
    283. }]
    284. })
    285. .then(data =>{
    286. res.status(200).json({
    287. success:true,
    288. msg:'房间信息查询成功!',
    289. roomList:data.rows.map(item =>{
    290. return item.get()
    291. }),
    292. count:data.count
    293. })
    294. })
    295. })
    296. roomRouter.get('/getAllINRoomPrice',(req,res) =>{//获取所有已入住的房间信息
    297. const { pageSize, offset } = req.query;
    298. room.findAndCountAll({
    299. limit:pageSize,
    300. offset:offset,
    301. where:{
    302. roomStatus:{
    303. [Op.eq]:'已入住'
    304. }
    305. },
    306. include:[{
    307. model:roomType,
    308. foreignKey:'type',
    309. attributes:['price','url']
    310. }]
    311. })
    312. .then(data =>{
    313. res.status(200).json({
    314. success:true,
    315. msg:'房间信息查询成功!',
    316. roomList:data.rows.map(item =>{
    317. return item.get()
    318. }),
    319. count:data.count
    320. })
    321. })
    322. })
    323. roomRouter.get('/getAllRoomTypePrice',(req,res) =>{
    324. const { pageSize, offset, type } = req.query;
    325. room.findAndCountAll({
    326. where:{
    327. type:{
    328. [Op.eq]:type
    329. }
    330. },
    331. include:[{
    332. model:roomType,
    333. foreignKey:'type',
    334. attributes:['price','url']
    335. }]
    336. })
    337. .then(data =>{
    338. res.status(200).json({
    339. success:true,
    340. msg:'房型查询成功!',
    341. roomList:data.rows.map(item =>{
    342. return item.get()
    343. }),
    344. count:data.count
    345. })
    346. })
    347. .catch(err =>{
    348. res.status(200).json({
    349. success:false,
    350. msg:'服务器出错!'
    351. })
    352. })
    353. })
    354. roomRouter.get('/getAllStatusRoom',(req,res) =>{//获取所有该状态的房间信息
    355. const { pageSize, offset, roomStatus } = req.query;
    356. room.findAndCountAll({
    357. limit:pageSize,
    358. offset:offset,
    359. where:{
    360. roomStatus:{
    361. [Op.eq]:roomStatus
    362. }
    363. },
    364. include:[{
    365. model:roomType,
    366. foreignKey:'type',
    367. attributes:['price','url']
    368. }]
    369. })
    370. .then(data =>{
    371. res.status(200).json({
    372. success:true,
    373. msg:'房间信息查询成功!',
    374. roomList:data.rows.map(item =>{
    375. return item.get()
    376. }),
    377. count:data.count
    378. })
    379. })
    380. })
    381. module.exports = roomRouter

    五,项目总结

  • 相关阅读:
    [ansible]playbook结合项目解释执行步骤
    Matlab 中@ 的用法
    【PTHREAD】线程状态
    Centos7环境下安装MySQL8详细教程
    微信小程序自定义组件及投票管理与个人中心界面搭建
    狂神说Es
    亚马逊的卫星发射升空,它和“星链”在讲什么故事?
    创建ffmpeg vs2019工程
    服务于金融新核心系统 星辰天合与中电金信完成产品兼容认证
    计算机毕业设计Python+djang的疫情数据可视化分析系统(源码+系统+mysql数据库+Lw文档)
  • 原文地址:https://blog.csdn.net/BS009/article/details/127611649