|
@@ -148,9 +148,9 @@ class CloudStorageView(View):
|
|
|
return self.device_commodity(request_dict, userID, response)
|
|
|
elif operation == 'switchdevicecommodity': # 提前使用设备关联套餐
|
|
|
return self.switch_device_commodity(request_dict, userID, response)
|
|
|
- elif operation == 'hasvod': #APP的回放界面,日历表显示当天有无录像
|
|
|
+ elif operation == 'hasvod': # APP的回放界面,日历表显示当天有无录像
|
|
|
return self.has_vod(request_dict, userID, response)
|
|
|
- elif operation == 'videoPlaybackTime': # 记录app播放时间
|
|
|
+ elif operation == 'videoPlaybackTime': # 记录app播放时间
|
|
|
return self.videoPlaybackTime(request_dict, userID, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
@@ -208,7 +208,7 @@ class CloudStorageView(View):
|
|
|
eq = ExperienceContextModel.objects.filter(uid=uid, experience_type=0).values('id')
|
|
|
|
|
|
if mold:
|
|
|
- qs = qs.filter(bucket__mold=mold,lang__lang=lang)
|
|
|
+ qs = qs.filter(bucket__mold=mold, lang__lang=lang)
|
|
|
else:
|
|
|
qs = qs.filter(lang__lang=lang)
|
|
|
|
|
@@ -218,14 +218,15 @@ class CloudStorageView(View):
|
|
|
qs = qs.filter(pay_type='10')
|
|
|
|
|
|
qs = qs.filter(~Q(pay_type='11')) # 过滤不显示激活码套餐
|
|
|
- qs = qs.filter(is_show=0) #过滤隐藏套餐
|
|
|
- #qs = qs.filter(id='11111111')
|
|
|
- #qs = qs.filter(bucket__region_id=regionObj.region_id) # 过滤大洲
|
|
|
- qs = qs.annotate(title=F('lang__title'),content=F('lang__content'),discount_content=F('lang__discount_content'))
|
|
|
+ qs = qs.filter(is_show=0) # 过滤隐藏套餐
|
|
|
+ # qs = qs.filter(id='11111111')
|
|
|
+ # qs = qs.filter(bucket__region_id=regionObj.region_id) # 过滤大洲
|
|
|
+ qs = qs.annotate(title=F('lang__title'), content=F('lang__content'),
|
|
|
+ discount_content=F('lang__discount_content'))
|
|
|
qs = qs.order_by('sort').values("id", "title", "content", "price", "day", "currency", "bucket__storeDay",
|
|
|
- "bucket__bucket", "bucket__area", "commodity_code",
|
|
|
- "commodity_type", "is_discounts", "virtual_price", "expire",
|
|
|
- "discount_price", "discount_content", "symbol","cycle_config_id")
|
|
|
+ "bucket__bucket", "bucket__area", "commodity_code",
|
|
|
+ "commodity_type", "is_discounts", "virtual_price", "expire",
|
|
|
+ "discount_price", "discount_content", "symbol", "cycle_config_id")
|
|
|
|
|
|
if qs.exists():
|
|
|
ql = list(qs)
|
|
@@ -242,10 +243,11 @@ class CloudStorageView(View):
|
|
|
del items_list[key]['cycle_config_id']
|
|
|
res_c = {'area': area, 'items': items_list}
|
|
|
res.append(res_c)
|
|
|
- #是否促销
|
|
|
+ # 是否促销
|
|
|
promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
|
- endTime__gte=nowTime).values('id','ruleConfig','ruleName',
|
|
|
- 'startTime','endTime','ruleDesc')
|
|
|
+ endTime__gte=nowTime).values('id', 'ruleConfig', 'ruleName',
|
|
|
+ 'startTime', 'endTime',
|
|
|
+ 'ruleDesc')
|
|
|
if promotion.exists():
|
|
|
promotion = {
|
|
|
'is_promotion': 1,
|
|
@@ -253,7 +255,7 @@ class CloudStorageView(View):
|
|
|
'promotionEndTime': promotion[0]['endTime'],
|
|
|
'promotionName': json.loads(promotion[0]['ruleName']).get(lang, ''),
|
|
|
'promotionDesc': json.loads(promotion[0]['ruleDesc']).get(lang, ''),
|
|
|
- 'nowTime':int(time.time())
|
|
|
+ 'nowTime': int(time.time())
|
|
|
}
|
|
|
else:
|
|
|
promotion = {
|
|
@@ -263,10 +265,10 @@ class CloudStorageView(View):
|
|
|
'meals': res,
|
|
|
'extra':
|
|
|
{
|
|
|
- 'cloud_banner': SERVER_DOMAIN+'web/images/cloud_cn_banner.png',
|
|
|
- 'cloud_en_baner': SERVER_DOMAIN_SSL+'web/images/cloud_en_banner.png'
|
|
|
+ 'cloud_banner': SERVER_DOMAIN + 'web/images/cloud_cn_banner.png',
|
|
|
+ 'cloud_en_baner': SERVER_DOMAIN_SSL + 'web/images/cloud_en_banner.png'
|
|
|
},
|
|
|
- 'promotion':promotion,
|
|
|
+ 'promotion': promotion,
|
|
|
}
|
|
|
return response.json(0, result)
|
|
|
else:
|
|
@@ -289,10 +291,9 @@ class CloudStorageView(View):
|
|
|
print(bucket__region)
|
|
|
print(bucket_name)
|
|
|
|
|
|
-
|
|
|
session = Session(
|
|
|
aws_access_key_id=AWS_ACCESS_KEY_ID[vh_qs[0]["bucket__mold"]],
|
|
|
- aws_secret_access_key = AWS_SECRET_ACCESS_KEY[vh_qs[0]["bucket__mold"]],
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[vh_qs[0]["bucket__mold"]],
|
|
|
region_name=bucket__region
|
|
|
)
|
|
|
'''
|
|
@@ -302,7 +303,7 @@ class CloudStorageView(View):
|
|
|
playlist_entries = []
|
|
|
fg = int(fg)
|
|
|
# ts_count = fg & 0xf
|
|
|
- #fg 64位整型,低四位代表ts文件总数,然后进行位运算,一次移四位,每四位转为十进制即为当前ts文件的秒数
|
|
|
+ # fg 64位整型,低四位代表ts文件总数,然后进行位运算,一次移四位,每四位转为十进制即为当前ts文件的秒数
|
|
|
for i in range(15):
|
|
|
shift = (i + 1) * 4
|
|
|
duration = (fg >> shift) & 0xf
|
|
@@ -386,7 +387,7 @@ class CloudStorageView(View):
|
|
|
"Effect": "Allow",
|
|
|
"Action": "s3:*",
|
|
|
"Resource": ["{aws_arn}:::{bucket_name}/{uid_channel}*".
|
|
|
- format(aws_arn=aws_arn, bucket_name=bucket_name, uid_channel=storage)]
|
|
|
+ format(aws_arn=aws_arn, bucket_name=bucket_name, uid_channel=storage)]
|
|
|
}
|
|
|
]
|
|
|
}
|
|
@@ -410,7 +411,7 @@ class CloudStorageView(View):
|
|
|
'endTime': ubqs[0]['endTime'],
|
|
|
'ip': ip,
|
|
|
'region': region_id,
|
|
|
- 'bucket_mold':ubqs[0]['bucket__mold']
|
|
|
+ 'bucket_mold': ubqs[0]['bucket__mold']
|
|
|
}
|
|
|
if sts_qs.exists():
|
|
|
sts_qs.update(data=json.dumps(res, default=str), addTime=now_time)
|
|
@@ -435,7 +436,7 @@ class CloudStorageView(View):
|
|
|
|
|
|
if uid == 'UWE2ZJ52SE4FX75U111A':
|
|
|
logger.info({
|
|
|
- "intoTime":intoTime,
|
|
|
+ "intoTime": intoTime,
|
|
|
})
|
|
|
|
|
|
dv_qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False).values('vodPrimaryUserID',
|
|
@@ -450,11 +451,11 @@ class CloudStorageView(View):
|
|
|
"dvQsModelOverTime": dvQsModelTimeOver,
|
|
|
})
|
|
|
|
|
|
-
|
|
|
if dv_qs[0]['vodPrimaryUserID'] != userID:
|
|
|
return response.json(10034)
|
|
|
now_time = int(time.time())
|
|
|
- bv_qs = UID_Bucket.objects.filter(uid=uid, endTime__gte=now_time ,channel=channel).values('bucket_id').order_by('addTime')
|
|
|
+ bv_qs = UID_Bucket.objects.filter(uid=uid, endTime__gte=now_time, channel=channel).values('bucket_id').order_by(
|
|
|
+ 'addTime')
|
|
|
if not bv_qs.exists():
|
|
|
return response.json(10030)
|
|
|
|
|
@@ -476,7 +477,7 @@ class CloudStorageView(View):
|
|
|
if not vh_qs.exists():
|
|
|
return response.json(0, vod_play_list)
|
|
|
|
|
|
- #不用关联外键查询,因为会查询非常慢
|
|
|
+ # 不用关联外键查询,因为会查询非常慢
|
|
|
bucket_qs = VodBucketModel.objects.values()
|
|
|
regroup_bucket_qs = {}
|
|
|
for bucket_dict in bucket_qs:
|
|
@@ -542,12 +543,12 @@ class CloudStorageView(View):
|
|
|
generatePresignedOverTime = int(time.time())
|
|
|
if uid == 'UWE2ZJ52SE4FX75U111A':
|
|
|
logger.info({
|
|
|
- "intoTime":intoTime,
|
|
|
- "dvQsModelOverTime":dvQsModelTimeOver,
|
|
|
- "UidBucketModelOverTime":UidBucketModelTimeOver,
|
|
|
- "vodHlsModelOverTime":vodHlsModelTimeOver,
|
|
|
- "awsObjectOverTime":awsObjectOverTime,
|
|
|
- "generatePresignedOverTime":generatePresignedOverTime,
|
|
|
+ "intoTime": intoTime,
|
|
|
+ "dvQsModelOverTime": dvQsModelTimeOver,
|
|
|
+ "UidBucketModelOverTime": UidBucketModelTimeOver,
|
|
|
+ "vodHlsModelOverTime": vodHlsModelTimeOver,
|
|
|
+ "awsObjectOverTime": awsObjectOverTime,
|
|
|
+ "generatePresignedOverTime": generatePresignedOverTime,
|
|
|
})
|
|
|
|
|
|
return response.json(0, vod_play_list)
|
|
@@ -665,7 +666,7 @@ class CloudStorageView(View):
|
|
|
|
|
|
nowTime = int(time.time())
|
|
|
order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
|
|
|
- "userID__userID", "userID__username","coupon_id")
|
|
|
+ "userID__userID", "userID__username", "coupon_id")
|
|
|
userid = order_list[0]['userID__userID']
|
|
|
username = order_list[0]['userID__username']
|
|
|
UID = order_list[0]['UID']
|
|
@@ -677,7 +678,8 @@ class CloudStorageView(View):
|
|
|
bucketId = smqs[0]['bucket_id']
|
|
|
if not smqs.exists():
|
|
|
return response.json(173)
|
|
|
- ubqs = UID_Bucket.objects.filter(uid=UID).values("id", "bucket_id", "bucket__storeDay", "bucket__region",
|
|
|
+ ubqs = UID_Bucket.objects.filter(uid=UID).values("id", "bucket_id", "bucket__storeDay",
|
|
|
+ "bucket__region",
|
|
|
"endTime", "use_status")
|
|
|
expire = smqs[0]['expire']
|
|
|
if order_list[0]['isSelectDiscounts'] == 1:
|
|
@@ -685,7 +687,7 @@ class CloudStorageView(View):
|
|
|
# 是否有促销
|
|
|
nowTime = int(time.time())
|
|
|
promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
|
- endTime__gte=nowTime).values('id','ruleConfig')
|
|
|
+ endTime__gte=nowTime).values('id', 'ruleConfig')
|
|
|
promotion_rule_id = ''
|
|
|
if promotion.exists():
|
|
|
promotion_rule_id = promotion[0]['id']
|
|
@@ -693,12 +695,12 @@ class CloudStorageView(View):
|
|
|
with transaction.atomic():
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|
|
|
- if ubq['use_status'] == 1 and ubq['bucket_id'] == bucketId: #套餐使用中并且相同套餐叠加过期时间
|
|
|
+ if ubq['use_status'] == 1 and ubq['bucket_id'] == bucketId: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
endTime = CommonService.calcMonthLater(expire, ubq['endTime'])
|
|
|
UID_Bucket.objects.filter(id=ubq['id']).update \
|
|
|
(uid=UID, channel=channel, bucket_id=bucketId,
|
|
|
endTime=endTime, updateTime=nowTime)
|
|
|
- else: #已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
+ else: # 已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
has_unused = Unused_Uid_Meal.objects.filter(uid=UID, bucket_id=bucketId).values("id")
|
|
|
nums = 2 if order_list[0]['isSelectDiscounts'] == 1 else 1
|
|
|
if promotion.exists():
|
|
@@ -706,15 +708,15 @@ class CloudStorageView(View):
|
|
|
if has_unused.exists():
|
|
|
Unused_Uid_Meal.objects.filter(id=has_unused[0]['id']).update(num=F('num') + nums)
|
|
|
else:
|
|
|
- Unused_Uid_Meal.objects.create(uid=UID,channel=channel,addTime=nowTime,num=nums,
|
|
|
- expire=smqs[0]['expire'],bucket_id=bucketId)
|
|
|
+ Unused_Uid_Meal.objects.create(uid=UID, channel=channel, addTime=nowTime, num=nums,
|
|
|
+ expire=smqs[0]['expire'], bucket_id=bucketId)
|
|
|
UID_Bucket.objects.filter(id=ubq['id']).update(has_unused=1)
|
|
|
uid_bucket_id = ubq['id']
|
|
|
else:
|
|
|
endTime = CommonService.calcMonthLater(expire)
|
|
|
ub_cqs = UID_Bucket.objects.create \
|
|
|
(uid=UID, channel=channel, bucket_id=bucketId, endTime=endTime, addTime=nowTime,
|
|
|
- updateTime=nowTime,use_status=1)
|
|
|
+ updateTime=nowTime, use_status=1)
|
|
|
uid_bucket_id = ub_cqs.id
|
|
|
|
|
|
dvq = Device_Info.objects.filter(UID=UID, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
@@ -735,9 +737,11 @@ class CloudStorageView(View):
|
|
|
|
|
|
# 核销coupon
|
|
|
if order_list[0]['coupon_id']:
|
|
|
- CouponModel.objects.filter(id=order_list[0]['coupon_id']).update(use_status=2, update_time=nowTime)
|
|
|
+ CouponModel.objects.filter(id=order_list[0]['coupon_id']).update(use_status=2,
|
|
|
+ update_time=nowTime)
|
|
|
|
|
|
- order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id, promotion_rule_id=promotion_rule_id)
|
|
|
+ order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id,
|
|
|
+ promotion_rule_id=promotion_rule_id)
|
|
|
datetime = time.strftime("%Y-%m-%d", time.localtime())
|
|
|
# 如果存在序列号,消息提示用序列号
|
|
|
device_info_qs = Device_Info.objects.filter(UID=UID).values('serial_number', 'Type')
|
|
@@ -747,11 +751,14 @@ class CloudStorageView(View):
|
|
|
device_name = CommonService.get_full_serial_number(UID, serial_number, device_type)
|
|
|
else:
|
|
|
device_name = UID
|
|
|
- sys_msg_text_list = ['温馨提示:尊敬的客户,您的'+device_name+'设备在'+datetime+'已成功购买云存套餐', 'Dear customer,you already subscribed the cloud storage package successfully for device ' + device_name + ' on '+ time.strftime("%b %dth,%Y", time.localtime())]
|
|
|
+ sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + device_name + '设备在' + datetime + '已成功购买云存套餐',
|
|
|
+ 'Dear customer,you already subscribed the cloud storage package successfully for device ' + device_name + ' on ' + time.strftime(
|
|
|
+ "%b %dth,%Y", time.localtime())]
|
|
|
self.do_vod_msg_Notice(UID, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
|
|
|
red_url = "{SERVER_DOMAIN_SSL}web/paid2/success.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
if lang != 'cn':
|
|
|
- red_url = "{SERVER_DOMAIN_SSL}web/paid2/en_success.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
+ red_url = "{SERVER_DOMAIN_SSL}web/paid2/en_success.html".format(
|
|
|
+ SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
redisObj.del_data(key=orderID + 'do_notify')
|
|
|
return HttpResponseRedirect(red_url)
|
|
|
return response.json(0, signature)
|
|
@@ -779,7 +786,7 @@ class CloudStorageView(View):
|
|
|
orderID = request_dict.get('orderID', None)
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
|
|
|
- logger.info("paymentID={paymentId},payerID={PayerID}".format(paymentId=paymentId,PayerID=PayerID))
|
|
|
+ logger.info("paymentID={paymentId},payerID={PayerID}".format(paymentId=paymentId, PayerID=PayerID))
|
|
|
|
|
|
# redis加锁,防止订单重复
|
|
|
redisObj = RedisObject()
|
|
@@ -819,7 +826,7 @@ class CloudStorageView(View):
|
|
|
nowTime = int(time.time())
|
|
|
order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
|
|
|
"userID__userID",
|
|
|
- "userID__username","coupon_id")
|
|
|
+ "userID__username", "coupon_id")
|
|
|
userid = order_list[0]['userID__userID']
|
|
|
username = order_list[0]['userID__username']
|
|
|
UID = order_list[0]['UID']
|
|
@@ -840,7 +847,7 @@ class CloudStorageView(View):
|
|
|
# 是否有促销
|
|
|
nowTime = int(time.time())
|
|
|
promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
|
- endTime__gte=nowTime).values('id','ruleConfig')
|
|
|
+ endTime__gte=nowTime).values('id', 'ruleConfig')
|
|
|
promotion_rule_id = ''
|
|
|
if promotion.exists():
|
|
|
promotion_rule_id = promotion[0]['id']
|
|
@@ -848,12 +855,12 @@ class CloudStorageView(View):
|
|
|
with transaction.atomic():
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|
|
|
- if ubq['use_status'] == 1 and ubq['bucket_id'] == bucketId: #套餐使用中并且相同套餐叠加过期时间
|
|
|
+ if ubq['use_status'] == 1 and ubq['bucket_id'] == bucketId: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
endTime = CommonService.calcMonthLater(expire, ubq['endTime'])
|
|
|
UID_Bucket.objects.filter(id=ubq['id']).update \
|
|
|
(uid=UID, channel=channel, bucket_id=bucketId,
|
|
|
endTime=endTime, updateTime=nowTime)
|
|
|
- else: #已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
+ else: # 已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
has_unused = Unused_Uid_Meal.objects.filter(uid=UID, bucket_id=bucketId).values("id")
|
|
|
nums = 2 if order_list[0]['isSelectDiscounts'] == 1 else 1
|
|
|
if promotion.exists():
|
|
@@ -861,15 +868,15 @@ class CloudStorageView(View):
|
|
|
if has_unused.exists():
|
|
|
Unused_Uid_Meal.objects.filter(id=has_unused[0]['id']).update(num=F('num') + nums)
|
|
|
else:
|
|
|
- Unused_Uid_Meal.objects.create(uid=UID,channel=channel,addTime=nowTime,num=nums,
|
|
|
- expire=smqs[0]['expire'],bucket_id=bucketId)
|
|
|
+ Unused_Uid_Meal.objects.create(uid=UID, channel=channel, addTime=nowTime, num=nums,
|
|
|
+ expire=smqs[0]['expire'], bucket_id=bucketId)
|
|
|
UID_Bucket.objects.filter(id=ubq['id']).update(has_unused=1)
|
|
|
uid_bucket_id = ubq['id']
|
|
|
else:
|
|
|
endTime = CommonService.calcMonthLater(expire)
|
|
|
ub_cqs = UID_Bucket.objects.create \
|
|
|
(uid=UID, channel=channel, bucket_id=bucketId, endTime=endTime, addTime=nowTime,
|
|
|
- updateTime=nowTime,use_status=1)
|
|
|
+ updateTime=nowTime, use_status=1)
|
|
|
uid_bucket_id = ub_cqs.id
|
|
|
|
|
|
dvq = Device_Info.objects.filter(UID=UID, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
@@ -892,7 +899,8 @@ class CloudStorageView(View):
|
|
|
if order_list[0]['coupon_id']:
|
|
|
CouponModel.objects.filter(id=order_list[0]['coupon_id']).update(use_status=2, update_time=nowTime)
|
|
|
|
|
|
- order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id, promotion_rule_id=promotion_rule_id)
|
|
|
+ order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id,
|
|
|
+ promotion_rule_id=promotion_rule_id)
|
|
|
datetime = time.strftime("%Y-%m-%d", time.localtime())
|
|
|
# 如果存在序列号,消息提示用序列号
|
|
|
device_info_qs = Device_Info.objects.filter(UID=UID).values('serial_number', 'Type')
|
|
@@ -947,7 +955,7 @@ class CloudStorageView(View):
|
|
|
return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': '签名失败'}))
|
|
|
orderID = out_trade_no
|
|
|
|
|
|
- #redis加锁,防止订单重复
|
|
|
+ # redis加锁,防止订单重复
|
|
|
redisObj = RedisObject()
|
|
|
isLock = redisObj.CONN.setnx(orderID + 'do_notify', 1)
|
|
|
redisObj.CONN.expire(orderID + 'do_notify', 60)
|
|
@@ -974,21 +982,22 @@ class CloudStorageView(View):
|
|
|
expire = smqs[0]['expire']
|
|
|
if order_list[0]['isSelectDiscounts'] == 1:
|
|
|
expire = smqs[0]['expire'] * 2
|
|
|
- #是否有促销
|
|
|
+ # 是否有促销
|
|
|
nowTime = int(time.time())
|
|
|
- promotion = PromotionRuleModel.objects.filter(status=1,startTime__lte=nowTime,endTime__gte=nowTime).values('id','ruleConfig')
|
|
|
+ promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
|
+ endTime__gte=nowTime).values('id', 'ruleConfig')
|
|
|
if promotion.exists():
|
|
|
promotion_rule_id = promotion[0]['id']
|
|
|
expire = expire * 2
|
|
|
with transaction.atomic():
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|
|
|
- if ubq['use_status'] == 1 and ubq['bucket_id'] == bucketId: #套餐使用中并且相同套餐叠加过期时间
|
|
|
+ if ubq['use_status'] == 1 and ubq['bucket_id'] == bucketId: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
endTime = CommonService.calcMonthLater(expire, ubq['endTime'])
|
|
|
UID_Bucket.objects.filter(id=ubq['id']).update \
|
|
|
(uid=UID, channel=channel, bucket_id=bucketId,
|
|
|
endTime=endTime, updateTime=nowTime)
|
|
|
- else: #已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
+ else: # 已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
has_unused = Unused_Uid_Meal.objects.filter(uid=UID, bucket_id=bucketId).values("id")
|
|
|
nums = 2 if order_list[0]['isSelectDiscounts'] == 1 else 1
|
|
|
if promotion.exists():
|
|
@@ -996,15 +1005,15 @@ class CloudStorageView(View):
|
|
|
if has_unused.exists():
|
|
|
Unused_Uid_Meal.objects.filter(id=has_unused[0]['id']).update(num=F('num') + nums)
|
|
|
else:
|
|
|
- Unused_Uid_Meal.objects.create(uid=UID,channel=channel,addTime=nowTime,num=nums,
|
|
|
- expire=smqs[0]['expire'],bucket_id=bucketId)
|
|
|
+ Unused_Uid_Meal.objects.create(uid=UID, channel=channel, addTime=nowTime, num=nums,
|
|
|
+ expire=smqs[0]['expire'], bucket_id=bucketId)
|
|
|
UID_Bucket.objects.filter(id=ubq['id']).update(has_unused=1)
|
|
|
uid_bucket_id = ubq['id']
|
|
|
else:
|
|
|
endTime = CommonService.calcMonthLater(expire)
|
|
|
ub_cqs = UID_Bucket.objects.create \
|
|
|
(uid=UID, channel=channel, bucket_id=bucketId, endTime=endTime, addTime=nowTime,
|
|
|
- updateTime=nowTime,use_status=1)
|
|
|
+ updateTime=nowTime, use_status=1)
|
|
|
uid_bucket_id = ub_cqs.id
|
|
|
|
|
|
dvq = Device_Info.objects.filter(UID=UID, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
@@ -1025,9 +1034,11 @@ class CloudStorageView(View):
|
|
|
|
|
|
# 核销coupon
|
|
|
if order_list[0]['coupon_id']:
|
|
|
- CouponModel.objects.filter(id=order_list[0]['coupon_id']).update(use_status=2, update_time=nowTime)
|
|
|
+ CouponModel.objects.filter(id=order_list[0]['coupon_id']).update(use_status=2,
|
|
|
+ update_time=nowTime)
|
|
|
|
|
|
- order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id, promotion_rule_id=promotion_rule_id)
|
|
|
+ order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id,
|
|
|
+ promotion_rule_id=promotion_rule_id)
|
|
|
datetime = time.strftime("%Y-%m-%d", time.localtime())
|
|
|
# 如果存在序列号,消息提示用序列号
|
|
|
device_info_qs = Device_Info.objects.filter(UID=UID).values('serial_number', 'Type')
|
|
@@ -1108,16 +1119,16 @@ class CloudStorageView(View):
|
|
|
# ubqs_count = ubqs.count()
|
|
|
# ubq = ubqs[ubqs_count - 1, ubqs_count]
|
|
|
# new_starTime = ubq['endTime'] + 1
|
|
|
- is_mold = 0 #判断国内外
|
|
|
- if smqs[0]['bucket__mold']==0:
|
|
|
+ is_mold = 0 # 判断国内外
|
|
|
+ if smqs[0]['bucket__mold'] == 0:
|
|
|
is_mold = 1
|
|
|
|
|
|
- order_qs = Order_Model.objects.filter(UID=uid , rank__bucket__mold=is_mold)
|
|
|
+ order_qs = Order_Model.objects.filter(UID=uid, rank__bucket__mold=is_mold)
|
|
|
if order_qs.exists():
|
|
|
return response.json(10041)
|
|
|
|
|
|
orderID = CommonService.createOrderID()
|
|
|
- #优惠券
|
|
|
+ # 优惠券
|
|
|
if coupon_id:
|
|
|
couponObj = CouponModel.objects.filter(id=coupon_id, use_status=0, distribute_time__lte=nowTime,
|
|
|
valid_time__gt=nowTime)
|
|
@@ -1126,9 +1137,9 @@ class CloudStorageView(View):
|
|
|
return response.json(10049)
|
|
|
price = Decimal(price)
|
|
|
coupon_discount = Decimal(couponQuery[0]['coupon_config__coupon_discount'])
|
|
|
- if couponQuery[0]['coupon_config__type'] == 1: #打折
|
|
|
- price = coupon_discount/10 * price
|
|
|
- elif couponQuery[0]['coupon_config__type'] == 2: #抵扣
|
|
|
+ if couponQuery[0]['coupon_config__type'] == 1: # 打折
|
|
|
+ price = coupon_discount / 10 * price
|
|
|
+ elif couponQuery[0]['coupon_config__type'] == 2: # 抵扣
|
|
|
price = price - coupon_discount
|
|
|
price = float(price)
|
|
|
if price < 0 or price == 0 or price < 0.01:
|
|
@@ -1136,28 +1147,36 @@ class CloudStorageView(View):
|
|
|
price = round(price, 2)
|
|
|
if pay_type == 1:
|
|
|
# 订阅周期扣款
|
|
|
- if(smqs[0]['cycle_config_id']):
|
|
|
- #查询是否有订阅过,活跃状态
|
|
|
+ if (smqs[0]['cycle_config_id']):
|
|
|
+ # 查询是否有订阅过,活跃状态
|
|
|
# return HttpResponse(price)
|
|
|
- checkHasSubscribe = Paypal.checkSubscriptions(userID,uid,rank)
|
|
|
+ checkHasSubscribe = Paypal.checkSubscriptions(userID, uid, rank)
|
|
|
if checkHasSubscribe is False:
|
|
|
return response.json(10050)
|
|
|
- subInfo = Paypal.subscriptions(store_info=smqs[0],lang=lang,orderID=orderID,price=price)
|
|
|
+ subInfo = Paypal.subscriptions(store_info=smqs[0], lang=lang, orderID=orderID, price=price)
|
|
|
if not subInfo:
|
|
|
return response.json(10048)
|
|
|
+ store_meal_qs = Store_Meal.objects.filter(id=rank, lang__lang='cn', is_show=0).values('lang__title',
|
|
|
+ 'lang__content')
|
|
|
+ if store_meal_qs.exists():
|
|
|
+ store_meal_name = store_meal_qs[0]['lang__title'] + '-' + store_meal_qs[0]['lang__content']
|
|
|
+ else:
|
|
|
+ store_meal_name = '未知套餐'
|
|
|
Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID,
|
|
|
desc=content, payType=pay_type, payTime=nowTime,
|
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
|
pay_url=subInfo['url'], isSelectDiscounts=is_select_discount,
|
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
|
- rank_id=rank, plan_id=subInfo['plan_id'],coupon_id=coupon_id,ai_rank_id=1)
|
|
|
+ rank_id=rank, plan_id=subInfo['plan_id'], coupon_id=coupon_id, ai_rank_id=1,
|
|
|
+ store_meal_name=store_meal_name
|
|
|
+ )
|
|
|
# if coupon_id:
|
|
|
# #冻结优惠券
|
|
|
# CouponModel.objects.filter(id=coupon_id, use_status=0, distribute_time__lte=nowTime,
|
|
|
# valid_time__gt=nowTime).update(use_status=1)
|
|
|
|
|
|
return response.json(0, {"redirectUrl": subInfo['url'], "orderID": orderID})
|
|
|
- #正常扣款
|
|
|
+ # 正常扣款
|
|
|
cal_url = "{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
if lang != 'cn':
|
|
|
cal_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
@@ -1184,17 +1203,24 @@ class CloudStorageView(View):
|
|
|
print(payment)
|
|
|
logger.info('paypal创建订单返回----------')
|
|
|
logger.info(payment)
|
|
|
- paymentID = payment['id'] # 获取paymentID
|
|
|
+ paymentID = payment['id'] # 获取paymentID
|
|
|
for link in payment.links:
|
|
|
if link.rel == "approval_url":
|
|
|
approval_url = str(link.href)
|
|
|
print("Redirect for approval: %s" % (approval_url))
|
|
|
+ store_meal_qs = Store_Meal.objects.filter(id=rank, lang__lang='cn', is_show=0).values('lang__title',
|
|
|
+ 'lang__content')
|
|
|
+ if store_meal_qs.exists():
|
|
|
+ store_meal_name = store_meal_qs[0]['lang__title'] + '-' + store_meal_qs[0]['lang__content']
|
|
|
+ else:
|
|
|
+ store_meal_name = '未知套餐'
|
|
|
Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID,
|
|
|
desc=content, payType=pay_type, payTime=nowTime,
|
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
|
pay_url=approval_url, isSelectDiscounts=is_select_discount,
|
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
|
- rank_id=rank, paymentID=paymentID,coupon_id=coupon_id,ai_rank_id=1)
|
|
|
+ rank_id=rank, paymentID=paymentID, coupon_id=coupon_id, ai_rank_id=1,
|
|
|
+ store_meal_name=store_meal_name)
|
|
|
return response.json(0, {"redirectUrl": approval_url, "orderID": orderID})
|
|
|
return response.json(10, 'generate_order_false')
|
|
|
elif pay_type == 2:
|
|
@@ -1218,7 +1244,7 @@ class CloudStorageView(View):
|
|
|
notify_url="{SERVER_DOMAIN_SSL}cloudstorage/doalicallback".format(
|
|
|
SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL),
|
|
|
quit_url="{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL),
|
|
|
- passback_params=quote("lang="+lang)
|
|
|
+ passback_params=quote("lang=" + lang)
|
|
|
# return_url="http://192.168.136.40/cloudstorage/payOK",
|
|
|
# notify_url="http://192.168.136.40/cloudstorage/aliPayCallback"
|
|
|
)
|
|
@@ -1232,12 +1258,19 @@ class CloudStorageView(View):
|
|
|
redirectUrl = aliPayObj.alipay_prefix + order_string
|
|
|
print('---------tttt')
|
|
|
print(redirectUrl)
|
|
|
+ store_meal_qs = Store_Meal.objects.filter(id=rank, lang__lang='cn', is_show=0).values('lang__title',
|
|
|
+ 'lang__content')
|
|
|
+ if store_meal_qs.exists():
|
|
|
+ store_meal_name = store_meal_qs[0]['lang__title'] + '-' + store_meal_qs[0]['lang__content']
|
|
|
+ else:
|
|
|
+ store_meal_name = '未知套餐'
|
|
|
Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID,
|
|
|
desc=content, payType=pay_type, payTime=nowTime,
|
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
|
pay_url=redirectUrl, isSelectDiscounts=is_select_discount,
|
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
|
- rank_id=rank,coupon_id=coupon_id,ai_rank_id=1)
|
|
|
+ rank_id=rank, coupon_id=coupon_id, ai_rank_id=1,
|
|
|
+ store_meal_name=store_meal_name)
|
|
|
|
|
|
return JsonResponse(status=200, data={'result_code': 0, 'reason': 'success',
|
|
|
'result': {"redirectUrl": redirectUrl, "orderID": orderID},
|
|
@@ -1252,7 +1285,8 @@ class CloudStorageView(View):
|
|
|
# 获取参数
|
|
|
response = ResponseObject()
|
|
|
|
|
|
- parameter_dict = pay.get_parameter(orderID, content, float(price) * 100, ip, notify_url, quote("lang="+lang))
|
|
|
+ parameter_dict = pay.get_parameter(orderID, content, float(price) * 100, ip, notify_url,
|
|
|
+ quote("lang=" + lang))
|
|
|
print('parameter_dict', parameter_dict)
|
|
|
# parameter_dict 参数中获取MWEB_URL 调转页面在路径后面添加redirect_url
|
|
|
# 统一调用接口
|
|
@@ -1260,11 +1294,18 @@ class CloudStorageView(View):
|
|
|
if not response:
|
|
|
return response.json(10, '生成订单错误.')
|
|
|
# 回调函数
|
|
|
+ store_meal_qs = Store_Meal.objects.filter(id=rank, lang__lang='cn', is_show=0).values('lang__title',
|
|
|
+ 'lang__content')
|
|
|
+ if store_meal_qs.exists():
|
|
|
+ store_meal_name = store_meal_qs[0]['lang__title'] + '-' + store_meal_qs[0]['lang__content']
|
|
|
+ else:
|
|
|
+ store_meal_name = '未知套餐'
|
|
|
Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID,
|
|
|
desc=content, payType=pay_type, payTime=nowTime,
|
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
|
pay_url=notify_url, isSelectDiscounts=is_select_discount,
|
|
|
- commodity_code=commodity_code, commodity_type=commodity_type, rank_id=rank, ai_rank_id=1)
|
|
|
+ commodity_code=commodity_code, commodity_type=commodity_type, rank_id=rank,
|
|
|
+ ai_rank_id=1, store_meal_name=store_meal_name)
|
|
|
return JsonResponse(status=200, data={'result_code': 0, 'reason': 'success',
|
|
|
'result': response,
|
|
|
'orderId': orderID,
|
|
@@ -1282,8 +1323,8 @@ class CloudStorageView(View):
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
|
|
|
redisObj = RedisObject()
|
|
|
- isLock = redisObj.CONN.setnx(uid+'do_experience_order', 1)
|
|
|
- redisObj.CONN.expire(uid+'do_experience_order', 60)
|
|
|
+ isLock = redisObj.CONN.setnx(uid + 'do_experience_order', 1)
|
|
|
+ redisObj.CONN.expire(uid + 'do_experience_order', 60)
|
|
|
logger = logging.getLogger('info')
|
|
|
if not isLock:
|
|
|
return response.json(5)
|
|
@@ -1321,8 +1362,9 @@ class CloudStorageView(View):
|
|
|
|
|
|
orderID = CommonService.createOrderID()
|
|
|
nowTime = int(time.time())
|
|
|
- smqs = Store_Meal.objects.filter(id=rank,lang__lang=lang,is_show=0). \
|
|
|
- values("day", "bucket_id", "bucket__storeDay", "expire", 'lang__content', 'price', 'currency', 'commodity_type')
|
|
|
+ smqs = Store_Meal.objects.filter(id=rank, lang__lang=lang, is_show=0). \
|
|
|
+ values("day", "bucket_id", "bucket__storeDay", "expire", 'lang__content', 'price', 'currency',
|
|
|
+ 'commodity_type')
|
|
|
if not smqs.exists():
|
|
|
return response.json(173)
|
|
|
bucketId = smqs[0]['bucket_id']
|
|
@@ -1334,40 +1376,44 @@ class CloudStorageView(View):
|
|
|
with transaction.atomic():
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|
|
|
- if ubq['use_status'] == 1 and ubq['bucket_id'] == bucketId: #套餐使用中并且相同套餐叠加过期时间
|
|
|
+ if ubq['use_status'] == 1 and ubq['bucket_id'] == bucketId: # 套餐使用中并且相同套餐叠加过期时间
|
|
|
endTime = CommonService.calcMonthLater(expire, ubq['endTime'])
|
|
|
UID_Bucket.objects.filter(id=ubq['id']).update \
|
|
|
(uid=uid, channel=channel, bucket_id=bucketId,
|
|
|
endTime=endTime, updateTime=nowTime)
|
|
|
- else: #已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
+ else: # 已过期或者不相同的套餐加入未使用的关联套餐表
|
|
|
has_unused = Unused_Uid_Meal.objects.filter(uid=uid, bucket_id=bucketId).values("id")
|
|
|
nums = 1
|
|
|
if has_unused.exists():
|
|
|
Unused_Uid_Meal.objects.filter(id=has_unused[0]['id']).update(num=F('num') + nums)
|
|
|
else:
|
|
|
- Unused_Uid_Meal.objects.create(uid=uid,channel=channel,addTime=nowTime,num=nums,
|
|
|
- expire=smqs[0]['expire'],bucket_id=bucketId)
|
|
|
+ Unused_Uid_Meal.objects.create(uid=uid, channel=channel, addTime=nowTime, num=nums,
|
|
|
+ expire=smqs[0]['expire'], bucket_id=bucketId)
|
|
|
UID_Bucket.objects.filter(id=ubq['id']).update(has_unused=1)
|
|
|
uid_bucket_id = ubq['id']
|
|
|
else:
|
|
|
endTime = CommonService.calcMonthLater(expire)
|
|
|
ub_cqs = UID_Bucket.objects.create \
|
|
|
(uid=uid, channel=channel, bucket_id=bucketId, endTime=endTime, addTime=nowTime,
|
|
|
- updateTime=nowTime,use_status=1)
|
|
|
+ updateTime=nowTime, use_status=1)
|
|
|
uid_bucket_id = ub_cqs.id
|
|
|
+ store_meal_qs = Store_Meal.objects.filter(id=rank, lang__lang='cn', is_show=0).values('lang__title',
|
|
|
+ 'lang__content')
|
|
|
+ if store_meal_qs.exists():
|
|
|
+ store_meal_name = store_meal_qs[0]['lang__title'] + '-' + store_meal_qs[0]['lang__content']
|
|
|
+ else:
|
|
|
+ store_meal_name = '未知套餐'
|
|
|
Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID,
|
|
|
desc=smqs[0]['lang__content'], payType=pay_type, payTime=nowTime,
|
|
|
price=smqs[0]['price'], currency=smqs[0]['currency'], addTime=nowTime,
|
|
|
updTime=nowTime,
|
|
|
- pay_url="体验版",
|
|
|
+ pay_url="体验版", store_meal_name=store_meal_name,
|
|
|
commodity_code=commodity_code, commodity_type=smqs[0]['commodity_type'],
|
|
|
rank_id=rank, status=1, uid_bucket_id=uid_bucket_id, ai_rank_id=1)
|
|
|
|
|
|
duq = Device_User.objects.filter(userID=userID).values('username')
|
|
|
dvq = Device_Info.objects.filter(UID=uid, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
|
|
|
|
-
|
|
|
-
|
|
|
if dvq.exists():
|
|
|
dvq_set_update_dict = {
|
|
|
'vodPrimaryUserID': userID,
|
|
@@ -1396,33 +1442,38 @@ class CloudStorageView(View):
|
|
|
'Dear customer,you already subscribed the cloud storage package successfully for device ' + device_name + ' on ' + time.strftime(
|
|
|
"%b %dth,%Y", time.localtime())]
|
|
|
|
|
|
- returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?lang={lang}".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL,lang=lang)
|
|
|
+ returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?lang={lang}".format(
|
|
|
+ SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, lang=lang)
|
|
|
if pay_type == 10:
|
|
|
ExperienceContextModel.objects.create(
|
|
|
experience_type=0,
|
|
|
uid=uid,
|
|
|
do_time=nowTime
|
|
|
)
|
|
|
- returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?paytype=10&lang={lang}".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL,lang=lang)
|
|
|
+ returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?paytype=10&lang={lang}".format(
|
|
|
+ SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, lang=lang)
|
|
|
datetime = time.strftime("%Y-%m-%d", time.localtime())
|
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + device_name + '设备在' + datetime + '已成功开通云存体验套餐',
|
|
|
- 'Dear customer,you already subscribed the free trial cloud storage service successfully for device ' + device_name + ' on '+ time.strftime("%b %dth,%Y", time.localtime())]
|
|
|
+ 'Dear customer,you already subscribed the free trial cloud storage service successfully for device ' + device_name + ' on ' + time.strftime(
|
|
|
+ "%b %dth,%Y", time.localtime())]
|
|
|
sms = 'SMS_222870823'
|
|
|
if pay_type == 11:
|
|
|
update_dict = {}
|
|
|
update_dict['is_activate'] = 1
|
|
|
update_dict['order'] = orderID
|
|
|
CDKcontextModel.objects.filter(cdk=cdk).update(**update_dict)
|
|
|
- returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?paytype=11&lang={lang}".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL,lang=lang)
|
|
|
+ returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?paytype=11&lang={lang}".format(
|
|
|
+ SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, lang=lang)
|
|
|
|
|
|
datetime = time.strftime("%Y-%m-%d", time.localtime())
|
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + device_name + '设备在' + datetime + '已成功兑换云存套餐',
|
|
|
- 'Dear customer, you already redeemed for the cloud storage package successfully for device ' +device_name +' on '+time.strftime("%b %dth,%Y", time.localtime())]
|
|
|
+ 'Dear customer, you already redeemed for the cloud storage package successfully for device ' + device_name + ' on ' + time.strftime(
|
|
|
+ "%b %dth,%Y", time.localtime())]
|
|
|
sms = 'SMS_219748439'
|
|
|
|
|
|
self.do_vod_msg_Notice(uid, channel, userID, lang, sys_msg_text_list, sms)
|
|
|
result = returnurl
|
|
|
- redisObj.del_data(key=uid+'do_experience_order')
|
|
|
+ redisObj.del_data(key=uid + 'do_experience_order')
|
|
|
return response.json(0, result)
|
|
|
except Exception as e:
|
|
|
logger.info('出错了~体验云存异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
@@ -1482,8 +1533,9 @@ class CloudStorageView(View):
|
|
|
now_time = int(time.time())
|
|
|
bucket_id_list = []
|
|
|
store_list = []
|
|
|
- uid_bucket = UID_Bucket.objects.filter(uid=uid, endTime__gte=now_time).values("id", "uid","bucket__content",
|
|
|
- "use_status","endTime","has_unused","bucket__id")
|
|
|
+ uid_bucket = UID_Bucket.objects.filter(uid=uid, endTime__gte=now_time).values("id", "uid", "bucket__content",
|
|
|
+ "use_status", "endTime",
|
|
|
+ "has_unused", "bucket__id")
|
|
|
if not uid_bucket:
|
|
|
return response.json(10030)
|
|
|
|
|
@@ -1502,11 +1554,11 @@ class CloudStorageView(View):
|
|
|
bucket_id_list.append(uid_bucket[0]['bucket__id'])
|
|
|
if has_unused == 1:
|
|
|
unuseds = Unused_Uid_Meal.objects.filter(uid=uid).annotate(unused_id=F('id')) \
|
|
|
- .values("unused_id","uid","bucket__content","num","bucket__id","expire")
|
|
|
+ .values("unused_id", "uid", "bucket__content", "num", "bucket__id", "expire")
|
|
|
month = 'month' if lang != 'cn' else '个月'
|
|
|
for ub in unuseds:
|
|
|
storage_time = ub['num'] * ub['expire']
|
|
|
- if lang != 'cn' and storage_time > 1: # 英文大于一个月使用复数
|
|
|
+ if lang != 'cn' and storage_time > 1: # 英文大于一个月使用复数
|
|
|
month += 's'
|
|
|
storage = "{storage_time}{month}".format(storage_time=storage_time, month=month)
|
|
|
unused_dict = {
|
|
@@ -1520,7 +1572,9 @@ class CloudStorageView(View):
|
|
|
}
|
|
|
store_list.append(unused_dict)
|
|
|
bucket_id_list.append(ub['bucket__id'])
|
|
|
- smqs = Store_Meal.objects.filter(bucket__id__in=bucket_id_list, lang__lang=lang).values('lang__lang','bucket__id','lang__title')
|
|
|
+ smqs = Store_Meal.objects.filter(bucket__id__in=bucket_id_list, lang__lang=lang).values('lang__lang',
|
|
|
+ 'bucket__id',
|
|
|
+ 'lang__title')
|
|
|
for index, value in enumerate(store_list):
|
|
|
for sm in smqs:
|
|
|
if value['bucket__id'] == sm['bucket__id']:
|
|
@@ -1538,10 +1592,10 @@ class CloudStorageView(View):
|
|
|
unused_id = request_dict.get('switch_commodity_id', None)
|
|
|
if unused_id:
|
|
|
# 切换设备套餐关联
|
|
|
- using_uid_bucket = UID_Bucket.objects.filter(uid=uid,has_unused=1).values("id", "uid", "endTime",
|
|
|
- "bucket__content","addTime")
|
|
|
- unuseds = Unused_Uid_Meal.objects.filter(id=unused_id).values("id","uid","channel","addTime","expire",
|
|
|
- "num","bucket_id")
|
|
|
+ using_uid_bucket = UID_Bucket.objects.filter(uid=uid, has_unused=1).values("id", "uid", "endTime",
|
|
|
+ "bucket__content", "addTime")
|
|
|
+ unuseds = Unused_Uid_Meal.objects.filter(id=unused_id).values("id", "uid", "channel", "addTime", "expire",
|
|
|
+ "num", "bucket_id")
|
|
|
if not unuseds.exists() or not using_uid_bucket.exists():
|
|
|
return response.json(10030)
|
|
|
unused = unuseds[0]
|
|
@@ -1549,10 +1603,11 @@ class CloudStorageView(View):
|
|
|
try:
|
|
|
with transaction.atomic():
|
|
|
count_unused = Unused_Uid_Meal.objects.filter(uid=uid).count()
|
|
|
- has_unused = 1 if count_unused>1 else 0
|
|
|
+ has_unused = 1 if count_unused > 1 else 0
|
|
|
endTime = CommonService.calcMonthLater(unused['expire'] * unused['num'])
|
|
|
- UID_Bucket.objects.filter(uid=uid).update(channel=unused['channel'],endTime=endTime,bucket_id=unused['bucket_id']
|
|
|
- ,updateTime=nowTime,use_status=1, has_unused=has_unused)
|
|
|
+ UID_Bucket.objects.filter(uid=uid).update(channel=unused['channel'], endTime=endTime,
|
|
|
+ bucket_id=unused['bucket_id']
|
|
|
+ , updateTime=nowTime, use_status=1, has_unused=has_unused)
|
|
|
Unused_Uid_Meal.objects.filter(id=unused_id).delete()
|
|
|
StsCrdModel.objects.filter(uid=uid).delete() # 删除sts记录
|
|
|
# VodHlsModel.objects.filter(uid=uid).delete() # 删除播放列表,后期数据量多时应该考虑延后删除
|
|
@@ -1571,12 +1626,14 @@ class CloudStorageView(View):
|
|
|
if dv_qs[0]['vodPrimaryUserID'] != userID:
|
|
|
return response.json(10034)
|
|
|
now_time = int(time.time())
|
|
|
- bv_qs = UID_Bucket.objects.filter(uid=uid, endTime__gte=now_time ,channel=channel).values('bucket_id').order_by('addTime')
|
|
|
+ bv_qs = UID_Bucket.objects.filter(uid=uid, endTime__gte=now_time, channel=channel).values('bucket_id').order_by(
|
|
|
+ 'addTime')
|
|
|
if not bv_qs.exists():
|
|
|
return response.json(10030)
|
|
|
|
|
|
had_vod_query = VodHlsModel.objects.extra(select={'date': "FROM_UNIXTIME(time,'%%Y-%%m-%%d')"}).values(
|
|
|
- 'date').filter(uid=uid,endTime__gte=now_time,channel=channel).annotate(count=Count('time')).order_by('-date')[:31]
|
|
|
+ 'date').filter(uid=uid, endTime__gte=now_time, channel=channel).annotate(count=Count('time')).order_by(
|
|
|
+ '-date')[:31]
|
|
|
|
|
|
had_vod_list = []
|
|
|
for vod in had_vod_query:
|
|
@@ -1644,15 +1701,16 @@ class CloudStorageView(View):
|
|
|
device_name = CommonService.get_full_serial_number(uid, serial_number, device_type)
|
|
|
else:
|
|
|
device_name = uid
|
|
|
- params = u'{"devname":"' + device_name + '","submittime":"' + time.strftime("%Y-%m-%d",time.localtime()) + '"}'
|
|
|
+ params = u'{"devname":"' + device_name + '","submittime":"' + time.strftime("%Y-%m-%d",
|
|
|
+ time.localtime()) + '"}'
|
|
|
self.sendMessage(username, params, sms)
|
|
|
|
|
|
self.pushApp(nowTime, uid, channel, sys_msg_text)
|
|
|
|
|
|
-
|
|
|
logger.info('出去了')
|
|
|
except Exception as e:
|
|
|
return repr(e)
|
|
|
+
|
|
|
# 云存到期续费提醒 提前3天
|
|
|
def do_vod_msg_end(self, request_dict):
|
|
|
response = ResponseObject()
|
|
@@ -1662,12 +1720,18 @@ class CloudStorageView(View):
|
|
|
# self.do_vod_msg(now_time,list)
|
|
|
|
|
|
# 过期前第7天提示一次
|
|
|
- list = UID_Bucket.objects.filter(Q(endTime__gt=now_time + 3600 * 144) & Q(endTime__lte=(now_time + 3600 * 168))).values('id','uid','bucket__area','channel','endTime')
|
|
|
- self.do_vod_msg(now_time,list)
|
|
|
+ list = UID_Bucket.objects.filter(
|
|
|
+ Q(endTime__gt=now_time + 3600 * 144) & Q(endTime__lte=(now_time + 3600 * 168))).values('id', 'uid',
|
|
|
+ 'bucket__area',
|
|
|
+ 'channel', 'endTime')
|
|
|
+ self.do_vod_msg(now_time, list)
|
|
|
|
|
|
# 过期前第3天提示一次
|
|
|
- list = UID_Bucket.objects.filter(Q(endTime__gt=now_time + 3600 * 48) & Q(endTime__lte=(now_time + 3600 * 72))).values('id','uid','bucket__area','channel','endTime')
|
|
|
- self.do_vod_msg(now_time,list)
|
|
|
+ list = UID_Bucket.objects.filter(
|
|
|
+ Q(endTime__gt=now_time + 3600 * 48) & Q(endTime__lte=(now_time + 3600 * 72))).values('id', 'uid',
|
|
|
+ 'bucket__area',
|
|
|
+ 'channel', 'endTime')
|
|
|
+ self.do_vod_msg(now_time, list)
|
|
|
return response.json(0)
|
|
|
|
|
|
def do_vod_msg(self, now_time, list):
|
|
@@ -1682,7 +1746,7 @@ class CloudStorageView(View):
|
|
|
for oo in oqlist:
|
|
|
if ub['id'] == oo['uid_bucket_id']:
|
|
|
# 如果存在序列号,消息提示用序列号
|
|
|
- uid=ub['uid']
|
|
|
+ uid = ub['uid']
|
|
|
device_info_qs = Device_Info.objects.filter(UID=uid).values('serial_number', 'Type')
|
|
|
serial_number = device_info_qs[0]['serial_number']
|
|
|
device_type = device_info_qs[0]['Type']
|
|
@@ -1691,9 +1755,12 @@ class CloudStorageView(View):
|
|
|
else:
|
|
|
device_name = uid
|
|
|
if ub['bucket__area'] == 'cn':
|
|
|
- sys_msg_text = "温馨提示:尊敬的客户,您" + device_name + "设备的云存套餐将在" + time.strftime("%Y-%m-%d", time.localtime(ub['endTime'])) + "到期"
|
|
|
+ sys_msg_text = "温馨提示:尊敬的客户,您" + device_name + "设备的云存套餐将在" + time.strftime("%Y-%m-%d",
|
|
|
+ time.localtime(ub[
|
|
|
+ 'endTime'])) + "到期"
|
|
|
else:
|
|
|
- sys_msg_text = 'Dear customer,the cloud storage package for your device '+device_name+' will expire on '+time.strftime('%m-%d-%y',time.localtime(ub['endTime']))
|
|
|
+ sys_msg_text = 'Dear customer,the cloud storage package for your device ' + device_name + ' will expire on ' + time.strftime(
|
|
|
+ '%m-%d-%y', time.localtime(ub['endTime']))
|
|
|
uq_list.append(SysMsgModel(
|
|
|
userID_id=oo['userID_id'],
|
|
|
addTime=now_time,
|
|
@@ -1714,13 +1781,13 @@ class CloudStorageView(View):
|
|
|
S3Email().faEmail(sys_msg_text, username)
|
|
|
elif data_valid.mobile_validate(username):
|
|
|
params = u'{"devname":"' + device_name + '","submittime":"' + time.strftime("%Y-%m-%d",
|
|
|
- time.localtime(ub['endTime'])) + '"}'
|
|
|
+ time.localtime(
|
|
|
+ ub[
|
|
|
+ 'endTime'])) + '"}'
|
|
|
self.sendMessage(username, params, 'SMS_219748440')
|
|
|
|
|
|
self.pushApp(now_time, ub['uid'], ub['channel'], sys_msg_text)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
def pushApp(self, nowTime, uid, channel, sys_msg_text):
|
|
|
n_time = nowTime
|
|
|
|
|
@@ -1838,21 +1905,21 @@ class CloudStorageView(View):
|
|
|
print(res)
|
|
|
return res.status_code
|
|
|
|
|
|
- def sendMessage(self, phone , params, temp_msg):
|
|
|
- # 购买成功
|
|
|
- sign_ms = '周视'
|
|
|
- # 发送手机验证码
|
|
|
- aliSms = AliSmsObject()
|
|
|
- res = aliSms.send_code_sms_cloud(phone=phone, params = params, sign_name=sign_ms,
|
|
|
- temp_msg=temp_msg)
|
|
|
+ def sendMessage(self, phone, params, temp_msg):
|
|
|
+ # 购买成功
|
|
|
+ sign_ms = '周视'
|
|
|
+ # 发送手机验证码
|
|
|
+ aliSms = AliSmsObject()
|
|
|
+ res = aliSms.send_code_sms_cloud(phone=phone, params=params, sign_name=sign_ms,
|
|
|
+ temp_msg=temp_msg)
|
|
|
|
|
|
def do_refund(self, request_dict, response):
|
|
|
- orderID = request_dict.get('orderID', None) # 商户订单号
|
|
|
+ orderID = request_dict.get('orderID', None) # 商户订单号
|
|
|
refund_amount = request_dict.get('refund_amount', None) # 退款金额
|
|
|
if not all([orderID, refund_amount]):
|
|
|
return response.json(444)
|
|
|
try:
|
|
|
- order_qs = Order_Model.objects.filter(orderID=orderID).\
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=orderID). \
|
|
|
values('status', 'payType', 'price', 'refunded_amount', 'currency', 'paymentID')
|
|
|
if not order_qs.exists():
|
|
|
return response.json(173)
|
|
@@ -1865,21 +1932,21 @@ class CloudStorageView(View):
|
|
|
refund_amount = float(refund_amount)
|
|
|
now_time = int(time.time())
|
|
|
payType = order_qs[0]['payType']
|
|
|
- price = order_qs[0]['price'] # 订单金额
|
|
|
- refunded_amount = order_qs[0]['refunded_amount'] # 已退款金额
|
|
|
- currency = order_qs[0]['currency'] # 货币
|
|
|
+ price = order_qs[0]['price'] # 订单金额
|
|
|
+ refunded_amount = order_qs[0]['refunded_amount'] # 已退款金额
|
|
|
+ currency = order_qs[0]['currency'] # 货币
|
|
|
|
|
|
# 判断是否符合付款条件
|
|
|
- if refunded_amount == float(price): # 已全额退款
|
|
|
+ if refunded_amount == float(price): # 已全额退款
|
|
|
return response.json(805)
|
|
|
if refund_amount + refunded_amount > float(price): # 退款金额超出订单价格
|
|
|
return response.json(805)
|
|
|
# 部分退款标识
|
|
|
- is_partial_refund = True if(float(price) > refund_amount + refunded_amount) else False
|
|
|
+ is_partial_refund = True if (float(price) > refund_amount + refunded_amount) else False
|
|
|
|
|
|
- out_request_no = str(time.strftime('%Y%m%d%H%M%S', time.localtime(now_time))) # 退款请求号
|
|
|
+ out_request_no = str(time.strftime('%Y%m%d%H%M%S', time.localtime(now_time))) # 退款请求号
|
|
|
# 根据支付类型处理退款
|
|
|
- if payType == 1: # PayPal
|
|
|
+ if payType == 1: # PayPal
|
|
|
paymentID = order_qs[0]['paymentID'] # PayPal PAYMENT_ID
|
|
|
if not paymentID:
|
|
|
return response.json(805)
|
|
@@ -1910,14 +1977,14 @@ class CloudStorageView(View):
|
|
|
alipay = aliPayObj.conf()
|
|
|
refund_response = alipay.api_alipay_trade_refund(refund_amount=refund_amount, out_trade_no=orderID,
|
|
|
out_request_no=out_request_no)
|
|
|
- refund_success = True if(refund_response['code'] == '10000') else False
|
|
|
+ refund_success = True if (refund_response['code'] == '10000') else False
|
|
|
elif payType == 3: # 微信
|
|
|
wechatPayObj = WechatPayObject()
|
|
|
refund_fee = int(refund_amount * 100) # 退款金额,单位为分,只能为整数
|
|
|
success = wechatPayObj.refund(out_trade_no=orderID, out_refund_no=out_request_no,
|
|
|
total_fee=refund_fee, refund_fee=refund_fee)
|
|
|
refund_success = True if success else False
|
|
|
- else: # 不支持退款的支付类型
|
|
|
+ else: # 不支持退款的支付类型
|
|
|
return response.json(805)
|
|
|
|
|
|
# 更新订单状态和已退款金额
|
|
@@ -1932,5 +1999,3 @@ class CloudStorageView(View):
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
-
|
|
|
-
|