|
@@ -153,6 +153,49 @@ class PaypalCycleNotify(View):
|
|
|
elif operation == 'subscriptionBreakNotify': # paypal 订阅相关回调
|
|
|
return self.do_subscription_break_notify(request_dict, request, response)
|
|
|
|
|
|
+ def create_vod(self, uid, expire, is_ai, now_time, channel, bucket_id, order_id, userid, username):
|
|
|
+ ubqs = UID_Bucket.objects.filter(uid=uid).values("id", "endTime", "use_status")
|
|
|
+ end_time = CommonService.calcMonthLater(expire)
|
|
|
+ use_flag = True
|
|
|
+ with transaction.atomic():
|
|
|
+ if ubqs.exists():
|
|
|
+ ubq = ubqs[0]
|
|
|
+ uid_bucket_id = ubq['id']
|
|
|
+ if ubq['use_status'] == 1 and ubq['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(uid=uid, channel=channel,
|
|
|
+ bucket_id=bucket_id,
|
|
|
+ endTime=end_time,
|
|
|
+ updateTime=now_time,
|
|
|
+ use_status=1,
|
|
|
+ orderId=order_id)
|
|
|
+
|
|
|
+ else:
|
|
|
+ ub_cqs = UID_Bucket.objects.create \
|
|
|
+ (uid=uid, channel=channel, bucket_id=bucket_id, endTime=end_time, addTime=now_time,
|
|
|
+ updateTime=now_time, use_status=1, orderId=order_id)
|
|
|
+ uid_bucket_id = ub_cqs.id
|
|
|
+ dvq = Device_Info.objects.filter(UID=uid, vodPrimaryUserID='', vodPrimaryMaster='')
|
|
|
+ if dvq.exists():
|
|
|
+ dvq_set_update_dict = {
|
|
|
+ 'vodPrimaryUserID': userid,
|
|
|
+ 'vodPrimaryMaster': username
|
|
|
+ }
|
|
|
+ dvq.update(**dvq_set_update_dict)
|
|
|
+ # 开通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)
|
|
|
+ return uid_bucket_id
|
|
|
+
|
|
|
def do_paypal_cycle_return(self, request_dict, response):
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
token = request_dict.get('token', None)
|
|
@@ -283,7 +326,7 @@ class PaypalCycleNotify(View):
|
|
|
logger.info(
|
|
|
'uid:{},uid_bucket_id:{},update_status:{},order_id:{}'.format(UID, uid_bucket_id, update_status,
|
|
|
orderID))
|
|
|
- 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, create_vod=1,
|
|
|
promotion_rule_id=promotion_rule_id, agreement_id=agreement_id)
|
|
|
# 如果存在序列号,消息提示用序列号
|
|
|
device_name = CommonService.query_serial_with_uid(uid=UID)
|
|
@@ -412,8 +455,8 @@ class PaypalCycleNotify(View):
|
|
|
'payType', 'currency', 'addTime',
|
|
|
'commodity_type', 'updTime', 'order_type',
|
|
|
'userID__userID', 'uid_bucket_id',
|
|
|
- 'userID__username', 'userID__region_country'
|
|
|
- )
|
|
|
+ 'userID__username', 'userID__region_country',
|
|
|
+ 'create_vod', 'coupon_id')
|
|
|
if not order_qs.exists():
|
|
|
PAY_LOGGER.info('PayPal周期扣款失败---根据order_id查询订单数据不存在')
|
|
|
return HttpResponse('fail', status=500)
|
|
@@ -424,10 +467,45 @@ class PaypalCycleNotify(View):
|
|
|
if not self.config_match_region(uid, country_id):
|
|
|
return HttpResponse('Fail', status=500)
|
|
|
|
|
|
+ orderID = CommonService.createOrderID()
|
|
|
UID = order_qs[0]['UID']
|
|
|
+ isSelectDiscounts = order_qs[0]['isSelectDiscounts']
|
|
|
+ coupon_id = order_qs[0]['coupon_id']
|
|
|
+ userid = order_qs[0]['userID__userID']
|
|
|
+ username = order_qs[0]['userID__username']
|
|
|
+ channel = order_qs[0]['channel']
|
|
|
+ rank = order_qs[0]['rank']
|
|
|
+ store_meal_qs = Store_Meal.objects.filter(id=rank).values("bucket_id", "expire", "is_ai")
|
|
|
+ if not store_meal_qs.exists():
|
|
|
+ PAY_LOGGER.info('{} PayPal周期扣款失败---套餐数据不存在'.format(UID))
|
|
|
+ return HttpResponse('fail', status=500)
|
|
|
+ expire = store_meal_qs[0]['expire']
|
|
|
+ is_ai = store_meal_qs[0]['is_ai']
|
|
|
+ bucketId = store_meal_qs[0]['bucket_id']
|
|
|
+
|
|
|
# PayPal周期扣款首次扣款
|
|
|
if billing_agreement.agreement_details.cycles_completed == '0':
|
|
|
- order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime)
|
|
|
+ if order_qs[0]['create_vod']:
|
|
|
+ order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime)
|
|
|
+ else:
|
|
|
+ # 是否有促销
|
|
|
+ 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
|
|
|
+ else:
|
|
|
+ promotion_rule_id = ''
|
|
|
+ if isSelectDiscounts:
|
|
|
+ expire = expire * 2
|
|
|
+ uid_bucket_id = self.create_vod(UID, expire, is_ai, nowTime, channel, bucketId, orderID,
|
|
|
+ userid, username)
|
|
|
+ order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime,
|
|
|
+ uid_bucket_id=uid_bucket_id, create_vod=1,
|
|
|
+ promotion_rule_id=promotion_rule_id, agreement_id=agreement_id)
|
|
|
+ # 核销coupon
|
|
|
+ if coupon_id:
|
|
|
+ CouponModel.objects.filter(id=coupon_id).update(use_status=2, update_time=nowTime)
|
|
|
PAY_LOGGER.info('{} PayPal周期扣款首次扣款成功'.format(UID))
|
|
|
return HttpResponse('success')
|
|
|
|
|
@@ -437,30 +515,13 @@ class PaypalCycleNotify(View):
|
|
|
|
|
|
desc = order_qs[0]['desc']
|
|
|
pay_type = order_qs[0]['payType']
|
|
|
- currency = order_qs[0]['currency']
|
|
|
commodity_code = order_qs[0]['commodity_code']
|
|
|
commodity_type = order_qs[0]['commodity_type']
|
|
|
plan_id = order_qs[0]['plan_id']
|
|
|
- userid = order_qs[0]['userID__userID']
|
|
|
- username = order_qs[0]['userID__username']
|
|
|
- channel = order_qs[0]['channel']
|
|
|
- rank = order_qs[0]['rank']
|
|
|
order_type = order_qs[0]['order_type']
|
|
|
- store_meal_qs = Store_Meal.objects.filter(id=rank).values("day", "bucket_id", "bucket__storeDay", "expire",
|
|
|
- "is_ai")
|
|
|
- if not store_meal_qs.exists():
|
|
|
- PAY_LOGGER.info('{} PayPal周期扣款失败---套餐数据不存在'.format(UID))
|
|
|
- return HttpResponse('fail', status=500)
|
|
|
-
|
|
|
- bucketId = store_meal_qs[0]['bucket_id']
|
|
|
- expire = store_meal_qs[0]['expire']
|
|
|
- is_ai = store_meal_qs[0]['is_ai']
|
|
|
endTime = CommonService.calcMonthLater(expire)
|
|
|
use_flag = True
|
|
|
- orderID = CommonService.createOrderID()
|
|
|
- ubqs = UID_Bucket.objects.filter(uid=UID).values("id", "bucket_id", "bucket__storeDay", "bucket__region",
|
|
|
- "endTime", "use_status")
|
|
|
-
|
|
|
+ ubqs = UID_Bucket.objects.filter(uid=UID).values("id", "endTime", "use_status")
|
|
|
with transaction.atomic():
|
|
|
if ubqs.exists():
|
|
|
ubq = ubqs[0]
|