修改了座位等级中文问题、空订单问题
This commit is contained in:
parent
963a80a670
commit
e435ae4035
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,9 +1,16 @@
|
||||
db = {
|
||||
db_service = {
|
||||
'host':'localhost',
|
||||
'user':'managerAgent',
|
||||
'password':'password123',
|
||||
'database':'ServiceDatabase'
|
||||
}
|
||||
|
||||
db_manager = {
|
||||
'host':'localhost',
|
||||
'user':'managerAgent',
|
||||
'password':'password123',
|
||||
'database':'ManagerDatabase'
|
||||
}
|
||||
|
||||
SECRET_KEY = 'ILOVEDATABASETECH'
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
from flask import render_template, request, g, redirect, url_for, session, jsonify
|
||||
from .config import db
|
||||
from .config import db_service
|
||||
import pymysql
|
||||
import csv
|
||||
import io
|
||||
@ -11,7 +11,7 @@ def index():
|
||||
flightID = request.args.get('flightID')
|
||||
|
||||
if flightID:
|
||||
conn = pymysql.connect(**db)
|
||||
conn = pymysql.connect(**db_service)
|
||||
cursor = conn.cursor(pymysql.cursors.DictCursor)
|
||||
|
||||
search_sql = """SELECT * FROM Flights WHERE ID = %s"""
|
||||
@ -41,7 +41,7 @@ def modify():
|
||||
|
||||
status = request.form.get('status', '未知')
|
||||
|
||||
conn = pymysql.connect(**db)
|
||||
conn = pymysql.connect(**db_service)
|
||||
cursor = conn.cursor(pymysql.cursors.DictCursor)
|
||||
|
||||
try:
|
||||
@ -55,7 +55,8 @@ def modify():
|
||||
|
||||
# 检查余座数是否为负值
|
||||
if new_first_class_seats < 0 or new_business_class_seats < 0 or new_economy_class_seats < 0:
|
||||
return jsonify({'message': '座位变化后余座数不能为负值'}), 400
|
||||
flash('座位变化后余座数不能为负值', 'error')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
# 更新座位数和价格
|
||||
update_sql = """
|
||||
@ -67,22 +68,23 @@ def modify():
|
||||
cursor.execute(update_sql, (new_first_class_seats, new_business_class_seats, new_economy_class_seats,
|
||||
first_class_price, business_class_price, economy_class_price, status, flight_id))
|
||||
conn.commit()
|
||||
flash('座位数、价格和状态更新成功', 'success')
|
||||
except Exception as e:
|
||||
print(e)
|
||||
conn.rollback()
|
||||
return jsonify({'message': '数据库错误,请稍后再试'}), 500
|
||||
flash(f'数据库错误:{e}', 'error')
|
||||
finally:
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
return jsonify({'message': '座位数、价格和状态更新成功'}), 200
|
||||
return redirect(url_for('index'))
|
||||
|
||||
|
||||
def delete_flight():
|
||||
if request.method == 'DELETE':
|
||||
flight_id = request.args.get('flightID')
|
||||
|
||||
conn = pymysql.connect(**db)
|
||||
conn = pymysql.connect(**db_service)
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
@ -103,7 +105,7 @@ from flask import flash, redirect, url_for, jsonify, request
|
||||
import pymysql
|
||||
import csv
|
||||
import io
|
||||
from .config import db
|
||||
from .config import db_service
|
||||
|
||||
def upload_csv():
|
||||
if request.method == 'POST':
|
||||
@ -112,7 +114,7 @@ def upload_csv():
|
||||
flash('没有文件上传', 'error')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
conn = pymysql.connect(**db)
|
||||
conn = pymysql.connect(**db_service)
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
|
@ -1,10 +1,10 @@
|
||||
from flask import request, jsonify, session, url_for, render_template, redirect
|
||||
from .config import db
|
||||
from .config import db_manager
|
||||
import pymysql
|
||||
|
||||
|
||||
def connect(managerID, encrypted_password):
|
||||
conn = pymysql.connect(**db)
|
||||
conn = pymysql.connect(**db_manager)
|
||||
cursor = conn.cursor(pymysql.cursors.DictCursor)
|
||||
args = (managerID, encrypted_password)
|
||||
verify_sql = "SELECT COUNT(*) FROM Managers WHERE ID = %s AND `Password` = %s;"
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -35,6 +35,10 @@ def book():
|
||||
passenger[key] = request.form.get(f'passengers[{i}][{key}]')
|
||||
passengers.append(passenger)
|
||||
|
||||
if not passengers:
|
||||
flash("请至少添加一位乘客", "error")
|
||||
return redirect(url_for('index'))
|
||||
|
||||
conn = pymysql.connect(**db)
|
||||
cursor = conn.cursor()
|
||||
|
||||
@ -85,7 +89,7 @@ def book():
|
||||
conn.rollback()
|
||||
print(e)
|
||||
flash("订票失败", "error")
|
||||
return redirect(url_for('search'))
|
||||
return redirect(url_for('index'))
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
|
@ -12,7 +12,7 @@ def verify_user(cursor: Cursor, phone_number: str, password: str) -> str:
|
||||
record = cursor.fetchone()
|
||||
if not record:
|
||||
return "NO_USER"
|
||||
if record[0] != password:
|
||||
if record['Password'] != password:
|
||||
return "WRONG_PASSWORD"
|
||||
return "USER_VERIFIED"
|
||||
|
||||
|
@ -39,6 +39,14 @@ def order():
|
||||
cursor.execute(tickets_sql, (order_id,))
|
||||
tickets = cursor.fetchall()
|
||||
|
||||
seatClass2Chinses = {
|
||||
'First Class': '头等舱',
|
||||
'Business Class': '商务舱',
|
||||
'Economy Class': '经济舱'
|
||||
}
|
||||
for ticket in tickets:
|
||||
ticket['Seat_class'] = seatClass2Chinses[ticket['Seat_class']]
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from flask import render_template, request, g, abort, redirect, url_for
|
||||
from flask import render_template, request, g, abort, redirect, url_for, flash
|
||||
from .config import db
|
||||
from .utils import get_cities
|
||||
import pymysql
|
||||
@ -13,6 +13,10 @@ def search():
|
||||
departure_date = request.args.get('departure-date')
|
||||
passengers = int(request.args.get('passengers', 1))
|
||||
|
||||
if not departure_city or not destination_city or not departure_date or not passengers:
|
||||
flash("请填写所有查询条件", "error")
|
||||
return render_template('search.html', cities=get_cities(), flights=[], username=g.name)
|
||||
|
||||
# Date validation
|
||||
try:
|
||||
departure_date_obj = datetime.datetime.strptime(departure_date, '%Y-%m-%d').date()
|
||||
|
@ -7,6 +7,19 @@
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/index.css') }}">
|
||||
<script src="{{ url_for('static', filename='js/index.js') }}" defer></script>
|
||||
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
var message = "";
|
||||
{% for msg in messages %}
|
||||
message += "{{ msg }}\n";
|
||||
{% endfor %}
|
||||
alert(message);
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
|
@ -5,6 +5,19 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>航班搜索结果</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/search.css') }}">
|
||||
<script>
|
||||
window.onload = function() {
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
var message = "";
|
||||
{% for msg in messages %}
|
||||
message += "{{ msg }}\n";
|
||||
{% endfor %}
|
||||
alert(message);
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
|
Loading…
x
Reference in New Issue
Block a user