浏览代码

修改统计云存数据接口

locky 8 月之前
父节点
当前提交
6cfe18f5b4
共有 1 个文件被更改,包括 47 次插入41 次删除
  1. 47 41
      Controller/TestApi.py

+ 47 - 41
Controller/TestApi.py

@@ -201,7 +201,7 @@ class testView(View):
         elif operation == 'checkSerialUID':
             return self.checkSerialUID(response)
         elif operation == 'statisticalCloudStorageData':
-            return self.statistical_cloud_storage_data()
+            return self.statistical_cloud_storage_data(response)
         else:
             return response.json(414)
 
@@ -1527,49 +1527,55 @@ class testView(View):
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
     @staticmethod
-    def statistical_cloud_storage_data():
+    def statistical_cloud_storage_data(response):
         """
         统计近一年的云存数据
         @return:
         """
-        joined_time = '2023-12-2'
-        uid_list = Device_Info.objects.filter(data_joined__gt=joined_time).values_list('UID', flat=True)
-        uid_set_qs = UidSetModel.objects.filter(uid__in=UidSetModel).values('uid', 'ucode', 'device_type')
-        cloud_vod_count, on_experience_count, only_experience_count, pay_count = 0, 0, 0, 0
-        two_mp_count = three_mp_count = four_mp_count = five_mp_count = eight_mp_count = 0, 0, 0, 0, 0
-        for uid_set in uid_set_qs:
-            ucode = uid_set['ucode']
-            cloud_vod = CommonService.is_cloud_device(
-                ucode, uid_set['device_type']
-            )
-            if cloud_vod:
-                uid = uid_set['uid']
-                cloud_vod_count += 1
-                experience_qs = ExperienceContextModel.objects.filter(uid=uid)
-                if experience_qs.exists():
-                    # 购买过付费套餐
-                    order_qs = Order_Model.objects.filter(UID=uid)
-                    if order_qs.exists():
-                        pay_count += 1
+        try:
+            # joined_time = '2023-12-2'
+            # uid_list = Device_Info.objects.filter(data_joined__gt=joined_time).values_list('UID', flat=True)
+            uid_list = []
+            uid_set_qs = UidSetModel.objects.filter(uid__in=uid_list).values('uid', 'ucode', 'device_type')
+            cloud_vod_count, on_experience_count, only_experience_count, pay_count = 0, 0, 0, 0
+            two_mp_count, three_mp_count, four_mp_count, five_mp_count, eight_mp_count = 0, 0, 0, 0, 0
+            for uid_set in uid_set_qs:
+                ucode = uid_set['ucode']
+                cloud_vod = CommonService.is_cloud_device(
+                    ucode, uid_set['device_type']
+                )
+                if cloud_vod:
+                    uid = uid_set['uid']
+                    cloud_vod_count += 1
+                    experience_qs = ExperienceContextModel.objects.filter(uid=uid)
+                    if experience_qs.exists():
+                        # 购买过付费套餐
+                        order_qs = Order_Model.objects.filter(UID=uid, status=1, payType__in=[1, 5])
+                        if order_qs.exists():
+                            pay_count += 1
+                        else:
+                            only_experience_count += 1
+                    # 未体验过云存
                     else:
-                        only_experience_count += 1
-                # 未体验过云存
-                else:
-                    on_experience_count += 1
-                # 查询设备分辨率
-                resolution_identification = ucode[-5]
-                if resolution_identification == '2':
-                    two_mp_count += 1
-                elif resolution_identification == '3':
-                    three_mp_count += 1
-                elif resolution_identification == '4':
-                    four_mp_count += 1
-                elif resolution_identification in ['5', 'A']:
-                    five_mp_count += 1
-                elif resolution_identification == '8':
-                    eight_mp_count += 1
-        print('支持云存设备数量:{}, 未使用过云存设备数量:{}, 仅体验设备数量:{}, 云存付费设备数量:{}'.
-              format(cloud_vod_count, on_experience_count, only_experience_count, pay_count))
-        print('2MP:{}, 3MP:{}, 4MP:{}, 5MP:{}, 8MP:{}'.
-              format(two_mp_count, three_mp_count, four_mp_count, five_mp_count, eight_mp_count))
+                        on_experience_count += 1
+                    # 查询设备分辨率
+                    resolution_identification = ucode[-5]
+                    if resolution_identification == '2':
+                        two_mp_count += 1
+                    elif resolution_identification == '3':
+                        three_mp_count += 1
+                    elif resolution_identification == '4':
+                        four_mp_count += 1
+                    elif resolution_identification in ['5', 'A']:
+                        five_mp_count += 1
+                    elif resolution_identification == '8':
+                        eight_mp_count += 1
+            res = '支持云存设备数量:{}, 未使用过云存设备数量:{}, 仅体验设备数量:{}, 云存付费设备数量:{}, '.\
+                format(cloud_vod_count, on_experience_count, only_experience_count, pay_count)
+            res += '2MP:{}, 3MP:{}, 4MP:{}, 5MP:{}, 8MP:{}'.\
+                format(two_mp_count, three_mp_count, four_mp_count, five_mp_count, eight_mp_count)
+            print(res)
+            return response.json(0, res)
+        except Exception as e:
+            return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))