|
@@ -1,26 +1,28 @@
|
|
|
#!/usr/bin/env python3
|
|
|
# -*- coding: utf-8 -*-
|
|
|
+import calendar
|
|
|
import datetime
|
|
|
import hashlib
|
|
|
import time
|
|
|
import uuid
|
|
|
|
|
|
+import paypalrestsdk
|
|
|
import xlrd
|
|
|
import xlwt
|
|
|
-import calendar
|
|
|
-
|
|
|
from django.db import transaction, connection
|
|
|
-from django.utils.encoding import escape_uri_path
|
|
|
+from django.db.models import F, Sum, Count, Q
|
|
|
from django.http import HttpResponse, StreamingHttpResponse
|
|
|
+from django.utils.encoding import escape_uri_path
|
|
|
from django.views.generic.base import View
|
|
|
+
|
|
|
+from Ansjer.config import PAYPAL_CRD
|
|
|
+from Controller.Cron.CronTaskController import CronUpdateDataView
|
|
|
from Model.models import VodBucketModel, CDKcontextModel, Store_Meal, Order_Model, \
|
|
|
UID_Bucket, ExperienceContextModel, Lang, CloudLogModel, UidSetModel, Unused_Uid_Meal, \
|
|
|
Device_Info, DeviceTypeModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
-from django.db.models import F, Sum, Count
|
|
|
-from Controller.Cron.CronTaskController import CronUpdateDataView
|
|
|
|
|
|
|
|
|
class serveManagement(View):
|
|
@@ -98,9 +100,41 @@ class serveManagement(View):
|
|
|
return self.deviceAttritionAlert(request_dict, response, request)
|
|
|
elif operation == 'deactivationPackage': # 停用套餐
|
|
|
return self.deactivationPackage(request_dict, response)
|
|
|
+ elif operation == 'paypal-cycle-cancel': # 取消循环扣款
|
|
|
+ return self.paypal_cycle_cancel(request_dict, response)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def paypal_cycle_cancel(request_dict, response):
|
|
|
+ """
|
|
|
+ 取消云存循环扣款
|
|
|
+ """
|
|
|
+ order_id = request_dict.get('orderID', None)
|
|
|
+ if not order_id:
|
|
|
+ return response.json(444)
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=order_id)
|
|
|
+ order_qs = order_qs.filter(~Q(agreement_id='')).values("agreement_id")
|
|
|
+ if not order_qs.exists():
|
|
|
+ return response.json(800)
|
|
|
+ paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
+ agreement_id = order_qs[0]['agreement_id']
|
|
|
+ try:
|
|
|
+ now_time = int(time.time())
|
|
|
+ billing_agreement = paypalrestsdk.BillingAgreement.find(agreement_id)
|
|
|
+ if billing_agreement.state != 'Active':
|
|
|
+ Order_Model.objects.filter(agreement_id=agreement_id).update(agreement_id='', updTime=now_time)
|
|
|
+ return response.json(0)
|
|
|
+ cancel_note = {"note": "Canceling the agreement"}
|
|
|
+ if billing_agreement.cancel(cancel_note):
|
|
|
+ Order_Model.objects.filter(agreement_id=agreement_id).update(agreement_id='', updTime=now_time)
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(10052)
|
|
|
+ except Exception as e:
|
|
|
+ print(repr(e))
|
|
|
+ return response.json(10052)
|
|
|
+
|
|
|
def getVodBucketList(self, userID, request_dict, response):
|
|
|
# 查询存储桶数据
|
|
|
print('request_dict: ', request_dict)
|
|
@@ -653,7 +687,7 @@ class serveManagement(View):
|
|
|
|
|
|
order_ql = omqs.values("orderID", "UID", "userID__username", "userID__NickName", "channel", "desc", "price",
|
|
|
"refunded_amount", "currency", "addTime", "updTime", "paypal", "payType",
|
|
|
- "rank__day", "rank__price", "status", "order_type")
|
|
|
+ "rank__day", "rank__price", "status", "order_type", "paymentID", "trade_no")
|
|
|
order_ql = order_ql.order_by('-addTime') # 根据CDK创建时间降序排序
|
|
|
order_ql = order_ql[(page - 1) * line:page * line]
|
|
|
for order in order_ql:
|
|
@@ -677,13 +711,17 @@ class serveManagement(View):
|
|
|
'order_type': order['order_type'],
|
|
|
}
|
|
|
# 添加设备套餐使用状态
|
|
|
- uid = order['UID']
|
|
|
- uid_bucket = UID_Bucket.objects.filter(uid=uid).values('use_status')
|
|
|
+ uid_bucket = UID_Bucket.objects.filter(uid=order['UID']).values('use_status')
|
|
|
user_status = uid_bucket[0]['use_status'] if uid_bucket.exists() else ''
|
|
|
+ # 判断订单是否已过期
|
|
|
if user_status != '':
|
|
|
data['user_status'] = user_status
|
|
|
else:
|
|
|
data['user_status'] = 2
|
|
|
+ # 添加PayPal交易号字段
|
|
|
+ data['trade_no'] = 'N/A'
|
|
|
+ if data['payType'] == 1:
|
|
|
+ data['trade_no'] = order['trade_no'] if order['trade_no'] else 'N/A'
|
|
|
order_list.append(data)
|
|
|
return response.json(
|
|
|
0, {'list': order_list, 'total': count})
|
|
@@ -993,18 +1031,10 @@ class serveManagement(View):
|
|
|
uid_bucket_qs = uid_bucket_qs.order_by('-addTime')[(page - 1) * line:page * line]
|
|
|
|
|
|
for uid_bucket in uid_bucket_qs:
|
|
|
- for order in order_qs.filter(
|
|
|
- uid_bucket_id=uid_bucket.id).values(
|
|
|
- 'uid_bucket_id',
|
|
|
- 'desc',
|
|
|
- 'userID__userID',
|
|
|
- 'UID',
|
|
|
- 'price',
|
|
|
- 'payType',
|
|
|
- 'userID__username',
|
|
|
- 'userID__phone',
|
|
|
- 'userID__userEmail',
|
|
|
- 'userID__data_joined'):
|
|
|
+ for order in order_qs.filter(uid_bucket_id=uid_bucket.id) \
|
|
|
+ .values('orderID', 'uid_bucket_id', 'desc', 'userID__userID',
|
|
|
+ 'UID', 'price', 'payType', 'userID__username', 'userID__phone',
|
|
|
+ 'userID__userEmail', 'userID__data_joined', 'agreement_id'):
|
|
|
# 套餐到期时间累加未使用套餐
|
|
|
unused_qs = Unused_Uid_Meal.objects.filter(uid=uid_bucket.uid).values('num', 'expire')
|
|
|
if unused_qs.exists():
|
|
@@ -1015,11 +1045,12 @@ class serveManagement(View):
|
|
|
endTime = time.strftime("%Y--%m--%d %H:%M:%S", time.localtime(endTime))
|
|
|
else:
|
|
|
endTime = time.strftime("%Y--%m--%d %H:%M:%S", time.localtime(uid_bucket.endTime))
|
|
|
-
|
|
|
uid = uid_bucket.uid.upper()
|
|
|
data = {
|
|
|
'id': uid_bucket.id,
|
|
|
+ 'orderId': order['orderID'],
|
|
|
'uid': uid,
|
|
|
+ 'agreementId': order['agreement_id'] if order['agreement_id'] else 'N/A',
|
|
|
'channel': uid_bucket.channel,
|
|
|
'status': uid_bucket.status,
|
|
|
'endTime': endTime,
|