|
@@ -0,0 +1,159 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+import time
|
|
|
+
|
|
|
+from django.db.models import F
|
|
|
+from django.views.generic.base import View
|
|
|
+
|
|
|
+from Model.models import Lang, ICloudStoreMeal, AiService, Order_Model, Device_User, CountryModel, UidSetModel, \
|
|
|
+ Device_Info, VodBucketModel
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from Service.CommonService import CommonService
|
|
|
+
|
|
|
+
|
|
|
+class IcloudServeView(View):
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
+ language = request_dict.get('language', 'en')
|
|
|
+ response = ResponseObject(language, 'pc')
|
|
|
+ if operation == 'xxx': # 不认证token接口
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ tko = TokenObject(
|
|
|
+ request.META.get('HTTP_AUTHORIZATION'),
|
|
|
+ returntpye='pc')
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ response.lang = tko.lang
|
|
|
+ user_id = tko.userID
|
|
|
+ # ai套餐信息相关
|
|
|
+ if operation == 'getIcloudStoreMealList':
|
|
|
+ return self.get_icloud_store_meal_list(request_dict, response)
|
|
|
+ elif operation == 'addOrEditIcloudStoreMeal':
|
|
|
+ return self.add_or_edit_icloud_store_meal(request_dict, response)
|
|
|
+ elif operation == 'getMealLang':
|
|
|
+ return self.get_meal_lang(request_dict, response)
|
|
|
+ # ai套餐语言相关
|
|
|
+ elif operation == 'getAiMealLanguage':
|
|
|
+ return self.getAiMealLanguage(request_dict, response)
|
|
|
+ elif operation == 'addOrEditAiMealLanguage':
|
|
|
+ return self.addOrEditAiMealLanguage(request_dict, response)
|
|
|
+ elif operation == 'deleteAiMealLanguage':
|
|
|
+ return self.deleteAiMealLanguage(request_dict, response)
|
|
|
+ # 设备ai套餐相关
|
|
|
+ elif operation == 'getDeviceAiMealList':
|
|
|
+ return self.getDeviceAiMealList(request_dict, response)
|
|
|
+ # ai用户信息相关
|
|
|
+ elif operation == 'getAiUserList':
|
|
|
+ return self.getAiUserList(request_dict, response)
|
|
|
+ # ai服务开通数量数据
|
|
|
+ elif operation == 'getAiDataList':
|
|
|
+ return self.getAiDataList(request_dict, response)
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_icloud_store_meal_list(request_dict, response):
|
|
|
+ is_select = request_dict.get('isSelect', None)
|
|
|
+ page = request_dict.get('pageNo', None)
|
|
|
+ line = request_dict.get('pageSize', None)
|
|
|
+ if is_select:
|
|
|
+ # 获取套餐ID作为选项
|
|
|
+ icloud_meal_qs = ICloudStoreMeal.objects.filter().values('id')
|
|
|
+ return response.json(0, {'list': CommonService.qs_to_list(icloud_meal_qs)})
|
|
|
+ if not all([page, line]):
|
|
|
+ return response.json(444)
|
|
|
+ page = int(page)
|
|
|
+ line = int(line)
|
|
|
+ try:
|
|
|
+ icloud_meal_qs = ICloudStoreMeal.objects.values()
|
|
|
+ total = icloud_meal_qs.count()
|
|
|
+ icloud_meals = icloud_meal_qs[(page - 1) * line:page * line]
|
|
|
+ icloud_meal_list = []
|
|
|
+ for icloud_meal in icloud_meals:
|
|
|
+ # 获取支付方式列表
|
|
|
+ pay_type_list = list(ICloudStoreMeal.objects.filter(id=icloud_meal['id']).values('pay_type__payment'))
|
|
|
+ # 获取套餐语言
|
|
|
+ lang_list = list(ICloudStoreMeal.objects.filter(id=icloud_meal['id']).values('lang__lang',
|
|
|
+ 'lang__title',
|
|
|
+ 'lang__content'))
|
|
|
+ # 获取存储桶信息
|
|
|
+ vod_bucket_qs = VodBucketModel.objects.filter(id=icloud_meal['bucket_id']).values('bucket')
|
|
|
+ # 组织响应数据
|
|
|
+ icloud_meal_list.append({
|
|
|
+ 'IcloudMealID': icloud_meal['id'],
|
|
|
+ 'price': icloud_meal['price'],
|
|
|
+ 'symbol': icloud_meal['symbol'],
|
|
|
+ 'currency': icloud_meal['currency'],
|
|
|
+ 'is_show': icloud_meal['is_show'],
|
|
|
+ 'is_delete': icloud_meal['is_delete'],
|
|
|
+ 'expire': icloud_meal['expire'],
|
|
|
+ 'pay_type': pay_type_list,
|
|
|
+ 'lang': lang_list,
|
|
|
+ 'size': icloud_meal['size'],
|
|
|
+ 'bucket': vod_bucket_qs[0]['bucket'],
|
|
|
+ 'addTime': icloud_meal['add_time'].strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
+ 'updTime': icloud_meal['update_time'].strftime("%Y-%m-%d %H:%M:%S"),
|
|
|
+ })
|
|
|
+ return response.json(0, {'list': icloud_meal_list, 'total': total})
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def add_or_edit_icloud_store_meal(request_dict, response):
|
|
|
+ # 添加/编辑套餐
|
|
|
+ meal_id = request_dict.get('MealID', None)
|
|
|
+ expire = int(request_dict.get('expire', None))
|
|
|
+ price = request_dict.get('price', None)
|
|
|
+ currency = request_dict.get('currency', None)
|
|
|
+ symbol = request_dict.get('symbol', None)
|
|
|
+ pay_type = request_dict.get('pay_type', None)
|
|
|
+ lang = request_dict.get('lang', None)
|
|
|
+ is_show = int(request_dict.get('is_show', 1))
|
|
|
+ is_delete = int(request_dict.get('is_delete', 0))
|
|
|
+ size = int(request_dict.get('size', None))
|
|
|
+ is_edit = request_dict.get('isEdit', None)
|
|
|
+
|
|
|
+ if not all([expire, price, currency, symbol, pay_type, lang, size]):
|
|
|
+ return response.json(444)
|
|
|
+ pay_type = pay_type.split(',')
|
|
|
+ lang = lang.split(',')
|
|
|
+ try:
|
|
|
+ icloud_store_meal_data = {
|
|
|
+ 'expire': expire,
|
|
|
+ 'price': price,
|
|
|
+ 'currency': currency,
|
|
|
+ 'symbol': symbol,
|
|
|
+ 'is_show': is_show,
|
|
|
+ 'size': size,
|
|
|
+ 'is_delete': is_delete
|
|
|
+ }
|
|
|
+ if is_edit:
|
|
|
+ if not meal_id:
|
|
|
+ return response.json(444)
|
|
|
+ ICloudStoreMeal.objects.filter(id=meal_id).update(**icloud_store_meal_data)
|
|
|
+ ICloudStoreMeal.objects.get(id=meal_id).pay_type.set(pay_type)
|
|
|
+ ICloudStoreMeal.objects.get(id=meal_id).lang.set(lang)
|
|
|
+ else:
|
|
|
+ icloud_meal_qs = ICloudStoreMeal.objects.create(**icloud_store_meal_data)
|
|
|
+ icloud_meal_qs.pay_type.set(pay_type)
|
|
|
+ icloud_meal_qs.lang.set(lang)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_meal_lang(request_dict, response):
|
|
|
+ lang = Lang.objects.filter(type=3).values('id', 'lang', 'title', 'content')
|
|
|
+ return response.json(0, list(lang))
|