|
@@ -6,6 +6,7 @@ from datetime import datetime
|
|
|
|
|
|
import requests
|
|
|
from django.db import transaction
|
|
|
+from django.db.models import Q
|
|
|
from django.views import View
|
|
|
|
|
|
from Ansjer.config import CRCKey, CONFIG_INFO, CONFIG_US, CONFIG_EUR, \
|
|
@@ -998,6 +999,8 @@ class SerialNumberView(View):
|
|
|
if not all([serial, username, wifi_name, wifi_password, time_stamp, token]):
|
|
|
return response.json(444)
|
|
|
|
|
|
+ if len(serial) < 14:
|
|
|
+ return response.json(444, '序列号长度小于14')
|
|
|
# 根据序列号获取p2p类型,设备类型信息
|
|
|
serial_number = serial[:9]
|
|
|
p2p_type = serial[9:10]
|
|
@@ -1016,13 +1019,18 @@ class SerialNumberView(View):
|
|
|
r = requests.post(url=url, data=data, timeout=30)
|
|
|
assert r.status_code == 200
|
|
|
r = r.json()
|
|
|
- assert r['result_code'] == 0
|
|
|
+ if r['result_code'] != 0:
|
|
|
+ return response.json(r['result_code'])
|
|
|
uid = CommonService.decode_data(r['result']['uid'])
|
|
|
|
|
|
# 查询用户是否存在,不存在则创建
|
|
|
device_user_qs = Device_User.objects.filter(username=username).values('userID')
|
|
|
if device_user_qs.exists():
|
|
|
user_id = device_user_qs[0]['userID']
|
|
|
+ # 判断设备是否已被其他账号添加
|
|
|
+ device_info_qs = Device_Info.objects.filter(~Q(userID_id=user_id), UID=uid).values('id')
|
|
|
+ if device_info_qs.exists():
|
|
|
+ return response.json(174)
|
|
|
# 已保存过,更新网络信息
|
|
|
device_info_qs = Device_Info.objects.filter(userID_id=user_id, UID=uid).values('id')
|
|
|
if device_info_qs.exists():
|
|
@@ -1031,6 +1039,10 @@ class SerialNumberView(View):
|
|
|
if device_net_info_qs.exists():
|
|
|
device_net_info_qs.update(wifi_name=wifi_name, wifi_password=wifi_password)
|
|
|
else:
|
|
|
+ # 判断设备是否已被其他账号添加
|
|
|
+ device_info_qs = Device_Info.objects.filter(UID=uid).values('id')
|
|
|
+ if device_info_qs.exists():
|
|
|
+ return response.json(174)
|
|
|
password = ''
|
|
|
user_id = CommonService.getUserID(μs=False, setOTAID=True)
|
|
|
user_data = {
|