|
@@ -18,17 +18,15 @@ from django.views.decorators.csrf import csrf_exempt
|
|
|
from Service.ModelService import ModelService
|
|
|
from Model.models import User_Brand,Device_User
|
|
|
from django.utils import timezone
|
|
|
-import traceback,time
|
|
|
+import traceback,time,json,urllib.request
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from collections import Counter
|
|
|
'''
|
|
|
-
|
|
|
-http://192.168.136.45:8077/userbrandinfo?operation=query&token=test&page=1&line=10
|
|
|
-
|
|
|
-http://192.168.136.39:8000/userbrandinfo?operation=query&token=test&page=1&line=5
|
|
|
-http://192.168.136.39:8000/userbrandinfo?operation=queryAll&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOiIxNTQzOTA5MDUwNDEzMTM4MDAxMzgwMDAiLCJsYW5nIjoiY24iLCJ1c2VyIjoiMTM4MDAxMzgwMDEiLCJtX2NvZGUiOiIxMjM0MTMyNDMyMTQiLCJleHAiOjE1NTk4OTY4NTd9.nhK3VSghSGjyXKjel4woz7R_3bhjgqQDlX-ypYsklNU&page=1&line=5
|
|
|
+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/queryAll?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOiIxNTQzOTA5MDUwNDEzMTM4MDAxMzgwMDAiLCJsYW5nIjoiY24iLCJ1c2VyIjoiMTM4MDAxMzgwMDEiLCJtX2NvZGUiOiIxMjM0MTMyNDMyMTQiLCJleHAiOjE1NTk4OTY4NTd9.nhK3VSghSGjyXKjel4woz7R_3bhjgqQDlX-ypYsklNU&page=1&line=5
|
|
|
'''
|
|
|
|
|
|
|
|
@@ -39,15 +37,18 @@ class UserBrandInfo(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- self.clientIP = CommonService.get_ip_address(request)
|
|
|
- return self.validation(request_dict=request.GET)
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- self.clientIP = CommonService.get_ip_address(request)
|
|
|
- return self.validation(request_dict=request.POST)
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
|
|
|
- def validation(self, request_dict, *args, **kwargs):
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
+ if operation is None:
|
|
|
+ return response.json(444, 'error path')
|
|
|
+ self.clientIP = CommonService.get_ip_address(request)
|
|
|
response = ResponseObject()
|
|
|
token = request_dict.get('token', None)
|
|
|
if token is not None:
|
|
@@ -55,18 +56,22 @@ class UserBrandInfo(View):
|
|
|
response.lang = tko.lang
|
|
|
if tko.code == 0:
|
|
|
userID = tko.userID
|
|
|
- operation = request_dict.get('operation', None)
|
|
|
if userID is not None:
|
|
|
- if operation == 'query':
|
|
|
+ if operation == 'queryByAdmin':
|
|
|
return self.query_info(request_dict, userID,response)
|
|
|
elif operation == 'add':
|
|
|
return self.add_info(request_dict, userID,response)
|
|
|
- elif operation == 'queryAll':
|
|
|
+ elif operation == 'queryAllByAdmin':
|
|
|
return self.query_all_info(request_dict, userID,response)
|
|
|
+ elif operation == 'deleteByAdmin':
|
|
|
+ return self.delete_by_admin(request_dict, userID,response)
|
|
|
elif operation == 'queryDeviceSupplier':
|
|
|
return self.query_deviceSupplier_info(request_dict, userID,response)
|
|
|
+ elif operation == 'queryArea':
|
|
|
+ return self.query_area_info(request_dict, userID,response)
|
|
|
+
|
|
|
else:
|
|
|
- return response.json(444,'444')
|
|
|
+ return response.json(444)
|
|
|
else:
|
|
|
return response.json(309)
|
|
|
else:
|
|
@@ -78,32 +83,87 @@ class UserBrandInfo(View):
|
|
|
|
|
|
|
|
|
|
|
|
- # http://192.168.136.39:8000/userbrandinfo?operation=add&token=test&deviceSupplier=12341234&deviceModel=deviceModel&osType=osType&osVersion=osVersion
|
|
|
+ # http://192.168.136.39:8000/userbrandinfo?operation=add&token=test&deviceSupplier=小米&deviceModel=HM NOTE 1TD&osType=WEB&osVersion=4.0.0
|
|
|
def add_info(self, request_dict, userID,response):
|
|
|
deviceSupplier = request_dict.get('deviceSupplier', None)
|
|
|
deviceModel = request_dict.get('deviceModel', None)
|
|
|
osType = request_dict.get('osType', None)
|
|
|
osVersion = request_dict.get('osVersion', None)
|
|
|
-
|
|
|
- print(self.clientIP)
|
|
|
- try:
|
|
|
- user_brand = User_Brand(
|
|
|
- userID=Device_User.objects.get(userID=userID),
|
|
|
- deviceSupplier=deviceSupplier,
|
|
|
- deviceModel=deviceModel,
|
|
|
- osType=osType,
|
|
|
- osVersion=osVersion,
|
|
|
- ip=self.clientIP,
|
|
|
- addTime = int(time.time())
|
|
|
- )
|
|
|
- user_brand.save()
|
|
|
- except Exception:
|
|
|
- errorInfo = traceback.format_exc()
|
|
|
- print(errorInfo)
|
|
|
- return response.json(424, {'details': errorInfo})
|
|
|
+ country = request_dict.get('country', None)
|
|
|
+ province = request_dict.get('province', None)
|
|
|
+ city = request_dict.get('city', None)
|
|
|
+ area = request_dict.get('area', None)
|
|
|
+ street = request_dict.get('street', None)
|
|
|
+ longitude = request_dict.get('longitude', None)
|
|
|
+ latitude = request_dict.get('latitude', None)
|
|
|
+ param_area = CommonService.get_param_flag(data=[country,province,city])
|
|
|
+ if param_area is True:
|
|
|
+ status = 1
|
|
|
+ country = country
|
|
|
+ province = province
|
|
|
+ city = city
|
|
|
+ area = area
|
|
|
+ street = street
|
|
|
+ longitude = longitude
|
|
|
+ latitude = latitude
|
|
|
+ else:
|
|
|
+ status = 0
|
|
|
+ try:
|
|
|
+ print ('http://test.dvema.com/getTZ?etk=ODhVRlpMVjBZNU5VdEhVMVl6UVRsSE9URXhNVUUlM0Q4OA==&ip='+self.clientIP+'&lang=EN')
|
|
|
+ resp=urllib.request.urlopen('http://test.dvema.com/getTZ?etk=ODhVRlpMVjBZNU5VdEhVMVl6UVRsSE9URXhNVUUlM0Q4OA==&ip='+self.clientIP+'&lang=EN')
|
|
|
+ html=resp.read()
|
|
|
+ html.decode('utf-8')
|
|
|
+ jsonData = json.loads(html)
|
|
|
+ print(jsonData['data']['city_name'])
|
|
|
+ country = jsonData['data']['country_name']
|
|
|
+ province = jsonData[ 'data']['region_name']
|
|
|
+ city = jsonData['data']['city_name']
|
|
|
+ area = ''
|
|
|
+ street = ''
|
|
|
+ longitude = jsonData['data']['longitude']
|
|
|
+ latitude = jsonData['data']['latitude']
|
|
|
+ except Exception:
|
|
|
+ print ('失败')
|
|
|
+ country = ''
|
|
|
+ province =''
|
|
|
+ city = ''
|
|
|
+ area = ''
|
|
|
+ street = ''
|
|
|
+ longitude = ''
|
|
|
+ latitude = ''
|
|
|
+ param_flag = CommonService.get_param_flag(data=[deviceSupplier, deviceModel,osType,osVersion])
|
|
|
+ if param_flag is True:
|
|
|
+ try:
|
|
|
+ user_brand = User_Brand(
|
|
|
+ userID=Device_User.objects.get(userID=userID),
|
|
|
+ deviceSupplier=deviceSupplier,
|
|
|
+ deviceModel=deviceModel,
|
|
|
+ osType=osType,
|
|
|
+ osVersion=osVersion,
|
|
|
+ ip=self.clientIP,
|
|
|
+ addTime = int(time.time()),
|
|
|
+ status = status,
|
|
|
+ country = country,
|
|
|
+ province = province,
|
|
|
+ city = city,
|
|
|
+ area = area,
|
|
|
+ street = street,
|
|
|
+ longitude = longitude,
|
|
|
+ latitude = latitude
|
|
|
+ )
|
|
|
+ user_brand.save()
|
|
|
+ except Exception:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print(errorInfo)
|
|
|
+ return response.json(424, {'details': errorInfo})
|
|
|
+ else:
|
|
|
+ print(type(user_brand.addTime))
|
|
|
+ return response.json(0,{'id':user_brand.id})
|
|
|
else:
|
|
|
- print(type(user_brand.addTime))
|
|
|
- return response.json(0,{'id':user_brand.id})
|
|
|
+ # 参数错误
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
def query_info(self, request_dict, userID,response):
|
|
@@ -111,18 +171,32 @@ class UserBrandInfo(View):
|
|
|
line = int(request_dict.get('line', None))
|
|
|
param_flag = CommonService.get_param_flag(data=[page, line])
|
|
|
if param_flag is True:
|
|
|
- user_brand_queryset = User_Brand.objects.filter(userID=userID).order_by('-id')
|
|
|
+ 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(444)
|
|
|
-
|
|
|
-
|
|
|
+ def delete_by_admin(self, request_dict, userID,response):
|
|
|
+ id_list = request_dict.getlist('id', None)
|
|
|
+ param_flag = CommonService.get_param_flag(data=[id_list])
|
|
|
+ if param_flag is True:
|
|
|
+ check_perm = ModelService.check_perm(userID=userID, permID=10)
|
|
|
+ if check_perm is True:
|
|
|
+ is_delete = User_Brand.objects.filter(id__in=id_list).delete()
|
|
|
+ return response.json(0, {'delete_count': is_delete[0]})
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+ else:
|
|
|
+ return response.json(444)
|
|
|
+ # 查询每个用户最新的一条记录统计信息
|
|
|
def query_all_info(self, request_dict, userID,response):
|
|
|
page = int(request_dict.get('page', None))
|
|
|
line = int(request_dict.get('line', None))
|
|
@@ -153,7 +227,7 @@ class UserBrandInfo(View):
|
|
|
else:
|
|
|
return response.json(444)
|
|
|
|
|
|
-
|
|
|
+ # 品牌统计的接口
|
|
|
def query_deviceSupplier_info(self, request_dict, userID,response):
|
|
|
check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
if check_perm is True:
|
|
@@ -173,12 +247,37 @@ class UserBrandInfo(View):
|
|
|
for k, v in enumerate(send_jsons):
|
|
|
deviceSupplier.append(v['fields']['deviceSupplier'])
|
|
|
deviceSupplier = Counter(deviceSupplier)
|
|
|
- return response.json(0, {'datas': deviceSupplier})
|
|
|
+ print (deviceSupplier)
|
|
|
+ return response.json(0, {'datas': deviceSupplier,'counts':counts})
|
|
|
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
+ # 区域统计的接口
|
|
|
+ def query_area_info(self, request_dict, userID,response):
|
|
|
+ check_perm = ModelService.check_perm(userID=userID,permID=30)
|
|
|
+ if check_perm is True:
|
|
|
+ # 按照用户去重复查询
|
|
|
+ user_brand_queryset = User_Brand.objects.all().order_by('userID').values_list('userID', flat=True).distinct()
|
|
|
+ print (user_brand_queryset)
|
|
|
+ send_jsons=[]
|
|
|
+ counts=0
|
|
|
+ for i in user_brand_queryset:
|
|
|
+ counts=counts+1
|
|
|
+ user_brand_querysetlast = User_Brand.objects.filter(userID=i).order_by('-addTime')[:1]
|
|
|
+ user_brand_querysetlast = CommonService.qs_to_dict(user_brand_querysetlast)
|
|
|
+ username = ModelService.get_user_name(userID=user_brand_querysetlast["datas"][0]['fields']['userID'])
|
|
|
+ user_brand_querysetlast["datas"][0]['fields']['username']=username
|
|
|
+ send_jsons.append(user_brand_querysetlast["datas"][0])
|
|
|
+ deviceSupplier=[]
|
|
|
+ for k, v in enumerate(send_jsons):
|
|
|
+ deviceSupplier.append(v['fields']['city'])
|
|
|
+ deviceSupplier = Counter(deviceSupplier)
|
|
|
+ deviceSupplier = deviceSupplier
|
|
|
|
|
|
+ return response.json(0, {'datas': deviceSupplier,'counts':counts})
|
|
|
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
|
|
|
|
|
|
|