|
@@ -40,7 +40,7 @@ from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_AR
|
|
|
from Controller.CheckUserData import DataValid
|
|
|
from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket, StsCrdModel, \
|
|
|
ExperienceContextModel, Pay_Type, CDKcontextModel, Device_User, SysMassModel, SysMsgModel, UidPushModel, \
|
|
|
- Unused_Uid_Meal, UIDMainUser, UserModel
|
|
|
+ Unused_Uid_Meal, UIDMainUser, UserModel, PromotionRuleModel
|
|
|
from Object.AWS.S3Email import S3Email
|
|
|
from Object.AliPayObject import AliPayObject
|
|
|
from Object.AliSmsObject import AliSmsObject
|
|
@@ -52,7 +52,7 @@ from Service.CommonService import CommonService
|
|
|
from Object.m3u8generate import PlaylistGenerator
|
|
|
from Object.WechatPayObject import WechatPayObject
|
|
|
from django.db.models import Q, F, Count
|
|
|
-
|
|
|
+from Ansjer.config import SERVER_TYPE
|
|
|
from Service.ModelService import ModelService
|
|
|
|
|
|
# SERVER_DOMAIN = 'http://test.dvema.com/'
|
|
@@ -232,13 +232,32 @@ class CloudStorageView(View):
|
|
|
|
|
|
res_c = {'area': area, 'items': items_list}
|
|
|
res.append(res_c)
|
|
|
+ #是否促销
|
|
|
+ nowTime = int(time.time())
|
|
|
+ promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
|
+ endTime__gte=nowTime).values('id','ruleConfig','ruleName',
|
|
|
+ 'startTime','endTime','ruleDesc')
|
|
|
+ if promotion.exists():
|
|
|
+ promotion = {
|
|
|
+ 'is_promotion': 1,
|
|
|
+ 'promotionStartTime': promotion[0]['startTime'],
|
|
|
+ 'promotionEndTime': promotion[0]['endTime'],
|
|
|
+ 'promotionName': json.loads(promotion[0]['ruleName']).get(lang, ''),
|
|
|
+ 'promotionDesc': json.loads(promotion[0]['ruleDesc']).get(lang, ''),
|
|
|
+ 'nowTime':int(time.time())
|
|
|
+ }
|
|
|
+ else:
|
|
|
+ promotion = {
|
|
|
+ 'is_promotion': 0
|
|
|
+ }
|
|
|
result = {
|
|
|
'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'
|
|
|
- }
|
|
|
+ },
|
|
|
+ 'promotion':promotion
|
|
|
}
|
|
|
return response.json(0, result)
|
|
|
else:
|
|
@@ -418,6 +437,7 @@ class CloudStorageView(View):
|
|
|
vh_qs = VodHlsModel.objects.filter \
|
|
|
(uid=uid, channel=channel, endTime__gte=now_time, time__range=(startTime, endTime)). \
|
|
|
values("id", "time", "sec", "bucket__bucket", "fg", "bucket__endpoint", "bucket__region", "bucket__mold")
|
|
|
+
|
|
|
vod_play_list = []
|
|
|
if not vh_qs.exists():
|
|
|
return response.json(0, vod_play_list)
|
|
@@ -726,12 +746,17 @@ class CloudStorageView(View):
|
|
|
data.pop('sign')
|
|
|
orderID = data['out_trade_no']
|
|
|
|
|
|
- order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
|
+ # redis加锁,防止订单重复
|
|
|
+ redisObj = RedisObject()
|
|
|
+ isLock = redisObj.CONN.setnx(orderID + 'do_notify', 1)
|
|
|
+ redisObj.CONN.expire(orderID + 'do_notify', 60)
|
|
|
+ if not isLock:
|
|
|
+ return response.json(5)
|
|
|
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
|
aliPayObj = AliPayObject()
|
|
|
alipay = aliPayObj.conf()
|
|
|
success = alipay.verify(data, signature)
|
|
|
-
|
|
|
if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
|
|
|
print("trade succeed")
|
|
|
|
|
@@ -754,6 +779,14 @@ 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_rule_id = ''
|
|
|
+ if promotion.exists():
|
|
|
+ promotion_rule_id = promotion[0]['id']
|
|
|
+ expire = expire * 2
|
|
|
with transaction.atomic():
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|
|
@@ -765,6 +798,8 @@ class CloudStorageView(View):
|
|
|
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():
|
|
|
+ nums = nums + 1
|
|
|
if has_unused.exists():
|
|
|
Unused_Uid_Meal.objects.filter(id=has_unused[0]['id']).update(num=F('num') + nums)
|
|
|
else:
|
|
@@ -795,18 +830,20 @@ class CloudStorageView(View):
|
|
|
# }
|
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
|
|
|
|
- order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_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())
|
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的'+UID+'设备在'+datetime+'已成功购买云存套餐', 'Dear customer,you already subscribed the cloud storage package successfully for device ' + UID + ' 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)
|
|
|
+ redisObj.del_data(key=orderID + 'do_notify')
|
|
|
return HttpResponseRedirect(red_url)
|
|
|
return response.json(0, signature)
|
|
|
except Exception as e:
|
|
|
if order_qs:
|
|
|
- order_qs.update(status=10)
|
|
|
+ order_qs.update(status=10, promotion_rule_id=promotion_rule_id)
|
|
|
+ redisObj.del_data(key=orderID + 'do_notify')
|
|
|
red_url = "{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
if lang != 'cn':
|
|
|
red_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
@@ -817,6 +854,12 @@ class CloudStorageView(View):
|
|
|
PayerID = request_dict.get('PayerID', None)
|
|
|
orderID = request_dict.get('orderID', None)
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
+ # redis加锁,防止订单重复
|
|
|
+ redisObj = RedisObject()
|
|
|
+ isLock = redisObj.CONN.setnx(orderID + 'do_notify', 1)
|
|
|
+ redisObj.CONN.expire(orderID + 'do_notify', 60)
|
|
|
+ if not isLock:
|
|
|
+ return response.json(5)
|
|
|
try:
|
|
|
order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
|
|
|
@@ -837,6 +880,7 @@ class CloudStorageView(View):
|
|
|
red_url = "{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
if lang != 'cn':
|
|
|
red_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
+ redisObj.del_data(key=orderID + 'do_notify')
|
|
|
return HttpResponseRedirect(red_url)
|
|
|
print("Payment execute successfully")
|
|
|
|
|
@@ -861,6 +905,14 @@ class CloudStorageView(View):
|
|
|
|
|
|
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_rule_id = ''
|
|
|
+ if promotion.exists():
|
|
|
+ promotion_rule_id = promotion[0]['id']
|
|
|
+ expire = expire * 2
|
|
|
with transaction.atomic():
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|
|
@@ -872,6 +924,8 @@ class CloudStorageView(View):
|
|
|
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():
|
|
|
+ nums = nums + 1
|
|
|
if has_unused.exists():
|
|
|
Unused_Uid_Meal.objects.filter(id=has_unused[0]['id']).update(num=F('num') + nums)
|
|
|
else:
|
|
@@ -902,7 +956,7 @@ class CloudStorageView(View):
|
|
|
# }
|
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
|
|
|
|
- order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_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())
|
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + UID + '设备在' + datetime + '已成功购买云存套餐',
|
|
|
'Dear customer,you already subscribed the cloud storage package successfully for device ' + UID + ' on ' + time.strftime(
|
|
@@ -914,15 +968,16 @@ class CloudStorageView(View):
|
|
|
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)
|
|
|
-
|
|
|
+ redisObj.del_data(key=orderID + 'do_notify')
|
|
|
return HttpResponseRedirect(red_url)
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
if order_qs:
|
|
|
- order_qs.update(status=10)
|
|
|
+ order_qs.update(status=10, promotion_rule_id=promotion_rule_id)
|
|
|
red_url = "{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
if lang != 'cn':
|
|
|
red_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
+ redisObj.del_data(key=orderID + 'do_notify')
|
|
|
return HttpResponseRedirect(red_url)
|
|
|
|
|
|
def do_pay_by_wechat_callback(self, request, response): # 微信支付回调
|
|
@@ -938,17 +993,25 @@ class CloudStorageView(View):
|
|
|
out_trade_no = data['out_trade_no'] # 商户订单号
|
|
|
order_qs = Order_Model.objects.filter(orderID=out_trade_no, status=0)
|
|
|
if trade_status == "SUCCESS":
|
|
|
- logger.info('微信回调返回值 进来了。')
|
|
|
check_sign = pay.get_notifypay(data)
|
|
|
if not check_sign:
|
|
|
return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': '签名失败'}))
|
|
|
- logger.info('签名成功')
|
|
|
orderID = out_trade_no
|
|
|
- print("进来了,微信支付成功回调")
|
|
|
+
|
|
|
+ #redis加锁,防止订单重复
|
|
|
+ redisObj = RedisObject()
|
|
|
+ isLock = redisObj.CONN.setnx(orderID + 'do_notify', 1)
|
|
|
+ redisObj.CONN.expire(orderID + 'do_notify', 60)
|
|
|
+ if not isLock:
|
|
|
+ return response.json(5)
|
|
|
|
|
|
nowTime = int(time.time())
|
|
|
order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
|
|
|
- "userID__userID", "userID__username")
|
|
|
+ "userID__userID", "userID__username","status")
|
|
|
+
|
|
|
+ logger.info(order_list[0]['UID'])
|
|
|
+ logger.info(orderID)
|
|
|
+
|
|
|
userid = order_list[0]['userID__userID']
|
|
|
username = order_list[0]['userID__username']
|
|
|
UID = order_list[0]['UID']
|
|
@@ -965,6 +1028,13 @@ 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_rule_id = ''
|
|
|
+ if promotion.exists():
|
|
|
+ promotion_rule_id = promotion[0]['id']
|
|
|
+ expire = expire * 2
|
|
|
with transaction.atomic():
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|
|
@@ -976,6 +1046,8 @@ class CloudStorageView(View):
|
|
|
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():
|
|
|
+ nums = nums + 1
|
|
|
if has_unused.exists():
|
|
|
Unused_Uid_Meal.objects.filter(id=has_unused[0]['id']).update(num=F('num') + nums)
|
|
|
else:
|
|
@@ -1006,20 +1078,24 @@ class CloudStorageView(View):
|
|
|
# }
|
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
|
|
|
|
- order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_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())
|
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + UID + '设备在' + datetime + '已成功购买云存套餐',
|
|
|
'Dear customer,you already subscribed the cloud storage package successfully for device ' + UID + ' on ' + time.strftime(
|
|
|
"%b %dth,%Y", time.localtime())]
|
|
|
-
|
|
|
self.do_vod_msg_Notice(UID, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
|
|
|
- return HttpResponse(pay.xml_to_dict({'return_code': 'SUCCESS', 'return_msg': 'OK'}))
|
|
|
+ redisObj.del_data(key=orderID + 'do_notify')
|
|
|
+ return HttpResponse("<xml>\
|
|
|
+ <return_code><![CDATA[SUCCESS]]></return_code>\
|
|
|
+ <return_msg><![CDATA[OK]]></return_msg>\
|
|
|
+ </xml>")
|
|
|
else:
|
|
|
- order_qs.update(status=10)
|
|
|
+ order_qs.update(status=10, promotion_rule_id=promotion_rule_id)
|
|
|
return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': '参数格式校验错误'}))
|
|
|
except Exception as e:
|
|
|
if order_qs:
|
|
|
- order_qs.update(status=10)
|
|
|
+ order_qs.update(status=10, promotion_rule_id=promotion_rule_id)
|
|
|
+ redisObj.del_data(key=orderID + 'do_notify')
|
|
|
return HttpResponse(pay.xml_to_dict({'return_code': 'FAIL', 'return_msg': repr(e)}))
|
|
|
|
|
|
def do_create_pay_order(self, request_dict, userID, ip, response): # 创建支付订单
|