parent
50e1e5cc42
commit
8396262159
10 changed files with 93 additions and 2 deletions
@ -0,0 +1,3 @@ |
||||
from django.contrib import admin |
||||
|
||||
# Register your models here. |
@ -0,0 +1,6 @@ |
||||
from django.apps import AppConfig |
||||
|
||||
|
||||
class ConfigConfig(AppConfig): |
||||
default_auto_field = 'django.db.models.BigAutoField' |
||||
name = 'config' |
@ -0,0 +1,3 @@ |
||||
from django.db import models |
||||
|
||||
# Create your models here. |
@ -0,0 +1,3 @@ |
||||
from django.test import TestCase |
||||
|
||||
# Create your tests here. |
@ -0,0 +1,23 @@ |
||||
""" |
||||
URL configuration for dingxin_toolbox_drf project. |
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see: |
||||
https://docs.djangoproject.com/en/4.2/topics/http/urls/ |
||||
Examples: |
||||
Function views |
||||
1. Add an import: from my_app import views |
||||
2. Add a URL to urlpatterns: path('', views.home, name='home') |
||||
Class-based views |
||||
1. Add an import: from other_app.views import Home |
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') |
||||
Including another URLconf |
||||
1. Import the include() function: from django.urls import include, path |
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) |
||||
""" |
||||
from django.contrib import admin |
||||
from django.urls import path, include |
||||
from config.views import * |
||||
|
||||
urlpatterns = [ |
||||
path('zy_switch_svip', zy_switch_svip) |
||||
] |
@ -0,0 +1,51 @@ |
||||
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. |
Loading…
Reference in new issue