|
@@ -18,7 +18,7 @@ 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
|
|
|
|
|
|
-from Model.models import Store_Meal, VodBucketModel
|
|
|
|
|
|
+from Model.models import Store_Meal, VodBucketModel, Pay_Type
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
@@ -79,7 +79,7 @@ class MealManage(View):
|
|
day = request_dict.get('day', None)
|
|
day = request_dict.get('day', None)
|
|
currency = request_dict.get('currency', None)
|
|
currency = request_dict.get('currency', None)
|
|
bucketID = request_dict.get('bucketID', None)
|
|
bucketID = request_dict.get('bucketID', None)
|
|
- type = request_dict.get('type', None)
|
|
|
|
|
|
+ paytype = request_dict.get('paytype', None)
|
|
if not title or not id or not price or not day or not content:
|
|
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')
|
|
own_perm = ModelService.check_perm(userID=userID, permID=40)
|
|
own_perm = ModelService.check_perm(userID=userID, permID=40)
|
|
@@ -90,8 +90,11 @@ class MealManage(View):
|
|
if Store_Meal.objects.filter(id=id):
|
|
if Store_Meal.objects.filter(id=id):
|
|
return response.json(10, '已存在')
|
|
return response.json(10, '已存在')
|
|
store_meal = Store_Meal(id=id, title=title, price=price, content=content, day=day, bucket_id=bucketID,
|
|
store_meal = Store_Meal(id=id, title=title, price=price, content=content, day=day, bucket_id=bucketID,
|
|
- currency=currency, type=type)
|
|
|
|
|
|
+ currency=currency)
|
|
store_meal.save()
|
|
store_meal.save()
|
|
|
|
+ paytype = paytype.split(',')
|
|
|
|
+ if len(paytype) > 0:
|
|
|
|
+ Store_Meal.objects.get(id=id).pay_type.set(paytype)
|
|
except Exception:
|
|
except Exception:
|
|
errorInfo = traceback.format_exc()
|
|
errorInfo = traceback.format_exc()
|
|
print(errorInfo)
|
|
print(errorInfo)
|
|
@@ -116,13 +119,26 @@ class MealManage(View):
|
|
line = int(request_dict.get('line', None))
|
|
line = int(request_dict.get('line', None))
|
|
if page is None or line is None:
|
|
if page is None or line is None:
|
|
return response.json(444)
|
|
return response.json(444)
|
|
- qs = Store_Meal.objects.values("id", "title", "price", "content", "day", "add_time", "update_time", "currency",
|
|
|
|
- "type", "bucket_id", "bucket__bucket", "commodity_type", "commodity_code",
|
|
|
|
|
|
+ qs = Store_Meal.objects.values("id", "title", "price", "content", "day", "add_time", "update_time", "currency"
|
|
|
|
+ , "bucket_id", "bucket__bucket", "bucket__area", "commodity_type", "commodity_code",
|
|
"bucket__storeDay")
|
|
"bucket__storeDay")
|
|
res = {}
|
|
res = {}
|
|
if qs.exists():
|
|
if qs.exists():
|
|
- res['count'] = qs.count()
|
|
|
|
- res['data'] = CommonService.qs_to_list(qs[(page - 1) * line:page * line])
|
|
|
|
|
|
+ ql = list(qs)
|
|
|
|
+ from operator import itemgetter
|
|
|
|
+ from itertools import groupby
|
|
|
|
+ ql.sort(key=itemgetter('bucket__area'))
|
|
|
|
+ ql=CommonService.qs_to_list(ql[(page - 1) * line:page * line])
|
|
|
|
+ for area, items in groupby(ql, key=itemgetter('bucket__area')):
|
|
|
|
+ items_list = list(items)
|
|
|
|
+ for key, val in enumerate(items_list):
|
|
|
|
+ pay_types = Pay_Type.objects.filter(store_meal=items_list[key]['id']).values("id", "payment")
|
|
|
|
+ items_list[key]['pay_type'] = list(pay_types)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ res['count'] = len(ql)
|
|
|
|
+ res['data'] = items_list
|
|
|
|
+
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
|
|
|
|
def update(self, request_dict, userID, response):
|
|
def update(self, request_dict, userID, response):
|
|
@@ -151,12 +167,17 @@ class MealManage(View):
|
|
store_meal.commodity_type = commodity_type
|
|
store_meal.commodity_type = commodity_type
|
|
store_meal.commodity_code = commodity_code
|
|
store_meal.commodity_code = commodity_code
|
|
store_meal.day = day
|
|
store_meal.day = day
|
|
- store_meal.type = type
|
|
|
|
if bucketID:
|
|
if bucketID:
|
|
store_meal.bucket_id = bucketID
|
|
store_meal.bucket_id = bucketID
|
|
if currency:
|
|
if currency:
|
|
store_meal.currency = currency
|
|
store_meal.currency = currency
|
|
store_meal.save()
|
|
store_meal.save()
|
|
|
|
+ type = type.split(',')
|
|
|
|
+ if len(type) > 0:
|
|
|
|
+ Store_Meal.objects.get(id=id).pay_type.set(type)
|
|
|
|
+ else:
|
|
|
|
+ Store_Meal.objects.get(id=id).pay_type.clear()
|
|
|
|
+
|
|
except Exception:
|
|
except Exception:
|
|
errorInfo = traceback.format_exc()
|
|
errorInfo = traceback.format_exc()
|
|
print(errorInfo)
|
|
print(errorInfo)
|