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.
51 lines
1.4 KiB
51 lines
1.4 KiB
from django.http import JsonResponse |
|
from django.shortcuts import render |
|
from django.views.decorators.csrf import csrf_exempt |
|
import pymysql |
|
|
|
zy_db_config = { |
|
'host': '172.16.3.223', |
|
'port': 3306, |
|
'user': 'zyds_select', |
|
'password': 'select', |
|
'db': 'suyi_cinema', |
|
} |
|
|
|
|
|
@csrf_exempt |
|
def zy_switch_svip(request): |
|
""" |
|
接口用于切换自营环境 |
|
http://172.16.1.168:8000/config/zy_switch_svip?svip=on |
|
""" |
|
# 通过Api model获取会员或非会员的api id |
|
svip = request.GET.get('svip') |
|
if svip == 'on': |
|
result = zy_switch_svip_db('svip') |
|
elif svip == 'off': |
|
result = zy_switch_svip_db('normal') |
|
else: |
|
result = False |
|
|
|
result_dict = { |
|
'status': 'success' if result else 'error', |
|
'message': '切换环境成功' if result else '切换环境失败', |
|
} |
|
return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) |
|
|
|
|
|
def zy_switch_svip_db(env_type): |
|
db_conn = pymysql.Connect(**zy_db_config) |
|
cursor = db_conn.cursor() |
|
# value 0-非华谊 1-华谊 |
|
sql_str = "UPDATE suyi_cinema.group_kv_config gkc SET gkc.value = %s WHERE gkc.key = 'svip_switch';" |
|
if env_type == 'svip': |
|
r = cursor.execute(sql_str, ('1',)) |
|
else: |
|
r = cursor.execute(sql_str, ('0',)) |
|
db_conn.commit() |
|
db_conn.close() |
|
print(r) |
|
return True if r==1 else False |
|
|
|
# Create your views here.
|
|
|