diff --git a/mock/cinema_sql.py b/mock/cinema_sql.py index d25cd9a..769a0c3 100644 --- a/mock/cinema_sql.py +++ b/mock/cinema_sql.py @@ -1,20 +1,31 @@ -FROM_SELL_ADD_GET_SHOW_SQL = '''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;''' +FROM_SELL_ADD_GET_SHOW_SQL = '''SELECT cms.cinema_movie_show_id 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_movie_show cms + LEFT JOIN cinema_hall_info chi ON cms.cinema_hall_id = chi.cinema_hall_id +WHERE cms.cinema_movie_show_id IN + (SELECT csa.cinema_sell_add_showid + FROM cinema_sell_add csa + WHERE csa.type = 2 + AND zz_audit_status IN (3, 5) + GROUP BY cinema_sell_add_showid) +ORDER BY cms.cinema_movie_show_id; +''' -FROM_REFUND_GET_SHOW_SQL = '''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;''' +FROM_REFUND_GET_SHOW_SQL = '''SELECT cms.cinema_movie_show_id 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_movie_show cms + LEFT JOIN cinema_hall_info chi ON cms.cinema_hall_id = chi.cinema_hall_id +WHERE cms.cinema_movie_show_id IN (SELECT cro.show_id + FROM cine.cinema_refund_order cro + WHERE cro.refund_order_id in (SELECT crod.refund_order_id + FROM cinema_refund_order_detail crod + WHERE crod.refund_status IN (0, 1, 2)) + GROUP BY cro.show_id) +ORDER BY cms.cinema_movie_show_id DESC;''' UPDATE_ZZ_PLATFORM_HOST_SQL = '''UPDATE cine.cinema_common_info SET cinema_common_info_val = %s WHERE cinema_common_info_key = 'zz_platform_host';''' diff --git a/mock/mock_templates/get_overtime_ticket_status_tmp.py b/mock/mock_templates/get_overtime_ticket_status_tmp.py index a7efe84..99dbad2 100644 --- a/mock/mock_templates/get_overtime_ticket_status_tmp.py +++ b/mock/mock_templates/get_overtime_ticket_status_tmp.py @@ -12,6 +12,34 @@ def handle_session_code(session_code): def get(cinema_data, request): + # 获取审核状态 + audit_config = ZZMockModel.objects.filter(ip=cinema_data.ip).first() + target_show_id = audit_config.auditShowId + target_status = audit_config.auditStatus + # 获取请求数据 + session_code = request.GET.get('sessionCode') + overtime_type = request.GET.get('overtimeType') + req_show_id = handle_session_code(session_code) + + print(target_show_id, target_status, session_code, overtime_type) + return handler(cinema_data, target_show_id, target_status, req_show_id, overtime_type) + + +def get_json(cinema_data, request): + # type_dict = { + # '1': + # '2': + # } + # 获取请求参数 + target_show_id = req_show_id = request.GET.get('show') + overtime_type = request.GET.get('type') + target_status = request.GET.get('status') + + print(target_show_id, target_status, req_show_id, overtime_type) + return handler(cinema_data, target_show_id, target_status, req_show_id, overtime_type) + + +def handler(cinema_data, target_show_id, target_status, req_show_id, overtime_type): # 审核状态映射 # 退票状态 1-未提交 2-审核中 3-审核通过 4-审核失败 # 售票状态 1-已审核 2-已驳回 3-审核中 4-已补登 5-未提交 6-提交失败 @@ -35,31 +63,15 @@ def get(cinema_data, request): '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.GET.get('sessionCode') - overtime_type = request.GET.get('overtimeType') - - print(target_show_id, target_status, session_code, overtime_type) - - # session_code转show_id - if len(session_code) == 16: - request_show_id = handle_session_code(session_code) - else: - request_show_id = session_code - # 如果不是要测试的场次直接返回None, 从而执行bypass - if request_show_id != target_show_id: + if req_show_id != target_show_id: + print('不相同') 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-提交失败 @@ -104,7 +116,7 @@ def get(cinema_data, request): 'operation': 2, 'status': refund_status_dict[refund_status] }) - print(ticket_list) + print('ticket_list', ticket_list) mock_data = {'message': '操作成功', 'data': {'ticketList': ticket_list}, 'code': '200', diff --git a/mock/urls.py b/mock/urls.py index 9039715..5e66655 100644 --- a/mock/urls.py +++ b/mock/urls.py @@ -30,5 +30,7 @@ urlpatterns = [ path('data/getOvertimeTicketStatus', get_overtime_ticket_status), path('api/get_overtime_show', get_overtime_show), path('api/get_response_json', get_response), - path('api/set_overtime_config', set_overtime_config) + path('api/set_overtime_config', set_overtime_config), + path('api/start_mock', enable_mock), + path('api/end_mock', disable_mock) ] diff --git a/mock/utils/mock_service.py b/mock/utils/mock_service.py index 8e2b155..5b26164 100644 --- a/mock/utils/mock_service.py +++ b/mock/utils/mock_service.py @@ -28,8 +28,13 @@ def mock(_ip, _api, **kwargs): 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 kwargs.get('type') == 'getJson': + mock_data = get_overtime_ticket_status_tmp.get_json(cinema_obj, kwargs.get('request')) + else: + mock_data = get_overtime_ticket_status_tmp.get(cinema_obj, kwargs.get('request')) + print('mock_data', mock_data) if mock_data is not None: + print("this is none") return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False}) else: bypass(kwargs.get('request')) diff --git a/mock/views.py b/mock/views.py index 143d6c0..49ab844 100644 --- a/mock/views.py +++ b/mock/views.py @@ -1,4 +1,5 @@ import datetime +import json import requests from django.shortcuts import render @@ -33,6 +34,7 @@ api_dict = { # 1、票房数据上报接口 POST /report/reportTicket @csrf_exempt def report_ticket(request): + print(request.GET) ip = request.META.get('REMOTE_ADDR') mock_service_switch = ZZMockModel.objects.filter(ip=ip).first() if mock_service_switch.reportTicket is True: @@ -104,6 +106,8 @@ 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: + r = mock_service.mock(ip, 'getOvertimeTicketStatus', request=request) + print('r', r) return mock_service.mock(ip, 'getOvertimeTicketStatus', request=request) else: return mock_service.bypass(request) @@ -183,7 +187,7 @@ def get_response(request): _api = request.GET.dict().get('api') _api = api_dict[_api] if _api == 'getOvertimeTicketStatus': - req = mock_service.mock(_ip, _api, request=request) + req = mock_service.mock(_ip, _api, request=request, type='getJson') else: req = mock_service.mock(_ip, _api) return req @@ -221,9 +225,14 @@ def set_overtime_config(request): # 启动mock +@csrf_exempt def enable_mock(request): - ip = request.GET.dict().get('ip') - mock_config = request.POST.dict().get('mock_config') + ip = request.GET.get('ip') + req_mock_config = json.loads(request.body)['mock_config'] + mock_config = dict() + for k, v in req_mock_config.items(): + mock_config[api_dict[k]] = v + print(mock_config) server_ip = get_local_ip() current_host = db(ip, GET_ZZ_PLATFORM_HOST_SQL)['data'][0]['cinema_common_info_val'] if current_host == 'https://zzcs.yinghezhong.com' or current_host == 'https://dy.yinghezhong.com': @@ -239,7 +248,7 @@ def enable_mock(request): # 停用mock服务 def disable_mock(request): - ip = request.query_params.dict().get('ip') + ip = request.GET.get('ip') server_ip = get_local_ip() current_host = db(ip, GET_ZZ_PLATFORM_HOST_SQL)['data'][0]['cinema_common_info_val'] if current_host == 'https://zzcs.yinghezhong.com' or current_host == 'https://dy.yinghezhong.com': diff --git a/update/utils/get_version.py b/update/utils/get_version.py index 437d37e..9867b1f 100644 --- a/update/utils/get_version.py +++ b/update/utils/get_version.py @@ -47,7 +47,6 @@ class GetVersion(object): @staticmethod def get_cinema_ver(q): - print('get_cinema_ver') if q.empty(): return else: