|
@@ -1518,78 +1518,80 @@ class CronComparedDataView(View):
|
|
|
|
|
|
@staticmethod
|
|
|
def thread_compared_paypal_order(order_list, start_time):
|
|
|
- LOGGER.info('paypal每日对账开始时间:{}'.format(int(time.time())))
|
|
|
- now_time = int(time.time())
|
|
|
- timestamp = int(start_time.timestamp())
|
|
|
- count = len(order_list)
|
|
|
- total = 0
|
|
|
- more_order_list = []
|
|
|
- for item in order_list:
|
|
|
- total += float(item['transaction_info']['transaction_amount']['value'])
|
|
|
- trade_no = item['transaction_info']['transaction_id']
|
|
|
- if item['transaction_info']['transaction_event_code'] in ['T1106', 'T1107']: # 付款退款
|
|
|
- trade_no = item['transaction_info']['paypal_reference_id']
|
|
|
- transaction_subject = item['transaction_info'].get('transaction_subject', '')
|
|
|
- agreement_id = item['transaction_info'].get('paypal_reference_id', '')
|
|
|
- refund_order = False
|
|
|
- if item['transaction_info']['transaction_event_code'] in ['T1106', 'T1107', 'T1201', 'T0114']:
|
|
|
- agreement_id = ''
|
|
|
- if item['transaction_info']['transaction_event_code'] in ['T0114']:
|
|
|
- transaction_subject = '争议费'
|
|
|
- else:
|
|
|
- refund_order = True
|
|
|
- transaction_subject = '退款费'
|
|
|
- more_order_list.append(trade_no)
|
|
|
- pay_time = int(datetime.datetime.strptime(item['transaction_info']['transaction_updated_date'],
|
|
|
- "%Y-%m-%dT%H:%M:%S%z").timestamp())
|
|
|
- order_qs = Order_Model.objects.filter(trade_no=trade_no, payType=1)
|
|
|
- if not order_qs.exists():
|
|
|
- order_dict = {
|
|
|
- 'trade_no': trade_no,
|
|
|
- 'agreement_id': agreement_id,
|
|
|
- 'pay_time': pay_time,
|
|
|
- 'username': item['payer_info'].get('email_address', ''),
|
|
|
- 'price': item['transaction_info']['transaction_amount']['value'],
|
|
|
- 'pay_type': 1,
|
|
|
- 'upd_time': now_time,
|
|
|
- 'status': 0,
|
|
|
- 'meal_name': transaction_subject
|
|
|
- }
|
|
|
- if agreement_id:
|
|
|
- order_dict['pay_type'] = 0
|
|
|
- order_dict['meal_name'] = 'paypal_cycle'
|
|
|
- order_dict['order_id'] = transaction_subject
|
|
|
- params = {'trade_no': trade_no, 'pay_time': pay_time, 'refund_order': refund_order}
|
|
|
- response = requests.get('https://www.zositeche.com/testApi/checkOrderExist', params=params)
|
|
|
- if response.status_code != 200:
|
|
|
- # 如果响应失败,记录在数据库
|
|
|
- abnormal_qs = AbnormalOrder.objects.filter(trade_no=trade_no)
|
|
|
- if not abnormal_qs.exists():
|
|
|
- AbnormalOrder.objects.create(**order_dict)
|
|
|
- continue
|
|
|
- result = response.json()
|
|
|
- if result['result_code'] != 0 or not result['result']['is_exist']:
|
|
|
- # 如果响应结果为空,记录在数据库
|
|
|
- abnormal_qs = AbnormalOrder.objects.filter(trade_no=trade_no)
|
|
|
- if not abnormal_qs.exists():
|
|
|
- AbnormalOrder.objects.create(**order_dict)
|
|
|
+ try:
|
|
|
+ now_time = int(time.time())
|
|
|
+ timestamp = int(start_time.timestamp())
|
|
|
+ count = len(order_list)
|
|
|
+ total = 0
|
|
|
+ more_order_list = []
|
|
|
+ for item in order_list:
|
|
|
+ total += float(item['transaction_info']['transaction_amount']['value'])
|
|
|
+ trade_no = item['transaction_info']['transaction_id']
|
|
|
+ if item['transaction_info']['transaction_event_code'] in ['T1106', 'T1107']: # 付款退款
|
|
|
+ trade_no = item['transaction_info']['paypal_reference_id']
|
|
|
+ transaction_subject = item['transaction_info'].get('transaction_subject', '')
|
|
|
+ agreement_id = item['transaction_info'].get('paypal_reference_id', '')
|
|
|
+ refund_order = False
|
|
|
+ if item['transaction_info']['transaction_event_code'] in ['T1106', 'T1107', 'T1201', 'T0114']:
|
|
|
+ agreement_id = ''
|
|
|
+ if item['transaction_info']['transaction_event_code'] in ['T0114']:
|
|
|
+ transaction_subject = '争议费'
|
|
|
+ else:
|
|
|
+ refund_order = True
|
|
|
+ transaction_subject = '退款费'
|
|
|
more_order_list.append(trade_no)
|
|
|
+ pay_time = int(datetime.datetime.strptime(item['transaction_info']['transaction_updated_date'],
|
|
|
+ "%Y-%m-%dT%H:%M:%S%z").timestamp())
|
|
|
+ order_qs = Order_Model.objects.filter(trade_no=trade_no, payType=1)
|
|
|
+ if not order_qs.exists():
|
|
|
+ order_dict = {
|
|
|
+ 'trade_no': trade_no,
|
|
|
+ 'agreement_id': agreement_id,
|
|
|
+ 'pay_time': pay_time,
|
|
|
+ 'username': item['payer_info'].get('email_address', ''),
|
|
|
+ 'price': item['transaction_info']['transaction_amount']['value'],
|
|
|
+ 'pay_type': 1,
|
|
|
+ 'upd_time': now_time,
|
|
|
+ 'status': 0,
|
|
|
+ 'meal_name': transaction_subject
|
|
|
+ }
|
|
|
+ if agreement_id:
|
|
|
+ order_dict['pay_type'] = 0
|
|
|
+ order_dict['meal_name'] = 'paypal_cycle'
|
|
|
+ order_dict['order_id'] = transaction_subject
|
|
|
+ params = {'trade_no': trade_no, 'pay_time': pay_time, 'refund_order': refund_order}
|
|
|
+ response = requests.get('https://www.zositeche.com/testApi/checkOrderExist', params=params)
|
|
|
+ if response.status_code != 200:
|
|
|
+ # 如果响应失败,记录在数据库
|
|
|
+ abnormal_qs = AbnormalOrder.objects.filter(trade_no=trade_no)
|
|
|
+ if not abnormal_qs.exists():
|
|
|
+ AbnormalOrder.objects.create(**order_dict)
|
|
|
+ continue
|
|
|
+ result = response.json()
|
|
|
+ if result['result_code'] != 0 or not result['result']['is_exist']:
|
|
|
+ # 如果响应结果为空,记录在数据库
|
|
|
+ abnormal_qs = AbnormalOrder.objects.filter(trade_no=trade_no)
|
|
|
+ if not abnormal_qs.exists():
|
|
|
+ AbnormalOrder.objects.create(**order_dict)
|
|
|
+ more_order_list.append(trade_no)
|
|
|
+ else:
|
|
|
+ if not refund_order:
|
|
|
+ order_qs.update(payTime=pay_time)
|
|
|
+ total = round(total, 2)
|
|
|
+ daily_reconciliation = DailyReconciliation.objects.filter(time=timestamp)
|
|
|
+ if daily_reconciliation.exists():
|
|
|
+ if daily_reconciliation.first().order_ids:
|
|
|
+ old_order_list = daily_reconciliation.first().order_ids.split(',')
|
|
|
+ more_order_list = list(set(old_order_list) | set(more_order_list))
|
|
|
+ order_ids = ','.join(more_order_list)
|
|
|
+ daily_reconciliation.update(paypal_num=count, paypal_total=total, upd_time=now_time, order_ids=order_ids)
|
|
|
else:
|
|
|
- if not refund_order:
|
|
|
- order_qs.update(payTime=pay_time)
|
|
|
- total = round(total, 2)
|
|
|
- daily_reconciliation = DailyReconciliation.objects.filter(time=timestamp)
|
|
|
- if daily_reconciliation.exists():
|
|
|
- if daily_reconciliation.first().order_ids:
|
|
|
- old_order_list = daily_reconciliation.first().order_ids.split(',')
|
|
|
- more_order_list = list(set(old_order_list) | set(more_order_list))
|
|
|
- order_ids = ','.join(more_order_list)
|
|
|
- daily_reconciliation.update(paypal_num=count, paypal_total=total, upd_time=now_time, order_ids=order_ids)
|
|
|
- else:
|
|
|
- order_ids = ','.join(more_order_list)
|
|
|
- DailyReconciliation.objects.create(paypal_num=count, paypal_total=total, time=timestamp,
|
|
|
- order_ids=order_ids, creat_time=now_time, upd_time=now_time)
|
|
|
- LOGGER.info('paypal每日对账结束时间:{}'.format(int(time.time())))
|
|
|
+ order_ids = ','.join(more_order_list)
|
|
|
+ DailyReconciliation.objects.create(paypal_num=count, paypal_total=total, time=timestamp,
|
|
|
+ order_ids=order_ids, creat_time=now_time, upd_time=now_time)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('paypal每日对账异常:errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
|
|
|
@staticmethod
|
|
|
def compared_wechat_order(response):
|
|
@@ -1717,7 +1719,6 @@ class CronComparedDataView(View):
|
|
|
|
|
|
@staticmethod
|
|
|
def thread_compared_ansjer_order(order_list, start_time):
|
|
|
- LOGGER.info('后台每日对账开始时间:{}'.format(int(time.time())))
|
|
|
while True:
|
|
|
response = requests.get('https://www.zositeche.com/cron/compared/AnsjerOrder',
|
|
|
params={'time': int(start_time.timestamp())})
|
|
@@ -1726,39 +1727,42 @@ class CronComparedDataView(View):
|
|
|
if result['result_code'] == 0:
|
|
|
eur_order_list = result['result']
|
|
|
break
|
|
|
- begin_date = start_time - datetime.timedelta(days=15)
|
|
|
- end_date = start_time + datetime.timedelta(days=15)
|
|
|
- start_timestamp = int(start_time.timestamp())
|
|
|
- now_time = int(time.time())
|
|
|
- more_order_list = []
|
|
|
- total = 0
|
|
|
- all_order_list = order_list + eur_order_list
|
|
|
- count = len(all_order_list)
|
|
|
- paypal_api = paypalrestsdk.Api(PAYPAL_CRD)
|
|
|
- for index, order in enumerate(all_order_list):
|
|
|
- total += float(order['price'])
|
|
|
- if not order['trade_no']:
|
|
|
- more_order_list.append(order['orderID'])
|
|
|
- continue
|
|
|
- if all_order_list.index(order) != index:
|
|
|
- more_order_list.append(order['orderID'])
|
|
|
- continue
|
|
|
- paypal_url = 'v1/reporting/transactions?start_date={}-{}-{}T00:00:00-0000&end_date={}-{}-{}T00:00:00-0000&transaction_id={}&fields=all&page_size=100&page=1'.format(
|
|
|
- begin_date.year, begin_date.month, begin_date.day, end_date.year, end_date.month, end_date.day,
|
|
|
- order['trade_no'])
|
|
|
- paypal_order_list = paypal_api.get(paypal_url)
|
|
|
- if not paypal_order_list['transaction_details']:
|
|
|
- more_order_list.append(order['orderID'])
|
|
|
- total = round(total, 2)
|
|
|
- daily_reconciliation = DailyReconciliation.objects.filter(time=start_timestamp)
|
|
|
- if daily_reconciliation.exists():
|
|
|
- if daily_reconciliation.first().order_ids:
|
|
|
- old_order_list = daily_reconciliation.first().order_ids.split(',')
|
|
|
- more_order_list = list(set(old_order_list) | set(more_order_list))
|
|
|
- order_ids = ','.join(more_order_list)
|
|
|
- daily_reconciliation.update(ansjer_total=total, ansjer_num=count, order_ids=order_ids, upd_time=now_time)
|
|
|
- else:
|
|
|
- order_ids = ','.join(more_order_list)
|
|
|
- DailyReconciliation.objects.create(order_ids=order_ids, ansjer_total=total, ansjer_num=count,
|
|
|
- time=start_timestamp, creat_time=now_time, upd_time=now_time)
|
|
|
- LOGGER.info('后台每日对账结束时间:{}'.format(int(time.time())))
|
|
|
+ try:
|
|
|
+ begin_date = start_time - datetime.timedelta(days=15)
|
|
|
+ end_date = start_time + datetime.timedelta(days=15)
|
|
|
+ start_timestamp = int(start_time.timestamp())
|
|
|
+ now_time = int(time.time())
|
|
|
+ more_order_list = []
|
|
|
+ total = 0
|
|
|
+ all_order_list = order_list + eur_order_list
|
|
|
+ count = len(all_order_list)
|
|
|
+ paypal_api = paypalrestsdk.Api(PAYPAL_CRD)
|
|
|
+ for index, order in enumerate(all_order_list):
|
|
|
+ total += float(order['price'])
|
|
|
+ if not order['trade_no']:
|
|
|
+ more_order_list.append(order['orderID'])
|
|
|
+ continue
|
|
|
+ if all_order_list.index(order) != index:
|
|
|
+ more_order_list.append(order['orderID'])
|
|
|
+ continue
|
|
|
+ paypal_url = 'v1/reporting/transactions?start_date={}-{}-{}T00:00:00-0000&end_date={}-{}-{}T00:00:00-0000&transaction_id={}&fields=all&page_size=100&page=1'.format(
|
|
|
+ begin_date.year, begin_date.month, begin_date.day, end_date.year, end_date.month, end_date.day,
|
|
|
+ order['trade_no'])
|
|
|
+ paypal_order_list = paypal_api.get(paypal_url)
|
|
|
+ if not paypal_order_list['transaction_details']:
|
|
|
+ more_order_list.append(order['orderID'])
|
|
|
+ total = round(total, 2)
|
|
|
+ daily_reconciliation = DailyReconciliation.objects.filter(time=start_timestamp)
|
|
|
+ if daily_reconciliation.exists():
|
|
|
+ if daily_reconciliation.first().order_ids:
|
|
|
+ old_order_list = daily_reconciliation.first().order_ids.split(',')
|
|
|
+ more_order_list = list(set(old_order_list) | set(more_order_list))
|
|
|
+ order_ids = ','.join(more_order_list)
|
|
|
+ daily_reconciliation.update(ansjer_total=total, ansjer_num=count, order_ids=order_ids, upd_time=now_time)
|
|
|
+ else:
|
|
|
+ order_ids = ','.join(more_order_list)
|
|
|
+ DailyReconciliation.objects.create(order_ids=order_ids, ansjer_total=total, ansjer_num=count,
|
|
|
+ time=start_timestamp, creat_time=now_time, upd_time=now_time)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('后台每日对账异常:errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|