示例#1
0
class ShopAttr(db.Model):
    id = db.PrimaryKeyField()
    sid = db.IntegerField()  #商品Id
    name = db.CharField(max_length=50)  #商品规格
    price = db.FloatField()  #商品价格
    order = db.TinyIntegerField(default=1)  #规格排序

    def validate(self):
        if self.sid and self.name:

            ft = ((ShopAttr.sid == self.sid) & (ShopAttr.name == self.name))

            if self.id:
                ft = ft & (ShopAttr.id != self.id)

            if ShopAttr.select().where(ft).count() > 0:
                raise Exception('此规格已存在')
        else:
            raise Exception('请输入规格,价格或设置分类id')

    @classmethod
    def maxorder(cls, sid):
        return ShopAttr.select().where(ShopAttr.sid == sid).count() + 1

    class Meta:
        db_table = 'shopattrs'
        order_by = ('order', )
示例#2
0
class Distribution(db.Model):
    """
    配送方式
    """
    id = db.TinyPrimaryKeyField()
    pdid = db.TinyIntegerField() # 是否为第一级
    name = db.CharField(max_length=20) # 配送方式名称
    price = db.FloatField(default=0.0) # 配送价格
    content = db.CharField() # 如果为第二级则有内容选择
    
    def validate(self):
        if self.name:
                        
            ft = (Distribution.name == self.name)
            if self.id:
                ft = ft & (Distribution.id != self.id)
                
            if Distribution.select().where(ft).count() > 0:
                raise Exception('此配送方式已存在')
        else:
            raise Exception('请输入配送方式')
    
    class Meta:
        db_table = 'distribution'
        order_by = ('pdid',)
示例#3
0
class Order(db.Model):
    id = db.PrimaryKeyField()
    uid = db.IntegerField(default=0)  #用户Id
    mobile = db.CharField(max_length=11)  #注册手机号
    uaid = db.IntegerField(default=0)  #收件地址
    distrid = db.TinyIntegerField(default=0)  #配送方式
    distribbed = db.CharField(max_length=24)  #配送时间
    payment = db.TinyIntegerField(max_length=1, default=1)  #付款方式 0货到付款  1支付宝
    message = db.CharField()  #付款留言
    isinvoice = db.TinyIntegerField(max_length=1, default=0)  #是否开发票
    invoicesub = db.TinyIntegerField(max_length=1, default=0)  #发票抬头 0个人 1公司
    invoicename = db.CharField(max_length=80)  #个人或公司名称
    invoicecontent = db.TinyIntegerField(max_length=1,
                                         default=1)  #发票类型 0蛋糕 1食品
    shippingprice = db.FloatField(default=0.0)  #配送价格
    price = db.FloatField(default=0.0)  #价格
    status = db.TinyIntegerField(max_length=1,
                                 default=0)  #订单状态 0等待付款 1付款成功 2已送货 3交易完成 4已取消
    ordered = db.IntegerField(default=int(time.time()))  #下单时间

    class Meta:
        db_table = 'orders'