|
@@ -184,21 +184,21 @@ class CloudStorageView(View):
|
|
|
mold = request_dict.get('mold', None)
|
|
|
uid = request_dict.get('uid', None)
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
+ is_ai = request_dict.get('is_ai', 0)
|
|
|
if not all([uid]):
|
|
|
return response.json(444)
|
|
|
+ is_ai = int(is_ai)
|
|
|
now_time = int(time.time())
|
|
|
# DVR/NVR设备暂不返回云存套餐列表
|
|
|
device_info_qs = Device_Info.objects.filter(Q(UID=uid), Q(Type__lte=4) | Q(Type=10001))
|
|
|
if device_info_qs.exists():
|
|
|
return response.json(0)
|
|
|
# 查询设备像素
|
|
|
- uid_set_qs = UidSetModel.objects.filter(uid=uid).values('ucode')
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid).values('ucode', 'is_ai')
|
|
|
if not uid_set_qs.exists():
|
|
|
return response.json(173)
|
|
|
ucode = uid_set_qs[0]['ucode']
|
|
|
- pixel_level = 0
|
|
|
- if ucode and int(ucode[-5]) >= 8:
|
|
|
- pixel_level = 1
|
|
|
+ pixel_level = 1 if ucode and int(ucode[-5]) >= 8 else 0
|
|
|
store_qs = Store_Meal.objects.filter(Q(lang__lang=lang), Q(is_show=0), ~Q(pay_type='11')) # 过滤激活码、隐藏套餐
|
|
|
experience_context_qs = ExperienceContextModel.objects.filter(uid=uid, experience_type=0)
|
|
|
|
|
@@ -207,7 +207,14 @@ class CloudStorageView(View):
|
|
|
|
|
|
# 没体验过的设备只返回体验套餐,体验过的不返回体验套餐
|
|
|
if experience_context_qs.exists():
|
|
|
- store_qs = store_qs.filter(~Q(pay_type='10'), Q(pixel_level=pixel_level)) # 筛选像素等级
|
|
|
+ if not is_ai: # 返回云存套餐
|
|
|
+ store_qs = store_qs.filter(~Q(pay_type='10'), Q(pixel_level=pixel_level), Q(is_ai=0)) # 筛选像素等级
|
|
|
+ else: # 返回云存+AI套餐
|
|
|
+ is_ai = uid_set_qs[0]['is_ai']
|
|
|
+ is_ai = 1 if is_ai != 2 and CONFIG_INFO != CONFIG_CN else 0 # 国内不支持AI服务
|
|
|
+ if not is_ai:
|
|
|
+ return response.json(0)
|
|
|
+ store_qs = store_qs.filter(~Q(pay_type='10'), Q(pixel_level=pixel_level), Q(is_ai=1)) # 筛选像素等级
|
|
|
else:
|
|
|
store_qs = store_qs.filter(pay_type='10') # 体验套餐不区分像素等级
|
|
|
|
|
@@ -748,6 +755,7 @@ class CloudStorageView(View):
|
|
|
if not all([uid, vod_status, channel]):
|
|
|
return response.json(444, 'uid,vod_status,channel')
|
|
|
vod_status = int(vod_status)
|
|
|
+ ai_status = int(ai_status)
|
|
|
device_info_qs = Device_Info.objects.filter(userID_id=user_id, UID=uid, isShare=False, isExist=1).values(
|
|
|
'vodPrimaryUserID', 'Type')
|
|
|
if not device_info_qs.exists() or device_info_qs[0]['vodPrimaryUserID'] != user_id:
|
|
@@ -768,12 +776,9 @@ class CloudStorageView(View):
|
|
|
return response.json(10031)
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
- if vod_status == 0:
|
|
|
+ if vod_status == 0: # 关闭云存开关
|
|
|
uid_bucket_qs.update(status=vod_status)
|
|
|
- ai_status = '0'
|
|
|
- if uid_set_qs[0].is_ai == 2:
|
|
|
- return response.json(0)
|
|
|
- uid_bucket_qs.update(status=vod_status, channel=channel)
|
|
|
+ return response.json(0)
|
|
|
uid_obj = UidTokenObject()
|
|
|
uid_obj.generate(data={'uid': uid, 'channel': channel})
|
|
|
|
|
@@ -783,90 +788,76 @@ class CloudStorageView(View):
|
|
|
urls = 'https://api.zositeche.com/'
|
|
|
uid_tk_url = '{}cloudstorage/getsignsts?uidToken={}'.format(urls, uid_obj.token)
|
|
|
store_hls_url = '{}cloudstorage/storeplaylist?uidToken={}'.format(urls, uid_obj.token)
|
|
|
- if uid_set_qs[0].is_ai != 2 and CONFIG_INFO != CONFIG_CN:
|
|
|
+
|
|
|
+ thing_name = CommonService.query_serial_with_uid(uid) # 存在序列号则为使用序列号作为物品名
|
|
|
+ topic_name = 'ansjer/generic/{}'.format(thing_name)
|
|
|
+ ai_service_qs = AiService.objects.filter(uid=uid, use_status=1)
|
|
|
+ if ai_status == 0: # 关闭
|
|
|
+ # mqtt通知设备关闭AI识别功能
|
|
|
+ msg = {'commandType': 'AIDisable'}
|
|
|
+ req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
|
|
|
+ if not req_success:
|
|
|
+ return response.json(10044)
|
|
|
+ ai_service_qs.update(detect_status=ai_status, endTime=end_time)
|
|
|
+ return response.json(0, {'uidTkUrl': uid_tk_url, 'storeHlsUrl': store_hls_url})
|
|
|
+ elif ai_status == 1: # 开启
|
|
|
if not all([appBundleId, app_type, token_val, uid, m_code, ai_status]):
|
|
|
return response.json(444, 'appBundleId, app_type, token_val, uid,m_code, ai_status')
|
|
|
-
|
|
|
# 如果传空上来,就默认为0
|
|
|
tz = '0' if tz == '' else tz.replace('GMT', '')
|
|
|
- ai_status = int(ai_status)
|
|
|
- ai_service_qs = AiService.objects.filter(uid=uid, use_status=1)
|
|
|
- if not ai_service_qs.exists():
|
|
|
- return response.json(10053)
|
|
|
-
|
|
|
uid_set_id = uid_set_qs[0].id
|
|
|
- interval = uid_set_qs[0].new_detect_interval if not interval else interval
|
|
|
qs_data = {
|
|
|
'updTime': now_time,
|
|
|
+ 'detect_interval': uid_set_qs[0].new_detect_interval if not interval else interval,
|
|
|
+ 'detect_group': detect_group if detect_group else ''
|
|
|
+ }
|
|
|
+ # 更新或创建uid_push数据
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(userID_id=user_id, m_code=m_code, uid_set__uid=uid)
|
|
|
+ uid_push_data = {
|
|
|
+ 'appBundleId': appBundleId,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'push_type': push_type,
|
|
|
+ 'token_val': token_val,
|
|
|
+ 'updTime': now_time,
|
|
|
+ 'lang': lang,
|
|
|
+ 'tz': tz
|
|
|
}
|
|
|
- if interval:
|
|
|
- qs_data['detect_interval'] = int(interval)
|
|
|
- qs_data['detect_group'] = detect_group if detect_group else ''
|
|
|
- uid_set_qs.update(**qs_data)
|
|
|
|
|
|
+ if uid_push_qs.exists():
|
|
|
+ uid_push_qs.update(**uid_push_data)
|
|
|
+ else:
|
|
|
+ uid_push_data['uid_set_id'] = uid_set_id
|
|
|
+ uid_push_data['userID_id'] = user_id
|
|
|
+ uid_push_data['m_code'] = m_code
|
|
|
+ uid_push_data['addTime'] = now_time
|
|
|
+ UidPushModel.objects.create(**uid_push_data)
|
|
|
+ etkObj = ETkObject(etk='')
|
|
|
+ etk = etkObj.encrypt(uid)
|
|
|
+ # mqtt通知设备开启AI识别功能
|
|
|
+ push_url = DETECT_PUSH_DOMAINS
|
|
|
+ # 欧洲域名固定返回欧洲域名
|
|
|
+ if domain_name in ['api.zositeche.com', 'api.loocam3.com', 'common.neutral3.com']:
|
|
|
+ push_url = 'https://push.zositeche.com/'
|
|
|
+ aiIdentificationUrl = '{}AiService/identification'.format(push_url)
|
|
|
+ msg = {
|
|
|
+ 'commandType': 'AIEnable',
|
|
|
+ 'payload': {
|
|
|
+ 'etk': etk,
|
|
|
+ 'endTime': end_time,
|
|
|
+ 'aiIdentificationUrl': aiIdentificationUrl,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
|
|
|
+ if not req_success:
|
|
|
+ return response.json(10044)
|
|
|
+ uid_set_qs.update(**qs_data)
|
|
|
qs_data['detect_status'] = ai_status # ai开关状态
|
|
|
qs_data['endTime'] = end_time
|
|
|
ai_service_qs.update(**qs_data)
|
|
|
- thing_name = CommonService.query_serial_with_uid(uid) # 存在序列号则为使用序列号作为物品名
|
|
|
- topic_name = 'ansjer/generic/{}'.format(thing_name)
|
|
|
-
|
|
|
- if ai_status == 0: # 关闭
|
|
|
- # mqtt通知设备关闭AI识别功能
|
|
|
- msg = {'commandType': 'AIDisable'}
|
|
|
- req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
|
|
|
- if not req_success:
|
|
|
- return response.json(10044)
|
|
|
- if vod_status == 0:
|
|
|
- return response.json(0)
|
|
|
- return response.json(0, {'uidTkUrl': uid_tk_url, 'storeHlsUrl': store_hls_url})
|
|
|
- elif ai_status == 1: # 开启
|
|
|
- # 更新或创建uid_push数据
|
|
|
- uid_push_qs = UidPushModel.objects.filter(userID_id=user_id, m_code=m_code, uid_set__uid=uid)
|
|
|
- uid_push_data = {
|
|
|
- 'appBundleId': appBundleId,
|
|
|
- 'app_type': app_type,
|
|
|
- 'push_type': push_type,
|
|
|
- 'token_val': token_val,
|
|
|
- 'updTime': now_time,
|
|
|
- 'lang': lang,
|
|
|
- 'tz': tz
|
|
|
- }
|
|
|
-
|
|
|
- if uid_push_qs.exists():
|
|
|
- uid_push_qs.update(**uid_push_data)
|
|
|
- else:
|
|
|
- uid_push_data['uid_set_id'] = uid_set_id
|
|
|
- uid_push_data['userID_id'] = user_id
|
|
|
- uid_push_data['m_code'] = m_code
|
|
|
- uid_push_data['addTime'] = now_time
|
|
|
- UidPushModel.objects.create(**uid_push_data)
|
|
|
- if appBundleId == 0 or appBundleId == '0':
|
|
|
- LOGGER.info('cloudstorage/changevodaistatus接口推送数据{}'.format(request_dict))
|
|
|
- etkObj = ETkObject(etk='')
|
|
|
- etk = etkObj.encrypt(uid)
|
|
|
-
|
|
|
- # mqtt通知设备开启AI识别功能
|
|
|
- push_url = DETECT_PUSH_DOMAINS
|
|
|
- # 欧洲域名固定返回欧洲域名
|
|
|
- if domain_name in ['api.zositeche.com', 'api.loocam3.com', 'common.neutral3.com']:
|
|
|
- push_url = 'https://push.zositeche.com/'
|
|
|
- aiIdentificationUrl = '{}AiService/identification'.format(push_url)
|
|
|
- msg = {
|
|
|
- 'commandType': 'AIEnable',
|
|
|
- 'payload': {
|
|
|
- 'etk': etk,
|
|
|
- 'endTime': end_time,
|
|
|
- 'aiIdentificationUrl': aiIdentificationUrl,
|
|
|
- }
|
|
|
- }
|
|
|
- req_success = CommonService.req_publish_mqtt_msg(thing_name, topic_name, msg)
|
|
|
- if not req_success:
|
|
|
- return response.json(10044)
|
|
|
- return response.json(0, {'uidTkUrl': uid_tk_url, 'storeHlsUrl': store_hls_url,
|
|
|
- 'aiIdentificationUrl': aiIdentificationUrl, 'endTime': end_time,
|
|
|
- 'etk': etk})
|
|
|
-
|
|
|
- return response.json(0, {'uidTkUrl': uid_tk_url, 'storeHlsUrl': store_hls_url})
|
|
|
+ return response.json(0, {'uidTkUrl': uid_tk_url, 'storeHlsUrl': store_hls_url,
|
|
|
+ 'aiIdentificationUrl': aiIdentificationUrl, 'endTime': end_time,
|
|
|
+ 'etk': etk})
|
|
|
+ uid_bucket_qs.update(status=vod_status, channel=channel)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
@@ -936,14 +927,14 @@ class CloudStorageView(View):
|
|
|
channel = order_list[0]['channel']
|
|
|
rank = order_list[0]['rank']
|
|
|
|
|
|
- store_qs = Store_Meal.objects.filter(id=rank).values("day", "bucket_id", "bucket__storeDay", "expire",
|
|
|
+ store_qs = Store_Meal.objects.filter(id=rank).values('day', 'bucket_id', 'expire',
|
|
|
'icloud_store_meal_id')
|
|
|
if not store_qs.exists():
|
|
|
return response.json(173)
|
|
|
bucket_id = store_qs[0]['bucket_id']
|
|
|
- uid_bucket_qs = UID_Bucket.objects.filter(uid=uid).values("id", "bucket_id", "bucket__storeDay",
|
|
|
- "bucket__region", "endTime", "use_status")
|
|
|
expire = store_qs[0]['expire']
|
|
|
+ uid_bucket_qs = UID_Bucket.objects.filter(uid=uid).values("id", "bucket_id",
|
|
|
+ "bucket__region", "endTime", "use_status")
|
|
|
# icloud_store_meal_id = store_qs[0]['icloud_store_meal_id']
|
|
|
# icloud_meal_qs = ICloudStoreMeal.objects.filter(id=icloud_store_meal_id).values('size')
|
|
|
# if not icloud_meal_qs.exists():
|
|
@@ -958,28 +949,20 @@ class CloudStorageView(View):
|
|
|
if promotion.exists():
|
|
|
promotion_rule_id = promotion[0]['id']
|
|
|
expire = expire * 2
|
|
|
+ end_time = CommonService.calcMonthLater(expire)
|
|
|
with transaction.atomic():
|
|
|
if uid_bucket_qs.exists():
|
|
|
uid_bucket = uid_bucket_qs.first()
|
|
|
- if uid_bucket['use_status'] == 1 and uid_bucket['bucket_id'] == bucket_id: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
- end_time = CommonService.calcMonthLater(expire, uid_bucket['endTime'])
|
|
|
- UID_Bucket.objects.filter(id=uid_bucket['id']).update(uid=uid, channel=channel,
|
|
|
- bucket_id=bucket_id, endTime=end_time,
|
|
|
- updateTime=now_time)
|
|
|
- else: # 已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
- unused_uid_qs = Unused_Uid_Meal.objects.filter(uid=uid, bucket_id=bucket_id)
|
|
|
- nums = 2 if order_list[0]['isSelectDiscounts'] == 1 else 1
|
|
|
- if promotion.exists():
|
|
|
- nums = nums + 1
|
|
|
- if unused_uid_qs.exists():
|
|
|
- unused_uid_qs.update(num=F('num') + nums)
|
|
|
- else:
|
|
|
- Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=now_time, num=nums,
|
|
|
- expire=store_qs[0]['expire'], bucket_id=bucket_id)
|
|
|
- UID_Bucket.objects.filter(id=uid_bucket['id']).update(has_unused=1)
|
|
|
uid_bucket_id = uid_bucket['id']
|
|
|
+ if uid_bucket['use_status'] == 1 and uid_bucket['endTime'] > now_time: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
+ Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=now_time, is_ai=0,
|
|
|
+ expire=expire, bucket_id=bucket_id, order_id=order_id)
|
|
|
+ UID_Bucket.objects.filter(id=uid_bucket_id).update(has_unused=1)
|
|
|
+ else:
|
|
|
+ UID_Bucket.objects.filter(id=uid_bucket_id).update(channel=channel, bucket_id=bucket_id,
|
|
|
+ endTime=end_time, updateTime=now_time,
|
|
|
+ use_status=1)
|
|
|
else:
|
|
|
- end_time = CommonService.calcMonthLater(expire)
|
|
|
uid_bucket = UID_Bucket.objects.create(uid=uid, channel=channel, bucket_id=bucket_id,
|
|
|
endTime=end_time, addTime=now_time, updateTime=now_time,
|
|
|
use_status=1)
|
|
@@ -1110,14 +1093,15 @@ class CloudStorageView(View):
|
|
|
uid = order_list[0]['UID']
|
|
|
channel = order_list[0]['channel']
|
|
|
rank = order_list[0]['rank']
|
|
|
- store_qs = Store_Meal.objects.filter(id=rank).values("day", "bucket_id", "bucket__storeDay", "expire",
|
|
|
+ store_qs = Store_Meal.objects.filter(id=rank).values("day", "bucket_id", "expire", "is_ai",
|
|
|
'icloud_store_meal_id')
|
|
|
if not store_qs.exists():
|
|
|
return response.json(173)
|
|
|
bucket_id = store_qs[0]['bucket_id']
|
|
|
- uid_bucket_qs = UID_Bucket.objects.filter(uid=uid).values("id", "bucket_id", "bucket__storeDay",
|
|
|
- "bucket__region", "endTime", "use_status")
|
|
|
+ is_ai = store_qs[0]['is_ai']
|
|
|
expire = store_qs[0]['expire']
|
|
|
+ uid_bucket_qs = UID_Bucket.objects.filter(uid=uid).values("id", "bucket_id",
|
|
|
+ "bucket__region", "endTime", "use_status")
|
|
|
# icloud_store_meal_id = store_qs[0]['icloud_store_meal_id']
|
|
|
# icloud_meal_qs = ICloudStoreMeal.objects.filter(id=icloud_store_meal_id).values('size')
|
|
|
# if not icloud_meal_qs.exists():
|
|
@@ -1132,28 +1116,22 @@ class CloudStorageView(View):
|
|
|
if promotion_rule_qs.exists():
|
|
|
promotion_rule_id = promotion_rule_qs[0]['id']
|
|
|
expire = expire * 2
|
|
|
+ end_time = CommonService.calcMonthLater(expire)
|
|
|
+ use_flag = True
|
|
|
with transaction.atomic():
|
|
|
if uid_bucket_qs.exists():
|
|
|
uid_bucket = uid_bucket_qs.first()
|
|
|
- if uid_bucket['use_status'] == 1 and uid_bucket['bucket_id'] == bucket_id: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
- end_time = CommonService.calcMonthLater(expire, uid_bucket['endTime'])
|
|
|
- UID_Bucket.objects.filter(id=uid_bucket['id']).update(uid=uid, channel=channel,
|
|
|
- endTime=end_time,
|
|
|
- bucket_id=bucket_id, updateTime=now_time)
|
|
|
- else: # 已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
- unused_uid_qs = Unused_Uid_Meal.objects.filter(uid=uid, bucket_id=bucket_id)
|
|
|
- nums = 2 if order_list[0]['isSelectDiscounts'] == 1 else 1
|
|
|
- if promotion_rule_qs.exists():
|
|
|
- nums = nums + 1
|
|
|
- if unused_uid_qs.exists():
|
|
|
- unused_uid_qs.update(num=F('num') + nums)
|
|
|
- else:
|
|
|
- Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=now_time, num=nums,
|
|
|
- expire=store_qs[0]['expire'], bucket_id=bucket_id)
|
|
|
- UID_Bucket.objects.filter(id=uid_bucket['id']).update(has_unused=1)
|
|
|
uid_bucket_id = uid_bucket['id']
|
|
|
+ if uid_bucket['use_status'] == 1 and uid_bucket['endTime'] > now_time: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
+ Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=now_time, order_id=order_id,
|
|
|
+ expire=expire, is_ai=is_ai, bucket_id=bucket_id)
|
|
|
+ UID_Bucket.objects.filter(id=uid_bucket_id).update(has_unused=1)
|
|
|
+ use_flag = False
|
|
|
+ else:
|
|
|
+ UID_Bucket.objects.filter(id=uid_bucket_id).update(channel=channel, bucket_id=bucket_id,
|
|
|
+ endTime=end_time, updateTime=now_time,
|
|
|
+ use_status=1)
|
|
|
else:
|
|
|
- end_time = CommonService.calcMonthLater(expire)
|
|
|
uid_bucket = UID_Bucket.objects.create(uid=uid, channel=channel, bucket_id=bucket_id,
|
|
|
endTime=end_time, addTime=now_time, updateTime=now_time,
|
|
|
use_status=1)
|
|
@@ -1174,6 +1152,14 @@ class CloudStorageView(View):
|
|
|
order_qs.update(status=1, updTime=now_time, uid_bucket_id=uid_bucket_id,
|
|
|
promotion_rule_id=promotion_rule_id)
|
|
|
date_time = time.strftime("%Y-%m-%d", time.localtime())
|
|
|
+ # 开通AI服务
|
|
|
+ if is_ai and use_flag:
|
|
|
+ ai_service = AiService.objects.filter(uid=uid, channel=channel)
|
|
|
+ if ai_service.exists(): # 有正在使用的套餐,套餐结束时间保存为套餐有效期
|
|
|
+ ai_service.update(updTime=now_time, use_status=1, orders_id=order_id, endTime=end_time)
|
|
|
+ else:
|
|
|
+ AiService.objects.create(uid=uid, channel=channel, detect_status=1, addTime=now_time,
|
|
|
+ updTime=now_time, endTime=end_time, use_status=1, orders_id=order_id)
|
|
|
# 开通云盘服务
|
|
|
# icloud_use_qs = IcloudUseDetails.objects.filter(user_id=userid).values('id')
|
|
|
# if not icloud_use_qs.exists():
|
|
@@ -1222,7 +1208,7 @@ class CloudStorageView(View):
|
|
|
|
|
|
def do_pay_by_wechat_callback(self, request, response): # 微信支付回调
|
|
|
"""
|
|
|
- 查询套餐列表
|
|
|
+ 微信支付回调
|
|
|
@param request: 请求体
|
|
|
@request_dict result_code: 业务结果
|
|
|
@request_dict out_trade_no: 商户订单号
|
|
@@ -1265,14 +1251,14 @@ class CloudStorageView(View):
|
|
|
uid = order_list[0]['UID']
|
|
|
channel = order_list[0]['channel']
|
|
|
rank = order_list[0]['rank']
|
|
|
- store_qs = Store_Meal.objects.filter(id=rank).values("day", "bucket_id", "bucket__storeDay", "expire",
|
|
|
+ store_qs = Store_Meal.objects.filter(id=rank).values("day", "bucket_id", "expire",
|
|
|
'icloud_store_meal_id')
|
|
|
if not store_qs.exists():
|
|
|
return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': '套餐不存在'}))
|
|
|
bucket_id = store_qs[0]['bucket_id']
|
|
|
- uid_bucket_qs = UID_Bucket.objects.filter(uid=uid).values("id", "bucket_id", "bucket__storeDay",
|
|
|
- "bucket__region", "endTime", "use_status")
|
|
|
expire = store_qs[0]['expire']
|
|
|
+ uid_bucket_qs = UID_Bucket.objects.filter(uid=uid).values("id", "bucket_id",
|
|
|
+ "bucket__region", "endTime", "use_status")
|
|
|
# icloud_store_meal_id = store_qs[0]['icloud_store_meal_id']
|
|
|
# icloud_meal_qs = ICloudStoreMeal.objects.filter(id=icloud_store_meal_id).values('size')
|
|
|
# if not icloud_meal_qs.exists():
|
|
@@ -1287,28 +1273,20 @@ class CloudStorageView(View):
|
|
|
if promotion_rule_qs.exists():
|
|
|
promotion_rule_id = promotion_rule_qs[0]['id']
|
|
|
expire = expire * 2
|
|
|
+ end_time = CommonService.calcMonthLater(expire)
|
|
|
with transaction.atomic():
|
|
|
if uid_bucket_qs.exists():
|
|
|
uid_bucket = uid_bucket_qs.first()
|
|
|
- if uid_bucket['use_status'] == 1 and uid_bucket['bucket_id'] == bucket_id: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
- end_time = CommonService.calcMonthLater(expire, uid_bucket['endTime'])
|
|
|
- UID_Bucket.objects.filter(id=uid_bucket['id']).update(uid=uid, channel=channel,
|
|
|
- bucket_id=bucket_id,
|
|
|
- endTime=end_time, updateTime=now_time)
|
|
|
- else: # 已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
- unused_uid_qs = Unused_Uid_Meal.objects.filter(uid=uid, bucket_id=bucket_id)
|
|
|
- nums = 2 if order_list[0]['isSelectDiscounts'] == 1 else 1
|
|
|
- if promotion_rule_qs.exists():
|
|
|
- nums = nums + 1
|
|
|
- if unused_uid_qs.exists():
|
|
|
- unused_uid_qs.update(num=F('num') + nums)
|
|
|
- else:
|
|
|
- Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=now_time, num=nums,
|
|
|
- expire=store_qs[0]['expire'], bucket_id=bucket_id)
|
|
|
- UID_Bucket.objects.filter(id=uid_bucket['id']).update(has_unused=1)
|
|
|
uid_bucket_id = uid_bucket['id']
|
|
|
+ if uid_bucket['use_status'] == 1 and uid_bucket['endTime'] > now_time: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
+ Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=now_time, is_ai=0,
|
|
|
+ expire=expire, bucket_id=bucket_id, order_id=order_id)
|
|
|
+ UID_Bucket.objects.filter(id=uid_bucket['id']).update(has_unused=1)
|
|
|
+ else:
|
|
|
+ UID_Bucket.objects.filter(id=uid_bucket_id).update(channel=channel, bucket_id=bucket_id,
|
|
|
+ endTime=end_time, updateTime=now_time,
|
|
|
+ use_status=1)
|
|
|
else:
|
|
|
- end_time = CommonService.calcMonthLater(expire)
|
|
|
uid_bucket = UID_Bucket.objects.create(uid=uid, channel=channel, bucket_id=bucket_id,
|
|
|
endTime=end_time, addTime=now_time,
|
|
|
updateTime=now_time, use_status=1)
|
|
@@ -1645,16 +1623,22 @@ class CloudStorageView(View):
|
|
|
order_id = CommonService.createOrderID()
|
|
|
now_time = int(time.time())
|
|
|
store_qs = Store_Meal.objects.filter(id=rank, lang__lang=lang, is_show=0).values("day", "bucket_id",
|
|
|
- "bucket__storeDay", "expire",
|
|
|
+ "expire",
|
|
|
'lang__content', 'price',
|
|
|
'currency', 'commodity_type',
|
|
|
'icloud_store_meal_id')
|
|
|
if not store_qs.exists():
|
|
|
return response.json(173)
|
|
|
bucket_id = store_qs[0]['bucket_id']
|
|
|
- uid_bucket_qs = UID_Bucket.objects.filter(uid=uid).values("id", "bucket_id", "bucket__storeDay",
|
|
|
- "bucket__region", "endTime", "use_status")
|
|
|
+ uid_bucket_qs = UID_Bucket.objects.filter(uid=uid).values("id", "bucket_id", "bucket__region",
|
|
|
+ "endTime", "use_status")
|
|
|
expire = store_qs[0]['expire']
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid, channel=channel).values('is_ai')
|
|
|
+ if not uid_set_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ is_ai = 1 if uid_set_qs[0]['is_ai'] != 2 else 0
|
|
|
+ use_flag = True
|
|
|
+ end_time = CommonService.calcMonthLater(expire)
|
|
|
# icloud_store_meal_id = store_qs[0]['icloud_store_meal_id']
|
|
|
# icloud_meal_qs = ICloudStoreMeal.objects.filter(id=icloud_store_meal_id).values('size')
|
|
|
# if not icloud_meal_qs.exists():
|
|
@@ -1664,27 +1648,22 @@ class CloudStorageView(View):
|
|
|
with transaction.atomic():
|
|
|
if uid_bucket_qs.exists():
|
|
|
uid_bucket = uid_bucket_qs.first()
|
|
|
- if uid_bucket['use_status'] == 1 and uid_bucket['bucket_id'] == bucket_id: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
- end_time = CommonService.calcMonthLater(expire, uid_bucket['endTime'])
|
|
|
- UID_Bucket.objects.filter(id=uid_bucket['id']).update(uid=uid, channel=channel,
|
|
|
- bucket_id=bucket_id,
|
|
|
- endTime=end_time, updateTime=now_time)
|
|
|
- else: # 已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
- unused_uid_qs = Unused_Uid_Meal.objects.filter(uid=uid, bucket_id=bucket_id)
|
|
|
- nums = 1
|
|
|
- if unused_uid_qs.exists():
|
|
|
- unused_uid_qs.update(num=F('num') + nums)
|
|
|
- else:
|
|
|
- Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=now_time, num=nums,
|
|
|
- expire=store_qs[0]['expire'], bucket_id=bucket_id)
|
|
|
- UID_Bucket.objects.filter(id=uid_bucket['id']).update(has_unused=1)
|
|
|
uid_bucket_id = uid_bucket['id']
|
|
|
+ if uid_bucket['use_status'] == 1 and uid_bucket['endTime'] > now_time:
|
|
|
+ Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=now_time, is_ai=is_ai,
|
|
|
+ order_id=order_id, expire=expire, bucket_id=bucket_id)
|
|
|
+ UID_Bucket.objects.filter(id=uid_bucket_id).update(has_unused=1)
|
|
|
+ use_flag = False
|
|
|
+ else:
|
|
|
+ UID_Bucket.objects.filter(id=uid_bucket_id).update(channel=channel, bucket_id=bucket_id,
|
|
|
+ endTime=end_time, updateTime=now_time,
|
|
|
+ use_status=1)
|
|
|
else:
|
|
|
- end_time = CommonService.calcMonthLater(expire)
|
|
|
uid_bucket = UID_Bucket.objects.create(uid=uid, channel=channel, bucket_id=bucket_id,
|
|
|
endTime=end_time, addTime=now_time, updateTime=now_time,
|
|
|
use_status=1)
|
|
|
uid_bucket_id = uid_bucket.id
|
|
|
+
|
|
|
# 开通云盘体验
|
|
|
# icloud_use_qs = IcloudUseDetails.objects.filter(user_id=user_id).values('id')
|
|
|
# if not icloud_use_qs.exists():
|
|
@@ -1714,6 +1693,14 @@ class CloudStorageView(View):
|
|
|
pay_url="体验版", store_meal_name=store_meal_name,
|
|
|
commodity_code=commodity_code, commodity_type=store_qs[0]['commodity_type'],
|
|
|
rank_id=rank, status=1, uid_bucket_id=uid_bucket_id, ai_rank_id=1)
|
|
|
+ # 开通AI服务,国内不支持AI
|
|
|
+ if is_ai and use_flag and CONFIG_INFO != CONFIG_CN:
|
|
|
+ ai_service = AiService.objects.filter(uid=uid, channel=channel)
|
|
|
+ if ai_service.exists(): # 有正在使用的套餐,套餐结束时间保存为套餐有效期
|
|
|
+ ai_service.update(updTime=now_time, use_status=1, orders_id=order_id, endTime=end_time)
|
|
|
+ else:
|
|
|
+ AiService.objects.create(uid=uid, channel=channel, detect_status=1, addTime=now_time,
|
|
|
+ updTime=now_time, endTime=end_time, use_status=1, orders_id=order_id)
|
|
|
|
|
|
device_user_qs = Device_User.objects.filter(userID=user_id).values('username')
|
|
|
device_info_qs = Device_Info.objects.filter(UID=uid, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
@@ -1882,12 +1869,11 @@ class CloudStorageView(View):
|
|
|
unused_uid_qs = Unused_Uid_Meal.objects.filter(uid=uid).annotate(unused_id=F('id')).values("unused_id",
|
|
|
"uid",
|
|
|
"bucket__content",
|
|
|
- "num",
|
|
|
"bucket__id",
|
|
|
"expire")
|
|
|
month = 'month' if lang != 'cn' else '个月'
|
|
|
for unused_uid in unused_uid_qs:
|
|
|
- storage_time = unused_uid['num'] * unused_uid['expire']
|
|
|
+ storage_time = unused_uid['expire']
|
|
|
if lang != 'cn' and storage_time > 1: # 英文大于一个月使用复数
|
|
|
month += 's'
|
|
|
storage = str(storage_time) + month
|
|
@@ -1935,7 +1921,8 @@ class CloudStorageView(View):
|
|
|
using_uid_bucket_qs = UID_Bucket.objects.filter(uid=uid, has_unused=1).values("id", "uid", "endTime",
|
|
|
"bucket__content", "addTime")
|
|
|
unused_uid_bucket_qs = Unused_Uid_Meal.objects.filter(id=unused_id).values("id", "uid", "channel", "addTime",
|
|
|
- "expire", "num", "bucket_id")
|
|
|
+ "expire", "is_ai", "bucket_id",
|
|
|
+ "order_id")
|
|
|
if not unused_uid_bucket_qs.exists() or not using_uid_bucket_qs.exists():
|
|
|
return response.json(10030)
|
|
|
unused_uid_bucket = unused_uid_bucket_qs.first()
|
|
@@ -1944,11 +1931,21 @@ class CloudStorageView(View):
|
|
|
with transaction.atomic():
|
|
|
count_unused = Unused_Uid_Meal.objects.filter(uid=uid).count()
|
|
|
has_unused = 1 if count_unused > 1 else 0
|
|
|
- end_time = CommonService.calcMonthLater(unused_uid_bucket['expire'] * unused_uid_bucket['num'])
|
|
|
+ end_time = CommonService.calcMonthLater(unused_uid_bucket['expire'])
|
|
|
UID_Bucket.objects.filter(uid=uid).update(channel=unused_uid_bucket['channel'], endTime=end_time,
|
|
|
bucket_id=unused_uid_bucket['bucket_id']
|
|
|
, updateTime=now_time, use_status=1,
|
|
|
has_unused=has_unused)
|
|
|
+ # 开通AI服务
|
|
|
+ if unused_uid_bucket['is_ai']:
|
|
|
+ ai_service = AiService.objects.filter(uid=uid, channel=unused_uid_bucket['channel'])
|
|
|
+ if ai_service.exists(): # 有正在使用的套餐,套餐结束时间保存为套餐有效期
|
|
|
+ ai_service.update(updTime=now_time, use_status=1, orders_id=unused_uid_bucket['order_id'],
|
|
|
+ endTime=end_time)
|
|
|
+ else:
|
|
|
+ AiService.objects.create(uid=uid, channel=unused_uid_bucket['channel'], detect_status=1,
|
|
|
+ addTime=now_time, updTime=now_time, endTime=end_time, use_status=1,
|
|
|
+ orders_id=unused_uid_bucket['order_id'])
|
|
|
Unused_Uid_Meal.objects.filter(id=unused_id).delete()
|
|
|
StsCrdModel.objects.filter(uid=uid).delete() # 删除sts记录
|
|
|
# VodHlsModel.objects.filter(uid=uid).delete() # 删除播放列表,后期数据量多时应该考虑延后删除
|