2021年6月7日 团队冲刺第二阶段04
昨天改了一些问题有点难,今天写了后台管理员添加影院内容与删改,并整理了整理代码,明天与队友进行代码的整合。
router.get('/api/admin/getCurrentPageHall',function(req,res){
let {
currentPage, pageSize,input
} = req.query;
let start = Number((currentPage-1)*pageSize);
pageSize = Number(pageSize);
let sqlStr = 'SELECT * FROM t_hall INNER JOIN t_cinema ON t_cinema.cinema_id = t_hall.cinema_id WHERE t_cinema.cinema_name LIKE ? ORDER BY hall_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_hall INNER JOIN t_cinema ON t_cinema.cinema_id = t_hall.cinema_id WHERE t_cinema.cinema_name LIKE ? ORDER BY hall_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/deleteHall',function(req,res){
let {
cinemaId,
hallName
} = req.body;
if (cinemaId){
let sqlStr = 'SELECT schedule_id FROM t_schedule WHERE cinema_id = ? AND hall_name = ?;';
conn.query(sqlStr,[cinemaId,hallName],(error,result,field)=>{
if (error){
console.log(error);
} else{
result = JSON.parse(JSON.stringify(result));
console.log(result);
if (result.length){
result.forEach((value)=>{
sqlStr = 'DELETE FROM t_schedule WHERE schedule_id = ?;';
conn.query(sqlStr,[value.schedule_id],(error,result,field)=>{
if (error){
console.log(error);
}
})
})
}
sqlStr = 'DELETE FROM t_hall WHERE cinema_id = ? AND name = ?';
conn.query(sqlStr,[cinemaId,hallName],(error,result,field)=>{
if (error){
console.log(error);
} else {
res.json({success_code:200});
}
})
}
});
}
});
//更新影厅信息
router.post('/api/admin/updateHallInfo',function(req,res){
let {
hallId,
cinemaId,
hallOldName,
hallNewName
} = req.body;
if (cinemaId){
let sqlStr = 'SELECT * FROM t_hall WHERE name = ? AND cinema_id = ? AND hall_id <> ? LIMIT 1;';
conn.query(sqlStr,[hallNewName,cinemaId,hallId],(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{
sqlStr = 'UPDATE t_schedule SET hall_name = ? WHERE cinema_id = ? AND hall_name = ?';
conn.query(sqlStr,[hallNewName,cinemaId,hallOldName],(error,result,field)=>{
if (error){
console.log(error);
} else{
//更新数据库
let sqlStr = 'UPDATE t_hall SET name = ? WHERE cinema_id = ? AND name = ?;';
conn.query(sqlStr,[hallNewName,cinemaId,hallOldName],(error,result,field)=>{
if (error){
res.json({error_code:1,message:'更新影影厅信息失败'});
console.log(error);
} else{
res.json({success_code:200})
}
})
}
});
}
}
});
}
});
//获取所有影院
router.get('/api/admin/getAllCinema',function(req,res){
let sqlStr = 'SELECT cinema_id,cinema_name FROM t_cinema;';
conn.query(sqlStr,(error,result,field)=>{
if (error){
console.log(error);
} else{
result = JSON.parse(JSON.stringify(result));
res.json({success_code:200,data:result});
}
})
});
//添加影厅信息
router.post('/api/admin/addHallInfo',function(req,res){
let {
cinemaId,
hallName
} = req.body;
let sqlStr = 'SELECT * FROM t_hall WHERE name = ? AND cinema_id = ? LIMIT 1;';
conn.query(sqlStr,[hallName,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 = 'INSERT INTO t_hall(cinema_id,name) VALUES(?,?);';
conn.query(sqlStr,[cinemaId,hallName],(error,result,field)=>{
if (error){
console.log(error);
} else{
res.json({success_code:200});
}
});
}
}
});
});
//获取当前页电影
router.get('/api/admin/getCurrentPageMovieSchedule',function(req,res){
let {
currentPage, pageSize,input
} = req.query;
let start = Number((currentPage-1)*pageSize);
pageSize = Number(pageSize);
let sqlStr = 'SELECT * FROM t_schedule INNER JOIN t_movie ON t_schedule.movie_id = t_movie.movie_id INNER JOIN t_cinema ON t_cinema.cinema_id = t_schedule.cinema_id WHERE t_movie.name LIKE ? ORDER BY schedule_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_schedule INNER JOIN t_movie ON t_schedule.movie_id = t_movie.movie_id INNER JOIN t_cinema ON t_cinema.cinema_id = t_schedule.cinema_id WHERE t_movie.name LIKE ? ORDER BY schedule_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.get('/api/admin/getAllMovie',function(req,res){
let sqlStr = 'SELECT * FROM t_movie;';
conn.query(sqlStr,(error,result,field)=>{
if (error){
console.log(error);
} else{
result = JSON.parse(JSON.stringify(result));
res.json({success_code:200,data:result});
}
})
});
//获取影院的影厅
router.get('/api/admin/getHallByCinemaId',function(req,res){
let cinemaId = req.query.cinemaId;
console.log(cinemaId);
let sqlStr = 'SELECT hall_id,name FROM t_hall WHERE cinema_id = ?;';
conn.query(sqlStr,[cinemaId],(error,result,field)=>{
if (error){
console.log(error);
} else{
result = JSON.parse(JSON.stringify(result));
console.log(result);
res.json({success_code:200,data:result});
}
})
});
//获取排片的某天的时间段安排
router.get('/api/admin/getHasScheduleDateTime',function(req,res){
let {
cinemaId,hallName,showDate
} = req.query;
let sqlStr = 'SELECT show_time FROM t_schedule WHERE cinema_id = ? AND hall_name = ? AND show_date = ?;';
conn.query(sqlStr,[cinemaId,hallName,showDate],(error,result,field)=>{
if (error){
console.log(error);
} else{
result = JSON.parse(JSON.stringify(result));
res.json({success_code:200,data:result});
}
})
});

浙公网安备 33010602011771号