| 
					
				 | 
			
			
				@@ -3,6 +3,7 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import logging 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import random 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import requests 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import time 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from django.db import transaction 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -17,7 +18,7 @@ from Object.uidManageResponseObject import uidManageResponseObject 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from Object.TokenObject import TokenObject 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from Service.AlgorithmService import AlgorithmBaseOn35 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from Service.CommonService import CommonService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-from Ansjer.config import CRCKey, SERVER_TYPE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from Ansjer.config import CRCKey, SERVER_TYPE, SERVER_DOMAIN_US, SERVER_DOMAIN_CN 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from Service.ModelService import ModelService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from Object.AWS.S3Email import S3Email 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -48,6 +49,8 @@ class SerialNumberView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return self.do_detach_uid(request, request_dict, response) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         elif operation == 'create': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return self.do_create(request_dict, response) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        elif operation == 'changeSerialNumberStatus': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return self.changeSerialNumberStatus(request_dict, response) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if token.code != 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return response.json(token.code) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -224,10 +227,18 @@ class SerialNumberView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             'operation': '序列号{}绑定uid: {}'.format(serial, uid.uid), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         LogModel.objects.create(**log) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        # 修改其他数据库的序列号使用状态为已占用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        company_serial_id = company_serial.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        data = {'company_serial_id': company_serial_id, 'status': 3} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        if SERVER_TYPE == 'Ansjer.us_config.formal_settings': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            url = '{}serialNumber/changeSerialNumberStatus'.format(SERVER_DOMAIN_CN) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        elif SERVER_TYPE == 'Ansjer.cn_config.formal_settings': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            url = '{}serialNumber/changeSerialNumberStatus'.format(SERVER_DOMAIN_US) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        requests.post(url=url, data=data, timeout=2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         return response.json(0, res) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     return response.json(5) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            else:   # 返回uid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            elif company_serial.status == 2:   # 返回uid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 uid_qs = UIDCompanySerialModel.objects.filter(company_serial_id=company_serial.id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if not uid_qs.exists(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     return response.json(173) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -245,6 +256,8 @@ class SerialNumberView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     'initStringApp': uid['uid__init_string_app'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return response.json(0, res) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            elif company_serial.status == 3: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return response.json(10042) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         except Exception as e: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             djangoLogger = logging.getLogger('django') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             djangoLogger.exception(repr(e)) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -323,6 +336,15 @@ class SerialNumberView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             up_qs.delete() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    # 修改其他数据库的序列号使用状态为已使用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    company_serial_id = company_serial_qs.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    data = {'company_serial_id': company_serial_id, 'status': 1} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if SERVER_TYPE == 'Ansjer.us_config.formal_settings': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        url = '{}serialNumber/changeSerialNumberStatus'.format(SERVER_DOMAIN_CN) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    elif SERVER_TYPE == 'Ansjer.cn_config.formal_settings': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        url = '{}serialNumber/changeSerialNumberStatus'.format(SERVER_DOMAIN_US) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    requests.post(url=url, data=data, timeout=2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 UIDModel.objects.filter(uid=uid).update(status=0, mac='')    # 重置uid的使用状态为未分配 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 uid_serial.delete() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -362,3 +384,20 @@ class SerialNumberView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return response.json(173) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return response.json(444) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # 序列号绑定和解绑uid时修改其他数据库序列号的使用状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    def changeSerialNumberStatus(self, request_dict, response): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        company_serial_id = request_dict.get('company_serial_id', None) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        status = request_dict.get('status', None) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if not all([company_serial_id, status]): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return response(444) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            # 更新CompanySerialModel表的序列号使用状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CompanySerialModel.objects.filter(id=company_serial_id).update(status=int(status)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return response.json(0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        except Exception as e: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            djangoLogger = logging.getLogger('django') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            djangoLogger.exception(repr(e)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return response.json(500, str(e)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 |