|
|
|
import requests
|
|
|
|
from update.models import Cinema
|
|
|
|
from django.http.response import JsonResponse
|
|
|
|
from mock.mock_templates import *
|
|
|
|
|
|
|
|
ZZ_URL = 'https://zzcs.yinghezhong.com'
|
|
|
|
|
|
|
|
|
|
|
|
def mock(_ip, _api, **kwargs):
|
|
|
|
print('mock')
|
|
|
|
cinema_obj = Cinema.objects.filter(ip=_ip).first()
|
|
|
|
if _api == 'reportTicket':
|
|
|
|
mock_data = report_ticket_tmp.get()
|
|
|
|
return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False})
|
|
|
|
if _api == 'reportFilmSchedule':
|
|
|
|
mock_data = report_film_schedule_tmp.get()
|
|
|
|
return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False})
|
|
|
|
if _api == 'uploadScreenSeatInfo':
|
|
|
|
mock_data = upload_screen_seat_info_tmp.get()
|
|
|
|
return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False})
|
|
|
|
if _api == 'getCinemaInfo':
|
|
|
|
mock_data = get_cinema_info_tmp.get(cinema_obj)
|
|
|
|
return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False})
|
|
|
|
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':
|
|
|
|
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'))
|
|
|
|
if mock_data is not None:
|
|
|
|
return JsonResponse(mock_data, json_dumps_params={'ensure_ascii': False})
|
|
|
|
else:
|
|
|
|
return 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):
|
|
|
|
print('bypass')
|
|
|
|
if _r.method == 'GET':
|
|
|
|
req_url = ZZ_URL + _r.path
|
|
|
|
req_params = dict(_r.GET)
|
|
|
|
response_dara = requests.get(req_url, params=req_params)
|
|
|
|
return JsonResponse(response_dara.json(), json_dumps_params={'ensure_ascii': False})
|
|
|
|
if _r.method == 'POST':
|
|
|
|
req_url = ZZ_URL + _r.path
|
|
|
|
req_params = dict(_r.GET)
|
|
|
|
req_data = dict(_r.POST)
|
|
|
|
response_dara = requests.post(req_url, params=req_params, data=req_data)
|
|
|
|
return JsonResponse(response_dara.json(), json_dumps_params={'ensure_ascii': False})
|