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

创建/编辑场景只下发最后一个任务,优化PayPal判断用户地区是否跟服务器地区匹配函数

locky 2 жил өмнө
parent
commit
8597c254e6

+ 20 - 4
Controller/PaymentCycle.py

@@ -400,13 +400,15 @@ class PaypalCycleNotify(View):
                 paymentID = paypal_body.get('parent_payment')
                 if paymentID and paypal_transaction_id:
                     # 查询客户地区信息,地区跟服务器配置不匹配,返回500
-                    order_qs = Order_Model.objects.filter(paymentID=paymentID).values('userID__region_country')
+                    order_qs = Order_Model.objects.filter(paymentID=paymentID).values('UID', 'userID__region_country')
                     if not order_qs.exists():
                         PAY_LOGGER.info('PayPal周期扣款失败---根据paymentID查询订单数据不存在')
                         return HttpResponse('Fail', status=500)
 
+                    # 判断用户地区是否跟服务器地区匹配
+                    uid = order_qs[0]['UID']
                     country_id = order_qs[0]['userID__region_country']
-                    if not self.config_match_region(country_id):
+                    if not self.config_match_region(uid, country_id):
                         return HttpResponse('Fail', status=500)
 
                     order_qs.update(status=1, updTime=nowTime, trade_no=paypal_transaction_id)
@@ -440,8 +442,10 @@ class PaypalCycleNotify(View):
                 PAY_LOGGER.info('PayPal周期扣款失败---根据order_id查询订单数据不存在')
                 return HttpResponse('fail', status=500)
 
+            # 判断用户地区是否跟服务器地区匹配
+            uid = order_qs[0]['UID']
             country_id = order_qs[0]['userID__region_country']
-            if not self.config_match_region(country_id):
+            if not self.config_match_region(uid, country_id):
                 return HttpResponse('Fail', status=500)
 
             UID = order_qs[0]['UID']
@@ -579,9 +583,21 @@ class PaypalCycleNotify(View):
             return HttpResponse('fail', status=500)
 
     @staticmethod
-    def config_match_region(country_id):
+    def config_match_region(uid, country_id):
+        """
+        判断用户地区是否跟服务器地区匹配
+        @param uid: uid
+        @param country_id: 国家表id
+        @return: bool
+        """
         country_qs = CountryModel.objects.filter(id=country_id).values('region_id')
+        # 不确定用户地区信息,默认美洲
+        if not country_qs.exists() and CONFIG_INFO == CONFIG_EUR:
+            PAY_LOGGER.info('PayPal周期扣款失败---不确定地区的用户请求欧洲服,uid:{},country_id:{}'.format(uid, country_id))
+            return False
+
         region_id = country_qs[0]['region_id']
+        PAY_LOGGER.info('uid{}的用户地区信息: country_id:{}, region_id:{}'.format(uid, country_id, region_id))
         if (CONFIG_INFO == CONFIG_US and region_id == 4) or (CONFIG_INFO == CONFIG_EUR and region_id != 4):
             PAY_LOGGER.info('PayPal周期扣款失败---服务器跟用户地区不匹配')
             return False

+ 29 - 29
Controller/SensorGateway/SmartSceneController.py

@@ -981,35 +981,35 @@ class SmartSceneView(View):
         @param tasks_list: app任务列表
         @return: task_list
         """
-        task_list = []
-        # 下发最后一个任务;如果最后一个任务有延时,则下发最后两个任务
-        # task_temp = tasks_list[-1:]
-        for task in tasks_list:
-            sensor_type = int(task['device_type'])
-            task_temp = {
-                'sensor_type': sensor_type
-            }
-            if sensor_type != -1:  # 不为-1时需要其他数据
-                task_temp['sensor_action'] = int(task['event_type'])
-
-                # 延时
-                if 'delay_time' in task and task['delay_time'] != 0:
-                    task_temp['sensor_delay'] = task['delay_time']
-
-                # 子设备返回长地址
-                sub_device_id = task.get('subDeviceId', None)
-                if sub_device_id:
-                    sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('ieee_addr').first()
-                    task_temp['sensor_ieee_addr'] = sub_device_qs['ieee_addr']
-                # 网关添加报警类型数据
-                else:
-                    task_temp['voice_type'] = task.get('voice_type')
-                    task_temp['voice_id'] = task.get('voice_id')
-                    task_temp['count'] = task.get('count')
-                    task_temp['delay_time'] = task.get('delay_time')
-                    task_temp['duration'] = task.get('duration')
-                    task_temp['value_type'] = task.get('value_type')
-            task_list.append(task_temp)
+        # 只下发最后一个任务
+        last_task = tasks_list[-1:]
+        sensor_type = int(last_task['device_type'])
+        task_temp = {
+            'sensor_type': sensor_type,
+            'sensor_delay': 0
+        }
+
+        # 延时
+        if 'delay_time' in last_task and last_task['delay_time'] != 0:
+            task_temp['sensor_delay'] = last_task['delay_time']
+
+        if sensor_type != -1:  # 不为-1时需要其他数据
+            task_temp['sensor_action'] = int(last_task['event_type'])
+
+            # 子设备返回长地址
+            sub_device_id = last_task.get('subDeviceId', None)
+            if sub_device_id:
+                sub_device_qs = GatewaySubDevice.objects.filter(id=sub_device_id).values('ieee_addr').first()
+                task_temp['sensor_ieee_addr'] = sub_device_qs['ieee_addr']
+            # 网关添加报警类型数据
+            else:
+                task_temp['voice_type'] = last_task.get('voice_type')
+                task_temp['voice_id'] = last_task.get('voice_id')
+                task_temp['count'] = last_task.get('count')
+                task_temp['delay_time'] = last_task.get('delay_time')
+                task_temp['duration'] = last_task.get('duration')
+                task_temp['value_type'] = last_task.get('value_type')
+        task_list = [task_temp]
         return task_list