|
@@ -1,6 +1,7 @@
|
|
|
import datetime as date_time
|
|
|
import json
|
|
|
import logging
|
|
|
+import threading
|
|
|
import time
|
|
|
import traceback
|
|
|
|
|
@@ -10,6 +11,7 @@ from django.db.models import Q, F
|
|
|
from django.http import HttpResponseRedirect, HttpResponse
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
+from AdminController.CloudServiceManage.AgentOrderController import AgentOrderView
|
|
|
from Ansjer.config import PAYPAL_CRD, SERVER_DOMAIN_SSL, PAYPAL_WEB_HOOK_ID, CONFIG_INFO, \
|
|
|
CONFIG_US, CONFIG_EUR
|
|
|
from Controller import CloudStorage
|
|
@@ -437,7 +439,7 @@ class PaypalCycleNotify(View):
|
|
|
order_qs = Order_Model.objects.filter(paymentID=paymentID).values('UID', 'userID__region_country',
|
|
|
'create_vod', 'orderID',
|
|
|
'channel', 'rank__is_ai',
|
|
|
- 'rank__expire',
|
|
|
+ 'rank__expire', 'rank_id',
|
|
|
'rank__bucket__id',
|
|
|
'isSelectDiscounts',
|
|
|
'userID__username',
|
|
@@ -452,6 +454,10 @@ class PaypalCycleNotify(View):
|
|
|
if not self.config_match_region(uid, country_id):
|
|
|
return HttpResponse('Fail', status=500)
|
|
|
|
|
|
+ # 检查是否云服务代理订单
|
|
|
+ order_id = order_qs[0]['orderID']
|
|
|
+ rank = order_qs[0]['rank_id']
|
|
|
+
|
|
|
if order_qs[0]['create_vod']:
|
|
|
order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime, fee=fee)
|
|
|
else:
|
|
@@ -463,7 +469,6 @@ class PaypalCycleNotify(View):
|
|
|
bucketId = order_qs[0]['rank__bucket__id']
|
|
|
userid = order_qs[0]['userID__userID']
|
|
|
username = order_qs[0]['userID__username']
|
|
|
- order_id = order_qs[0]['orderID']
|
|
|
coupon_id = order_qs[0]['coupon_id']
|
|
|
promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
|
endTime__gte=nowTime).values('id', 'ruleConfig')
|
|
@@ -482,8 +487,16 @@ class PaypalCycleNotify(View):
|
|
|
# 核销coupon
|
|
|
if coupon_id:
|
|
|
CouponModel.objects.filter(id=coupon_id).update(use_status=2, update_time=nowTime)
|
|
|
-
|
|
|
- PAY_LOGGER.info('PayPal周期扣款成功---更新交易id:{}'.format(paypal_transaction_id))
|
|
|
+ # PayPal支付成功后异步检查是否代理订单
|
|
|
+ try:
|
|
|
+ check_thread = threading.Thread(
|
|
|
+ target=AgentOrderView.check_agent_service_package, args=(order_id, uid, rank)
|
|
|
+ )
|
|
|
+ check_thread.start()
|
|
|
+ except Exception as e:
|
|
|
+ PAY_LOGGER.error('PayPal周期扣款异步检查代理订单失败,order_id:{},e:{}'.format(order_id, repr(e)))
|
|
|
+
|
|
|
+ PAY_LOGGER.info('PayPal周期扣款成功{}---更新交易id:{}'.format(order_id, paypal_transaction_id))
|
|
|
return HttpResponse('success')
|
|
|
else:
|
|
|
PAY_LOGGER.info('PayPal周期扣款失败---paymentID:{}或paypal_transaction_id:{}为空'.
|
|
@@ -564,6 +577,14 @@ class PaypalCycleNotify(View):
|
|
|
# 核销coupon
|
|
|
if coupon_id:
|
|
|
CouponModel.objects.filter(id=coupon_id).update(use_status=2, update_time=nowTime)
|
|
|
+ # PayPal首次扣款异步检查是否代理订单
|
|
|
+ try:
|
|
|
+ check_thread = threading.Thread(
|
|
|
+ target=AgentOrderView.check_agent_service_package, args=(order_id, UID, rank)
|
|
|
+ )
|
|
|
+ check_thread.start()
|
|
|
+ except Exception as e:
|
|
|
+ PAY_LOGGER.error('{}PayPal周期扣款首次异步检查代理订单失败:{}'.format(order_id, repr(e)))
|
|
|
PAY_LOGGER.info('{} PayPal周期扣款首次扣款成功'.format(UID))
|
|
|
return HttpResponse('success')
|
|
|
|
|
@@ -676,7 +697,17 @@ class PaypalCycleNotify(View):
|
|
|
# 记录新订单号和更新状态
|
|
|
PaypalWebHookEvent.objects.filter(id=paypal_webhook_event_qs.id).update(newOrderID=orderID,
|
|
|
update_status=update_status)
|
|
|
- PAY_LOGGER.info('{} PayPal周期扣款成功'.format(UID))
|
|
|
+
|
|
|
+ # PayPal检查是否云服务代理订单
|
|
|
+ try:
|
|
|
+ check_thread = threading.Thread(
|
|
|
+ target=AgentOrderView.check_agent_service_package, args=(orderID, UID, rank)
|
|
|
+ )
|
|
|
+ check_thread.start()
|
|
|
+ except Exception as e:
|
|
|
+ PAY_LOGGER.error('{}PayPal周期扣款检查代理订单失败:{}'.format(order_id, repr(e)))
|
|
|
+
|
|
|
+ PAY_LOGGER.info('{} PayPal周期扣款成功{}'.format(UID, orderID))
|
|
|
return HttpResponse('success')
|
|
|
except Exception as e:
|
|
|
PAY_LOGGER.info('PayPal周期扣款异常: errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|