From 83962621596b6c3aff3e119dd6b63abe772b7df6 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Fri, 6 Jun 2025 14:07:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0config=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=8C=E7=AC=AC=E4=B8=80=E4=B8=AA=E5=8A=9F=E8=83=BD=E4=B8=BA?= =?UTF-8?q?=E8=87=AA=E8=90=A5=E7=8E=AF=E5=A2=83=E5=88=87=E6=8D=A2SVIP?= =?UTF-8?q?=E5=92=8C=E6=99=AE=E9=80=9A=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/__init__.py | 0 config/admin.py | 3 ++ config/apps.py | 6 ++++ config/migrations/__init__.py | 0 config/models.py | 3 ++ config/tests.py | 3 ++ config/urls.py | 23 +++++++++++++++ config/views.py | 51 +++++++++++++++++++++++++++++++++ dingxin_toolbox_drf/settings.py | 5 ++-- dingxin_toolbox_drf/urls.py | 1 + 10 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 config/__init__.py create mode 100644 config/admin.py create mode 100644 config/apps.py create mode 100644 config/migrations/__init__.py create mode 100644 config/models.py create mode 100644 config/tests.py create mode 100644 config/urls.py create mode 100644 config/views.py diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/admin.py b/config/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/config/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/config/apps.py b/config/apps.py new file mode 100644 index 0000000..0ebf97c --- /dev/null +++ b/config/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ConfigConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'config' diff --git a/config/migrations/__init__.py b/config/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/models.py b/config/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/config/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/config/tests.py b/config/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/config/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..9d1f69d --- /dev/null +++ b/config/urls.py @@ -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) +] diff --git a/config/views.py b/config/views.py new file mode 100644 index 0000000..c81443c --- /dev/null +++ b/config/views.py @@ -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. diff --git a/dingxin_toolbox_drf/settings.py b/dingxin_toolbox_drf/settings.py index 99b6e0d..e22829b 100644 --- a/dingxin_toolbox_drf/settings.py +++ b/dingxin_toolbox_drf/settings.py @@ -116,7 +116,8 @@ INSTALLED_APPS = [ 'update', 'mock', 'dspt_api', - 'product' + 'product', + 'config' ] MIDDLEWARE = [ @@ -224,7 +225,7 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ -STATIC_URL = '/static' +STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') # STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] diff --git a/dingxin_toolbox_drf/urls.py b/dingxin_toolbox_drf/urls.py index c7abe51..8898acf 100644 --- a/dingxin_toolbox_drf/urls.py +++ b/dingxin_toolbox_drf/urls.py @@ -32,6 +32,7 @@ urlpatterns = [ path('', include('mock.urls')), path('docs/', include_docs_urls(title='接口文档')), path('prd/', include('product.urls')), + path('config/', include('config.urls')), ] websocket_urlpatterns = [