|
@@ -0,0 +1,169 @@
|
|
|
+from Model.models import Order_Model,UID_Bucket,UserExModel,App_Info
|
|
|
+from django.http import JsonResponse
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from django.views import View
|
|
|
+
|
|
|
+from django.utils.decorators import method_decorator
|
|
|
+from django.views.generic import TemplateView
|
|
|
+from django.views.decorators.csrf import csrf_exempt
|
|
|
+from Service.ModelService import ModelService
|
|
|
+class Cloudsum(TemplateView):
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
+ return super(Cloudsum, self).dispatch(*args, **kwargs)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ return self.validation(request_dict=request.GET)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ return self.validation(request_dict=request.POST)
|
|
|
+
|
|
|
+ def validation(self, request_dict, *args, **kwargs):
|
|
|
+ response = ResponseObject()
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ operation = request_dict.get('operation', None)
|
|
|
+ print("userID",userID)
|
|
|
+ print('operation:', operation)
|
|
|
+ if userID is None or operation is None:
|
|
|
+ return response.json(444, 'operation')
|
|
|
+ if operation == 'cloudservicesum':
|
|
|
+ return self.cloudservicesum(userID, response)
|
|
|
+ if operation == 'userappversion':
|
|
|
+ return self.userappversion(userID, response)
|
|
|
+
|
|
|
+ # 类型:用户手机
|
|
|
+ # 统计用户手机型号 已有
|
|
|
+ # 统计某段时间内新用户的增长数
|
|
|
+ # 统计一天用户打开zosi app的频率 已有
|
|
|
+ # 统计用户下载zosi app数,卸载人数
|
|
|
+ # 统计用户使用zosi app的版本√
|
|
|
+ def userappversion(self, userID, response):
|
|
|
+ # own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ # if own_permission is not True:
|
|
|
+ # return response.json(404)
|
|
|
+ version = UserExModel.objects.values_list('appBundleId').order_by('appBundleId').distinct()
|
|
|
+ res = App_Info.objects.filter(appBundleId__in=version).values_list('appBundleId','newAppversion')
|
|
|
+ return response.json(0, dict(res))
|
|
|
+
|
|
|
+ # 类型:云存服务统计
|
|
|
+ # 统计开通云存的设备有多少台√
|
|
|
+ # 统计未支付,支付成功的订单√
|
|
|
+ # 统计开通云存的增长率
|
|
|
+ # 统计已开通云存的各套餐总数√
|
|
|
+ # 统计已支付的订单总金额√
|
|
|
+ def cloudservicesum(self, userID, response):
|
|
|
+ # own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ # if own_permission is not True:
|
|
|
+ # return response.json(404)
|
|
|
+ from django.db.models import Sum
|
|
|
+ uid_cloud = UID_Bucket.objects.values('uid').distinct().count()
|
|
|
+ pay_0 = Order_Model.objects.filter(status='0').count()
|
|
|
+ pay_1 = Order_Model.objects.filter(status='1').count()
|
|
|
+ money = Order_Model.objects.filter(status='1').aggregate(Sum('price'))
|
|
|
+ print(type(money))
|
|
|
+ print(money)
|
|
|
+ cloud_sum = UID_Bucket.objects.all().count()
|
|
|
+ data_dict = {
|
|
|
+ "开通云存的设备数": uid_cloud,
|
|
|
+ "未支付的订单数": pay_0,
|
|
|
+ "已支付的订单数": pay_1,
|
|
|
+ "已支付的订单总金额": money['price__sum'],
|
|
|
+ "已开通云存的各套餐总数": cloud_sum,
|
|
|
+ }
|
|
|
+ return response.json(0, data_dict)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class Cloudsum_test(View):
|
|
|
+ def dispatch(self, requset, *args, **kwargs):
|
|
|
+ return super(Cloudsum_test, self).dispatch(requset, *args, **kwargs)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ print('operation:',operation)
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
+ response = ResponseObject()
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ userID = tko.userID
|
|
|
+ print('userID:',userID)
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ if userID is None or operation is None:
|
|
|
+ return response.json(444, 'operation')
|
|
|
+ if operation == 'cloudservicesum':
|
|
|
+ return self.cloudservicesum(userID, response)
|
|
|
+
|
|
|
+ def cloudservicesum(self, userID, response):
|
|
|
+ # own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ # if own_permission is not True:
|
|
|
+ # return response.json(404)
|
|
|
+ from django.db.models import Sum
|
|
|
+ uid_cloud = UID_Bucket.objects.values('uid').distinct().count()
|
|
|
+ pay_0 = Order_Model.objects.filter(status='0').count()
|
|
|
+ pay_1 = Order_Model.objects.filter(status='1').count()
|
|
|
+ money = Order_Model.objects.filter(status='1').aggregate(Sum('price'))
|
|
|
+ cloud_sum = UID_Bucket.objects.all().count()
|
|
|
+ data_dict = {
|
|
|
+ "开通云存的设备数": uid_cloud,
|
|
|
+ "未支付的订单数": pay_0,
|
|
|
+ "已支付的订单数": pay_1,
|
|
|
+ "已支付的订单总金额": money['price__sum'],
|
|
|
+ "已开通云存的各套餐总数": cloud_sum,
|
|
|
+ }
|
|
|
+ return response.json(0, data_dict)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def test(request):
|
|
|
+ from django.db.models import Sum
|
|
|
+ pay_0 = Order_Model.objects.filter(status='0').count()
|
|
|
+ pay_1 = Order_Model.objects.filter(status='1').count()
|
|
|
+ money = Order_Model.objects.filter(status='1').aggregate(Sum('price'))
|
|
|
+ print(pay_0)
|
|
|
+ print(money['price__sum'])
|
|
|
+ data_dict = {
|
|
|
+ "未支付的订单数": pay_0,
|
|
|
+ "已支付的订单数": pay_1,
|
|
|
+ "已支付的订单总金额": money['price__sum'],
|
|
|
+ }
|
|
|
+ return JsonResponse(data_dict, json_dumps_params={'ensure_ascii':False},safe=False)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|