|
@@ -41,7 +41,7 @@ from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_AR
|
|
from Controller.CheckUserData import DataValid
|
|
from Controller.CheckUserData import DataValid
|
|
from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket, StsCrdModel, \
|
|
from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket, StsCrdModel, \
|
|
ExperienceContextModel, Pay_Type, CDKcontextModel, Device_User, SysMassModel, SysMsgModel, UidPushModel, \
|
|
ExperienceContextModel, Pay_Type, CDKcontextModel, Device_User, SysMassModel, SysMsgModel, UidPushModel, \
|
|
- Unused_Uid_Meal, UIDMainUser, UserModel, PromotionRuleModel, VideoPlaybackTimeModel, CloudLogModel
|
|
|
|
|
|
+ Unused_Uid_Meal, UIDMainUser, UserModel, PromotionRuleModel, VideoPlaybackTimeModel, CloudLogModel, CouponModel
|
|
from Object.AWS.S3Email import S3Email
|
|
from Object.AWS.S3Email import S3Email
|
|
from Object.AliPayObject import AliPayObject
|
|
from Object.AliPayObject import AliPayObject
|
|
from Object.AliSmsObject import AliSmsObject
|
|
from Object.AliSmsObject import AliSmsObject
|
|
@@ -54,6 +54,7 @@ from Object.m3u8generate import PlaylistGenerator
|
|
from Object.WechatPayObject import WechatPayObject
|
|
from Object.WechatPayObject import WechatPayObject
|
|
from django.db.models import Q, F, Count
|
|
from django.db.models import Q, F, Count
|
|
from Controller.PaymentCycle import Paypal
|
|
from Controller.PaymentCycle import Paypal
|
|
|
|
+from decimal import Decimal
|
|
from Ansjer.config import SERVER_TYPE
|
|
from Ansjer.config import SERVER_TYPE
|
|
from Service.ModelService import ModelService
|
|
from Service.ModelService import ModelService
|
|
|
|
|
|
@@ -193,7 +194,7 @@ class CloudStorageView(View):
|
|
mold = request_dict.get('mold', None)
|
|
mold = request_dict.get('mold', None)
|
|
uid = request_dict.get('uid', None)
|
|
uid = request_dict.get('uid', None)
|
|
lang = request_dict.get('lang', 'en')
|
|
lang = request_dict.get('lang', 'en')
|
|
-
|
|
|
|
|
|
+ nowTime = int(time.time())
|
|
# DVR/NVR设备暂不返回云存套餐列表
|
|
# DVR/NVR设备暂不返回云存套餐列表
|
|
device_info_qs = Device_Info.objects.filter(Q(UID=uid), Q(Type__lte=4) | Q(Type=10001))
|
|
device_info_qs = Device_Info.objects.filter(Q(UID=uid), Q(Type__lte=4) | Q(Type=10001))
|
|
if device_info_qs.exists():
|
|
if device_info_qs.exists():
|
|
@@ -238,7 +239,6 @@ class CloudStorageView(View):
|
|
res_c = {'area': area, 'items': items_list}
|
|
res_c = {'area': area, 'items': items_list}
|
|
res.append(res_c)
|
|
res.append(res_c)
|
|
#是否促销
|
|
#是否促销
|
|
- nowTime = int(time.time())
|
|
|
|
promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
endTime__gte=nowTime).values('id','ruleConfig','ruleName',
|
|
endTime__gte=nowTime).values('id','ruleConfig','ruleName',
|
|
'startTime','endTime','ruleDesc')
|
|
'startTime','endTime','ruleDesc')
|
|
@@ -255,6 +255,11 @@ class CloudStorageView(View):
|
|
promotion = {
|
|
promotion = {
|
|
'is_promotion': 0
|
|
'is_promotion': 0
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ #优惠券
|
|
|
|
+ couponObj = CouponModel.objects.filter(userID_id=userID,use_status=0,distributeTime__lte=nowTime,
|
|
|
|
+ valid_time__gt=nowTime).annotate(coupon_id=F('id')).values(
|
|
|
|
+ "coupon_id","type","coupon_discount")
|
|
result = {
|
|
result = {
|
|
'meals': res,
|
|
'meals': res,
|
|
'extra':
|
|
'extra':
|
|
@@ -262,7 +267,8 @@ class CloudStorageView(View):
|
|
'cloud_banner': SERVER_DOMAIN+'web/images/cloud_cn_banner.png',
|
|
'cloud_banner': SERVER_DOMAIN+'web/images/cloud_cn_banner.png',
|
|
'cloud_en_baner': SERVER_DOMAIN_SSL+'web/images/cloud_en_banner.png'
|
|
'cloud_en_baner': SERVER_DOMAIN_SSL+'web/images/cloud_en_banner.png'
|
|
},
|
|
},
|
|
- 'promotion':promotion
|
|
|
|
|
|
+ 'promotion':promotion,
|
|
|
|
+ 'couponList':list(couponObj),
|
|
}
|
|
}
|
|
return response.json(0, result)
|
|
return response.json(0, result)
|
|
else:
|
|
else:
|
|
@@ -835,6 +841,10 @@ class CloudStorageView(View):
|
|
# }
|
|
# }
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
|
|
|
|
|
|
+ # 核销coupon
|
|
|
|
+ if order_list[0]['coupon_id']:
|
|
|
|
+ CouponModel.objects.filter(id=order_list[0]['coupon_id']).update(use_status=1)
|
|
|
|
+
|
|
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())
|
|
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())]
|
|
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())]
|
|
@@ -892,7 +902,7 @@ class CloudStorageView(View):
|
|
nowTime = int(time.time())
|
|
nowTime = int(time.time())
|
|
order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
|
|
order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
|
|
"userID__userID",
|
|
"userID__userID",
|
|
- "userID__username")
|
|
|
|
|
|
+ "userID__username","coupon_id")
|
|
userid = order_list[0]['userID__userID']
|
|
userid = order_list[0]['userID__userID']
|
|
username = order_list[0]['userID__username']
|
|
username = order_list[0]['userID__username']
|
|
UID = order_list[0]['UID']
|
|
UID = order_list[0]['UID']
|
|
@@ -961,6 +971,10 @@ class CloudStorageView(View):
|
|
# }
|
|
# }
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
|
|
|
|
|
|
+ # 核销coupon
|
|
|
|
+ if order_list[0]['coupon_id']:
|
|
|
|
+ CouponModel.objects.filter(id=order_list[0]['coupon_id']).update(use_status=1)
|
|
|
|
+
|
|
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())
|
|
datetime = time.strftime("%Y-%m-%d", time.localtime())
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + UID + '设备在' + datetime + '已成功购买云存套餐',
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + UID + '设备在' + datetime + '已成功购买云存套餐',
|
|
@@ -1083,6 +1097,10 @@ class CloudStorageView(View):
|
|
# }
|
|
# }
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
# UIDMainUser.objects.create(**uid_main_dict)
|
|
|
|
|
|
|
|
+ # 核销coupon
|
|
|
|
+ if order_list[0]['coupon_id']:
|
|
|
|
+ CouponModel.objects.filter(id=order_list[0]['coupon_id']).update(use_status=1)
|
|
|
|
+
|
|
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())
|
|
datetime = time.strftime("%Y-%m-%d", time.localtime())
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + UID + '设备在' + datetime + '已成功购买云存套餐',
|
|
sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + UID + '设备在' + datetime + '已成功购买云存套餐',
|
|
@@ -1109,6 +1127,7 @@ class CloudStorageView(View):
|
|
pay_type = int(request_dict.get('pay_type', None))
|
|
pay_type = int(request_dict.get('pay_type', None))
|
|
rank = request_dict.get('rank', None)
|
|
rank = request_dict.get('rank', None)
|
|
is_select_discount = request_dict.get('is_select_discount', 0)
|
|
is_select_discount = request_dict.get('is_select_discount', 0)
|
|
|
|
+ coupon_id = request_dict.get('coupon_id', 0)
|
|
lang = request_dict.get('lang', 'en')
|
|
lang = request_dict.get('lang', 'en')
|
|
if not uid or not channel or not pay_type or not rank:
|
|
if not uid or not channel or not pay_type or not rank:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
@@ -1161,6 +1180,24 @@ class CloudStorageView(View):
|
|
return response.json(10041)
|
|
return response.json(10041)
|
|
|
|
|
|
orderID = CommonService.createOrderID()
|
|
orderID = CommonService.createOrderID()
|
|
|
|
+
|
|
|
|
+ #优惠券
|
|
|
|
+ if coupon_id:
|
|
|
|
+ couponObj = CouponModel.objects.filter(id=coupon_id, use_status=0, distributeTime__lte=nowTime,
|
|
|
|
+ valid_time__gt=nowTime)
|
|
|
|
+ couponQuery = couponObj.values("id", "type", "coupon_discount")
|
|
|
|
+ if not couponQuery.exists():
|
|
|
|
+ return response.json(10049)
|
|
|
|
+ price = Decimal(price)
|
|
|
|
+ coupon_discount = Decimal(couponQuery[0]['coupon_discount'])
|
|
|
|
+ if couponQuery[0]['type'] == 1: #折扣
|
|
|
|
+ price = coupon_discount/10 * price
|
|
|
|
+ elif couponQuery[0]['type'] == 2: #抵扣
|
|
|
|
+ price = price - couponQuery[0]['coupon_discount']
|
|
|
|
+ if price < 0:
|
|
|
|
+ return response.json(10049)
|
|
|
|
+ couponObj.update(use_status=1)
|
|
|
|
+
|
|
if pay_type == 1:
|
|
if pay_type == 1:
|
|
# 订阅周期扣款
|
|
# 订阅周期扣款
|
|
if(smqs[0]['cycle_config_id']):
|
|
if(smqs[0]['cycle_config_id']):
|
|
@@ -1172,7 +1209,7 @@ class CloudStorageView(View):
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
pay_url=subInfo['url'], isSelectDiscounts=is_select_discount,
|
|
pay_url=subInfo['url'], isSelectDiscounts=is_select_discount,
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
- rank_id=rank, plan_id=subInfo['plan_id'])
|
|
|
|
|
|
+ rank_id=rank, plan_id=subInfo['plan_id'],coupon_id=coupon_id)
|
|
return response.json(0, {"redirectUrl": subInfo['url'], "orderID": orderID})
|
|
return response.json(0, {"redirectUrl": subInfo['url'], "orderID": orderID})
|
|
|
|
|
|
#正常扣款
|
|
#正常扣款
|
|
@@ -1210,7 +1247,7 @@ class CloudStorageView(View):
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
pay_url=approval_url, isSelectDiscounts=is_select_discount,
|
|
pay_url=approval_url, isSelectDiscounts=is_select_discount,
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
- rank_id=rank, paymentID=paymentID)
|
|
|
|
|
|
+ rank_id=rank, paymentID=paymentID,coupon_id=coupon_id)
|
|
return response.json(0, {"redirectUrl": approval_url, "orderID": orderID})
|
|
return response.json(0, {"redirectUrl": approval_url, "orderID": orderID})
|
|
return response.json(10, 'generate_order_false')
|
|
return response.json(10, 'generate_order_false')
|
|
elif pay_type == 2:
|
|
elif pay_type == 2:
|
|
@@ -1253,7 +1290,7 @@ class CloudStorageView(View):
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
pay_url=redirectUrl, isSelectDiscounts=is_select_discount,
|
|
pay_url=redirectUrl, isSelectDiscounts=is_select_discount,
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
- rank_id=rank)
|
|
|
|
|
|
+ rank_id=rank,coupon_id=coupon_id)
|
|
|
|
|
|
return JsonResponse(status=200, data={'result_code': 0, 'reason': 'success',
|
|
return JsonResponse(status=200, data={'result_code': 0, 'reason': 'success',
|
|
'result': {"redirectUrl": redirectUrl, "orderID": orderID},
|
|
'result': {"redirectUrl": redirectUrl, "orderID": orderID},
|