Преглед на файлове

优化周期扣款接口

peng преди 1 година
родител
ревизия
e9a32ebf0a
променени са 1 файла, в които са добавени 40 реда и са изтрити 38 реда
  1. 40 38
      Controller/PaymentCycle.py

+ 40 - 38
Controller/PaymentCycle.py

@@ -467,60 +467,62 @@ class PaypalCycleNotify(View):
             if not self.config_match_region(uid, country_id):
                 return HttpResponse('Fail', status=500)
 
+            orderID = CommonService.createOrderID()
             UID = order_qs[0]['UID']
-            if order_qs[0]['addTime'] + 9200 > nowTime:  # 避免续费订单重复支付
-                PAY_LOGGER.info('{} PayPal周期扣款失败---续费订单已创建'.format(UID))
-                return HttpResponse('success')
-
-            desc = order_qs[0]['desc']
-            pay_type = order_qs[0]['payType']
             isSelectDiscounts = order_qs[0]['isSelectDiscounts']
-            commodity_code = order_qs[0]['commodity_code']
-            commodity_type = order_qs[0]['commodity_type']
-            plan_id = order_qs[0]['plan_id']
+            coupon_id = order_qs[0]['coupon_id']
             userid = order_qs[0]['userID__userID']
             username = order_qs[0]['userID__username']
             channel = order_qs[0]['channel']
             rank = order_qs[0]['rank']
-            order_type = order_qs[0]['order_type']
-            coupon_id = order_qs[0]['coupon_id']
             store_meal_qs = Store_Meal.objects.filter(id=rank).values("bucket_id", "expire", "is_ai")
             if not store_meal_qs.exists():
                 PAY_LOGGER.info('{} PayPal周期扣款失败---套餐数据不存在'.format(UID))
                 return HttpResponse('fail', status=500)
-
-            bucketId = store_meal_qs[0]['bucket_id']
             expire = store_meal_qs[0]['expire']
             is_ai = store_meal_qs[0]['is_ai']
+            bucketId = store_meal_qs[0]['bucket_id']
+
+            # PayPal周期扣款首次扣款
+            if billing_agreement.agreement_details.cycles_completed == '0':
+                if order_qs[0]['create_vod']:
+                    order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime)
+                else:
+                    # 是否有促销
+                    promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
+                                                                  endTime__gte=nowTime).values('id', 'ruleConfig')
+                    if promotion.exists():
+                        promotion_rule_id = promotion[0]['id']
+                        expire = expire * 2
+                    else:
+                        promotion_rule_id = ''
+                    if isSelectDiscounts:
+                        expire = expire * 2
+                    uid_bucket_id = self.create_vod(UID, expire, is_ai, nowTime, channel, bucketId, orderID,
+                                                    userid, username)
+                    order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime,
+                                    uid_bucket_id=uid_bucket_id, create_vod=1,
+                                    promotion_rule_id=promotion_rule_id, agreement_id=agreement_id)
+                    # 核销coupon
+                    if coupon_id:
+                        CouponModel.objects.filter(id=coupon_id).update(use_status=2, update_time=nowTime)
+                PAY_LOGGER.info('{} PayPal周期扣款首次扣款成功'.format(UID))
+                return HttpResponse('success')
+
+            if order_qs[0]['addTime'] + 9200 > nowTime:  # 避免续费订单重复支付
+                PAY_LOGGER.info('{} PayPal周期扣款失败---续费订单已创建'.format(UID))
+                return HttpResponse('success')
+
+            desc = order_qs[0]['desc']
+            pay_type = order_qs[0]['payType']
+            commodity_code = order_qs[0]['commodity_code']
+            commodity_type = order_qs[0]['commodity_type']
+            plan_id = order_qs[0]['plan_id']
+            order_type = order_qs[0]['order_type']
             endTime = CommonService.calcMonthLater(expire)
             use_flag = True
-            orderID = CommonService.createOrderID()
             ubqs = UID_Bucket.objects.filter(uid=UID).values("id", "endTime", "use_status")
-
             with transaction.atomic():
-                # PayPal周期扣款首次扣款
-                if billing_agreement.agreement_details.cycles_completed == '0':
-                    if order_qs[0]['create_vod']:
-                        order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime)
-                    else:
-                        # 是否有促销
-                        promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
-                                                                      endTime__gte=nowTime).values('id', 'ruleConfig')
-                        if promotion.exists():
-                            promotion_rule_id = promotion[0]['id']
-                            expire = expire * 2
-                        if isSelectDiscounts:
-                            expire = expire * 2
-                        uid_bucket_id = self.create_vod(UID, expire, is_ai, nowTime, channel, bucketId, orderID,
-                                                        userid, username)
-                        order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime,
-                                        uid_bucket_id=uid_bucket_id, create_vod=1,
-                                        promotion_rule_id=promotion_rule_id, agreement_id=agreement_id)
-                        # 核销coupon
-                        if coupon_id:
-                            CouponModel.objects.filter(id=coupon_id).update(use_status=2, update_time=nowTime)
-                    PAY_LOGGER.info('{} PayPal周期扣款首次扣款成功'.format(UID))
-                    return HttpResponse('success')
                 if ubqs.exists():
                     ubq = ubqs[0]
                     uid_bucket_id = ubq['id']