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.
200 lines
11 KiB
200 lines
11 KiB
# 排片数据 |
|
GET_SHOW_DATA = """ |
|
SELECT hi.cinema_hall_name as hall_name, |
|
hi.cinema_hall_id as hall_id, |
|
mi.cinema_movie_alias as movie_name, |
|
mi.cinema_movie_id as movie_id, |
|
mlt.cinema_movie_lang_type_desc as language, |
|
DATE_FORMAT(ms.cinema_movie_show_start_time, '%%Y-%%m-%%d') as show_date, |
|
DATE_FORMAT(ms.cinema_movie_show_start_time, '%%H:%%i') as start_time, |
|
DATE_FORMAT(ms.cinema_movie_show_end_time, '%%H:%%i') as end_time, |
|
CAST(TIME_TO_SEC(TIMEDIFF(ms.cinema_movie_show_end_time, ms.cinema_movie_show_start_time)) / |
|
60 AS UNSIGNED) as length, |
|
IFNULL(MINUTE(TIMEDIFF(ms.cinema_movie_show_start_time, (SELECT MAX(cinema_movie_show_end_time) |
|
FROM cinema_movie_show t |
|
WHERE t.cinema_hall_id = ms.cinema_hall_id |
|
AND t.cinema_movie_show_start_date = ms.cinema_movie_show_start_date |
|
AND t.cinema_del_flag = 1 |
|
AND ms.cinema_movie_show_start_time >= t.cinema_movie_show_end_time))), |
|
0) as duration |
|
FROM cinema_movie_show ms |
|
LEFT JOIN cinema_hall_info hi ON ms.cinema_hall_id = hi.cinema_hall_id |
|
LEFT JOIN cinema_movie_info mi ON ms.cinema_movie_id = mi.cinema_movie_id |
|
LEFT JOIN cinema_movie_lang_type mlt ON mi.cinema_movie_lang_id = mlt.cinema_movie_lang_type_id |
|
WHERE ms.cinema_del_flag = 1 |
|
AND ms.cinema_movie_show_start_time >= %s |
|
AND ms.cinema_movie_show_start_time <= %s |
|
ORDER BY show_date, hall_id, start_time; |
|
""" |
|
|
|
# 获取销售数据 |
|
GET_SELL_DATA = """ |
|
SELECT md.movie_name, |
|
md.movie_id, |
|
md.show_date, |
|
md.start_time, |
|
md.hall_name, |
|
md.hall_id, |
|
SUM(md.count) as total_count, |
|
SUM(md.income) as total_income, |
|
md.seat_num, |
|
ROUND(IF(SUM(md.income) = 0, 0.0, SUM(md.income) / SUM(md.count)), 2) as average_price, |
|
ROUND(SUM(md.count) / md.seat_num * 100, 2) as rate |
|
FROM ( |
|
-- 售票 |
|
SELECT ms.cinema_movie_show_id as cinema_movie_show_id, |
|
mi.cinema_movie_alias as movie_name, |
|
mi.cinema_movie_id as movie_id, |
|
DATE_FORMAT(ms.cinema_movie_show_start_time, '%%Y-%%m-%%d') as show_date, |
|
CAST(TIME(ms.cinema_movie_show_start_time) AS CHAR) as start_time, |
|
hi.cinema_hall_name as hall_name, |
|
hi.cinema_hall_id as hall_id, |
|
SUM(IF(sl.cinema_ticket_status <> 3, 1, 0)) as count, |
|
SUM(IF(sl.cinema_ticket_status <> 3, sl.cinema_ticket_income, 0)) as income, |
|
ms.cinema_hall_seat_num as seat_num |
|
FROM cinema_movie_show ms |
|
LEFT JOIN cinema_sell_log sl ON ms.cinema_movie_show_id = sl.cinema_movie_show_id |
|
JOIN cinema_movie_info mi ON ms.cinema_movie_id = mi.cinema_movie_id |
|
JOIN cinema_hall_info hi ON ms.cinema_hall_id = hi.cinema_hall_id |
|
WHERE ms.cinema_movie_show_joinflg = 0 |
|
AND ms.cinema_movie_show_start_time >= %s |
|
AND ms.cinema_movie_show_start_time <= %s |
|
AND ms.cinema_del_flag = 1 |
|
AND NOT (ms.cinema_movie_show_sold_num = 0 AND ms.cinema_movie_show_status <> 1) |
|
GROUP BY ms.cinema_movie_show_id, CAST(ms.cinema_movie_show_id AS CHAR) |
|
UNION |
|
-- 补登 |
|
SELECT ms.cinema_movie_show_id as cinema_movie_show_id, |
|
mi.cinema_movie_alias as movie_name, |
|
mi.cinema_movie_id as movie_id, |
|
DATE_FORMAT(ms.cinema_movie_show_start_time, '%%Y-%%m-%%d') as show_date, |
|
CAST(TIME(ms.cinema_movie_show_start_time) AS CHAR) as start_time, |
|
hi.cinema_hall_name as hall_name, |
|
hi.cinema_hall_id as hall_id, |
|
SUM(sa.cinema_sell_add_num) as count, |
|
SUM(sa.cinema_sell_add_total) as income, |
|
ms.cinema_hall_seat_num as seat_num |
|
FROM cinema_sell_add sa |
|
LEFT JOIN cinema_movie_show ms ON sa.cinema_sell_add_showid = ms.cinema_movie_show_id |
|
LEFT JOIN cinema_hall_info hall ON ms.cinema_hall_id = hall.cinema_hall_id |
|
LEFT JOIN cinema_show_policy_map spm ON sa.cinema_sell_add_showid = spm.cinema_movie_show_id AND |
|
sa.cinema_sell_add_policy = spm.cinema_show_policy_map_id |
|
JOIN cinema_hall_info hi ON ms.cinema_hall_id = hi.cinema_hall_id |
|
JOIN cinema_movie_info mi ON ms.cinema_movie_id = mi.cinema_movie_id |
|
WHERE ms.cinema_movie_show_joinflg = 0 |
|
AND ms.cinema_movie_show_start_time >= %s |
|
AND ms.cinema_movie_show_start_time <= %s |
|
AND ms.cinema_del_flag = 1 |
|
AND NOT (ms.cinema_movie_show_sold_num = 0 AND ms.cinema_movie_show_status <> 1) |
|
GROUP BY ms.cinema_movie_show_id, CAST(ms.cinema_movie_show_id AS CHAR)) as md |
|
GROUP BY md.cinema_movie_show_id, CAST(md.cinema_movie_show_id AS CHAR) |
|
ORDER BY md.show_date, md.hall_id, md.start_time; |
|
""" |
|
|
|
# 获取指定日期的可放映影片 |
|
GET_AVAILABLE_MOVIE = """ |
|
SELECT cmi.cinema_movie_alias, |
|
cmi.cinema_movie_id, |
|
cmi.cinema_movie_time, |
|
cmlt.cinema_movie_lang_type_desc as language, |
|
scvm.system_const_val_desc as media_type, |
|
cmi.cinema_movie_start_datetime, |
|
cmi.cinema_movie_end_datetime |
|
FROM cinema_movie_info cmi |
|
JOIN cinema_movie_lang_type cmlt ON cmi.cinema_movie_lang_id = cmlt.cinema_movie_lang_type_id |
|
JOIN system_const_val_map scvm ON cmi.cinema_movie_media_type = scvm.system_const_val_value |
|
WHERE scvm.system_const_sub_module = 'new_media_type' |
|
AND cmi.cinema_movie_start_datetime <= %s |
|
AND cmi.cinema_movie_end_datetime > %s; |
|
""" |
|
|
|
# 获取指定日期的可用于排片的影片 |
|
GET_HANDLE_MOVIE = f""" |
|
SELECT cmi.cinema_movie_alias, |
|
cmi.cinema_movie_id, |
|
cmi.cinema_movie_time, |
|
cmlt.cinema_movie_lang_type_desc as language, |
|
scvm.system_const_val_desc as media_type, |
|
cmi.cinema_movie_start_datetime, |
|
cmi.cinema_movie_end_datetime |
|
FROM cinema_movie_info cmi |
|
JOIN cinema_movie_lang_type cmlt ON cmi.cinema_movie_lang_id = cmlt.cinema_movie_lang_type_id |
|
JOIN system_const_val_map scvm ON cmi.cinema_movie_media_type = scvm.system_const_val_value |
|
WHERE scvm.system_const_sub_module = 'new_media_type' |
|
AND cmi.cinema_movie_start_datetime <= %s |
|
AND cmi.cinema_movie_end_datetime > %s |
|
AND cmi.cinema_movie_id NOT IN ( |
|
""" |
|
|
|
# 获取新上映的影片 |
|
GET_NEW_MOVIE = """SELECT cmi.cinema_movie_alias, |
|
cmi.cinema_movie_id, |
|
cmi.cinema_movie_time, |
|
cmlt.cinema_movie_lang_type_desc as language, |
|
scvm.system_const_val_desc as media_type, |
|
cmi.cinema_movie_start_datetime, |
|
cmi.cinema_movie_end_datetime |
|
FROM cinema_movie_info cmi |
|
JOIN cinema_movie_lang_type cmlt ON cmi.cinema_movie_lang_id = cmlt.cinema_movie_lang_type_id |
|
JOIN system_const_val_map scvm ON cmi.cinema_movie_media_type = scvm.system_const_val_value |
|
WHERE scvm.system_const_sub_module = 'new_media_type' |
|
AND cmi.cinema_movie_start_datetime >= %s |
|
AND cmi.cinema_movie_start_datetime <= %s;""" |
|
|
|
# 获取影厅支持的制式 |
|
GET_HALL_MEDIA_TYPE = """ |
|
SELECT chi.cinema_hall_name, cms.cinema_hall_id, scvm.system_const_val_desc as media_type |
|
FROM cinema_movie_show cms |
|
JOIN cinema_movie_info cmi ON cms.cinema_movie_id = cmi.cinema_movie_id |
|
JOIN cinema_hall_info chi ON cms.cinema_hall_id = chi.cinema_hall_id |
|
JOIN system_const_val_map scvm ON cmi.cinema_movie_media_type = scvm.system_const_val_value |
|
WHERE scvm.system_const_sub_module = 'new_media_type' |
|
AND chi.cinema_delete_flag = 0 |
|
GROUP BY chi.cinema_hall_id, media_type; |
|
""" |
|
|
|
# 获取模板日期 |
|
GET_TEMPLATE_DATE = """ |
|
SELECT cms.cinema_movie_show_start_date as template_date, COUNT(cinema_movie_show_id) as show_count |
|
FROM cinema_movie_show cms |
|
WHERE cms.cinema_del_flag = 1 |
|
AND cms.cinema_movie_show_start_time >= %s |
|
AND cms.cinema_movie_show_start_time <= %s |
|
GROUP BY cms.cinema_movie_show_start_date |
|
HAVING show_count > (SELECT COUNT(chi.cinema_hall_id) FROM cinema_hall_info chi WHERE chi.cinema_delete_flag = 0) * %s |
|
ORDER BY template_date DESC |
|
LIMIT 1; |
|
""" |
|
|
|
|
|
# 获取目标日期的销售总额 |
|
GET_TOTAL_INCOME = """ |
|
SELECT SUM(md.income) as total_income |
|
FROM ( |
|
-- 售票 |
|
SELECT SUM(IF(sl.cinema_ticket_status <> 3, sl.cinema_ticket_income, 0)) as income |
|
FROM cinema_movie_show ms |
|
LEFT JOIN cinema_sell_log sl ON ms.cinema_movie_show_id = sl.cinema_movie_show_id |
|
JOIN cinema_movie_info mi ON ms.cinema_movie_id = mi.cinema_movie_id |
|
JOIN cinema_hall_info hi ON ms.cinema_hall_id = hi.cinema_hall_id |
|
WHERE ms.cinema_movie_show_joinflg = 0 |
|
AND ms.cinema_movie_show_start_time >= %s |
|
AND ms.cinema_movie_show_start_time <= %s |
|
AND ms.cinema_del_flag = 1 |
|
AND NOT (ms.cinema_movie_show_sold_num = 0 AND ms.cinema_movie_show_status <> 1) |
|
UNION |
|
-- 补登 |
|
SELECT SUM(sa.cinema_sell_add_total) as income |
|
FROM cinema_sell_add sa |
|
LEFT JOIN cinema_movie_show ms ON sa.cinema_sell_add_showid = ms.cinema_movie_show_id |
|
LEFT JOIN cinema_hall_info hall ON ms.cinema_hall_id = hall.cinema_hall_id |
|
LEFT JOIN cinema_show_policy_map spm ON sa.cinema_sell_add_showid = spm.cinema_movie_show_id AND |
|
sa.cinema_sell_add_policy = spm.cinema_show_policy_map_id |
|
JOIN cinema_hall_info hi ON ms.cinema_hall_id = hi.cinema_hall_id |
|
JOIN cinema_movie_info mi ON ms.cinema_movie_id = mi.cinema_movie_id |
|
WHERE ms.cinema_movie_show_joinflg = 0 |
|
AND ms.cinema_movie_show_start_time >= %s |
|
AND ms.cinema_movie_show_start_time <= %s |
|
AND ms.cinema_del_flag = 1 |
|
AND NOT (ms.cinema_movie_show_sold_num = 0 AND ms.cinema_movie_show_status <> 1)) md |
|
""" |