A menu management application built with Django, featuring: - Dish management with cover images - Order system with party dates and participants - REST API with Django REST Framework - Bootstrap-styled frontend Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
907 B
Python
33 lines
907 B
Python
from django.utils import timezone
|
|
|
|
from menu.models import Order
|
|
|
|
|
|
class OrderService:
|
|
"""订单业务逻辑"""
|
|
|
|
@staticmethod
|
|
def get_queryset(status_filter=None):
|
|
"""获取订单查询集"""
|
|
queryset = Order.objects.prefetch_related('dishes', 'dishes__category')
|
|
if status_filter:
|
|
queryset = queryset.filter(status=status_filter)
|
|
return queryset
|
|
|
|
@staticmethod
|
|
def create_order(serializer, dish_ids):
|
|
"""创建订单并绑定菜品"""
|
|
if dish_ids is None:
|
|
dish_ids = []
|
|
|
|
order = serializer.save(dish_ids=dish_ids)
|
|
return Order.objects.prefetch_related('dishes', 'dishes__category').get(pk=order.pk)
|
|
|
|
@staticmethod
|
|
def complete_order(order):
|
|
"""完成订单"""
|
|
order.status = 'completed'
|
|
order.completed_at = timezone.now()
|
|
order.save()
|
|
return order
|