Sfoglia il codice sorgente

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

lang 3 anni fa
parent
commit
654ab9fa57
3 ha cambiato i file con 69 aggiunte e 38 eliminazioni
  1. 59 34
      Controller/DetectControllerV2.py
  2. 9 3
      Controller/PaymentCycle.py
  3. 1 1
      Model/models.py

+ 59 - 34
Controller/DetectControllerV2.py

@@ -89,6 +89,7 @@ class DetectControllerViewV2(View):
         tz = request_dict.get('tz', '0')
         company_secrete = request_dict.get('company_secrete', None)
         region = request_dict.get('region', None)  # app必须传:2:国内 1:国外
+        electricity_status = request_dict.get('electricity_status', None)
         if not region:
             return response.json(444, 'region')
         region = int(region)
@@ -101,8 +102,8 @@ class DetectControllerViewV2(View):
             tz = tz.replace("GMT", "")
         detect_group = request_dict.get('detect_group', None)
         interval = request_dict.get('interval', None)
-        if not status:
-            return response.json(444, 'status')
+        if not status and not electricity_status:
+            return response.json(444, 'status and electricity_status')
         if not company_secrete:
             return response.json(444, 'company_secrete')
         company = CompanyModel.objects.filter(secret=company_secrete)
@@ -114,41 +115,44 @@ class DetectControllerViewV2(View):
         # 判断推送类型对应key是否存在
         print('push_type:', push_type)
 
-        if push_type == '0':
-            if appBundleId not in APNS_CONFIG.keys():
-                return response.json(904)
-        elif push_type == '1':
-            if appBundleId not in FCM_CONFIG.keys():
-                return response.json(904)
-        elif push_type == '2':
-            if appBundleId not in JPUSH_CONFIG.keys():
-                return response.json(904)
-        else:
-            return response.json(173)
-        dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
-        status = int(status)
-        # 获取用户区域
-        # ip = self.ip
-        # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
-        # area = ipInfo['country_name']
-        # if area == 'China':
-        #     DETECT_PUSH_DOMAIN_V2 = 'cn.push.dvema.com'
-        # else:
-        #     DETECT_PUSH_DOMAIN_V2 = 'en.push.dvema.com'
-
-        nowTime = int(time.time())
-        if dvqs.exists():
+        try:
+            if push_type == '0':
+                if appBundleId not in APNS_CONFIG.keys():
+                    return response.json(904)
+            elif push_type == '1':
+                if appBundleId not in FCM_CONFIG.keys():
+                    return response.json(904)
+            elif push_type == '2':
+                if appBundleId not in JPUSH_CONFIG.keys():
+                    return response.json(904)
+            else:
+                return response.json(173)
+            dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
+            # 获取用户区域
+            # ip = self.ip
+            # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
+            # area = ipInfo['country_name']
+            # if area == 'China':
+            #     DETECT_PUSH_DOMAIN_V2 = 'cn.push.dvema.com'
+            # else:
+            #     DETECT_PUSH_DOMAIN_V2 = 'en.push.dvema.com'
+
+            nowTime = int(time.time())
+            if not dvqs.exists():
+                return response.json(14)
             # 修改状态
-            dvqs.update(NotificationMode=status)
+            if status:
+                dvqs.update(NotificationMode=int(status))
             uid_set_qs = UidSetModel.objects.filter(uid=uid)
             # uid配置信息是否存在
 
             if uid_set_qs.exists():
                 uid_set_id = uid_set_qs[0].id
                 qs_data = {
-                    'detect_status': status,
                     'updTime': nowTime,
                 }
+                if status:
+                    qs_data['detect_status'] = int(status)
                 if interval:
                     qs_data['detect_interval'] = int(interval)
                 if detect_group:
@@ -161,8 +165,9 @@ class DetectControllerViewV2(View):
                     'uid': uid,
                     'addTime': nowTime,
                     'updTime': nowTime,
-                    'detect_status': status,
                 }
+                if status:
+                    qs_data['detect_status'] = int(status)
                 if interval:
                     qs_data['detect_interval'] = int(interval)
                 if detect_group:
@@ -172,12 +177,30 @@ class DetectControllerViewV2(View):
 
                 uid_set_id = uid_set_qs.id
 
-            if status == 0:
-                UidPushModel.objects.filter(uid_set__uid=uid).delete()
+            # 初始化UidPushModel推送表
+            if electricity_status:
+                uid_push_create_dict = {
+                    'uid_set_id': uid_set_id,
+                    'userID_id': userID,
+                    'appBundleId': appBundleId,
+                    'app_type': app_type,
+                    'push_type': push_type,
+                    'token_val': token_val,
+                    'm_code': m_code,
+                    'addTime': nowTime,
+                    'updTime': nowTime,
+                    'lang': lang,
+                    'tz': tz
+                }
+                # 绑定设备推送
+                UidPushModel.objects.create(**uid_push_create_dict)
+                return response.json(0)
+
+            if status == '0':
                 # 状态为0的时候删除redis缓存数据
                 self.do_delete_redis(uid)
                 return response.json(0)
-            elif status == 1:
+            elif status == '1':
                 uid_push_qs = UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid)
 
                 if uid_push_qs.exists():
@@ -230,8 +253,10 @@ class DetectControllerViewV2(View):
                 detectUrls = "{DETECT_PUSH_DOMAIN_V2}notifyV2/push?etk={etk}&company_secrete={company_secrete}&region={region}". \
                     format(etk=etk, company_secrete=company_secrete, DETECT_PUSH_DOMAIN_V2=urls, region=region)
                 return response.json(0, {'detectUrl': detectUrl, 'detectUrls': detectUrls})
-        else:
-            return response.json(14)
+            else:
+                return response.json(173)
+        except Exception as e:
+            return response.json(500, repr(e))
 
     def do_delete_redis(self, uid, detect_interval=0):
         keyPattern = '{uid}*'.format(uid=uid)

+ 9 - 3
Controller/PaymentCycle.py

@@ -310,6 +310,7 @@ class PaypalCycleNotify(View):
 
                     # 订阅续费订单(如果完成周期数`不是0, 则说明是续费订单,)
                     if billing_agreement.agreement_details.cycles_completed == '0':
+                        logger.info('订阅续费订单完成周期数==0,结束')
                         return HttpResponse('success')
                     oldOrderID = billing_agreement.description
                     order_qs = Order_Model.objects.filter(orderID=oldOrderID, status=1)
@@ -319,9 +320,12 @@ class PaypalCycleNotify(View):
                                                  "userID__userID","uid_bucket_id",
                                                  "userID__username",'plan_id','addTime','desc','payType','currency','commodity_type','updTime')
                     nowTime = int(time.time())
-                    if order_list[0]['userID__userID'] + 9200 > nowTime:  #避免续费订单重复支付
+                    if order_list[0]['addTime'] + 9200 > nowTime:  #避免续费订单重复支付
+                        logger.info('-----------------------paypal重复异步回调')
                         return HttpResponse('success')
 
+                    logger.info('-----走入订阅过程-------------')
+
                     userid = order_list[0]['userID__userID']
                     username = order_list[0]['userID__username']
                     UID = order_list[0]['UID']
@@ -426,6 +430,8 @@ class PaypalCycleNotify(View):
                         return HttpResponse('success')
                 except Exception as e:
                     print(e)
+                    logger.info('-----------------------paypal异步回调失败')
+                    logger.info(e)
                     return HttpResponse('fail')
         return HttpResponse('fail')
 
@@ -433,10 +439,10 @@ class PaypalCycleNotify(View):
     def do_test(self, request_dict, request, response):
         paypalrestsdk.configure(PAYPAL_CRD)
         billing_agreement = paypalrestsdk.BillingAgreement
-        billing_agreement = billing_agreement.find("I-HT38K76XPMGJ")
+        billing_agreement = billing_agreement.find("I-17SRPP7TS71U")
         print("Got Billing Agreement Details for Billing Agreement[%s]" % (
             billing_agreement.id))
-        exit()
+        exit(billing_agreement)
         #normal_pay
         # json_str = '{"id":"WH-8SU832847J141682K-0FF265943E8692615","event_version":"1.0","create_time":"2022-01-10T06:31:49.863Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"Payment completed for $ 0.02 USD","resource":{"amount":{"total":"0.02","currency":"USD","details":{"subtotal":"0.02"}},"payment_mode":"INSTANT_TRANSFER","create_time":"2022-01-10T06:31:45Z","transaction_fee":{"currency":"USD","value":"0.02"},"parent_payment":"PAYID-MHN5E5Y1RH70069CT417990V","update_time":"2022-01-10T06:31:45Z","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","application_context":{"related_qualifiers":[{"id":"0FJ93448LU7282046","type":"CART"}]},"protection_eligibility":"ELIGIBLE","links":[{"method":"GET","rel":"self","href":"https://api.sandbox.paypal.com/v1/payments/sale/6N498138TH641260G"},{"method":"POST","rel":"refund","href":"https://api.sandbox.paypal.com/v1/payments/sale/6N498138TH641260G/refund"},{"method":"GET","rel":"parent_payment","href":"https://api.sandbox.paypal.com/v1/payments/payment/PAYID-MHN5E5Y1RH70069CT417990V"}],"id":"6N498138TH641260G","state":"completed","invoice_number":""},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-8SU832847J141682K-0FF265943E8692615","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-8SU832847J141682K-0FF265943E8692615/resend","rel":"resend","method":"POST"}]}'
         json_agreement_str = '{"id":"WH-9BE23393R5338163R-48P08088YL173821A","event_version":"1.0","create_time":"2022-01-10T10:27:42.925Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"Payment completed for $ 0.02 USD","resource":{"billing_agreement_id":"I-K8PCK2NJC6N6","amount":{"total":"0.02","currency":"USD","details":{"subtotal":"0.02"}},"payment_mode":"INSTANT_TRANSFER","update_time":"2022-01-10T10:27:19Z","create_time":"2022-01-10T10:27:19Z","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","transaction_fee":{"currency":"USD","value":"0.02"},"protection_eligibility":"ELIGIBLE","links":[{"method":"GET","rel":"self","href":"https://api.sandbox.paypal.com/v1/payments/sale/4H259512Y67055105"},{"method":"POST","rel":"refund","href":"https://api.sandbox.paypal.com/v1/payments/sale/4H259512Y67055105/refund"}],"id":"4H259512Y67055105","state":"completed","invoice_number":""},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9BE23393R5338163R-48P08088YL173821A","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-9BE23393R5338163R-48P08088YL173821A/resend","rel":"resend","method":"POST"}]}'

+ 1 - 1
Model/models.py

@@ -315,7 +315,7 @@ class Access_Log(models.Model):
 
 
 class Equipment_Info(models.Model):
-    id = models.AutoField(primary_key=True, verbose_name=u'自增标记ID')
+    id = models.BigAutoField(primary_key=True, verbose_name=u'自增标记ID')
     devUid = models.CharField(default='', db_index=True, blank=True, max_length=32, verbose_name=u'设备ID')
     devNickName = models.CharField(blank=True, max_length=32, default='', verbose_name=u'设备昵称')
     Channel = models.IntegerField(default=1, blank=True, verbose_name=u'设备通道')