Jelajahi Sumber

航班与城市相关数据库操作

kindring 3 tahun lalu
induk
melakukan
14ba2ed1b9
13 mengubah file dengan 35 tambahan dan 22 penghapusan
  1. 2 1
      .gitignore
  2. 2 2
      app.js
  3. 4 4
      configs/database.json
  4. 2 0
      controller/c_area.js
  5. 3 3
      database/d_air.js
  6. 2 2
      database/d_area.js
  7. 1 1
      database/d_user.js
  8. 1 0
      database/pool.js
  9. 1 1
      maps/progress.js
  10. 10 1
      routes/admin.js
  11. 2 2
      routes/citys.js
  12. 0 1
      routes/userApi.js
  13. 5 4
      routes/users.js

+ 2 - 1
.gitignore

@@ -1,2 +1,3 @@
 /node_modules/
-/.idea/
+/.idea/
+configs/database.json

+ 2 - 2
app.js

@@ -39,9 +39,9 @@ app.use(bodyParser.json({ limit: '10mb' }));
 
 
 app.use('/', indexRouter);
-app.use('/users', usersRouter);
+app.use('/user', usersRouter);
 app.use('/admin', adminRouter);
-app.use('/api/citys/',citysRouter);
+app.use('/api/city/',citysRouter);
 app.use('/api/captcha', captcha);
 
 

+ 4 - 4
configs/database.json

@@ -1,8 +1,8 @@
 {
-    "host": "localhost",
-    "port": "3306",
+    "host": "kindring.cn",
+    "port": "3307",
     "user": "air",
-    "password": "airFly",
+    "password": "airair",
     "connectionLimit": "100",
-    "database": "db_air"
+    "database": "air_db"
 }

+ 2 - 0
controller/c_area.js

@@ -37,6 +37,8 @@ async function updateCity(cityId,cityType,cityName){
     return result;
 }
 
+
+
 module.exports = {
     addCity,
     searchCity,

+ 3 - 3
database/d_air.js

@@ -18,10 +18,10 @@ const checkArgumentsIsEmpty = require("../until/checkArgumentsIsEmpty");
  */
 function flightSearch(departureCity,targetCity,routeType,startUnixTime,endUnixTime){
     let sql=``,values=[];
-    sql = `select f.* ,dep.cityname as departureCityName,tar.cityname as targetCityName from
+    sql = `select f.* ,dep.cityname as departureCityName,tar.cityName as targetCityName from
             flight as f
-            LEFT JOIN (select id,cityname from area ) as dep on dep.id = f.departureCity
-            LEFT JOIN (select id,cityname from area ) as tar on tar.id = f.targetCity
+            LEFT JOIN (select id,cityName from area ) as dep on dep.id = f.departureCity
+            LEFT JOIN (select id,cityName from area ) as tar on tar.id = f.targetCity
             where f.departureCity = ? and f.targetCity = ?`;
     values.push(departureCity,targetCity);
     if(routeType){

+ 2 - 2
database/d_area.js

@@ -12,7 +12,7 @@ const checkArgumentsIsEmpty = require('../until/checkArgumentsIsEmpty')
  */
 function addArea(cityType = field.cityType_domestic,cityName){
     let sql=``,values=[];
-    sql+=`insert into (cityname,cityType) values(?,?);`
+    sql+=`insert into area (cityName,cityType) values(?,?);`
     values.push(cityName,cityType)
     return mysql.pq(sql,values);
 }
@@ -49,7 +49,7 @@ function updateCity(cityId,cityType,cityName){
         values.push(cityType)
     }
     if(cityName){
-        sql+=' cityname = ?'
+        sql+=' cityName = ?'
         values.push(cityName)
     }
     sql += ` where id = ?;`

+ 1 - 1
database/d_user.js

@@ -32,7 +32,7 @@ function findPhoneUser(userType,phone){
  * @returns {Promise<unknown>}
  */
 function login(userType,account,passwd){
-    let sql = `select * from user where type = ? and account = ? and passwd = ?`;
+    let sql = `select * from user where accountType = ? and account = ? and passwd = ?`;
     let values = [...arguments];
     return mysql.pq(sql,values);
 }

+ 1 - 0
database/pool.js

@@ -14,6 +14,7 @@ const databseConfig = require('../configs/database.json'); //数据库连接的
 const pool = mysql.createPool({
     connectionLimit: databseConfig.connectionLimit || 100, //连接限制
     host: databseConfig.host, //地址
+    port: databseConfig.port,//端口
     user: databseConfig.user, //用户
     password: databseConfig.password, // 密码
     database: databseConfig.database // 数据库名称

+ 1 - 1
maps/progress.js

@@ -6,7 +6,7 @@ module.exports = {
     // 验证码session字段
     captchaSessionField: 'captcha',
     // 后台登陆地址
-    adminLoginUrl: '/admin/login',
+    adminLoginUrl: '/alogin',
     // 用户登陆地址
     userLoginUrl: '/login',
 }

+ 10 - 1
routes/admin.js

@@ -24,11 +24,20 @@ router.post('/login',
     paramsCheck({
         post:{
             account:{required:true},
-            passwd:{required:true}
+            passwd:{required:true},
+            captcha: { required: true }
         }}),
     async (req,res)=>{
         try{
+            console.log('登录')
+            // 用户登陆
+            let result = {
+                rcode: code.customError
+            };
+            // 提前检查验证码是否正确
+            if (req.body.captcha.toLowerCase() != req.session.captcha) return res.json({...result, msg: `验证码错误,captcha error` });
             let results = await c_user.login(field.adminType,req.body.account,req.body.passwd);
+            console.log(results);
             req.session[progress.adminSessionField] = results;
             res.json({
                 rcode: code.ok,

+ 2 - 2
routes/citys.js

@@ -7,7 +7,7 @@ const field = require('../maps/field')
 
 router.get('/list',async (req,res)=>{
     try{
-        let results = await c_area.searchCity(req.query.cityType);
+        let results = await c_area.searchCity(req.query.type);
         res.json({
             rcode: code.ok,
             data: results
@@ -29,7 +29,7 @@ router.post('/add',
     checkLogin(field.adminType),
     paramsCheck({
         post:{
-            cityType:{required:true},
+            cityType:{required:true,default:field.cityType_domestic},
             cityName:{required:true}
         }
     }),

+ 0 - 1
routes/userApi.js

@@ -1,4 +1,3 @@
 const router = require('express').Router();
 
-
 module.exports = router;

+ 5 - 4
routes/users.js

@@ -1,9 +1,10 @@
-var express = require('express');
-var router = express.Router();
-
-/* GET users listing. */
+const router = require('express').Router();
+const userApi = require('./userApi');
+/* 登录页面, . */
 router.get('/', function(req, res, next) {
   res.send('respond with a resource');
 });
 
+router.use('/api',userApi)
+
 module.exports = router;