|
@@ -1,169 +1,121 @@
|
|
|
-from Model.models import Order_Model,UID_Bucket,UserExModel,App_Info
|
|
|
-from django.http import JsonResponse
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+"""
|
|
|
+@Time : 2021/1/8 12:00
|
|
|
+@Auth : liehaoquan
|
|
|
+@File :Cloudsum.py
|
|
|
+@IDE :PyCharm
|
|
|
+"""
|
|
|
+from Model.models import Order_Model, UID_Bucket, UserExModel, App_Info
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from django.views import View
|
|
|
+from Service.ModelService import Device_User,ModelService
|
|
|
+from django.db.models import Count, Sum
|
|
|
|
|
|
-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)
|
|
|
+class Cloudsum(View):
|
|
|
+ def dispatch(self, requset, *args, **kwargs):
|
|
|
+ return super(Cloudsum, self).dispatch(requset, *args, **kwargs)
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
+ operation = kwargs.get('operation')
|
|
|
request.encoding = 'utf-8'
|
|
|
- return self.validation(request_dict=request.GET)
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
+ operation = kwargs.get('operation')
|
|
|
request.encoding = 'utf-8'
|
|
|
- return self.validation(request_dict=request.POST)
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
|
|
|
- def validation(self, request_dict, *args, **kwargs):
|
|
|
+ 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)
|
|
|
- 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)
|
|
|
+ if operation == 'usercount':
|
|
|
+ return self.usercount(userID, request_dict, response)
|
|
|
+ if operation == 'usercloud':
|
|
|
+ return self.usercloud(userID, response)
|
|
|
|
|
|
# 类型:用户手机
|
|
|
# 统计用户手机型号 已有
|
|
|
- # 统计某段时间内新用户的增长数
|
|
|
+ # 统计某段时间内新用户的增长数√
|
|
|
# 统计一天用户打开zosi app的频率 已有
|
|
|
# 统计用户下载zosi app数,卸载人数
|
|
|
# 统计用户使用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))
|
|
|
+ own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ if own_permission is not True:
|
|
|
+ return response.json(404)
|
|
|
+ res = UserExModel.objects.extra(tables=['App_Info'],
|
|
|
+ select={'appname':'App_Info.appName',
|
|
|
+ 'appversion':'App_Info.newAppversion'},
|
|
|
+ where=["user_ex.appBundleId=app_Info.appBundleId"]).\
|
|
|
+ values('appBundleId','appname','appversion').annotate(dates=Count('appBundleId')).order_by()
|
|
|
+ print(res.query)
|
|
|
+ print(res)
|
|
|
+ return response.json(0, list(res))
|
|
|
+
|
|
|
+ # 统计某段时间内新用户的增长数
|
|
|
+ def usercount(self, userID, request_dict, response):
|
|
|
+ own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ if own_permission is not True:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+ # 优化代码
|
|
|
+ # usercountyear = request_dict.get('usercountyear', None)
|
|
|
+ # if usercountyear == None:
|
|
|
+ # return response.json(444)
|
|
|
+ # usercountyear = int(usercountyear)
|
|
|
+ # count = Device_User.objects.extra(select={'dates': "DATE_FORMAT(data_joined,'%%Y-%%m')"},
|
|
|
+ # where=["data_joined between '%s-01-01' and '%s-01-01' "],
|
|
|
+ # params=[usercountyear, usercountyear+1]).values(
|
|
|
+ # 'dates').annotate(用户合计=Count('data_joined')).order_by('dates')
|
|
|
+ count = Device_User.objects.extra(select={'dates': "DATE_FORMAT(data_joined,'%%Y-%%m')"},).values(
|
|
|
+ 'dates').annotate(用户合计=Count('data_joined')).order_by('dates')
|
|
|
+ print(count.query)
|
|
|
+ return response.json(0, list(count))
|
|
|
|
|
|
# 类型:云存服务统计
|
|
|
# 统计开通云存的设备有多少台√
|
|
|
# 统计未支付,支付成功的订单√
|
|
|
- # 统计开通云存的增长率
|
|
|
+ # 统计开通云存的增长率 (每个月开通云存的总数)√
|
|
|
# 统计已开通云存的各套餐总数√
|
|
|
# 统计已支付的订单总金额√
|
|
|
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
|
|
|
+ own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ if own_permission is not True:
|
|
|
+ return response.json(404)
|
|
|
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)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ return response.json(0, data_dict)
|
|
|
|
|
|
+ # 每个月开通云存的总数
|
|
|
+ def usercloud(self, userID, response):
|
|
|
+ own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
+ if own_permission is not True:
|
|
|
+ return response.json(404)
|
|
|
+ a = Order_Model.objects.extra(select={'dates': "FROM_UNIXTIME(addTime,'%%Y-%%m')"}).values(
|
|
|
+ 'dates').filter(status=1).annotate(开通云存合计=Count('addTime')).order_by('dates')
|
|
|
+ return response.json(0, list(a))
|