Эх сурвалжийг харах

后台paypal订单每日对账

peng 1 жил өмнө
parent
commit
8647f346d2

+ 40 - 40
Controller/Cron/CronTaskController.py

@@ -1433,7 +1433,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:
@@ -1442,49 +1442,48 @@ 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']
             order_qs = Order_Model.objects.filter(trade_no=trade_no, payType=1)
-            if not order_qs.exists():
-                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()
-                order_dict = {
-                    'trade_no': trade_no,
-                    'agreement_id': agreement_id,
-                    'pay_time': pay_time,
-                    'username': item['payer_info']['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}
-                response = requests.get('https://www.zositeche.com/testApi/checkOrderExist', params=params)
-                if response.status_code != 200:
-                    # 如果响应失败,记录在数据库
-                    AbnormalOrder.objects.create(**order_dict)
-                    continue
-                result = response.json()
-                if result['result_code'] != 0 or not result['result']['is_exist']:
-                    # 如果响应结果为空,记录在数据库
-                    AbnormalOrder.objects.create(**order_dict)
+            # if not order_qs.exists():
+            #     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()
+            #     order_dict = {
+            #         'trade_no': trade_no,
+            #         'agreement_id': agreement_id,
+            #         'pay_time': pay_time,
+            #         'username': item['payer_info']['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}
+            #     response = requests.get('https://www.zositeche.com/testApi/checkOrderExist', params=params)
+            #     if response.status_code != 200:
+            #         # 如果响应失败,记录在数据库
+            #         AbnormalOrder.objects.create(**order_dict)
+            #         continue
+            #     result = response.json()
+            #     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)
@@ -1591,9 +1590,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:
@@ -1629,7 +1628,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
@@ -1646,9 +1645,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)