You've already forked opc-backend
60 lines
3.0 KiB
Python
60 lines
3.0 KiB
Python
|
|
import uuid
|
||
|
|
from django.db import models
|
||
|
|
|
||
|
|
class ResourceType(models.TextChoices):
|
||
|
|
ACCESS_CONTROL = 'ACCESS_CONTROL', '门禁通行'
|
||
|
|
MEETING_ROOM = 'MEETING_ROOM', '会议室'
|
||
|
|
|
||
|
|
class OrderStatus(models.TextChoices):
|
||
|
|
PENDING_PAY = 'PENDING_PAY', '待支付'
|
||
|
|
PAID = 'PAID', '已支付'
|
||
|
|
USED = 'USED', '已使用'
|
||
|
|
REFUNDED = 'REFUNDED', '已退款'
|
||
|
|
CANCELLED = 'CANCELLED', '已取消'
|
||
|
|
|
||
|
|
class ReservationResource(models.Model):
|
||
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||
|
|
name = models.CharField(max_length=128)
|
||
|
|
type = models.CharField(max_length=32, choices=ResourceType.choices)
|
||
|
|
description = models.TextField(null=True, blank=True)
|
||
|
|
capacity = models.IntegerField(null=True, blank=True)
|
||
|
|
location = models.CharField(max_length=256, null=True, blank=True)
|
||
|
|
cover_url = models.CharField(max_length=512, null=True, blank=True)
|
||
|
|
price_per_unit = models.DecimalField(max_digits=8, decimal_places=2, default=0.00)
|
||
|
|
price_unit = models.CharField(max_length=32, default='次')
|
||
|
|
is_active = models.BooleanField(default=True)
|
||
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
||
|
|
updated_at = models.DateTimeField(auto_now=True)
|
||
|
|
|
||
|
|
class Meta:
|
||
|
|
db_table = 'reservation_resources'
|
||
|
|
|
||
|
|
class ReservationOrder(models.Model):
|
||
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||
|
|
order_no = models.CharField(max_length=64, unique=True)
|
||
|
|
user = models.ForeignKey('users.User', on_delete=models.CASCADE, related_name='reservation_orders')
|
||
|
|
resource = models.ForeignKey(ReservationResource, on_delete=models.CASCADE, related_name='orders')
|
||
|
|
start_time = models.DateTimeField()
|
||
|
|
end_time = models.DateTimeField()
|
||
|
|
quantity = models.IntegerField(default=1)
|
||
|
|
unit_price = models.DecimalField(max_digits=8, decimal_places=2)
|
||
|
|
total_amount = models.DecimalField(max_digits=10, decimal_places=2)
|
||
|
|
status = models.CharField(max_length=32, choices=OrderStatus.choices, default=OrderStatus.PENDING_PAY)
|
||
|
|
wx_prepay_id = models.CharField(max_length=128, null=True, blank=True)
|
||
|
|
wx_transaction_id = models.CharField(max_length=128, null=True, blank=True)
|
||
|
|
paid_at = models.DateTimeField(null=True, blank=True)
|
||
|
|
refund_reason = models.TextField(null=True, blank=True)
|
||
|
|
refund_amount = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
|
||
|
|
wx_refund_id = models.CharField(max_length=128, null=True, blank=True)
|
||
|
|
refunded_at = models.DateTimeField(null=True, blank=True)
|
||
|
|
qr_code_url = models.CharField(max_length=512, null=True, blank=True)
|
||
|
|
verified_by = models.ForeignKey('users.User', on_delete=models.SET_NULL, null=True, blank=True, related_name='verified_orders')
|
||
|
|
verified_at = models.DateTimeField(null=True, blank=True)
|
||
|
|
remark = models.TextField(null=True, blank=True)
|
||
|
|
is_deleted = models.BooleanField(default=False)
|
||
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
||
|
|
updated_at = models.DateTimeField(auto_now=True)
|
||
|
|
|
||
|
|
class Meta:
|
||
|
|
db_table = 'reservation_orders'
|