Parcourir la source

后台paypal订单每日对账

peng il y a 1 an
Parent
commit
841f67567b
1 fichiers modifiés avec 10 ajouts et 10 suppressions
  1. 10 10
      Controller/Cron/CronTaskController.py

+ 10 - 10
Controller/Cron/CronTaskController.py

@@ -1255,7 +1255,7 @@ class CronComparedDataView(View):
             )
             order_list = PayPalService(PAYPAL_CRD['client_id'], PAYPAL_CRD['client_secret']).get_transactions(data)
             thread = threading.Thread(target=CronComparedDataView.thread_compared_pyapal_order,
-                                      args=(order_list['transaction_details'],))
+                                      args=(order_list['transaction_details'], end_date))
             thread.start()
             return response.json(0)
         except Exception as e:
@@ -1264,15 +1264,13 @@ class CronComparedDataView(View):
             return response.json(500)
 
     @staticmethod
-    def thread_compared_pyapal_order(order_list):
+    def thread_compared_pyapal_order(order_list, start_time):
         now_time = int(time.time())
-        now = datetime.datetime.now()
-        midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)
-        timestamp = midnight.timestamp()
+        timestamp = int(start_time.timestamp())
         count = len(order_list)
         total = 0
         for item in order_list:
-            total += item['transaction_info']['transaction_amount']['value']
+            total += float(item['transaction_info']['transaction_amount']['value'])
             trade_no = item['transaction_info']['transaction_id']
             if item['transaction_info']['transaction_event_code'] == 'T1107':
                 trade_no = item['transaction_info']['paypal_reference_id']
@@ -1307,6 +1305,7 @@ class CronComparedDataView(View):
                 if result['result_code'] != 0 or not result['result']['is_exist']:
                     # 如果响应结果为空,记录在数据库
                     AbnormalOrder.objects.create(**order_dict)
+        total = round(total, 2)
         daily_reconciliation = DailyReconciliation.objects.filter(time=timestamp)
         if daily_reconciliation.exists():
             daily_reconciliation.update(paypal_num=count, paypal_total=total, upd_time=now_time)
@@ -1413,9 +1412,9 @@ class CronComparedDataView(View):
     @staticmethod
     def compared_ansjer_order(response):
         today = datetime.datetime.today()
-        start_date = today - datetime.timedelta(days=2)
+        start_date = today - datetime.timedelta(days=1)
         start_date = datetime.datetime(start_date.year, start_date.month, start_date.day)
-        end_date = start_date + datetime.timedelta(days=1)
+        end_date = datetime.datetime(today.year, today.month, today.day)
         start_date_stamp = int(start_date.timestamp())
         end_date_stamp = int(end_date.timestamp())
         try:
@@ -1451,7 +1450,7 @@ class CronComparedDataView(View):
         count = len(all_order_list)
 
         for index, order in enumerate(all_order_list):
-            total += order['price']
+            total += float(order['price'])
             if all_order_list.index(order) != index:
                 more_order_list.append(order['trade_no'])
                 continue
@@ -1468,9 +1467,10 @@ class CronComparedDataView(View):
             if not paypal_order_list['transaction_details']:
                 more_order_list.append(order['trade_no'])
         trade_nos = ','.join(more_order_list)
+        total = round(total, 2)
         daily_reconciliation = DailyReconciliation.objects.filter(time=start_timestamp)
         if daily_reconciliation.exists():
             daily_reconciliation.update(ansjer_total=total, ansjer_num=count, trade_nos=trade_nos, upd_time=now_time)
         else:
             DailyReconciliation.objects.create(trade_nos=trade_nos, ansjer_total=total, ansjer_num=count,
-                                               time=start_timestamp, crete_time=now_time, upd_time=now_time)
+                                               time=start_timestamp, creat_time=now_time, upd_time=now_time)