chenjunkai преди 6 години
родител
ревизия
f83a669d60
променени са 1 файла, в които са добавени 21 реда и са изтрити 18 реда
  1. 21 18
      Controller/MealManage.py

+ 21 - 18
Controller/MealManage.py

@@ -1,5 +1,5 @@
-#!/usr/bin/env python3  
-# -*- coding: utf-8 -*-  
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
 """
 @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
 @AUTHOR: ASJRD018
@@ -16,11 +16,12 @@ from django.utils.decorators import method_decorator
 from django.views.decorators.csrf import csrf_exempt
 from Service.ModelService import ModelService
 from Service.CommonService import CommonService
-from Model.models import Store_Meal,VodBucketModel
+from Model.models import Store_Meal, VodBucketModel
 import traceback
 from django.utils import timezone
 from Object.TokenObject import TokenObject
 from Object.ResponseObject import ResponseObject
+
 '''
 http://192.168.136.40:8077/meal/manage?operation=add&token=local&title=套餐A&price=$199&content=存7天&day=7&id=1
 http://192.168.136.45:8077/meal/manage?operation=update&token=test&id=1&title=套餐A&price=$199&content=存3天&day=7
@@ -78,12 +79,12 @@ class MealManage(View):
         price = request_dict.get('price', None)
         content = request_dict.get('content', None)
         day = request_dict.get('day', None)
-        bucketID = request_dict.get('bucketID',None)
+        bucketID = request_dict.get('bucketID', None)
         if not title or not id or not price or not day or not content:
-            return response.json(444,'title,id,price,content,day,bucketID')
+            return response.json(444, 'title,id,price,content,day,bucketID')
         try:
-            bucketQs= VodBucketModel.objects.filter(id=bucketID)
-            store_meal = Store_Meal(id=id,title=title,price=price,content=content,day=day,bucket_id=bucketID)
+            bucketQs = VodBucketModel.objects.filter(id=bucketID)
+            store_meal = Store_Meal(id=id, title=title, price=price, content=content, day=day, bucket_id=bucketID)
             store_meal.save()
         except Exception:
             errorInfo = traceback.format_exc()
@@ -92,8 +93,8 @@ class MealManage(View):
         else:
             if store_meal.id:
                 return response.json(0, {
-                    'bucket__bucket':bucketQs[0].bucket,
-                    'bucket__storeDay':bucketQs[0].storeDay,
+                    'bucket__bucket': bucketQs[0].bucket,
+                    'bucket__storeDay': bucketQs[0].storeDay,
                     'id': id,
                     'title': title,
                     'price': price,
@@ -107,14 +108,13 @@ class MealManage(View):
         line = int(request_dict.get('line', None))
         if page is None or line is None:
             return response.json(444)
-        queryset = Store_Meal.objects.all()
-        if queryset.exists():
-            count = queryset.count()
-            res = queryset[(page - 1) * line:page * line]
-            send_json = CommonService.qs_to_dict(res)
-            send_json['count'] = count
-            return response.json(0, send_json)
-        return response.json(0)
+        qs = Store_Meal.objects.values("id", "title", "price", "content", "day", "add_time", "update_time", "bucket_id",
+                                       "bucket__bucket")
+        res = {}
+        if qs.exists():
+            res['count'] = qs.count()
+            res['data'] = CommonService.qs_to_list(qs[(page - 1) * line:page * line])
+        return response.json(0, res)
 
     def update(self, request_dict, userID, response):
         own_perm = ModelService.check_permission(userID=userID, permID=30)
@@ -196,6 +196,8 @@ class MealManage(View):
 用户获取全部套餐信息
 http://192.168.136.40:8077/meal/list?token=local
 '''
+
+
 class MealView(View):
     @method_decorator(csrf_exempt)
     def dispatch(self, *args, **kwargs):
@@ -229,7 +231,8 @@ class MealView(View):
             return response.json(414)
 
     def do_query_list(self, response):
-        qs = Store_Meal.objects.all().values("id","title","content","price","day","bucket__storeDay","bucket__bucket")
+        qs = Store_Meal.objects.all().values("id", "title", "content", "price", "day", "bucket__storeDay",
+                                             "bucket__bucket")
         if qs.exists():
             # res = CommonService.qs_to_list(qs)
             return response.json(0, list(qs))