|
|
|
from django.db import models
|
|
|
|
from apps.user.models import MyUser
|
|
|
|
from apps.goods.models import Goods
|
|
|
|
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
|
|
|
|
class Cart(models.Model):
|
|
|
|
"""
|
|
|
|
购物车模型
|
|
|
|
"""
|
|
|
|
user = models.ForeignKey(verbose_name='用户', to=MyUser, on_delete=models.DO_NOTHING, null=True, blank=True)
|
|
|
|
goods = models.ForeignKey(verbose_name='商品', to=Goods, on_delete=models.DO_NOTHING, null=True, blank=True)
|
|
|
|
goods_num = models.IntegerField(verbose_name='购物车中的商品数量', default=1)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.goods.id)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = '购物车信息'
|
|
|
|
verbose_name_plural = '购物车信息'
|
|
|
|
managed = True
|
|
|
|
db_table = 'd_cart'
|
|
|
|
|
|
|
|
|
|
|
|
class Order(models.Model):
|
|
|
|
ORDER_STATUS = (
|
|
|
|
('paying', '待支付'),
|
|
|
|
('paid', '已支付'),
|
|
|
|
('shipping', '配送中'),
|
|
|
|
('complete', '订单结束'),
|
|
|
|
('cancel', '订单取消'),
|
|
|
|
)
|
|
|
|
order_id = models.CharField(verbose_name='订单号', max_length=50, null=True, blank=True)
|
|
|
|
order_total = models.IntegerField(verbose_name='商品总件数', default=0)
|
|
|
|
order_price = models.DecimalField(verbose_name='订单中金额', max_digits=10, decimal_places=2, default=0)
|
|
|
|
address = models.CharField(verbose_name='收货地址', max_length=100, default='')
|
|
|
|
contact_name = models.CharField(verbose_name='联系人', max_length=20, default='')
|
|
|
|
contact_mobile = models.CharField(verbose_name='联系电话', max_length=11, default='')
|
|
|
|
pay_method = models.IntegerField(verbose_name='支付方式', default=0)
|
|
|
|
memo = models.CharField(verbose_name='订单备注', max_length=200, default='')
|
|
|
|
order_status = models.IntegerField(verbose_name='用户', choices=ORDER_STATUS, max_length=20)
|
|
|
|
user = models.ForeignKey(verbose_name='用户', to=MyUser, on_delete=models.DO_NOTHING)
|
|
|
|
create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = '订单信息'
|
|
|
|
verbose_name_plural = '订单信息'
|
|
|
|
managed = True
|
|
|
|
db_table = 'd_order'
|
|
|
|
|
|
|
|
|
|
|
|
class OrderGoods(models.Model):
|
|
|
|
"""
|
|
|
|
订单商品关联表
|
|
|
|
"""
|
|
|
|
order = models.ForeignKey(verbose_name='订单主表', to=Order, on_delete=models.DO_NOTHING)
|
|
|
|
goods = models.ForeignKey(verbose_name='商品表', to=Goods, on_delete=models.DO_NOTHING)
|
|
|
|
goods_num = models.IntegerField(verbose_name='商品数量', default=0)
|
|
|
|
price = models.DecimalField(verbose_name='下单时商品价格', max_digits=10, decimal_places=2)
|
|
|
|
create_time = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = '订单商品信息'
|
|
|
|
verbose_name_plural = '订单商品信息'
|
|
|
|
managed = True
|
|
|
|
db_table = 'd_order_goods'
|