zoukankan      html  css  js  c++  java
  • 2021年4月30日 团队冲刺阶段04

    时间:1.6个小时左右

    代码:170行左右

    博客:1

    学习内容:完成了电影后台管理的增删改查,电影票、影院、排片

    代码:

    //获取当前页影院
    router.get('/api/admin/getCurrentPageCinema',function(req,res){
      let {
        currentPage, pageSize,input
      } = req.query;
      let start = Number((currentPage-1)*pageSize);
      pageSize = Number(pageSize);
      let sqlStr = 'SELECT * FROM t_cinema WHERE cinema_name LIKE ? ORDER BY cinema_id ;';
      let total;
      conn.query(sqlStr,["%"+input+"%"],(error,result,field)=>{
        if (error){
          console.log(error);
        } else{
          result = JSON.parse(JSON.stringify(result));
          total = result.length;
        }
      });
      sqlStr = 'SELECT * FROM t_cinema WHERE cinema_name LIKE ? ORDER BY cinema_id LIMIT ?,?;';
      conn.query(sqlStr,["%"+input+"%",start,pageSize],(error,result,field)=>{
        if (error){
          console.log(error);
        } else{
          result = JSON.parse(JSON.stringify(result));
          res.json({success_code:200,data:result,total:total});
        }
      })
    });
    //更新影院信息
    router.post('/api/admin/updateCinemaInfo',function(req,res){
      let {
        cinemaId,
        cinemaName,
        cinemaPhone,
        address
      } = req.body;
      if (cinemaId){
        let sqlStr = 'SELECT * from t_cinema WHERE cinema_id = ? LIMIT 1;';
        conn.query(sqlStr,[cinemaId],(error,result,field)=>{
          if (error){
            console.log(error);
          } else{
            sqlStr = 'SELECT * FROM t_cinema WHERE cinema_name = ? AND cinema_id <> ? LIMIT 1 ;';
            conn.query(sqlStr,[cinemaName,cinemaId],(error,result,field)=>{
              if (error){
                console.log(error);
              } else{
                result = JSON.parse(JSON.stringify(result));
                if (result[0]){
                  res.json({error_code:1,message:'影院名已存在!'});
                } else{
                  //更新数据库
                  let sqlStr = 'UPDATE t_cinema SET cinema_name = ?,cinema_phone = ?,specified_address = ? WHERE cinema_id = ?;';
                  conn.query(sqlStr,[cinemaName,cinemaPhone,address,cinemaId],(error,result,field)=>{
                    if (error){
                      res.json({error_code:1,message:'更新影院信息失败'});
                      console.log(error);
                    } else{
                      res.json({success_code:200})
                    }
                  })
                }
              }
            });
          }
        })
      }
    });
    //删除影院信息
    router.post('/api/admin/deleteCinemaInfo',function(req,res){
      let {
        cinemaId
      } = req.body;
        if (cinemaId){
          let sqlStr = 'DELETE FROM t_cinema WHERE cinema_id =?';
          conn.query(sqlStr,[cinemaId],(error,result,field)=>{
            if (error){
              console.log(error);
            } else {
              res.json({success_code:200});
            }
          })
        }
    });
    //添加影院信息
    router.post('/api/admin/addCinemaInfo',function(req,res){
      let {
        cinemaName,
        cinemaPhone,
        address
      } = req.body;
      sqlStr = 'SELECT * FROM t_cinema WHERE cinema_name = ? LIMIT 1 ;';
      conn.query(sqlStr,[cinemaName],(error,result,field)=>{
        if (error){
          console.log(error);
        } else{
          result = JSON.parse(JSON.stringify(result));
          if (result[0]){
            res.json({error_code:1,message:'影院名已存在!'});
          } else{
            let sqlStr = 'INSERT INTO t_cinema(cinema_name,cinema_phone,specified_address) VALUES(?,?,?);';
            conn.query(sqlStr,[cinemaName,cinemaPhone,address],(error,result,field)=>{
              if (error){
                console.log(error);
              } else{
                res.json({success_code:200});
              }
            })
          }
        }
      });
    });
  • 相关阅读:
    SpringMVC详解
    会话控制cookie和session
    jsp详解
    Jquery Enter事件
    JS获取request字符串
    net 2.0使用ajax
    C#通过WebClient/HttpWebRequest实现http的post/get方法
    WCF Rest:不使用UriTemplate使用post方式传参解决HTTP400问题以及参数映射问题
    关于ASP.NET 中站点地图sitemap 的使用
    Web.config自定义节点configSections
  • 原文地址:https://www.cnblogs.com/j-y-s/p/14903303.html
Copyright © 2011-2022 走看看