From 8940d23028eecab8dd9cc54492542435a8e06ee7 Mon Sep 17 00:00:00 2001 From: RogerWork Date: Fri, 24 May 2024 18:09:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E5=95=86=E6=8E=A5=E5=8F=A3=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dingxin_toolbox_drf/settings.py | 1 + dingxin_toolbox_drf/urls.py | 1 + dspt_api/__init__.py | 0 dspt_api/admin.py | 3 + dspt_api/apps.py | 6 + dspt_api/migrations/0001_initial.py | 120 ++++++++++++++++++ dspt_api/migrations/0002_ecenv_type.py | 18 +++ dspt_api/migrations/0003_ecchannel_type.py | 18 +++ ...capi_m_path_ecapi_type_alter_ecapi_path.py | 27 ++++ .../0005_alter_ecapiparams_value.py | 18 +++ dspt_api/migrations/__init__.py | 0 dspt_api/models.py | 116 +++++++++++++++++ dspt_api/serializers.py | 45 +++++++ dspt_api/tests.py | 3 + dspt_api/urls.py | 12 ++ dspt_api/views.py | 46 +++++++ 16 files changed, 434 insertions(+) create mode 100644 dspt_api/__init__.py create mode 100644 dspt_api/admin.py create mode 100644 dspt_api/apps.py create mode 100644 dspt_api/migrations/0001_initial.py create mode 100644 dspt_api/migrations/0002_ecenv_type.py create mode 100644 dspt_api/migrations/0003_ecchannel_type.py create mode 100644 dspt_api/migrations/0004_remove_ecapi_m_path_ecapi_type_alter_ecapi_path.py create mode 100644 dspt_api/migrations/0005_alter_ecapiparams_value.py create mode 100644 dspt_api/migrations/__init__.py create mode 100644 dspt_api/models.py create mode 100644 dspt_api/serializers.py create mode 100644 dspt_api/tests.py create mode 100644 dspt_api/urls.py create mode 100644 dspt_api/views.py diff --git a/dingxin_toolbox_drf/settings.py b/dingxin_toolbox_drf/settings.py index 7852b3b..6ddb6e9 100644 --- a/dingxin_toolbox_drf/settings.py +++ b/dingxin_toolbox_drf/settings.py @@ -82,6 +82,7 @@ INSTALLED_APPS = [ 'django_filters', 'update', 'mock', + 'dspt_api' ] MIDDLEWARE = [ diff --git a/dingxin_toolbox_drf/urls.py b/dingxin_toolbox_drf/urls.py index b5a6aa1..9c57425 100644 --- a/dingxin_toolbox_drf/urls.py +++ b/dingxin_toolbox_drf/urls.py @@ -24,6 +24,7 @@ urlpatterns = [ path('admin/', admin.site.urls), path('api-token-auth/', obtain_auth_token), path('update/', include('update.urls')), # cinema Update 备注 + path('ec/', include('dspt_api.urls')), # 电商平台接口 path('', include('mock.urls')), path('docs/', include_docs_urls(title='接口文档')), ] diff --git a/dspt_api/__init__.py b/dspt_api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dspt_api/admin.py b/dspt_api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/dspt_api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/dspt_api/apps.py b/dspt_api/apps.py new file mode 100644 index 0000000..5d80165 --- /dev/null +++ b/dspt_api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class DsptApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'dspt_api' diff --git a/dspt_api/migrations/0001_initial.py b/dspt_api/migrations/0001_initial.py new file mode 100644 index 0000000..154d9b4 --- /dev/null +++ b/dspt_api/migrations/0001_initial.py @@ -0,0 +1,120 @@ +# Generated by Django 4.2.7 on 2024-05-23 07:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='CinemaIds', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('env', models.CharField(max_length=10, verbose_name='环境')), + ('cinema_id', models.IntegerField(verbose_name='影院id')), + ('cinema_name', models.CharField(max_length=30, verbose_name='影院名称')), + ('cid', models.CharField(max_length=10, verbose_name='影院cid')), + ], + options={ + 'verbose_name': '影院cid', + 'verbose_name_plural': '影院cid', + 'db_table': 'ec_cinema_cid', + }, + ), + migrations.CreateModel( + name='EcApi', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('desc', models.CharField(max_length=20, verbose_name='接口描述')), + ('path', models.CharField(max_length=50, verbose_name='非会员接口地址')), + ('m_path', models.CharField(max_length=50, verbose_name='会员接口地址')), + ], + options={ + 'verbose_name': '接口', + 'verbose_name_plural': '接口', + 'db_table': 'ec_api', + }, + ), + migrations.CreateModel( + name='EcApiGroup', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('group_id', models.CharField(max_length=20, verbose_name='接口分组id')), + ('name', models.CharField(max_length=20, verbose_name='接口分组id')), + ('order', models.IntegerField(verbose_name='子接口顺序')), + ('api_id', models.IntegerField(verbose_name='接口id')), + ], + options={ + 'verbose_name': '接口组', + 'verbose_name_plural': '接口组', + 'db_table': 'ec_api_group', + }, + ), + migrations.CreateModel( + name='EcApiParams', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('api_id', models.IntegerField(verbose_name='接口id')), + ('param', models.CharField(max_length=50, verbose_name='参数')), + ('desc', models.CharField(max_length=500, verbose_name='参数描述')), + ('value', models.CharField(max_length=500, verbose_name='参数值模版')), + ('is_checked', models.BooleanField(default=False, verbose_name='是否默认勾选')), + ('is_request', models.BooleanField(default=False, verbose_name='是否是必选项')), + ], + options={ + 'verbose_name': '接口参数', + 'verbose_name_plural': '接口参数', + 'db_table': 'ec_api_params', + }, + ), + migrations.CreateModel( + name='EcChannel', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('env', models.CharField(max_length=10, verbose_name='环境')), + ('name', models.CharField(max_length=20, verbose_name='渠道名称')), + ('pid', models.CharField(max_length=10, verbose_name='渠道id')), + ('channel_key', models.CharField(max_length=20, verbose_name='渠道key')), + ], + options={ + 'verbose_name': '渠道', + 'verbose_name_plural': '渠道', + 'db_table': 'ec_channel', + }, + ), + migrations.CreateModel( + name='EcEnv', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=20, verbose_name='环境名称')), + ('code', models.CharField(max_length=20, verbose_name='环境编码')), + ('host', models.CharField(max_length=50, verbose_name='环境地址')), + ], + options={ + 'verbose_name': '环境', + 'verbose_name_plural': '环境', + 'db_table': 'ec_env', + }, + ), + migrations.CreateModel( + name='EcRequestLog', + fields=[ + ('id', models.IntegerField(primary_key=True, serialize=False)), + ('ip', models.CharField(max_length=20, verbose_name='请求ip')), + ('env', models.CharField(max_length=10, verbose_name='环境')), + ('request', models.CharField(max_length=500, verbose_name='请求链接')), + ('response', models.CharField(max_length=10000, verbose_name='返回值')), + ('request_datetime', models.DateTimeField(verbose_name='请求发送时间')), + ], + options={ + 'verbose_name': '请求日志', + 'verbose_name_plural': '请求日志', + 'db_table': 'ec_request_log', + }, + ), + ] diff --git a/dspt_api/migrations/0002_ecenv_type.py b/dspt_api/migrations/0002_ecenv_type.py new file mode 100644 index 0000000..791dbfc --- /dev/null +++ b/dspt_api/migrations/0002_ecenv_type.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-05-23 08:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dspt_api', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='ecenv', + name='type', + field=models.CharField(default='', max_length=20, verbose_name='会员非会员'), + ), + ] diff --git a/dspt_api/migrations/0003_ecchannel_type.py b/dspt_api/migrations/0003_ecchannel_type.py new file mode 100644 index 0000000..8a4548b --- /dev/null +++ b/dspt_api/migrations/0003_ecchannel_type.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-05-23 08:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dspt_api', '0002_ecenv_type'), + ] + + operations = [ + migrations.AddField( + model_name='ecchannel', + name='type', + field=models.CharField(default='', max_length=20, verbose_name='会员非会员'), + ), + ] diff --git a/dspt_api/migrations/0004_remove_ecapi_m_path_ecapi_type_alter_ecapi_path.py b/dspt_api/migrations/0004_remove_ecapi_m_path_ecapi_type_alter_ecapi_path.py new file mode 100644 index 0000000..c29ff22 --- /dev/null +++ b/dspt_api/migrations/0004_remove_ecapi_m_path_ecapi_type_alter_ecapi_path.py @@ -0,0 +1,27 @@ +# Generated by Django 4.2.7 on 2024-05-23 09:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dspt_api', '0003_ecchannel_type'), + ] + + operations = [ + migrations.RemoveField( + model_name='ecapi', + name='m_path', + ), + migrations.AddField( + model_name='ecapi', + name='type', + field=models.CharField(default='', max_length=20, verbose_name='会员非会员'), + ), + migrations.AlterField( + model_name='ecapi', + name='path', + field=models.CharField(max_length=50, verbose_name='接口地址'), + ), + ] diff --git a/dspt_api/migrations/0005_alter_ecapiparams_value.py b/dspt_api/migrations/0005_alter_ecapiparams_value.py new file mode 100644 index 0000000..ca3702b --- /dev/null +++ b/dspt_api/migrations/0005_alter_ecapiparams_value.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.7 on 2024-05-23 10:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dspt_api', '0004_remove_ecapi_m_path_ecapi_type_alter_ecapi_path'), + ] + + operations = [ + migrations.AlterField( + model_name='ecapiparams', + name='value', + field=models.CharField(blank=True, max_length=500, null=True, verbose_name='参数值模版'), + ), + ] diff --git a/dspt_api/migrations/__init__.py b/dspt_api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dspt_api/models.py b/dspt_api/models.py new file mode 100644 index 0000000..04e66df --- /dev/null +++ b/dspt_api/models.py @@ -0,0 +1,116 @@ +from django.db import models + + +class EcChannel(models.Model): + id = models.IntegerField(primary_key=True) + env = models.CharField(verbose_name='环境', max_length=10, null=False) # 电商平台 dspt 自营电商 zyds + name = models.CharField(verbose_name='渠道名称', max_length=20, null=False) # 电商平台 dspt 自营电商 zyds + pid = models.CharField(verbose_name='渠道id', max_length=10, null=False) # pid + channel_key = models.CharField(verbose_name='渠道key', max_length=20, null=False) # pid key + type = models.CharField(verbose_name='会员非会员', max_length=20, default='', null=False) # 会员 member 非会员 nonmember + + def __str__(self): + return self.name + + class Meta: + verbose_name = '渠道' + verbose_name_plural = '渠道' + db_table = 'ec_channel' + + +class EcEnv(models.Model): + id = models.IntegerField(primary_key=True) + name = models.CharField(verbose_name='环境名称', max_length=20, null=False) # 电商平台 自营电商 + code = models.CharField(verbose_name='环境编码', max_length=20, null=False) # 电商平台 dspt 自营电商 zyds + type = models.CharField(verbose_name='会员非会员', max_length=20, default='', null=False) # 会员 member 非会员 nonmember + host = models.CharField(verbose_name='环境地址', max_length=50, null=False) # 环境地址 + + def __str__(self): + return self.name + + class Meta: + verbose_name = '环境' + verbose_name_plural = '环境' + db_table = 'ec_env' + + +class EcApi(models.Model): + id = models.IntegerField(primary_key=True) + desc = models.CharField(verbose_name='接口描述', max_length=20, null=False) + path = models.CharField(verbose_name='接口地址', max_length=50, null=False) + type = models.CharField(verbose_name='会员非会员', max_length=20, default='', null=False) # 会员 member 非会员 nonmember + + def __str__(self): + return self.desc + + class Meta: + verbose_name = '接口' + verbose_name_plural = '接口' + db_table = 'ec_api' + + +class EcApiParams(models.Model): + id = models.IntegerField(primary_key=True) + api_id = models.IntegerField(verbose_name='接口id', null=False) + param = models.CharField(verbose_name='参数', max_length=50, null=False) + desc = models.CharField(verbose_name='参数描述', max_length=500, null=False) + value = models.CharField(verbose_name='参数值模版', max_length=500, null=True, blank=True) + is_checked = models.BooleanField(verbose_name='是否默认勾选', null=False, default=False) + is_request = models.BooleanField(verbose_name='是否是必选项', null=False, default=False) + + def __str__(self): + return self.param + + class Meta: + verbose_name = '接口参数' + verbose_name_plural = '接口参数' + db_table = 'ec_api_params' + + +class EcCinemaIds(models.Model): + id = models.IntegerField(primary_key=True) + env = models.CharField(verbose_name='环境', max_length=10, null=False) # 电商平台 dspt 自营电商 zyds + cinema_id = models.IntegerField(verbose_name='影院id', null=False) + cinema_name = models.CharField(verbose_name='影院名称', max_length=30, null=False) + cid = models.CharField(verbose_name='影院cid', max_length=10, null=False) + + def __str__(self): + return self.cid + + class Meta: + verbose_name = '影院cid' + verbose_name_plural = '影院cid' + db_table = 'ec_cinema_cid' + + +class EcRequestLog(models.Model): + id = models.IntegerField(primary_key=True) + ip = models.CharField(verbose_name='请求ip', max_length=20, null=False) # 接口测试人的ip + env = models.CharField(verbose_name='环境', max_length=10, null=False) # 电商平台 dspt 自营电商 zyds + request = models.CharField(verbose_name='请求链接', max_length=500, null=False) + response = models.CharField(verbose_name='返回值', max_length=10000, null=False) + request_datetime = models.DateTimeField(verbose_name='请求发送时间', null=False) + + def __str__(self): + return self.ip + + class Meta: + verbose_name = '请求日志' + verbose_name_plural = '请求日志' + db_table = 'ec_request_log' + + +class EcApiGroup(models.Model): + id = models.IntegerField(primary_key=True) + group_id = models.CharField(verbose_name='接口分组id', max_length=20, null=False) + name = models.CharField(verbose_name='接口分组id', max_length=20, null=False) + order = models.IntegerField(verbose_name='子接口顺序', null=False) + api_id = models.IntegerField(verbose_name='接口id', null=False) + + def __str__(self): + return self.name + + class Meta: + verbose_name = '接口组' + verbose_name_plural = '接口组' + db_table = 'ec_api_group' diff --git a/dspt_api/serializers.py b/dspt_api/serializers.py new file mode 100644 index 0000000..3b8a03b --- /dev/null +++ b/dspt_api/serializers.py @@ -0,0 +1,45 @@ +from rest_framework import serializers + +from dspt_api.models import EcChannel, EcEnv, EcApi, EcApiParams, EcCinemaIds, EcRequestLog, EcApiGroup + + +class EcChannelSerializer(serializers.ModelSerializer): + class Meta: + model = EcChannel + fields = '__all__' + + +class EcEnvSerializer(serializers.ModelSerializer): + class Meta: + model = EcEnv + fields = '__all__' + + +class EcApiSerializer(serializers.ModelSerializer): + class Meta: + model = EcApi + fields = '__all__' + + +class EcApiParamsSerializer(serializers.ModelSerializer): + class Meta: + model = EcApiParams + fields = '__all__' + + +class EcCinemaIdsSerializer(serializers.ModelSerializer): + class Meta: + model = EcCinemaIds + fields = '__all__' + + +class EcRequestLogSerializer(serializers.ModelSerializer): + class Meta: + model = EcRequestLog + fields = '__all__' + + +class EcApiGroupSerializer(serializers.ModelSerializer): + class Meta: + model = EcApiGroup + fields = '__all__' diff --git a/dspt_api/tests.py b/dspt_api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/dspt_api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/dspt_api/urls.py b/dspt_api/urls.py new file mode 100644 index 0000000..52bdbcc --- /dev/null +++ b/dspt_api/urls.py @@ -0,0 +1,12 @@ +from dspt_api import views +from django.urls import path + +urlpatterns = [ + path('get_channel', views.EcChannelViewSet.as_view({'get': 'list'}), name='get_ec_channel'), + path('get_env', views.EcEnvViewSet.as_view({'get': 'list'}), name='get_ec_env'), + path('get_api', views.EcApiViewSet.as_view({'get': 'list'}), name='get_ec_api'), + path('get_api_params', views.EcApiParamsViewSet.as_view({'get': 'list'}), name='get_ec_api_params'), + path('get_cinema_ids', views.EcCinemaIdsViewSet.as_view({'get': 'list'}), name='get_ec_cinema_ids'), + path('get_request_log', views.EcRequestLogViewSet.as_view({'get': 'list'}), name='get_ec_request_log'), + path('get_api_group', views.EcApiGroupViewSet.as_view({'get': 'list'}), name='get_ec_api_group'), +] diff --git a/dspt_api/views.py b/dspt_api/views.py new file mode 100644 index 0000000..a04d11b --- /dev/null +++ b/dspt_api/views.py @@ -0,0 +1,46 @@ +from django_filters.rest_framework import DjangoFilterBackend +from rest_framework import filters +from rest_framework import viewsets + +from dspt_api.models import EcChannel, EcEnv, EcApi, EcApiParams, EcCinemaIds, EcRequestLog, EcApiGroup +from dspt_api.serializers import EcChannelSerializer, EcEnvSerializer, EcApiSerializer, EcApiParamsSerializer, \ + EcCinemaIdsSerializer, EcRequestLogSerializer, EcApiGroupSerializer + + +# Create your views here. +class EcChannelViewSet(viewsets.ModelViewSet): + queryset = EcChannel.objects.all() + serializer_class = EcChannelSerializer + + +class EcEnvViewSet(viewsets.ModelViewSet): + queryset = EcEnv.objects.all() + serializer_class = EcEnvSerializer + + +class EcApiViewSet(viewsets.ModelViewSet): + queryset = EcApi.objects.all() + serializer_class = EcApiSerializer + + +class EcApiParamsViewSet(viewsets.ModelViewSet): + queryset = EcApiParams.objects.all() + serializer_class = EcApiParamsSerializer + filter_backends = (filters.SearchFilter, DjangoFilterBackend) + # http://172.16.1.114:8000/ec/get_api_params?api_id=1 + filterset_fields = ('api_id',) + + +class EcCinemaIdsViewSet(viewsets.ModelViewSet): + queryset = EcCinemaIds + serializer_class = EcCinemaIdsSerializer + + +class EcRequestLogViewSet(viewsets.ModelViewSet): + queryset = EcRequestLog.objects.all() + serializer_class = EcRequestLogSerializer + + +class EcApiGroupViewSet(viewsets.ModelViewSet): + queryset = EcApiGroup.objects.all() + serializer_class = EcApiGroupSerializer