浏览代码

Merge branch 'pzb' of ssh://192.168.136.45:10022/SERVER/AnsjerServer into pzb

chenjunkai 6 年之前
父节点
当前提交
a5d34a1bd3
共有 2 个文件被更改,包括 45 次插入18 次删除
  1. 44 17
      Controller/UserBrandController.py
  2. 1 1
      Model/models.py

+ 44 - 17
Controller/UserBrandController.py

@@ -24,8 +24,11 @@ from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
 from collections import Counter
 from collections import Counter
 '''
 '''
-http://192.168.136.45:8077/userbrandinfo/query?token=test&page=1&line=10
-http://192.168.136.39:8000/userbrandinfo/query?token=test&page=1&line=5
+http://192.168.136.39:8000/userbrandinfo/queryByAdmin?token=test&page=1&line=10  全部记录
+http://192.168.136.39:8000/userbrandinfo/queryArea?token=test   市的区域统计
+http://192.168.136.39:8000/userbrandinfo/queryDeviceSupplier?token=test 品牌统计
+http://192.168.136.39:8000/userbrandinfo/queryAllByAdmin?token=test&page=1&line=10  全部记录中过滤查询每个用户的最新一条数据
+
 http://192.168.136.39:8000/userbrandinfo/queryAll?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOiIxNTQzOTA5MDUwNDEzMTM4MDAxMzgwMDAiLCJsYW5nIjoiY24iLCJ1c2VyIjoiMTM4MDAxMzgwMDEiLCJtX2NvZGUiOiIxMjM0MTMyNDMyMTQiLCJleHAiOjE1NTk4OTY4NTd9.nhK3VSghSGjyXKjel4woz7R_3bhjgqQDlX-ypYsklNU&page=1&line=5
 http://192.168.136.39:8000/userbrandinfo/queryAll?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOiIxNTQzOTA5MDUwNDEzMTM4MDAxMzgwMDAiLCJsYW5nIjoiY24iLCJ1c2VyIjoiMTM4MDAxMzgwMDEiLCJtX2NvZGUiOiIxMjM0MTMyNDMyMTQiLCJleHAiOjE1NTk4OTY4NTd9.nhK3VSghSGjyXKjel4woz7R_3bhjgqQDlX-ypYsklNU&page=1&line=5
 '''
 '''
 
 
@@ -97,11 +100,30 @@ class UserBrandInfo(View):
         longitude = request_dict.get('longitude', None)
         longitude = request_dict.get('longitude', None)
         latitude = request_dict.get('latitude', None)
         latitude = request_dict.get('latitude', None)
         appId = request_dict.get('appId', None)
         appId = request_dict.get('appId', None)
-        param_area = CommonService.get_param_flag(data=[country])
+
+        if country is None:
+            country=''
+        if province is None:
+            province=''
+        if city is None:
+            city = ''
+        if area is None:
+            area=''
+        if street is None:
+            street=''
+        if longitude is None:
+            longitude=''
+        if latitude is None:
+            latitude=''
+        param_area = CommonService.get_param_flag(data=[country,province,city,longitude,latitude])
         must_fill_in = CommonService.get_param_flag(data=[appId,deviceSupplier,deviceModel,osType,osVersion])
         must_fill_in = CommonService.get_param_flag(data=[appId,deviceSupplier,deviceModel,osType,osVersion])
         if must_fill_in is False:
         if must_fill_in is False:
             return response.json(444,'appId,deviceSupplier,deviceModel,osType,osVersion')
             return response.json(444,'appId,deviceSupplier,deviceModel,osType,osVersion')
         if  param_area is True:
         if  param_area is True:
+            if '省' in province:
+                province = province.replace('省','')
+            if '市' in city:
+                city = city.replace('市','')
             status = 1
             status = 1
             country = country
             country = country
             province = province
             province = province
@@ -112,8 +134,8 @@ class UserBrandInfo(View):
             latitude = latitude
             latitude = latitude
         else:
         else:
             status = 0
             status = 0
-            jsonData = CommonService.getIpIpInfo(ip=self.clientIP,lang='EN')
-            print(jsonData['city_name'])
+            print (self.clientIP)
+            jsonData = CommonService.getIpIpInfo(ip=self.clientIP,lang='CN')
             country = jsonData['country_name']
             country = jsonData['country_name']
             province = jsonData['region_name']
             province = jsonData['region_name']
             city = jsonData['city_name']
             city = jsonData['city_name']
@@ -162,17 +184,21 @@ class UserBrandInfo(View):
         line = int(request_dict.get('line', None))
         line = int(request_dict.get('line', None))
         param_flag = CommonService.get_param_flag(data=[page, line])
         param_flag = CommonService.get_param_flag(data=[page, line])
         if param_flag is True:
         if param_flag is True:
-            user_brand_queryset = User_Brand.objects.all().order_by('-id')
-            if user_brand_queryset.exists():
-                count = user_brand_queryset.count()
-                res = user_brand_queryset[(page - 1) * line:page * line]
-                send_json = CommonService.qs_to_dict(res)
-                for k, v in enumerate(send_json["datas"]):
-                        username = ModelService.get_user_name(userID=send_json["datas"][k]['fields']['userID'])
-                        send_json["datas"][k]['fields']['username']=username
-                send_json['count'] = count
-                return response.json(0, send_json)
-            return response.json(0, {'datas': [], 'count': 0})
+            check_perm = ModelService.check_perm(userID=userID,permID=30)
+            if check_perm is True:
+                user_brand_queryset = User_Brand.objects.all().order_by('-id')
+                if user_brand_queryset.exists():
+                    count = user_brand_queryset.count()
+                    res = user_brand_queryset[(page - 1) * line:page * line]
+                    send_json = CommonService.qs_to_dict(res)
+                    for k, v in enumerate(send_json["datas"]):
+                            username = ModelService.get_user_name(userID=send_json["datas"][k]['fields']['userID'])
+                            send_json["datas"][k]['fields']['username']=username
+                    send_json['count'] = count
+                    return response.json(0, send_json)
+                return response.json(0, {'datas': [], 'count': 0})
+            else:
+                return response.json(404)
         else:
         else:
             return response.json(444)
             return response.json(444)
     def delete_by_admin(self, request_dict, userID,response):
     def delete_by_admin(self, request_dict, userID,response):
@@ -246,6 +272,7 @@ class UserBrandInfo(View):
     # 区域统计的接口
     # 区域统计的接口
     def query_area_info(self, request_dict, userID,response):
     def query_area_info(self, request_dict, userID,response):
         check_perm = ModelService.check_perm(userID=userID,permID=30)
         check_perm = ModelService.check_perm(userID=userID,permID=30)
+        district = request_dict.get('district', None)
         if check_perm is True:
         if check_perm is True:
             # 按照用户去重复查询
             # 按照用户去重复查询
             user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID', flat=True).distinct()
             user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID', flat=True).distinct()
@@ -261,7 +288,7 @@ class UserBrandInfo(View):
                 send_jsons.append(user_brand_querysetlast["datas"][0])
                 send_jsons.append(user_brand_querysetlast["datas"][0])
             deviceSupplier=[]
             deviceSupplier=[]
             for k, v in enumerate(send_jsons):
             for k, v in enumerate(send_jsons):
-                deviceSupplier.append(v['fields']['city'])
+                deviceSupplier.append(v['fields'][district])
             deviceSupplier = Counter(deviceSupplier)
             deviceSupplier = Counter(deviceSupplier)
             deviceSupplier = deviceSupplier
             deviceSupplier = deviceSupplier
 
 

+ 1 - 1
Model/models.py

@@ -360,7 +360,7 @@ class StatResModel(models.Model):
         ordering = ('id',)
         ordering = ('id',)
 
 
 
 
-#
+
 class FeedBackModel(models.Model):
 class FeedBackModel(models.Model):
     id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
     id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
     userID = models.ForeignKey(Device_User, null=True, blank=True, to_field='userID', on_delete=models.CASCADE)
     userID = models.ForeignKey(Device_User, null=True, blank=True, to_field='userID', on_delete=models.CASCADE)