• 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});
              }
            })
          }
        }
      });
    });
  • 相关阅读:
    mvc中压缩html
    简单瀑布流
    MVC4 WebAPI
    css实现隔行换色
    网站变黑白
    reset.css
    选择文本改变浏览器默认的背景色和前景色
    DataBinder.Eval用法范例
    精妙SQL語句
    asp.net面试题收集
  • 原文地址:https://www.cnblogs.com/j-y-s/p/14903303.html
Copyright © 2020-2023  润新知