|
@@ -30,6 +30,7 @@ from Object.utils.PayPalUtil import PayPalService
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.VodHlsService import SplitVodHlsObject
|
|
|
from Object.UnicomObject import UnicomObjeect
|
|
|
+from Object.WechatPayObject import WechatPayObject
|
|
|
|
|
|
|
|
|
class CronDelDataView(View):
|
|
@@ -1215,6 +1216,8 @@ class CronComparedDataView(View):
|
|
|
response = ResponseObject()
|
|
|
if operation == 'PaypalOrder': # 定时对比paypal订单
|
|
|
return self.compared_paypal_order(response)
|
|
|
+ elif operation == 'WechatOrder': # 定时对比微信订单
|
|
|
+ return self.compared_wechat_order(response)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
@@ -1234,7 +1237,7 @@ class CronComparedDataView(View):
|
|
|
('transaction_status', 'S')
|
|
|
)
|
|
|
order_list = PayPalService(PAYPAL_CRD['client_id'], PAYPAL_CRD['client_secret']).get_transactions(data)
|
|
|
- thread = threading.Thread(target=CronComparedDataView.thread_compared_order,
|
|
|
+ thread = threading.Thread(target=CronComparedDataView.thread_compared_pyapal_order,
|
|
|
args=(order_list['transaction_details'],))
|
|
|
thread.start()
|
|
|
return response.json(0)
|
|
@@ -1244,7 +1247,7 @@ class CronComparedDataView(View):
|
|
|
return response.json(500)
|
|
|
|
|
|
@staticmethod
|
|
|
- def thread_compared_order(order_list):
|
|
|
+ def thread_compared_pyapal_order(order_list):
|
|
|
now_time = int(time.time())
|
|
|
for item in order_list:
|
|
|
trade_no = item['transaction_info']['transaction_id']
|
|
@@ -1252,7 +1255,7 @@ class CronComparedDataView(View):
|
|
|
trade_no = item['transaction_info']['paypal_reference_id']
|
|
|
order_qs = Order_Model.objects.filter(trade_no=trade_no, payType=1)
|
|
|
if not order_qs.exists():
|
|
|
- order_id = item['transaction_info'].get('transaction_subject', '')
|
|
|
+ transaction_subject = item['transaction_info'].get('transaction_subject', '')
|
|
|
agreement_id = item['transaction_info'].get('paypal_reference_id', '')
|
|
|
pay_time = datetime.datetime.strptime(item['transaction_info']['transaction_initiation_date'],
|
|
|
"%Y-%m-%dT%H:%M:%S%z").timestamp()
|
|
@@ -1264,11 +1267,13 @@ class CronComparedDataView(View):
|
|
|
'price': item['transaction_info']['transaction_amount']['value'],
|
|
|
'pay_type': 1,
|
|
|
'upd_time': now_time,
|
|
|
- 'status': 0
|
|
|
+ 'status': 0,
|
|
|
+ 'meal_name': transaction_subject
|
|
|
}
|
|
|
if agreement_id:
|
|
|
order_dict['pay_type'] = 0
|
|
|
- order_dict['order_id'] = order_id
|
|
|
+ order_dict['meal_name'] = 'paypal_cycle'
|
|
|
+ order_dict['order_id'] = transaction_subject
|
|
|
params = {'trade_no': trade_no}
|
|
|
response = requests.get('https://www.zositeche.com/testApi/checkOrderExist', params=params)
|
|
|
if response.status_code != 200:
|
|
@@ -1279,3 +1284,39 @@ class CronComparedDataView(View):
|
|
|
if result['result_code'] != 0 or not result['result']['is_exist']:
|
|
|
# 如果响应结果为空,记录在数据库
|
|
|
AbnormalOrder.objects.create(**order_dict)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def compared_wechat_order(response):
|
|
|
+ today = datetime.datetime.today()
|
|
|
+ start_date = today - datetime.timedelta(days=1)
|
|
|
+ start_date = start_date.strftime("%Y%m%d")
|
|
|
+ try:
|
|
|
+ order_list = WechatPayObject().download_bill(start_date)
|
|
|
+ thread = threading.Thread(target=CronComparedDataView.thread_compared_wechat_order,
|
|
|
+ args=(order_list,))
|
|
|
+ thread.start()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('CronComparedDataView.compared_paypal_order, errLine:{}, errMsg:{}'.format(
|
|
|
+ e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def thread_compared_wechat_order(order_list):
|
|
|
+ now_time = int(time.time())
|
|
|
+ for order in order_list:
|
|
|
+ if order['交易类型'] != '`APP':
|
|
|
+ continue
|
|
|
+ order_id = order['商户订单号'].replace('`', '')
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=order_id)
|
|
|
+ if not order_qs.exists():
|
|
|
+ order_dict = {
|
|
|
+ 'trade_no': order['微信订单号'].replace('`', ''),
|
|
|
+ 'order_id': order_id,
|
|
|
+ 'pay_type': 3,
|
|
|
+ 'price': order['订单金额'].replace('`', ''),
|
|
|
+ 'pay_time': int(datetime.datetime.strptime(order['\ufeff交易时间'], "`%Y-%m-%d %H:%M:%S").timestamp()),
|
|
|
+ 'upd_time': now_time,
|
|
|
+ 'meal_name': order['商品名称'].replace('`', ''),
|
|
|
+ }
|
|
|
+ AbnormalOrder.objects.create(**order_dict)
|