Example #1
0
class Authenticate(BaseModel, db.Model):
    """实名认证信息"""
    __tablename__ = "user_authenticates"
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    type = db.Column(  # 认证类型
        db.Enum(  # 枚举
            "PERSONAL",  # 个人,
            "BUSINESS",  # 商家
            "ADVERTISEMENT",  # 广告商 
        ),
        nullable=False,
        index=True)
    status = db.Column(  # 认证状态
        db.Enum(
            "PENDING",  # 新申请
            "COMPLETED",  # 完成
            "REJECTED",  # 被拒绝
        ),
        default="PENDING",
        nullable=False,
        index=True)
Example #2
0
class Product(BaseModel, db.Model):
    """商品"""
    __tablename__ = "products"

    id = db.Column(db.Integer, primary_key=True)
    seller_id = db.Column(db.Integer,
                          db.ForeignKey("user_profile.user_id"),
                          nullable=False)
    name = db.Column(db.String(32), nullable=False)
    description = db.Column(db.Text())
    price = db.Column(db.Integer, nullable=False)
    status = db.Column(
        db.Enum(
            "SELLING",  # 出售中
            "SELLED"  # 已出售
        ),
        default="SELLING")
    attachments = db.relationship("ProductMedia", backref="product")
Example #3
0
class User(BaseModel, db.Model, UserMixin):
    """用户"""
    __tablename__ = "user"

    id = db.Column(db.Integer, primary_key=True)  # 用户编号
    type = db.Column(  # 账户类型
        db.Enum(  # 枚举
            "PERSONAL",  # 个人,
            "BUSINESS",  # 商家
            "ADVERTISEMENT",  # 广告商
            "ADMINISTRATOR",  # 管理员
        ),
        nullable=False,
        index=True)
    username = db.Column(db.String(32), unique=True, nullable=False)  # 用户暱称
    password_hash = db.Column(db.String(128), nullable=False)  # 密码的散列值
    profile = db.relationship("Profile", backref="user")

    # 加上property装饰器后,会把函数变为属性,属性名即为函数名
    @property
    def password(self):
        """读取属性的函数行为"""
        raise AttributeError("这个属性只能设置,不能读取")

    # 使用这个装饰器, 对应设置属性操作
    @password.setter
    def password(self, value):
        """
        设置属性  user.password = ""
        :param value: 设置属性时的数据 value就是 "", 原始的明文密码
        :return:
        """
        self.password_hash = werkzeug.security.generate_password_hash(value)

    def check_password(self, passwd):
        """
        检验密码的正确性
        :param passwd:  用户登录时填写的原始密码
        :return: 如果正确,返回True, 否则返回False
        """
        return werkzeug.security.check_password_hash(self.password_hash,
                                                     passwd)
Example #4
0
class Status(BaseModel, db.Model):
    """评价"""
    __tablename__ = "statuses"
    id = db.Column(db.Integer, primary_key=True)
    order_id = db.Column(db.Integer,
                         db.ForeignKey("orders.id"),
                         nullable=False)
    # source_id = db.Column(db.Integer, db.ForeignKey("user_profile.user_id"), nullable=False)  # 评价人
    # target_id = db.Column(db.Integer, db.ForeignKey("user_profile.user_id"), nullable=False)  # 被评价人
    level = db.Column(  # 评价等级
        db.Enum(
            "PENDING",  # 没有作出评价
            "POSITIVE",  # 好评
            "NEUTRAL",  # 中评
            "NEGATIVE"  # 差评
        ),
        default="PENDING",
        nullable=False,
        index=True)
    text = db.Column(db.Text())
    reply = db.Column(db.Text())
Example #5
0
class Order(BaseModel, db.Model):
    """订单"""
    __tablename__ = "orders"

    id = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.Integer,
                           db.ForeignKey("products.id"),
                           nullable=False)
    buyer_id = db.Column(db.Integer,
                         db.ForeignKey("user_profile.user_id"),
                         nullable=False)
    status = db.Column(  # 订单状态
        db.Enum(
            "PENDING",  # 新订单
            "PURCHASED",  # 买家已付款
            "DELIVERED",  # 卖家已发货
            "COMPLETED",  # 已完成
            "CANCELLED"  # 已取消
        ),
        default="PENDING",
        nullable=False,
        index=True)
    comments = db.Column(db.Text())  # 备注