Ver Fonte

fix key error bucket store day

chenjunkai há 6 anos atrás
pai
commit
b255c996bf
1 ficheiros alterados com 16 adições e 18 exclusões
  1. 16 18
      Controller/CloudVod.py

+ 16 - 18
Controller/CloudVod.py

@@ -11,24 +11,22 @@
 @file: CloudVod.py
 @file: CloudVod.py
 @Contact: chanjunkai@163.com
 @Contact: chanjunkai@163.com
 """
 """
-import datetime
 import json
 import json
-import time
 import math
 import math
+import time
+import urllib
 
 
 import oss2
 import oss2
 import paypalrestsdk
 import paypalrestsdk
 from aliyunsdkcore import client
 from aliyunsdkcore import client
 from aliyunsdksts.request.v20150401 import AssumeRoleRequest
 from aliyunsdksts.request.v20150401 import AssumeRoleRequest
 from django.http import JsonResponse
 from django.http import JsonResponse
-from django.utils import timezone
 from django.utils.decorators import method_decorator
 from django.utils.decorators import method_decorator
 from django.views.decorators.csrf import csrf_exempt
 from django.views.decorators.csrf import csrf_exempt
 from django.views.generic.base import View
 from django.views.generic.base import View
-import urllib
 
 
 from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, SERVER_DOMAIN
 from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, SERVER_DOMAIN
-from Model.models import Device_Meal, Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket
+from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket
 from Object.ResponseObject import ResponseObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
 from Object.UidTokenObject import UidTokenObject
 from Object.UidTokenObject import UidTokenObject
@@ -119,12 +117,13 @@ class CloudVodView(View):
         if not did or not channel or not rank:
         if not did or not channel or not rank:
             return response.json(444, 'did,channel,rank')
             return response.json(444, 'did,channel,rank')
         smqs = Store_Meal.objects.filter(id=rank).values("currency", "price", "content", "day", "bucket__storeDay")
         smqs = Store_Meal.objects.filter(id=rank).values("currency", "price", "content", "day", "bucket__storeDay")
+        if not smqs.exists():
+            return response.json(10, '套餐不存在')
         currency = smqs[0]['currency']
         currency = smqs[0]['currency']
         price = smqs[0]['price']
         price = smqs[0]['price']
         content = smqs[0]['content']
         content = smqs[0]['content']
         day = smqs[0]['day']
         day = smqs[0]['day']
-        if not smqs.exists():
-            return response.json(10, '套餐不存在')
+
         qs = Device_Info.objects.filter(userID_id=userID, id=did).values("UID")
         qs = Device_Info.objects.filter(userID_id=userID, id=did).values("UID")
         if not qs.exists():
         if not qs.exists():
             return response.json(13)
             return response.json(13)
@@ -188,7 +187,9 @@ class CloudVodView(View):
         channel = utko.channel
         channel = utko.channel
         print(channel)
         print(channel)
         print(UID)
         print(UID)
-        ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel, status=1).values('channel','bucket__bucket','bucket__endpoint','bucket__region','endTime')
+        ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel, status=1).values('channel', 'bucket__bucket',
+                                                                                    'bucket__endpoint',
+                                                                                    'bucket__region', 'endTime')
         if not ubqs.exists():
         if not ubqs.exists():
             res = {'code': 403}
             res = {'code': 403}
             return JsonResponse(status=200, data=res)
             return JsonResponse(status=200, data=res)
@@ -228,10 +229,7 @@ class CloudVodView(View):
             "Version": "1",
             "Version": "1",
             "Statement": [
             "Statement": [
                 {
                 {
-                    "Action": [
-                        "oss:PutObject",
-                        "oss:DeleteObject",
-                    ],
+                    "Action": ["oss:PutObject", "oss:DeleteObject", ],
                     "Resource": [Resource_access],
                     "Resource": [Resource_access],
                     "Effect": "Allow",
                     "Effect": "Allow",
                     "Condition": {
                     "Condition": {
@@ -258,8 +256,7 @@ class CloudVodView(View):
             'arn': token['AssumedRoleUser']['Arn'],
             'arn': token['AssumedRoleUser']['Arn'],
             'code': 0,
             'code': 0,
             'storage': storage,
             'storage': storage,
-            'ip': ip
-        }
+            'ip': ip}
         if oc_qs.exists():
         if oc_qs.exists():
             oc_qs.update(data=json.dumps(res), addTime=now_time_stamp)
             oc_qs.update(data=json.dumps(res), addTime=now_time_stamp)
         else:
         else:
@@ -342,7 +339,7 @@ class CloudVodView(View):
         rank_id = order_list[0]['rank_id']
         rank_id = order_list[0]['rank_id']
         UID = order_list[0]['UID']
         UID = order_list[0]['UID']
         channel = order_list[0]['channel']
         channel = order_list[0]['channel']
-        smqs = Store_Meal.objects.filter(id=rank_id).values("day", "bucket_id")
+        smqs = Store_Meal.objects.filter(id=rank_id).values("day", "bucket_id","bucket__storeDay")
         bucketId = smqs[0]['bucket_id']
         bucketId = smqs[0]['bucket_id']
         if not smqs.exists():
         if not smqs.exists():
             return response.json(0, '套餐已删除')
             return response.json(0, '套餐已删除')
@@ -429,20 +426,21 @@ class CloudVodView(View):
         if utko.flag is False:
         if utko.flag is False:
             return response.json(444, 'uidToken')
             return response.json(444, 'uidToken')
         if not uidToken or not storeTime or not sec:
         if not uidToken or not storeTime or not sec:
-            return response.json(444,'uidToken,time,sec')
+            return response.json(444, 'uidToken,time,sec')
         UID = utko.UID
         UID = utko.UID
         channel = utko.channel
         channel = utko.channel
         print(channel)
         print(channel)
         print(UID)
         print(UID)
         qs = UID_Bucket.objects.filter(uid=UID, channel=channel, status=1).values("channel", "bucket__storeDay",
         qs = UID_Bucket.objects.filter(uid=UID, channel=channel, status=1).values("channel", "bucket__storeDay",
-                                                                                   "bucket_id")
+                                                                                  "bucket_id")
         if not qs.exists():
         if not qs.exists():
             return response.json(10, '设备未购买')
             return response.json(10, '设备未购买')
         # nowTime = time.time()
         # nowTime = time.time()
         storeDay = qs[0]['bucket__storeDay']
         storeDay = qs[0]['bucket__storeDay']
         bucketID = qs[0]['bucket_id']
         bucketID = qs[0]['bucket_id']
         endTime = int(storeTime) + storeDay * 86400
         endTime = int(storeTime) + storeDay * 86400
-        VodHlsModel.objects.create(uid=UID, channel=channel, time=storeTime, endTime=endTime, bucket_id=bucketID, sec=sec)
+        VodHlsModel.objects.create(uid=UID, channel=channel, time=storeTime, endTime=endTime, bucket_id=bucketID,
+                                   sec=sec)
         return response.json(0)
         return response.json(0)
 
 
     def do_get_playlist(self, request_dict, userID, response):
     def do_get_playlist(self, request_dict, userID, response):