You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
6.3 KiB
177 lines
6.3 KiB
|
1 week ago
|
import os
|
||
|
|
|
||
|
|
from fastapi import FastAPI, Query
|
||
|
|
import pymysql
|
||
|
|
from pymysql.cursors import DictCursor
|
||
|
|
|
||
|
|
# fastAPI 创建实例
|
||
|
|
app = FastAPI()
|
||
|
|
print('version', '2026年5月7日16:25:12')
|
||
|
|
|
||
|
|
# 测试单机数据库设置
|
||
|
|
db_config = {
|
||
|
|
'host': '192.168.55.99',
|
||
|
|
'user': 'dbadmin',
|
||
|
|
'password': 'fXMSR37mLP7w88ji',
|
||
|
|
'database': 'cine'
|
||
|
|
}
|
||
|
|
|
||
|
|
# 手动设置过场退票场次和预期的审核结果
|
||
|
|
test_show_info = {
|
||
|
|
'movie_name': '魔法满屋(国语)', # 影片名称
|
||
|
|
'show_start_time': '2026-04-29 18:00:00', # 场次开场时间
|
||
|
|
'hall_id': '1', # 影厅id
|
||
|
|
'status': '1' # 期望返回的结果 可设置为 0不通过 1通过 2待审核 99待提交
|
||
|
|
}
|
||
|
|
|
||
|
|
# 审核状态映射
|
||
|
|
# 退票状态 1-未提交 2-审核中 3-审核通过 4-审核失败
|
||
|
|
# 售票状态 1-已审核 2-已驳回 3-审核中 4-已补登 5-未提交 6-提交失败
|
||
|
|
# 专资接口 # operation 1售票 2退票 # status 0不通过 1通过 2待审核 99待提交
|
||
|
|
refund_status_dict = {
|
||
|
|
'3': '1',
|
||
|
|
'4': '0'
|
||
|
|
}
|
||
|
|
sell_status_dict = {
|
||
|
|
'1': '1',
|
||
|
|
'2': '0',
|
||
|
|
'4': '1',
|
||
|
|
}
|
||
|
|
|
||
|
|
# 创建数据库实例
|
||
|
|
conn = pymysql.Connect(**db_config)
|
||
|
|
cursor = conn.cursor(cursor=DictCursor)
|
||
|
|
|
||
|
|
|
||
|
|
# 获取超时售票数据
|
||
|
|
def get_over_sell_ticket(show_id):
|
||
|
|
query_str = """SELECT csad.id,
|
||
|
|
csad.ticket_no AS ticket_no,
|
||
|
|
csa.cinema_sell_add_status AS add_status,
|
||
|
|
csa.zz_audit_status AS audit_status,
|
||
|
|
csa.cinema_sell_add_showid AS show_id
|
||
|
|
FROM cinema_sell_add_detail csad
|
||
|
|
LEFT JOIN cinema_sell_add csa ON csad.cinema_sell_add_id = csa.cinema_sell_add_id
|
||
|
|
WHERE csad.ticket_no <> ''
|
||
|
|
AND csa.cinema_sell_add_showid = %s
|
||
|
|
ORDER BY csad.id DESC;"""
|
||
|
|
cursor.execute(query_str, (show_id,))
|
||
|
|
result = cursor.fetchall()
|
||
|
|
print('get_over_sell_ticket', show_id, result)
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
# 获取过场退票数据
|
||
|
|
def get_over_refund_ticket(show_id):
|
||
|
|
query_str = """SELECT crod.id, crod.cinema_sell_id, crod.refund_status, cslei.ticket_no
|
||
|
|
FROM cinema_refund_order_detail crod
|
||
|
|
LEFT JOIN cinema_sell_log_ext_info cslei ON crod.cinema_sell_id = cslei.cinema_sell_id
|
||
|
|
WHERE refund_order_id IN
|
||
|
|
(SELECT cinema_refund_order.refund_order_id FROM cinema_refund_order WHERE show_id = %s)
|
||
|
|
ORDER BY id DESC;"""
|
||
|
|
cursor.execute(query_str, (show_id,))
|
||
|
|
result = cursor.fetchall()
|
||
|
|
return result
|
||
|
|
|
||
|
|
|
||
|
|
# 获取场次id
|
||
|
|
def get_show_id(show_info):
|
||
|
|
query_sql = """SELECT cinema_movie_show_id, cinema_zz_movie_show_code
|
||
|
|
FROM cinema_movie_show
|
||
|
|
WHERE cinema_movie_name = %s
|
||
|
|
AND cinema_movie_show_start_time = %s
|
||
|
|
AND cinema_hall_id = %s;"""
|
||
|
|
cursor.execute(query_sql, (show_info['movie_name'], show_info['show_start_time'], show_info['hall_id']))
|
||
|
|
result = cursor.fetchone()
|
||
|
|
print('get_show_id', result)
|
||
|
|
return str(result['cinema_movie_show_id']), result['cinema_zz_movie_show_code']
|
||
|
|
|
||
|
|
|
||
|
|
# operation 1售票 2退票
|
||
|
|
# status 0不通过 1通过 2待审核 99待提交
|
||
|
|
|
||
|
|
# http://127.0.0.1/data/getOvertimeTicketStatus
|
||
|
|
@app.get("/data/getOvertimeTicketStatus")
|
||
|
|
async def get_overtime_ticket_status(cinemaCode: str,
|
||
|
|
endSessionDate: str,
|
||
|
|
filmCode: str,
|
||
|
|
overtimeType: str,
|
||
|
|
sessionCode: str):
|
||
|
|
# 过场退票
|
||
|
|
test_show_id, session_code = get_show_id(test_show_info)
|
||
|
|
if test_show_id is None:
|
||
|
|
print('检查test_show_info中的场次信息!!!')
|
||
|
|
print(test_show_id, type(test_show_id))
|
||
|
|
ticket_list = []
|
||
|
|
# 处理过场退票部分
|
||
|
|
if overtimeType == '1':
|
||
|
|
all_tickets = get_over_refund_ticket(test_show_id)
|
||
|
|
for ticket in all_tickets:
|
||
|
|
refund_status = str(ticket['refund_status'])
|
||
|
|
|
||
|
|
if refund_status == '1':
|
||
|
|
continue
|
||
|
|
if refund_status == '2':
|
||
|
|
if session_code == sessionCode:
|
||
|
|
test_status = test_show_info['status']
|
||
|
|
else:
|
||
|
|
test_status = '99'
|
||
|
|
ticket_list.append({
|
||
|
|
'ticketNo': ticket['ticket_no'],
|
||
|
|
'operation': 2,
|
||
|
|
'status': test_status
|
||
|
|
})
|
||
|
|
else:
|
||
|
|
ticket_list.append({
|
||
|
|
'ticketNo': ticket['ticket_no'],
|
||
|
|
'operation': 2,
|
||
|
|
'status': refund_status_dict[refund_status]
|
||
|
|
})
|
||
|
|
elif overtimeType == '0':
|
||
|
|
all_tickets = get_over_sell_ticket(test_show_id)
|
||
|
|
print('get_overtime_ticket_status', 'sell', all_tickets)
|
||
|
|
# zz_audit_status 专资审核状态 1-已审核 2-已驳回 3-审核中 4-已补登 5-未提交 6-提交失败
|
||
|
|
# cinema_sell_add_status 补登状态 1-已审核 2-已驳回 3-审核中,
|
||
|
|
for ticket in all_tickets:
|
||
|
|
sell_status = str(ticket['audit_status'])
|
||
|
|
if sell_status in ('5', '6'):
|
||
|
|
continue
|
||
|
|
elif sell_status == '3':
|
||
|
|
ticket_list.append({
|
||
|
|
'ticketNo': ticket['ticket_no'],
|
||
|
|
'operation': 1,
|
||
|
|
'status': test_show_info['status']
|
||
|
|
})
|
||
|
|
else:
|
||
|
|
ticket_list.append({
|
||
|
|
'ticketNo': ticket['ticket_no'],
|
||
|
|
'operation': 1,
|
||
|
|
'status': sell_status_dict[sell_status]
|
||
|
|
})
|
||
|
|
print(ticket_list)
|
||
|
|
return {"message": "操作成功",
|
||
|
|
"data": {"ticketList": ticket_list},
|
||
|
|
"code": "200",
|
||
|
|
"status": "success"}
|
||
|
|
|
||
|
|
|
||
|
|
@app.post("/report/reportTicket")
|
||
|
|
async def report_ticket():
|
||
|
|
return {"message": "操作成功", "data": {}, "code": "200", "status": "success"}
|
||
|
|
|
||
|
|
|
||
|
|
@app.post("/query/validError")
|
||
|
|
async def valid_error():
|
||
|
|
return {"message": "操作成功", "data": {}, "code": "200", "status": "success"}
|
||
|
|
|
||
|
|
|
||
|
|
# 推荐手动执行
|
||
|
|
# uvicorn dinghao_zz:app --host 0.0.0.0 --port 8000 --reload
|
||
|
|
|
||
|
|
# 不推荐
|
||
|
|
if __name__ == "__main__":
|
||
|
|
import uvicorn
|
||
|
|
|
||
|
|
# 设置指定IP
|
||
|
|
uvicorn.run(app='dinghao:app', host="192.168.114.12", port=8000, reload=True)
|