From 7f005cc2986d60e3c95b6f9f0ed7d0bb64f7fce0 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Fri, 22 Dec 2023 16:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90mock?= =?UTF-8?q?=E7=9A=84=E5=90=8E=E5=8F=B0=E9=80=BB=E8=BE=91=20=E7=9B=B2?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...uditsessioncode_zzmockmodel_auditstatus.py | 23 +++ mock/mock_templates/__init__.py | 5 +- mock/mock_templates/download_film_info_tmp.py | 142 ++++++++++++++++++ .../get_overtime_ticket_status_tmp.py | 125 +++++++++++++++ mock/mock_templates/get_screen_info_tmp.py | 42 +++--- mock/mock_templates/valid_error_tmp.py | 3 + mock/models.py | 3 + mock/urls.py | 5 + mock/utils/mock_service.py | 14 +- mock/views.py | 86 ++++++++++- 10 files changed, 425 insertions(+), 23 deletions(-) create mode 100644 mock/migrations/0002_zzmockmodel_auditsessioncode_zzmockmodel_auditstatus.py create mode 100644 mock/mock_templates/download_film_info_tmp.py create mode 100644 mock/mock_templates/get_overtime_ticket_status_tmp.py create mode 100644 mock/mock_templates/valid_error_tmp.py diff --git a/mock/migrations/0002_zzmockmodel_auditsessioncode_zzmockmodel_auditstatus.py b/mock/migrations/0002_zzmockmodel_auditsessioncode_zzmockmodel_auditstatus.py new file mode 100644 index 0000000..d02bf96 --- /dev/null +++ b/mock/migrations/0002_zzmockmodel_auditsessioncode_zzmockmodel_auditstatus.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.7 on 2023-12-22 03:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mock', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='zzmockmodel', + name='auditSessionCode', + field=models.CharField(help_text='需要审核的过场场次编码', max_length=20, null=True, verbose_name='需要审核的过场场次编码'), + ), + migrations.AddField( + model_name='zzmockmodel', + name='auditStatus', + field=models.CharField(help_text='需要审核的过场场次状态', max_length=3, null=True, verbose_name='需要审核的过场场次状态'), + ), + ] diff --git a/mock/mock_templates/__init__.py b/mock/mock_templates/__init__.py index 7a810b7..6b17b10 100644 --- a/mock/mock_templates/__init__.py +++ b/mock/mock_templates/__init__.py @@ -2,4 +2,7 @@ __all__ = ['get_cinema_info_tmp', 'report_ticket_tmp', 'report_film_schedule_tmp', 'upload_screen_seat_info_tmp', - 'get_screen_info_tmp'] + 'get_screen_info_tmp', + 'download_film_info_tmp', + 'get_overtime_ticket_status_tmp', + 'valid_error_tmp'] diff --git a/mock/mock_templates/download_film_info_tmp.py b/mock/mock_templates/download_film_info_tmp.py new file mode 100644 index 0000000..f9c7551 --- /dev/null +++ b/mock/mock_templates/download_film_info_tmp.py @@ -0,0 +1,142 @@ +import pymysql +from pymysql.cursors import DictCursor + + +def get(): + mock_data = { + 'message': '操作成功', + 'data': + { + 'filmList': + [ + { + 'filmCode': '001299992022', + 'duration': 90, + 'aliasName': None, + 'keyEndtime': '2050-12-31', + 'keyStarttime': '2022-01-01', + 'reshowFlag': False, + 'publishDate': '2023-01-01', + 'filmName': 'Mock测试影片(不要排片!)', + 'producer': '无', + 'publisher': '暂空', + 'language': None, + 'version': '0' + } + ], + 'pageable': + { + 'size': 20, + 'totalPages': 1, + 'page': 1 + } + }, + 'code': '200', + 'status': 'success' + } + return mock_data + + +""" +国家编码(3)+ 发行版本编码(1)+ 当年流水编码(4)+ 年份(4) +例如 001d12342023 + +国家编码: +001 中国 +002 中国香港 +003 中国台湾 +011 朝鲜 +012 日本 +013 越南 +014 泰国 +015 缅甸 +016 新加坡 +017 印尼 +018 斯里兰卡 +019 印度 +020 巴基斯坦 +021 蒙古 +022 伊拉克 +023 黎巴嫩 +024 土尔其 +025 菲律宾 +026 尼泊尔 +027 叙利亚 +035 澳大利亚 +036 新西兰 +041 埃及 +042 阿尔及利亚 +043 突尼斯 +044 摩洛哥 +051 美国 +052 墨西哥 +053 委内瑞拉 +054 古巴 +055 哥伦比亚 +056 玻利维亚 +058 阿根廷 +059 加拿大 +060 巴西 +073 丹麦 +076 荷兰 +077 西班牙 +078 意大利 +079 西德 +080 东德 +081 瑞士 +082 奥地利 +083 波兰 +084 捷克 +085 匈牙利 +086 罗马尼亚 +087 保加利亚 +088 南斯拉夫 +089 阿尔巴尼亚 +090 希腊 +091 俄罗斯 +092 比利时 +093 瑞典 +其他未列出的三位编码由《影片编码原则》保留。 + +发行版本: +0、故事片观摩影片 +1、故事片普通 +2、故事片普通立体 +3、故事片IMAX +4、故事片IMAX立体 +5、故事片胶片(进口) +6、故事片其他特种电影 +7、故事片其他 +8、故事片中国巨幕 +9、故事片中国巨幕立体 +a、动画片观摩影片 +b、动画片普通 +o、动画片普通立体 +d、动画片IMAX +e、动画片IMAX立体 +f、动画片胶片(进口) +g、动画片其他特种电影 +h、动画片其他 +i、动画片中国巨幕 +j、动画片中国巨幕立体 +k、纪录片观摩影片 +l、纪录片普通 +m、纪录片普通立体 +n、纪录片IMAX +o、纪录片IMAX立体 +p、纪录片胶片(进口) +q、纪录片其他特种电影 +r、纪录片其他 +s、纪录片中国巨幕 +t、纪录片中国巨幕立体 +u、科教片观摩影片 +v、科教片普逋 +w、科教片普通立体 +x、科教片IMAX +y、科教片IMAX立体 +z、科教片胶片(进口) +A、科教片其他特种电影 +B、科教片其他 +C、科教片中国巨幕 +D、科教片中国巨幕立体 +""" diff --git a/mock/mock_templates/get_overtime_ticket_status_tmp.py b/mock/mock_templates/get_overtime_ticket_status_tmp.py new file mode 100644 index 0000000..c834b6b --- /dev/null +++ b/mock/mock_templates/get_overtime_ticket_status_tmp.py @@ -0,0 +1,125 @@ +import pymysql +from pymysql.cursors import DictCursor +from mock.models import ZZMockModel + + +# 转换sessionCode为show_id +def handle_session_code(session_code): + while session_code.startswith('0'): + session_code = session_code[1:] + return session_code + + +def get(cinema_data, request): + # 审核状态映射 + # 退票状态 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', + } + + # 定义影院数据库 + db_config = { + 'host': cinema_data.ip, + 'user': cinema_data.db_user, + 'password': cinema_data.db_pwd, + 'database': 'cine', + 'connect_timeout': 5, + } + + # 获取审核状态 + audit_config = ZZMockModel.objects.filter(ip=cinema_data.ip).first() + target_show_id = audit_config.auditShowId + target_status = audit_config.auditStatus + + # 获取请求数据 + session_code = request.query_params.get('sessionCode') + overtime_type = request.query_params.get('overtimeType') + + # session_code装show_id + request_show_id = handle_session_code(session_code) + + # 如果不是要测试的场次直接返回None, 从而执行bypass + if request_show_id != target_show_id: + return None + + db_conn = pymysql.Connect(**db_config) + db_cursor = db_conn.cursor(cursor=DictCursor) + ticket_list = [] + # 处理过场收票 + + if overtime_type == '0': + # zz_audit_status 专资审核状态 1-已审核 2-已驳回 3-审核中 4-已补登 5-未提交 6-提交失败 + # cinema_sell_add_status 补登状态 1-已审核 2-已驳回 3-审核中, + sell_sql = """ + 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; + """ + db_cursor.execute(sell_sql, (target_show_id,)) + sell_tickets = db_cursor.fetchall() + for ticket in sell_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': 2, + 'status': target_status + }) + else: + ticket_list.append({ + 'ticketNo': ticket['ticket_no'], + 'operation': 2, + 'status': sell_status_dict[sell_status] + }) + # 处理过场退票 + if overtime_type == '1': + # cinema_refund_order_detail + refund_sql = """ + 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; + """ + db_cursor.execute(refund_sql, (target_show_id,)) + refund_tickets = db_cursor.fetchall() + + for ticket in refund_tickets: + refund_status = str(ticket['refund_status']) + if refund_status == '1': + continue + elif refund_status == '2': + ticket_list.append({ + 'ticketNo': ticket['ticket_no'], + 'operation': 2, + 'status': target_status + }) + else: + ticket_list.append({ + 'ticketNo': ticket['ticket_no'], + 'operation': 2, + 'status': refund_status_dict[refund_status] + }) + print(ticket_list) + mock_data = {'message': '操作成功', + 'data': {'ticketList': ticket_list}, + 'code': '200', + 'status': 'success'} + return mock_data diff --git a/mock/mock_templates/get_screen_info_tmp.py b/mock/mock_templates/get_screen_info_tmp.py index 179e487..9d6ece6 100644 --- a/mock/mock_templates/get_screen_info_tmp.py +++ b/mock/mock_templates/get_screen_info_tmp.py @@ -13,10 +13,6 @@ def get(cinema_data): db_conn = pymysql.Connect(**db_config) db_cursor = db_conn.cursor(cursor=DictCursor) - # cinema_info - cinema_info_sql_str = 'SELECT * FROM cinema_info;' - db_cursor.execute(cinema_info_sql_str) - cinema_info_data = db_cursor.fetchone() # cinema_set cinema_set_sql_str = 'SELECT * FROM cinema_set;' db_cursor.execute(cinema_set_sql_str) @@ -25,21 +21,27 @@ def get(cinema_data): cinema_hall_info_sql_str = 'SELECT * FROM cinema_hall_info;' db_cursor.execute(cinema_hall_info_sql_str) cinema_hall_info_data = db_cursor.fetchall() - hall_num = len(cinema_hall_info_data) db_conn.close() - mock_data = {'message': '操作成功', - 'data': { - 'cinemaChainName': cinema_info_data['cinema_chain_name'], - 'manager': cinema_info_data['cinema_manager'], - 'screens': hall_num, - 'managerTel': cinema_info_data['cinema_telephone'], - 'cinemaName': cinema_set_data['cinema_platform_name'], - 'cinemaCode': cinema_set_data['cinema_num'], # 适配字段 - 'cinemaLevel': cinema_info_data['cinema_level'], - 'businessStatus': '12', # 定义字段 - 'officialName': cinema_info_data['official_name'], - 'fax': cinema_info_data['cinema_fax'] - }, - 'code': '200', - 'status': 'success'} + hall_list = [] + for hall in cinema_hall_info_data: + hall_dict = { + 'isArt': False if hall['cinema_zz_hall_is_art'] == 0 else True, + 'hallType': hall['cinema_zz_hall_type'], + 'showType': hall['cinema_zz_hall_show_type'], + 'isRed': False if hall['cinema_zz_hall_is_red'] == 0 else True, + 'screenName': hall['cinema_hall_real_name'], + 'seatCount': int(hall['cinema_hall_seat_num']), + 'screenCode': hall['cinema_zz_hall_code'] + } + hall_list.append(hall_dict) + mock_data = { + 'message': '操作成功', + 'data': + { + 'screenList': hall_list, + 'cinemaCode': cinema_set_data['cinema_num'] + }, + 'code': '200', + 'status': 'success' + } return mock_data diff --git a/mock/mock_templates/valid_error_tmp.py b/mock/mock_templates/valid_error_tmp.py new file mode 100644 index 0000000..4653798 --- /dev/null +++ b/mock/mock_templates/valid_error_tmp.py @@ -0,0 +1,3 @@ +def get(): + mock_data = {'message': '操作成功', 'data': [], 'code': '200', 'status': 'success'} + return mock_data diff --git a/mock/models.py b/mock/models.py index ed5a031..6be191f 100644 --- a/mock/models.py +++ b/mock/models.py @@ -15,6 +15,9 @@ class ZZMockModel(models.Model): getOvertimeTicketStatus = models.BooleanField(verbose_name='超时票务受理情况查询接口', null=False, help_text='超时票务受理情况查询接口') validError = models.BooleanField(verbose_name='数据清洗错误查询接口', null=False, help_text='数据清洗错误查询接口') + auditShowId = models.CharField(verbose_name='需要审核的过场场次编码', null=True, max_length=20, help_text='需要审核的过场场次编码') + auditStatus = models.CharField(verbose_name='需要审核的过场场次状态', null=True, max_length=3, help_text='需要审核的过场场次状态') + def __str__(self): return self.ip diff --git a/mock/urls.py b/mock/urls.py index 773102e..7cdb856 100644 --- a/mock/urls.py +++ b/mock/urls.py @@ -25,4 +25,9 @@ urlpatterns = [ path('report/downloadFilmInfo', download_film_info), path('data/getCinemaInfo', get_cinema_info), path('data/getScreenInfo', get_screen_info), + path('data/downloadFilmInfo', download_film_info), + path('query/validError', valid_error), + path('data/getOvertimeTicketStatus', get_overtime_ticket_status), + + ] diff --git a/mock/utils/mock_service.py b/mock/utils/mock_service.py index 3e453ca..8e2b155 100644 --- a/mock/utils/mock_service.py +++ b/mock/utils/mock_service.py @@ -6,7 +6,7 @@ from mock.mock_templates import * ZZ_URL = 'https://zzcs.yinghezhong.com' -def mock(_ip, _api, *args, **kwargs): +def mock(_ip, _api, **kwargs): print('mock') cinema_obj = Cinema.objects.filter(ip=_ip).first() if _api == 'reportTicket': @@ -24,6 +24,18 @@ def mock(_ip, _api, *args, **kwargs): if _api == 'getScreenInfo': mock_data = get_screen_info_tmp.get(cinema_obj) return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False}) + if _api == 'downloadFilmInfo': + mock_data = download_film_info_tmp.get() + return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False}) + if _api == 'getOvertimeTicketStatus': + mock_data = get_overtime_ticket_status_tmp.get(cinema_obj, kwargs.get('request')) + if mock_data is not None: + return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False}) + else: + bypass(kwargs.get('request')) + if _api == 'validError': + mock_data = valid_error_tmp.get() + return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False}) def bypass(_r): diff --git a/mock/views.py b/mock/views.py index 51f2c90..16bf8de 100644 --- a/mock/views.py +++ b/mock/views.py @@ -3,7 +3,11 @@ from django.shortcuts import render from django.http.response import JsonResponse from mock.utils import mock_service from mock.models import ZZMockModel +from update.models import Cinema from django.views.decorators.csrf import csrf_exempt +from pymysql.cursors import DictCursor +import pymysql +from mock.mock_templates import * ZZ_URL = 'https://zzcs.yinghezhong.com' @@ -75,8 +79,88 @@ def get_screen_info(request): else: return mock_service.bypass(request) + # 超时票务审批 # 1、超时票务受理情况查询接口 GET /data/getOvertimeTicketStatus -# +# 参数 场次id 审核状态 0不通过 1通过 2待审核 99待提交 +def get_overtime_ticket_status(request): + ip = request.META.get('REMOTE_ADDR') + mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() + if mock_service_switch.getOvertimeTicketStatus is True: + return mock_service.mock(ip, 'getOvertimeTicketStatus', request=request) + else: + return mock_service.bypass(request) + + # 数据查询 # 2、数据清洗错误查询接口 POST /query/validError +def valid_error(request): + ip = request.META.get('REMOTE_ADDR') + mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() + if mock_service_switch.validError is True: + return mock_service.mock(ip, 'validError') + else: + return mock_service.bypass(request) + + +# 获取过场信息 +def get_overtime_show(request): + query_params = request.query_params.dict() + ip = query_params.get('ip') + cinema_data = Cinema.objects.filter(ip=ip).first() + db_config = { + 'host': cinema_data.ip, + 'user': cinema_data.db_user, + 'password': cinema_data.db_pwd, + 'database': 'cine', + 'connect_timeout': 5, + } + # 获取过场售票 + sql_str = ''' + SELECT csa.cinema_sell_add_showid AS show_id, + cms.cinema_movie_name AS name, + cms.cinema_movie_show_start_time AS start_time, + chi.cinema_hall_name AS hall_name + FROM cinema_sell_add csa + LEFT JOIN cinema_hall_info chi ON csa.cinema_sell_add_hall = chi.cinema_hall_id + LEFT JOIN cinema_movie_show cms ON csa.cinema_sell_add_showid = cms.cinema_movie_show_id + GROUP BY csa.cinema_sell_add_showid ORDER BY cms.cinema_movie_show_start_time DESC; + ''' + db_conn = pymysql.Connect(**db_config) + db_cursor = db_conn.cursor(cursor=DictCursor) + db_cursor.execute(sql_str) + show_data = db_cursor.fetchall() + sell_show_list = [] + for show in show_data: + sell_show_list.append({'id': show['show_id'], + 'show': show['name'] + ' ' + show['start_time'] + ' ' + show[ + 'hall_name'] if show['hall_name'] is not None else '' + }) + # 获取过场退票场次 + sql_str = ''' + SELECT csl.cinema_movie_show_id AS show_id, + csl.cinema_movie_name AS name, + csl.cinema_movie_show_start_time AS start_time, + chi.cinema_hall_name AS hall_name + FROM cinema_sell_log csl + LEFT JOIN cinema_hall_info chi ON csl.cinema_hall_id = chi.cinema_hall_id + WHERE csl.cinema_sell_id IN (SELECT cinema_sell_id FROM cinema_refund_order_detail) + GROUP BY cinema_movie_id ORDER BY csl.cinema_movie_show_start_time DESC; + ''' + db_conn = pymysql.Connect(**db_config) + db_cursor = db_conn.cursor(cursor=DictCursor) + db_cursor.execute(sql_str) + show_data = db_cursor.fetchall() + refund_show_list = [] + for show in show_data: + refund_show_list.append({'id': show['show_id'], + 'show': show['name'] + ' ' + show['start_time'] + ' ' + show[ + 'hall_name'] if show['hall_name'] is not None else '' + }) + return JsonResponse({'sell': sell_show_list, 'refund': refund_show_list}, json_dumps_params={'ensure_ascii': False}) + + +# 获取mock数据的json +def get_response(request, _api): + _ip = request.query_params.dict().get('ip') + return mock_service.mock(_ip, _api)