|
@@ -5,6 +5,8 @@ import datetime
|
|
|
import hashlib
|
|
|
import time
|
|
|
import uuid
|
|
|
+import json
|
|
|
+
|
|
|
|
|
|
import paypalrestsdk
|
|
|
import requests
|
|
@@ -22,7 +24,7 @@ from Controller.UnicomCombo.UnicomComboTaskController import UnicomComboTaskView
|
|
|
from Model.models import VodBucketModel, CDKcontextModel, Store_Meal, Order_Model, \
|
|
|
UID_Bucket, ExperienceContextModel, Lang, CloudLogModel, UidSetModel, Unused_Uid_Meal, \
|
|
|
Device_Info, DeviceTypeModel, UnicomComboOrderInfo, AiService, CountryModel, CouponLang, CouponConfigModel, \
|
|
|
- CouponCombo, CouponModel, Device_User, AbnormalOrder, DailyReconciliation
|
|
|
+ CouponCombo, CouponModel, Device_User, AbnormalOrder, DailyReconciliation, StsCrdModel, LogModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.UnicomObject import UnicomObjeect
|
|
@@ -136,6 +138,9 @@ class serveManagement(View):
|
|
|
return self.deleteDevicePackage(userID, request_dict, response)
|
|
|
elif operation == 'experiencereset': # 重置设备云存体验
|
|
|
return self.do_experience_reset(request_dict, userID, response)
|
|
|
+ elif operation == 'mealTransfer':
|
|
|
+ return self.meal_transfer(request, request_dict, response)
|
|
|
+
|
|
|
# 云存用户信息
|
|
|
elif operation == 'getCloudUserList': # 获取云存用户信息
|
|
|
return self.getCloudUserList(request_dict, response)
|
|
@@ -1519,6 +1524,108 @@ class serveManagement(View):
|
|
|
else:
|
|
|
return response.json(0, '重置云存体验失败')
|
|
|
|
|
|
+ def meal_transfer(self, request, request_dict, response):
|
|
|
+ # 云存套餐转移,同一用户下不同设备间的云存套餐转移
|
|
|
+ old_uid = request_dict.get("old_uid", None)
|
|
|
+ new_uid = request_dict.get("new_uid", None)
|
|
|
+ nowTime = int(time.time())
|
|
|
+
|
|
|
+ # 查询转出设备正在使用的套餐
|
|
|
+ old_using_uid_bucket = UID_Bucket.objects.filter(uid=old_uid, endTime__gte=nowTime).values('id',
|
|
|
+ 'bucket_id',
|
|
|
+ 'has_unused',
|
|
|
+ 'bucket__content').order_by('addTime')
|
|
|
+ if not old_using_uid_bucket.exists():
|
|
|
+ return response.json(10013)
|
|
|
+ bucket_content = old_using_uid_bucket[0]['bucket__content']
|
|
|
+
|
|
|
+ # 免费存储桶不可转移
|
|
|
+ old_vod_bucket_id = old_using_uid_bucket[0]['bucket_id']
|
|
|
+ is_free = VodBucketModel.objects.get(id=old_vod_bucket_id).is_free
|
|
|
+ if is_free == 1:
|
|
|
+ return response.json(10012)
|
|
|
+
|
|
|
+ # 查询转入设备是否存在正在使用的套餐和未使用的套餐
|
|
|
+ new_using_uid_bucket = UID_Bucket.objects.filter(uid=new_uid, endTime__gte=nowTime)
|
|
|
+ new_unused_uid_bucket = Unused_Uid_Meal.objects.filter(uid=new_uid)
|
|
|
+ if new_using_uid_bucket.exists() or new_unused_uid_bucket.exists():
|
|
|
+ return response.json(10014)
|
|
|
+
|
|
|
+ old_ai_service = AiService.objects.filter(uid=old_uid, endTime__gte=nowTime, use_status=1).values('id',
|
|
|
+ 'detect_interval',
|
|
|
+ 'detect_status',
|
|
|
+ 'detect_group')
|
|
|
+ new_ai_service = AiService.objects.filter(uid=new_uid, endTime__gte=nowTime, use_status=1)
|
|
|
+ if new_ai_service.exists(): # 转入设备有开通AI功能,不能转
|
|
|
+ return response.json(10014)
|
|
|
+
|
|
|
+ new_uid_set = UidSetModel.objects.filter(uid=new_uid).values('is_ai')
|
|
|
+ if old_ai_service.exists() and new_uid_set[0]['is_ai'] == 2: # 转出设备有开通AI,但是转入设备不支持AI,不能转
|
|
|
+ return response.json(10016)
|
|
|
+
|
|
|
+ with transaction.atomic():
|
|
|
+ # 如果转出设备有未使用套餐,更改第一个未使用套餐为正在使用
|
|
|
+ if old_using_uid_bucket[0]['has_unused'] == 1:
|
|
|
+ old_unused_uid_bucket = Unused_Uid_Meal.objects.filter(uid=old_uid).values('id', 'channel',
|
|
|
+ 'bucket_id',
|
|
|
+ 'addTime', 'expire',
|
|
|
+ 'is_ai',
|
|
|
+ 'order_id')
|
|
|
+ count = old_unused_uid_bucket.count()
|
|
|
+ unused = old_unused_uid_bucket[0]
|
|
|
+ has_unused = 1 if count > 1 else 0 # 如果存在不止一个未使用套餐,has_unused=1
|
|
|
+ endTime = CommonService.calcMonthLater(unused['expire'])
|
|
|
+ data_dict = {
|
|
|
+ 'uid': old_uid,
|
|
|
+ 'channel': unused['channel'],
|
|
|
+ 'bucket_id': unused['bucket_id'],
|
|
|
+ 'addTime': unused['addTime'],
|
|
|
+ 'endTime': endTime,
|
|
|
+ 'updateTime': nowTime,
|
|
|
+ 'status': 1,
|
|
|
+ 'use_status': 1,
|
|
|
+ 'has_unused': has_unused
|
|
|
+ }
|
|
|
+ UID_Bucket.objects.create(**data_dict) # 正在使用套餐表添加数据
|
|
|
+ Unused_Uid_Meal.objects.filter(uid=old_uid).first().delete() # 删除未使用套餐表中的数据
|
|
|
+ if unused['is_ai']: # 开通AI服务
|
|
|
+ AiService.objects.create(uid=old_uid, channel=unused['channel'],
|
|
|
+ detect_status=old_ai_service[0]['detect_status'],
|
|
|
+ addTime=nowTime, updTime=nowTime, endTime=endTime, use_status=1,
|
|
|
+ orders_id=unused['order_id'],
|
|
|
+ detect_group=old_ai_service[0]['detect_group'],
|
|
|
+ detect_interval=old_ai_service[0]['detect_interval'])
|
|
|
+
|
|
|
+ # 更新正在使用套餐的uid,重置拥有未使用套餐
|
|
|
+ old_using_uid_bucket_id = old_using_uid_bucket[0]['id']
|
|
|
+ UID_Bucket.objects.filter(id=old_using_uid_bucket_id).update(uid=new_uid, has_unused=0)
|
|
|
+ StsCrdModel.objects.filter(uid=old_uid).delete() # 删除转出设备stscrd表关联数据
|
|
|
+
|
|
|
+ # 转移AI服务
|
|
|
+ if old_ai_service.exists() and new_uid_set[0]['is_ai'] != 2:
|
|
|
+ AiService.objects.filter(id=old_ai_service[0]['id']).update(uid=new_uid, detect_status=0,
|
|
|
+ detect_group='', detect_interval=60)
|
|
|
+ msg = {'commandType': 'AIDisable'}
|
|
|
+ thing_name = CommonService.query_serial_with_uid(old_uid) # 存在序列号则为使用序列号作为物品名
|
|
|
+ topic_name = 'ansjer/generic/{}'.format('')
|
|
|
+ req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
|
|
|
+ if not req_success:
|
|
|
+ return response.json(10044)
|
|
|
+
|
|
|
+ ip = CommonService.get_ip_address(request)
|
|
|
+ content = json.loads(json.dumps(request_dict))
|
|
|
+ log = {
|
|
|
+ 'ip': ip,
|
|
|
+ 'user_id': 1,
|
|
|
+ 'status': 200,
|
|
|
+ 'time': int(time.time()),
|
|
|
+ 'url': 'cloudTransfer/mealTransfer',
|
|
|
+ 'content': json.dumps(content),
|
|
|
+ 'operation': '设备{}的套餐{}转移给设备{}'.format(old_uid, bucket_content, new_uid),
|
|
|
+ }
|
|
|
+ LogModel.objects.create(**log)
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
@classmethod
|
|
|
def getCloudUserList(cls, request_dict, response):
|
|
|
print('request_dict: ', request_dict)
|