Browse Source

Merge branch 'test' of http://192.168.136.99:3000/servers/ASJServer into peng

peng 9 months ago
parent
commit
108d27c516
2 changed files with 30 additions and 18 deletions
  1. 21 14
      Controller/InAppPurchaseController.py
  2. 9 4
      Service/UserDeviceService.py

+ 21 - 14
Controller/InAppPurchaseController.py

@@ -4,6 +4,7 @@
 import logging
 import time
 import json
+import threading
 
 import requests
 from appstoreserverlibrary.models.Environment import Environment
@@ -111,6 +112,17 @@ class InAppPurchaseView(View):
             else:
                 return response.json(444, "app_type不存在")
 
+            # 验证订单是否存在
+            order_qs = Order_Model.objects.filter(orderID=order_id, UID=uid, app_type=app_type).values("rank_id")
+            if not order_qs.exists():
+                return response.json(173)
+            if order_qs["transaction_id"]:
+                return response.json(0)
+            if UID_Bucket.objects.filter(orderId=order_id).exists():
+                return response.json(0)
+            if Unused_Uid_Meal.objects.filter(order_id=order_id).exists():
+                return response.json(0)
+
             # 实例化订阅类
             in_app_purchase = InAppPurchase(bundle_id=bundle_id)
 
@@ -136,14 +148,8 @@ class InAppPurchaseView(View):
                                        created_time=int(time.time()), updated_time=int(time.time()),
                                        access_result="SUCCESS")
 
-            if Order_Model.objects.filter(orderID=order_id, transaction_id=transaction_id).exists():
-                return response.json(174, "订单已支付充值")
-            if UID_Bucket.objects.filter(orderId=order_id).exists():
-                return response.json(174, "订单已充值")
-            if Unused_Uid_Meal.objects.filter(order_id=order_id).exists():
-                return response.json(174, "订单已充值")
-
             # 查询交易信息
+            transaction_info = ""
             attempts = 0
             while attempts < 6:
                 try:
@@ -153,9 +159,12 @@ class InAppPurchaseView(View):
                     attempts += 1
                     if attempts == 5:
                         OrderPayLog.objects.create(order_id=order_id, order_no=transaction_id,
-                                                   business_name=f"{order_id}获取transactionInfo",
+                                                   business_name=f"{order_id}获取transactionInfo超时",
                                                    created_time=int(time.time()), updated_time=int(time.time()),
                                                    access_result="ERROR")
+                        return response.json(5)
+                    logger.info(
+                        f"订单orderId:{order_id}, transaction_id:{transaction_id}, 第{attempts}次获取支付信息超时")
 
             signed_transaction_info = transaction_info.signedTransactionInfo
             # 解析交易信息
@@ -173,15 +182,11 @@ class InAppPurchaseView(View):
                 logger.info(f"苹果内购认证交易订单orderID:{order_id}, InAppPurchasePackage表未查询到product_id")
                 return response.json(173, "内购商品id不存在")
 
-            # 验证订单是否存在
-            order_qs = Order_Model.objects.filter(orderID=order_id, UID=uid, app_type=app_type).values("rank_id")
-            if not order_qs.exists():
-                return response.json(173, "订单不存在")
-
             # 验证套餐是否存在
             store_qs = Store_Meal.objects.filter(id=order_qs[0]['rank_id']).values(
                 'id', 'currency', 'price', 'lang__content', 'day', 'commodity_type', 'lang__title', 'expire',
                 'commodity_code', 'discount_price', 'bucket_id', 'bucket__mold', 'cycle_config_id', 'is_ai')
+
             if not store_qs.exists():
                 return response.json(173, "云存套餐不存在")
 
@@ -247,7 +252,9 @@ class InAppPurchaseView(View):
             sys_msg_text_list = cls.cloud_storage_message(uid)
 
             # 发送云存套餐购买消息
-            cls.do_vod_msg_notice(uid, user_id, lang, sys_msg_text_list)
+            asy = threading.Thread(target=cls.do_vod_msg_notice,
+                                   args=(uid, user_id, lang, sys_msg_text_list))
+            asy.start()
 
             redis_obj.del_data(redis_key)
             pay_result_url = CommonService.get_payment_status_url(lang, 'success')

+ 9 - 4
Service/UserDeviceService.py

@@ -45,13 +45,18 @@ class UserDeviceService:
                              'isCameraOpenCloud', 'serial_number').order_by('-data_joined')
         dv_list = CommonService.qs_to_list(dv_qs)
         uid_list = []
-        seen = set()
+        exist_uid = []
         unique_results = []
         for item in dv_qs:
-            key = (item['userID'], item['UID'])  # 根据 userID_id 和 UID 进行去重
-            if key not in seen:
-                seen.add(key)
+            UID = item['UID']
+            # 删除重复的uid数据
+            if UID not in exist_uid:
+                exist_uid.append(UID)
                 unique_results.append(item)
+            else:
+                Device_Info.objects.filter(id=item['id']).delete()
+                username = CommonService.get_username(user_id)
+                LOGGER.info('{}删除重复uid{}'.format(username, UID))
 
         # 分页操作
         dv_list = unique_results[(page - 1) * line:page * line]