Ejemplo n.º 1
0
class Order(BaseModel, db.Model):
    """订单"""

    __tablename__ = "ih_order_info"

    id = db.Column(db.Integer, primary_key=True)  # 订单编号
    user_id = db.Column(db.Integer, db.ForeignKey("ih_user_profile.id"), nullable=False)  # 下订单的用户编号
    house_id = db.Column(db.Integer, db.ForeignKey("ih_house_info.id"), nullable=False)  # 预订的房间编号
    begin_date = db.Column(db.DateTime, nullable=False)  # 预订的起始时间
    end_date = db.Column(db.DateTime, nullable=False)  # 预订的结束时间
    days = db.Column(db.Integer, nullable=False)  # 预订的总天数
    house_price = db.Column(db.Integer, nullable=False)  # 房屋的单价
    amount = db.Column(db.Integer, nullable=False)  # 订单的总金额
    status = db.Column(  # 订单的状态
        db.Enum(
            "WAIT_ACCEPT",  # 待接单,
            "WAIT_PAYMENT",  # 待支付
            "PAID",  # 已支付
            "WAIT_COMMENT",  # 待评价
            "COMPLETE",  # 已完成
            "CANCELED",  # 已取消
            "REJECTED"  # 已拒单
        ),
        default="WAIT_ACCEPT", index=True)
    comment = db.Column(db.Text)  # 订单的评论信息或者拒单原因
Ejemplo n.º 2
0
class House(BaseModel, db.Model):
    '''房屋信息'''
    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)  #房屋编号
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)  #房屋主人的用户编号
    area_id = db.Column(db.Integer,
                        db.ForeignKey("ih_area_info.id"),
                        nullable=False)  #归属地的区域编号
    title = db.Column(db.String(64), nullable=False)  #标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default='')  #地址
    room_count = db.Column(db.Integer, default=1)  #房间数目
    acreage = db.Column(db.Integer, default=0)  #房屋面积
    unit = db.Column(db.String(32), default='')  #房屋单元,如几室几厅
    capacity = db.Column(db.Integer, default=1)  #房屋容纳的人数
    beds = db.Column(db.String(64), default='')  #房屋床铺的配置
    deposit = db.Column(db.Integer, default=0)  #房屋押金
    min_days = db.Column(db.Integer, default=1)  #最少入住天数
    max_days = db.Column(db.Integer, default=0)  #最多入住天数,0表示不限制
    order_count = db.Column(db.Integer, default=0)  #预订完成的该房屋的订单数
    index_image_url = db.Column(db.String(256), default="")  #房屋主图片的路径

    # secondary相当于找中间表
    # 所有的relationship都表中都是没有的,ForeignKey到时会在表中建一个字段
    facilities = db.relationship("Facility", secondary=house_facilyty)  #房屋的设施
    images = db.relationship("HouseImage")  #房屋的图片
    orders = db.relationship("Order", backref='house')  #房屋的订单
Ejemplo n.º 3
0
class Order(BaseModel, db.Model):
    '''订单'''

    __tablename__ = "ih_order_info"
    id = db.Column(db.Integer, primary_key=True)  #订单编号
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)  #下订单的用户编号
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ih_house_info.id"),
                         nullable=False)  #预订的房间编号
    begin_date = db.Column(db.DateTime, nullable=False)  #预订的起始时间
    end_date = db.Column(db.DateTime, nullable=False)  #预订的结束时间
    days = db.Column(db.Integer, nullable=False)  #预订的总天数
    house_price = db.Column(db.Integer, nullable=False)  #房屋的单价
    amount = db.Column(db.Integer, nullable=False)  #订单的总金额
    status = db.Column(  #订单的状态
        db.Enum(  #枚举, django choice
            "WAIT_ACCEPT",  #待接单
            "WAIT_PAYMENT",  #待支付
            "PAID",  #已支付
            "WAIT_COMMENT",  #待评价
            "COMPLETE",  #已完成
            "CANCELED",  #已取消
            "REJECTED"  #已拒单
        ),
        default="WAIT_ACCEPT",
        index=True  #指明在mysql中这个字段建立索引,加快查询速度
    )
    comment = db.Column(db.Text)  #订单的评论信息或者拒单原因
    trade_no = db.Column(db.String(80))  #交易的流水号,支付宝的
class House(BaseModel):

    __tablename__ = 'ihome_python_house_info'

    id = db.Column(db.Integer, primary_key=True)
    # 在多表中建立外键
    user_id = db.Column(db.Integer, db.ForeignKey('ihome_python_user_profile.id'), nullable=False)
    area_id = db.Column(db.Integer, db.ForeignKey('ihome_python_area_info.id'), nullable=False)

    title = db.Column(db.String(64), nullable=False)  # 标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default="")  # 地址
    room_count = db.Column(db.Integer, default=1)  # 房间数目
    acreage = db.Column(db.Integer, default=0)  # 房屋面积
    unit = db.Column(db.String(32), default="")  # 房屋单元, 如几室几厅
    capacity = db.Column(db.Integer, default=1)  # 房屋容纳的人数
    beds = db.Column(db.String(64), default="")  # 房屋床铺的配置
    deposit = db.Column(db.Integer, default=0)  # 房屋押金
    min_days = db.Column(db.Integer, default=1)  # 最少入住天数
    max_days = db.Column(db.Integer, default=0)  # 最多入住天数,0表示不限制
    order_count = db.Column(db.Integer, default=0)  # 预订完成的该房屋的订单数
    index_image_url = db.Column(db.String(256), default="")  # 房屋主图片的路径

    facilities = db.relationship('Facility', secondary=house_facility)
    images = db.relationship('HouseImage')
    orders = db.relationship('Order', backref='house')
Ejemplo n.º 5
0
class Order(BaseModel, db.Model):
    """订单详情模型类"""
    __tablename__ = "ih_order_info"

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ih_house_info.id"),
                         nullable=False)

    begin_date = db.Column(db.DateTime, nullable=False)
    end_data = db.Column(db.DateTime, nullable=False)
    days = db.Column(db.Integer, nullable=False)  # 总预订天数

    house_price = db.Column(db.Integer, nullable=False)  # 房屋单价
    amount = db.Column(db.Integer, nullable=False)  # 订单总金额

    # 订单状态: 默认待接单
    status = db.Column(
        db.Enum(
            "WAIT_ACCEPT",  # 待接单
            "WAIT_PAYMENT",  # 待支付
            "PAID",  # 已支付
            "WAIT_COMMENT",  # 待评价
            "COMPLETE",  # 已完成
            "CANCELED",  # 已取消
            "REJECTED"  # 已拒单
        ),
        default="WAIT_ACCEPT",
        index=True)

    comment = db.Column(db.Text)  # 订单评论信息或者拒单原因
Ejemplo n.º 6
0
class Order(BaseModel, db.Model):
    """订单"""

    __tablename__ = "ih_order_info"

    id = db.Column(db.Integer, primary_key=True)  # 订单编号

    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)  # 下订单的用户编号
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ih_house_info.id"),
                         nullable=False)  # 预订的房间编号

    begin_date = db.Column(db.DateTime, nullable=False)  # 预订的起始时间
    end_date = db.Column(db.DateTime, nullable=False)  # 预订的结束时间
    days = db.Column(db.Integer, nullable=False)  # 预订的总天数
    house_price = db.Column(db.Integer, nullable=False)  # 房屋的单价
    amount = db.Column(db.Integer, nullable=False)  # 订单的总金额
    status = db.Column(  # 订单的状态
        db.Enum(
            "WAIT_ACCEPT",  # 待接单,
            "WAIT_PAYMENT",  # 待支付
            "PAID",  # 已支付
            "WAIT_COMMENT",  # 待评价
            "COMPLETE",  # 已完成
            "CANCELED",  # 已取消
            "REJECTED"  # 已拒单
        ),
        default="WAIT_ACCEPT",
        index=True)
    comment = db.Column(db.Text)  # 订单的评论信息或者拒单原因

    def to_dict(self):
        """将订单信息转换为字典数据"""
        order_dict = {
            "order_id":
            self.id,
            "title":
            self.house.title,
            "img_url":
            constants.QINIU_URL_DOMAIN +
            self.house.index_image_url if self.house.index_image_url else "",
            "start_date":
            self.begin_date.strftime("%Y-%m-%d"),
            "end_date":
            self.end_date.strftime("%Y-%m-%d"),
            "ctime":
            self.create_time.strftime("%Y-%m-%d %H:%M:%S"),
            "days":
            self.days,
            "amount":
            self.amount,
            "status":
            self.status,
            "comment":
            self.comment if self.comment else ""
        }
        return order_dict
Ejemplo n.º 7
0
class Order(BaseModel, db.Model):

    __tablename__ = 'ihome_python_order_info'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('ihome_python_user_profile.id'),
                        nullable=False)
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ihome_python_house_info.id"),
                         nullable=False)  # 预订的房间编号
    begin_date = db.Column(db.DateTime, nullable=False)  # 预订的起始时间
    end_date = db.Column(db.DateTime, nullable=False)  # 预订的结束时间
    days = db.Column(db.Integer, nullable=False)  # 预订的总天数
    house_price = db.Column(db.Integer, nullable=False)  # 房屋的单价
    amount = db.Column(db.Integer, nullable=False)  # 订单的总金额
    status = db.Column(  # 订单的状态
        db.Enum(  # 枚举     # django choice
            "WAIT_ACCEPT",  # 待接单,
            "WAIT_PAYMENT",  # 待支付
            "PAID",  # 已支付
            "WAIT_COMMENT",  # 待评价
            "COMPLETE",  # 已完成
            "CANCELED",  # 已取消
            "REJECTED"  # 已拒单
        ),
        default="WAIT_ACCEPT",
        index=True)  # 指明在mysql中这个字段建立索引,加快查询速度
    comment = db.Column(db.Text)  # 订单的评论信息或者拒单原因
    trade_no = db.Column(db.String(80))  # 交易的流水号 支付宝的

    def to_dict(self):
        """将订单信息转换为字典数据"""
        order_dict = {
            "order_id":
            self.id,
            "title":
            self.house.title,
            "img_url":
            constants.QINIU_URL_DOMAIN +
            self.house.index_image_url if self.house.index_image_url else "",
            "start_date":
            self.begin_date.strftime("%Y-%m-%d"),
            "end_date":
            self.end_date.strftime("%Y-%m-%d"),
            "ctime":
            self.create_time.strftime("%Y-%m-%d %H:%M:%S"),
            "days":
            self.days,
            "amount":
            self.amount,
            "status":
            self.status,
            "comment":
            self.comment if self.comment else ""
        }
        return order_dict
Ejemplo n.º 8
0
class HouseImage(BaseModel,db.Model):
    """房屋图片"""
    __tablename__ = "i_house_image"

    id = db.Column(db.Integer,primary_key=True)
    house_id = db.Column(db.Integer,db.ForeignKey("i_house.id"),nullable=False) # 房屋编码
    url = db.Column(db.String(256),nullable=False) # 图片的路径
class HouseImage(BaseModel):

    __tablename__ = "ihome_python_house_image"

    id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer, db.ForeignKey("ihome_python_house_info.id"), nullable=False)  # 房屋编号
    url = db.Column(db.String(256), nullable=False)  # 图片的路径
Ejemplo n.º 10
0
class HouseImage(BaseModel, db.Model):
    """房屋图片模型类"""
    __tablename__ = "ih_house_image"

    id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ih_house_info.id"),
                         nullable=False)
    url = db.Column(db.String(256), nullable=False)  # 所有图片路径地址
Ejemplo n.º 11
0
class Order(BaseModel,db.Model):
    """订单"""

    __tablename__ = "ihome_order"

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("ihome_user.id"), nullable=False)
    house_id = db.Column(db.Integer, db.ForeignKey("ihome_house.id"), nullable=False)
    begin_date = db.Column(db.DateTime, nullable=False)
    end_date = db.Column(db.DateTime, nullable=False)
    days = db.Column(db.Integer, nullable=False)
    house_price = db.Column(db.Integer, nullable=False)
    amount = db.Column(db.Integer, nullable=False)
    status = db.Column(
        db.Enum(
            "WAIT_ACCEPT",  # 待接单,
            "WAIT_PAYMENT",  # 待支付
            "PAID",  # 已支付
            "WAIT_COMMENT",  # 待评价
            "COMPLETE",  # 已完成
            "CANCELED",  # 已取消
            "REJECTED"  # 已拒单
        ),
        default="WAIT_ACCEPT", index=True)
    comment = db.Column(db.Text)
    trade_no = db.Column(db.String(128))  # 交易号

    def to_dict(self):
        """将订单信息转换为字典数据"""
        order_dict = {
            "order_id": self.id,
            "title": self.house.title,
            "img_url": constants.QINIU_URL_DOMAIN + self.house.index_image_url if self.house.index_image_url else "",
            "start_date": self.begin_date.strftime("%Y-%m-%d"),
            "end_date": self.end_date.strftime("%Y-%m-%d"),
            "ctime": self.create_time.strftime("%Y-%m-%d %H:%M:%S"),
            "days": self.days,
            "amount": self.amount,
            "status": self.status,
            "comment": self.comment if self.comment else ""
        }
        return order_dict
Ejemplo n.º 12
0
    name = db.Column(db.String(32), nullable=False)  # 区域名字

    houses = db.relationship("House", backref="area")  # 区域的房屋

    def area_dict(self):
        area_dict = {'aid': self.id, 'aname': self.name}
        return area_dict


# 房屋设施表,建立房屋与设施的多对多关系
# 如果是多对多, 直接操作底层的表
house_facility = db.Table(
    "ih_house_facility",
    db.Column("house_id",
              db.Integer,
              db.ForeignKey("ih_house_info.id"),
              primary_key=True),  # 房屋编号
    db.Column("facility_id",
              db.Integer,
              db.ForeignKey("ih_facility_info.id"),
              primary_key=True)  # 设施编号
)


class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号
Ejemplo n.º 13
0
            "mobile": self.phone,
            "avatar": constants.QINIU_URL_DOMAIN + self.avatar_url if self.avatar_url else "",
            "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S")
        }
        return user_dict

    def auth_to_dict(self):
        return {
            'real_name': self.real_name,
            'id_card': self.real_id_card
        }


ihome_house_facility = db.Table(
    "ihome_house_facility",
    db.Column("house_id", db.Integer, db.ForeignKey("ihome_house.id"), primary_key=True),  # 房屋编号
    db.Column("facility_id", db.Integer, db.ForeignKey("ihome_facility.id"), primary_key=True)  # 设施编号
)


class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ihome_house"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号
    # 房屋主人的用户编号
    user_id = db.Column(db.Integer, db.ForeignKey("ihome_user.id"), nullable=False)
    # 归属地的区域编号
    area_id = db.Column(db.Integer, db.ForeignKey("ihome_area.id"), nullable=False)
    title = db.Column(db.String(64), nullable=False)  # 标题
Ejemplo n.º 14
0
class House(BaseModel,db.Model):
    """房屋信息"""
    __tablename__ = "i_house"

    id = db.Column(db.Integer,primary_key=True) # 房屋编号
    user_id = db.Column(db.Integer,db.ForeignKey("i_user.id")) # 房屋主人用户编号的
    area_id = db.Column(db.Integer,db.ForeignKey("i_area.id")) # 所属城区的区域编号
    title = db.Column(db.String(64),nullable=False) # 房屋标题
    price = db.Column(db.Integer,default=0) #单价
    address = db.Column(db.String(512),default="") # 地址
    room_count = db.Column(db.Integer, default=1)  # 房间数目
    acreage = db.Column(db.Integer, default=0)  # 房屋面积
    unit = db.Column(db.String(32), default="")  # 房屋单元, 如几室几厅
    capacity = db.Column(db.Integer, default=1)  # 房屋容纳的人数
    beds = db.Column(db.String(64),default="") # 房屋床铺的配置
    deposit = db.Column(db.Integer,default=0) # 房屋押金
    min_days = db.Column(db.Integer,default=1) # 最少入住天数
    max_days = db.Column(db.Integer,default=0) # 最多入住天数,0表示不限制
    order_count = db.Column(db.Integer,default=0) # 预定完成的该房间订单数
    index_image_url= db.Column(db.String(256),default="") # 房间图片地址
    facilities = db.relationship("Facility", secondary=house_facility)  # 房屋的设施
    images = db.relationship("HouseImage")  # 房屋的图片
    orders = db.relationship("Order", backref="house")  # 房屋的订单

    def to_basic_dict(self):
        """将基本信息转化为字典数据"""
        house_dict = {
            "house_id":self.id,
            "title":self.title,
            "price":self.price,
            "area_name":self.area.name,
            "img_url": constants.QINIU_URL_DOMAIN + self.index_image_url if self.index_image_url else "",
            "room_count": self.room_count,
            "order_count": self.order_count,
            "address": self.address,
            "ctime":self.create_time.strtime("%Y-%m-%d")
        }
        return house_dict

    def to_full_dict(self):
        """将详细信息转换为字典数据"""
        house_dict = {
            "hid":self.id,
            "user_id":self.user_id,
            "user_name":self.user.name,
            "user_avatar": constants.QINIU_URL_DOMAIN + self.user.avatar_url if self.user.avatar_url else "",
            "title":self.title,
            "price":self.price,
            "address":self.address,
            "room_count":self.room_count,
            "acreage":self.acreage,
            "unit":self.unit,
            "capactiy":self.capacity,
            "min_days":self.min_days,
            "max_days":self.max_days,
        }

        #房屋图片
        img_urls = []
        for img in self.images:
            img_urls.append(constants.QINIU_URL_DOMAIN + img.url)
        house_dict["img_urls"] = img_urls

        #房屋设施
        facilities = []
        for facility in self.facilities:
            facilities.append(facilities.id)
        house_dict["facilities"] = facilities

        #评论信息
        comments = []
        orders = Order.query.filter(Order.house_id==self.id,Order.comment != None)\
            .order_by(Order.update_time.desc())\
            .limit(constants.HOUSE_DETAIL_COMMENT_DISPLAY_COUNTS)
        house_dict["comments"] = comments
Ejemplo n.º 15
0
class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)  # 房屋主人的用户编号
    area_id = db.Column(db.Integer,
                        db.ForeignKey("ih_area_info.id"),
                        nullable=False)  # 归属地的区域编号
    title = db.Column(db.String(64), nullable=False)  # 标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default="")  # 地址
    room_count = db.Column(db.Integer, default=1)  # 房间数目
    acreage = db.Column(db.Integer, default=0)  # 房屋面积
    unit = db.Column(db.String(32), default="")  # 房屋单元, 如几室几厅
    capacity = db.Column(db.Integer, default=1)  # 房屋容纳的人数
    beds = db.Column(db.String(64), default="")  # 房屋床铺的配置
    deposit = db.Column(db.Integer, default=0)  # 房屋押金
    min_days = db.Column(db.Integer, default=1)  # 最少入住天数
    max_days = db.Column(db.Integer, default=0)  # 最多入住天数,0表示不限制
    order_count = db.Column(db.Integer, default=0)  # 预订完成的该房屋的订单数
    index_image_url = db.Column(db.String(256), default="")  # 房屋主图片的路径
    facilities = db.relationship("Facility", secondary=house_facility)  # 房屋的设施
    images = db.relationship("HouseImage")  # 房屋的图# 接单片
    orders = db.relationship("Order", backref="house")  # 房屋的订单

    def to_basic_dict(self):
        return {
            "house_id":
            self.id,
            "title":
            self.title,
            "price":
            self.price,
            "area_name":
            self.area.name,
            "img_url":
            constants.QINIU_USER_ACCESS_DOMAIN_URL +
            self.index_image_url if self.index_image_url else "",
            "room_count":
            self.room_count,
            "order_count":
            self.order_count,
            "address":
            self.address,
            "user_avatar":
            constants.QINIU_USER_ACCESS_DOMAIN_URL +
            self.user.avatar_url if self.user.avatar_url else "",
            "ctime":
            self.create_time.strftime("%Y-%m-%d")
        }

    def to_full_dict(self):
        """将详细信息转换为字典数据"""
        house_dict = {
            "hid":
            self.id,
            "user_id":
            self.user_id,
            "user_name":
            self.user.name,
            "user_avatar":
            constants.QINIU_USER_ACCESS_DOMAIN_URL +
            self.user.avatar_url if self.user.avatar_url else "",
            "title":
            self.title,
            "price":
            self.price,
            "address":
            self.address,
            "room_count":
            self.room_count,
            "acreage":
            self.acreage,
            "unit":
            self.unit,
            "capacity":
            self.capacity,
            "beds":
            self.beds,
            "deposit":
            self.deposit,
            "min_days":
            self.min_days,
            "max_days":
            self.max_days,
        }
        # 房屋图片
        house_dict["image_urls"] = [
            constants.QINIU_USER_ACCESS_DOMAIN_URL + image.url
            for image in self.images
        ]

        # 房屋设施
        house_dict["facilities"] = [
            facilitie.id for facilitie in self.facilities
        ]

        # 评论数据
        orders = Order.query.filter(
            Order.house_id == self.id, Order.comment != None,
            Order.status == "COMPLETE").order_by(
                Order.create_time.desc()).limit(
                    constants.HOUSE_DETAIL_COMMENT_DISPLAY_COUNTS)
        house_dict["comments"] = [{
            "comment_user": order.user.name,
            "comment_time": str(order.update_time),
            "comment_content": order.comment
        } for order in orders]

        return house_dict
Ejemplo n.º 16
0
class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号
    user_id = db.Column(db.Integer, db.ForeignKey(
        "ih_user_profile.id"), nullable=False)  # 房屋主人的用户编号
    area_id = db.Column(db.Integer, db.ForeignKey(
        "ih_area_info.id"), nullable=False)  # 归属地的区域编号
    title = db.Column(db.String(64), nullable=False)  # 标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default="")  # 地址
    room_count = db.Column(db.Integer, default=1)  # 房间数目
    acreage = db.Column(db.Integer, default=0)  # 房屋面积
    unit = db.Column(db.String(32), default="")  # 房屋单元, 如几室几厅
    capacity = db.Column(db.Integer, default=1)  # 房屋容纳的人数
    beds = db.Column(db.String(64), default="")  # 房屋床铺的配置
    deposit = db.Column(db.Integer, default=0)  # 房屋押金
    min_days = db.Column(db.Integer, default=1)  # 最少入住天数
    max_days = db.Column(db.Integer, default=0)  # 最多入住天数,0表示不限制
    order_count = db.Column(db.Integer, default=0)  # 预订完成的该房屋的订单数
    index_image_url = db.Column(db.String(256), default="")  # 房屋主图片的路径
    facilities = db.relationship("Facility", secondary=house_facility)  # 房屋的设施
    images = db.relationship("HouseImage")  # 房屋的图片
    orders = db.relationship("Order", backref="house")  # 房屋的订单

    def __repr__(self):
        return f'<House: {self.title}>'

    def to_basic_dict(self):
        return {
            'id': self.id,
            'user_avatar': constants.QINIU_URL_DOMAIN + self.user.avatar_url if self.user.avatar_url else "",
            'area_name': self.area.name,
            'address': self.address,
            'title': self.title,
            'room_count': self.room_count,
            'order_count': self.order_count,
            'price': '%.2f' % (self.price/100),
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S'),
            'update_time': self.update_time.strftime('%Y-%m-%d %H:%M:%S'),
            'index_image_url': constants.QINIU_URL_DOMAIN + self.index_image_url if self.index_image_url else ""
        }

    def to_full_dict(self):
        house_dict = {
            'hid': self.id,
            'uid': self.user_id,
            'uname': self.user.name,
            'user_avatar': constants.QINIU_URL_DOMAIN + self.user.avatar_url if self.user.avatar_url else "",
            'title': self.title,
            'price': '%.2f' % (self.price/100),
            'address': self.address,
            'room_count': self.room_count,
            'acreage': self.acreage,
            'unit': self.unit,
            'capacity': self.capacity,
            'beds': self.beds,
            'deposit': '%.2f' % (self.deposit/100),
            'min_days': self.min_days,
            'max_days': self.max_days,
        }
        # 获取房屋图片url
        image_urls = []
        for image in self.images:
            image_urls.append(constants.QINIU_URL_DOMAIN + image.url)
        house_dict['image_urls'] = image_urls

        # 设备信息
        facilities = []
        for facility in self.facilities:
            facilities.append(facility.id)
        house_dict['facilities'] = facilities

        # 评论信息
        # 订单完成,且评论不为空的最新20跳评论
        comments = []
        orders = Order.query.filter(Order.house_id == self.id,
                                    Order.status == 'COMPLETE',
                                    Order.comment != None).order_by(
            Order.create_time.desc()).limit(constants.HOUSE_DETAIL_COMMENTS_DISPLAY_COUNT)
        for order in orders:
            comment = {
                'user_name': order.user.name if order.user.name != order.user.mobile else '匿名用户',
                'comment': order.comment,
                'ctime': order.update_time.strftime('%Y-%m-%d %H:%M:%S')
            }
            comments.append(comment)
        house_dict['comments'] = comments

        return house_dict
Ejemplo n.º 17
0
        auth_dict = {
            'user_id': self.id,
            'real_name': self.real_name,
            'id_card': self.id_card
        }
        return auth_dict


# 房屋设施表,建立房屋与设施的多对多关系
# 没有设置id, 联合主键做id
house_facility = db.Table(
    'ihome_python_house_facility', db.Column('id',
                                             db.Integer,
                                             primary_key=True),
    db.Column('house_id', db.Integer,
              db.ForeignKey('ihome_python_house_info.id')),
    db.Column('facility_id', db.Integer,
              db.ForeignKey('ihome_python_facility_info.id')))


class House(BaseModel, db.Model):

    __tablename__ = 'ihome_python_house_info'

    id = db.Column(db.Integer, primary_key=True)
    # 在多表(从表)中建立外键
    user_id = db.Column(db.Integer,
                        db.ForeignKey('ihome_python_user_profile.id'),
                        nullable=False)
    area_id = db.Column(db.Integer,
                        db.ForeignKey('ihome_python_area_info.id'),
Ejemplo n.º 18
0
class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号

    title = db.Column(db.String(64), nullable=False)  # 标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default="")  # 地址
    room_count = db.Column(db.Integer, default=1)  # 房间数目
    acreage = db.Column(db.Integer, default=0)  # 房屋面积
    unit = db.Column(db.String(32), default="")  # 房屋单元, 如几室几厅
    capacity = db.Column(db.Integer, default=1)  # 房屋容纳的人数
    beds = db.Column(db.String(64), default="")  # 房屋床铺的配置
    deposit = db.Column(db.Integer, default=0)  # 房屋押金
    min_days = db.Column(db.Integer, default=1)  # 最少入住天数
    max_days = db.Column(db.Integer, default=0)  # 最多入住天数,0表示不限制
    order_count = db.Column(db.Integer, default=0)  # 预订完成的该房屋的订单数
    index_image_url = db.Column(db.String(256), default="")  # 房屋主图片的路径

    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)  # 房屋主人的用户编号
    area_id = db.Column(db.Integer,
                        db.ForeignKey("ih_area_info.id"),
                        nullable=False)  # 归属地的区域编号

    # 如果是多对多, 只需要在一方增加relationship, 同时需要告诉他第三张表的名字
    facilities = db.relationship("Facility", secondary=house_facility)  # 房屋的设施
    images = db.relationship("HouseImage")  # 房屋的图片
    orders = db.relationship("Order", backref="house")  # 房屋的订单

    def to_base_dict(self):
        house_dict = {
            "house_id":
            self.id,
            "title":
            self.title,
            "price":
            self.price,
            "area_name":
            self.area.name,
            "img_url":
            constants.QINIU_URL_DOMAIN +
            self.index_image_url if self.index_image_url else "",
            "room_count":
            self.room_count,
            "order_count":
            self.order_count,
            "address":
            self.address,
            "user_avatar":
            constants.QINIU_URL_DOMAIN +
            self.user.avatar_url if self.user.avatar_url else "",
            "ctime":
            self.create_time.strftime("%Y-%m-%d")
        }
        return house_dict

    def to_full_dict(self):
        """将详细信息转换为字典数据"""
        house_dict = {
            "hid":
            self.id,
            "user_id":
            self.user_id,
            "user_name":
            self.user.name,
            "user_avatar":
            constants.QINIU_URL_DOMAIN +
            self.user.avatar_url if self.user.avatar_url else "",
            "title":
            self.title,
            "price":
            self.price,
            "address":
            self.address,
            "room_count":
            self.room_count,
            "acreage":
            self.acreage,
            "unit":
            self.unit,
            "capacity":
            self.capacity,
            "beds":
            self.beds,
            "deposit":
            self.deposit,
            "min_days":
            self.min_days,
            "max_days":
            self.max_days,
        }

        # 房屋图片
        img_urls = []
        for image in self.images:
            img_urls.append(constants.QINIU_URL_DOMAIN + image.url)
        house_dict["img_urls"] = img_urls

        # 房屋设施
        facilities = []
        for facility in self.facilities:
            facilities.append(facility.id)
        house_dict["facilities"] = facilities

        # 评论信息
        comments = []
        orders = Order.query.filter(Order.house_id == self.id, Order.status == "COMPLETE", Order.comment != None) \
            .order_by(Order.update_time.desc()).limit(constants.HOUSE_DETAIL_COMMENT_DISPLAY_COUNTS)
        for order in orders:
            comment = {
                "comment":
                order.comment,  # 评论的内容
                "user_name":
                order.user.name
                if order.user.name != order.user.mobile else "匿名用户",  # 发表评论的用户
                "ctime":
                order.update_time.strftime("%Y-%m-%d %H:%M:%S")  # 评价的时间
            }
            comments.append(comment)
        house_dict["comments"] = comments  # [{},{},{}]
        return house_dict
Ejemplo n.º 19
0
class House(BaseModel, db.Model):
    """房屋信息模型类"""
    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)
    area_id = db.Column(db.Integer,
                        db.ForeignKey("ih_area_info.id"),
                        nullable=False)

    title = db.Column(db.String(64), nullable=False)
    price = db.Column(db.Integer, default=0)  # 单价,单位:分/晚
    address = db.Column(db.String(512), default="")
    index_image_url = db.Column(db.String(256), default="")

    deposit = db.Column(db.Integer, default=0)  # 入住押金

    room_count = db.Column(db.Integer, default=1)  # 房间数目
    acreage = db.Column(db.Integer, default=0)  # 房屋面积
    unite = db.Column(db.String(32), default="")  # 房屋单元,如几室几厅
    capacity = db.Column(db.Integer, default=1)  # 房屋容纳人数
    beds = db.Column(db.String(64), default="")  # 房屋床铺配置

    min_days = db.Column(db.Integer, default=1)  # 最少入住天数,默认一晚
    max_days = db.Column(db.Integer, default=0)  # 最多入住天数,0表示无限制

    order_count = db.Column(db.Integer, default=0)  # 房屋已完成订单总数
    order = db.relationship("Order", backref="house")  # 房屋的订单情况

    images = db.relationship("HouseImage")  # 房屋的所有图片
    facilities = db.relationship("Facility", secondary=house_facility)  # 房屋的设施

    def to_basic_dict(self):
        """将对象转换为字典"""
        house_dict = {
            "house_id":
            self.id,
            "title":
            self.title,
            "price":
            self.price,
            "address":
            self.address,
            "area_name":
            self.area.name,
            "image_url":
            constants.QINIU_URL_DOMAIN +
            self.index_image_url if self.index_image_url else "",
            "room_count":
            self.room_count,
            "order_count":
            self.order_count,
            "user_avatar":
            constants.QINIU_URL_DOMAIN +
            self.user.avatar_url if self.user.avatar_url else "",
            "creat_time":
            self.create_time.strftime("%Y-%m-%d")
        }
        return house_dict

    def to_full_dict(self):
        """将对象转换为字典"""
        house_dict = {
            "hid":
            self.id,
            "user_id":
            self.user_id,
            "user_name":
            self.user.name,
            "user_avatar":
            constants.QINIU_URL_DOMAIN +
            self.user.avatar_url if self.user.avatar_url else "",
            "title":
            self.title,
            "price":
            self.price,
            "address":
            self.address,
            "deposit":
            self.deposit,
            "room_count":
            self.room_count,
            "acreage":
            self.acreage,
            "unit":
            self.unite,
            "capacity":
            self.capacity,
            "beds":
            self.beds,
            "min_days":
            self.min_days,
            "max_days":
            self.max_days
        }

        # 房屋图片处理
        img_urls = []
        for image in self.images:
            img_urls.append(constants.QINIU_URL_DOMAIN + img_url)
        house_dict["img_urls"] = img_urls

        # 房屋设施处理
        facilities = []
        for facility in self.facilities:
            facilities.append(facility.id)
        house_dict["facilities"] = facilities

        # 评论信息处理
        comments = []
        orders = Order.query.filter(Order.house_id == self.id, Order.status == "COMPLETE", Order.comment != None).\
            order_by(Order.updata_time.desc()).limit(constants.HOUSE_DETAIL_COMMENT_DISPLAY_COUNTS)
        for order in orders:
            comment = {
                "comment":
                order.comment,  # 获取评论
                "user_name":
                order.user.name if order.user.name != order.user.name else
                "匿名用户",  # 设置用户手机号码隐私
                "ctime":
                order.update_time.strftime("%Y-%m-%d %H:%M:%S")  # 设置时间格式
            }
            comments.append(comment)
        house_dict["comments"] = comments

        return house_dict
Ejemplo n.º 20
0
    id = db.Column(db.Integer, primary_key=True)  # 区域编号
    name = db.Column(db.String(32), nullable=False)  # 城区名字
    hourses = db.relationship('House', backref='area')  # 城区的房屋

    def to_dict(self):
        area_dict = {'aid': self.id, 'aname': self.name}
        return area_dict


# 房屋设施表,建立房屋与设施的多对多关系
house_facility = db.Table(
    'ih_house_facility',
    db.Column('hourse_id',
              db.Integer,
              db.ForeignKey('ih_house_info.id'),
              primary_key=True),  # 房屋编号
    db.Column('facility_id',
              db.Integer,
              db.ForeignKey('ih_facility_info.id'),
              primary_key=True)  # 设施编号
)


class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号
    user_id = db.Column(db.Integer,
Ejemplo n.º 21
0
class House(BaseModel, db.Model):

    __tablename__ = 'ihome_python_house_info'

    id = db.Column(db.Integer, primary_key=True)
    # 在多表(从表)中建立外键
    user_id = db.Column(db.Integer,
                        db.ForeignKey('ihome_python_user_profile.id'),
                        nullable=False)
    area_id = db.Column(db.Integer,
                        db.ForeignKey('ihome_python_area_info.id'),
                        nullable=False)

    title = db.Column(db.String(64), nullable=False)  # 标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default="")  # 地址
    room_count = db.Column(db.Integer, default=1)  # 房间数目
    acreage = db.Column(db.Integer, default=0)  # 房屋面积
    unit = db.Column(db.String(32), default="")  # 房屋单元, 如几室几厅
    capacity = db.Column(db.Integer, default=1)  # 房屋容纳的人数
    beds = db.Column(db.String(64), default="")  # 房屋床铺的配置
    deposit = db.Column(db.Integer, default=0)  # 房屋押金
    min_days = db.Column(db.Integer, default=1)  # 最少入住天数
    max_days = db.Column(db.Integer, default=0)  # 最多入住天数,0表示不限制
    order_count = db.Column(db.Integer, default=0)  # 预订完成的该房屋的订单数
    index_image_url = db.Column(db.String(256), default="")  # 房屋主图片的路径

    facilities = db.relationship('Facility',
                                 backref='house',
                                 secondary=house_facility)  #
    images = db.relationship('HouseImage')
    orders = db.relationship('Order', backref='house')

    def to_basic_dict(self):
        basic_dict = {
            'house_id':
            self.id,
            'img_url':
            constants.QINIU_URL_DOMAIN +
            self.index_image_url if self.index_image_url else "",
            'title':
            self.title,
            'price':
            self.price,
            'area_name':
            self.area.name,
            'ctime':
            self.create_time.strftime('%Y-%m-%d')
        }
        return basic_dict

    def to_detail_dict(self):
        detail_dict = {
            'hid':
            self.id,
            'house_id':
            self.id,
            'img_url':
            constants.QINIU_URL_DOMAIN +
            self.index_image_url if self.index_image_url else "",
            'title':
            self.title,
            'price':
            self.price,
            'area_name':
            self.area.name,
            'ctime':
            self.create_time.strftime('%Y-%m-%d'),
            'user_avatar':
            constants.QINIU_URL_DOMAIN +
            self.user.avatar_url if self.user.avatar_url else '',
            'user_name':
            self.user.name,
            'user_id':
            self.user_id,
            'room_count':
            self.room_count,
            'acreage':
            self.acreage,
            'unit':
            self.unit,
            'capacity':
            self.capacity,
            'beds':
            self.beds,
            'deposit':
            self.deposit,
            'min_days':
            self.min_days,
            'max_days':
            self.max_days,
            'order_count':
            self.order_count,
            'index_image_url':
            constants.QINIU_URL_DOMAIN +
            self.index_image_url if self.index_image_url else '',
            # 'comments': [{'user_name': 'wwwww', 'ctime': self.create_time.strftime('%Y-%m-%d'), 'comment': '很好'}],
            'facilities': [facility.id for facility in self.facilities],
            'img_urls':
            [constants.QINIU_URL_DOMAIN + image.url for image in self.images],
        }
        try:
            comments = [{
                "user_name": house_order.user.name,
                "ctime": self.create_time.strftime('%Y-%m-%d'),
                "comment": house_order.comment
            } for house_order in self.orders]
        except Exception as e:
            current_app.logger.error(e)
            comments = None
            return jsonify(errno=RET.DBERR, errmsg='get comments err from db')

        detail_dict.setdefault('comments', comments)

        return detail_dict
    real_name = db.Column(db.String(32))
    id_card = db.Column(db.String(20))
    # 用户头像路径
    avatar_url = db.Column(db.String(128))

    # 在一表中,或者多表中写relationship
    houses = db.relationship('House', backref='user')
    orders = db.relationship('Order', backref='user')


# 房屋设施表,建立房屋与设施的多对多关系
# 没有设置id, 联合主键做id
house_facility = db.Table(
    'ihome_python_house_facility',
    db.Column('id', db.Integer, primary_key=True),
    db.Column('house_id', db.Integer, db.ForeignKey('ihome_python_house_info.id')),
    db.Column('facility_id', db.Integer, db.ForeignKey('ihome_python_facility_info.id'))
)

class House(BaseModel):

    __tablename__ = 'ihome_python_house_info'

    id = db.Column(db.Integer, primary_key=True)
    # 在多表中建立外键
    user_id = db.Column(db.Integer, db.ForeignKey('ihome_python_user_profile.id'), nullable=False)
    area_id = db.Column(db.Integer, db.ForeignKey('ihome_python_area_info.id'), nullable=False)

    title = db.Column(db.String(64), nullable=False)  # 标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default="")  # 地址
Ejemplo n.º 23
0
class House(BaseModel, db.Model):
    """房屋信息"""
    __tablename__ = "ih_house_info"
    house_id = db.Column(db.Integer, primary_key=True)  # 房屋编号
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.user_id"),
                        nullable=False)  # 房屋主人的用户编号
    area_id = db.Column(db.Integer,
                        db.ForeignKey("ih_area_info.area_id"),
                        nullable=False)  # 归属地的区域编号
    title = db.Column(db.String(64), nullable=False)  # 标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default="")  # 地址
    room_count = db.Column(db.Integer, default=1)  # 房间数目
    acreage = db.Column(db.Integer, default=0)  # 房屋面积
    unit = db.Column(db.String(32), default="")  # 房屋单元, 如几室几厅
    capacity = db.Column(db.Integer, default=1)  # 房屋容纳的人数
    beds = db.Column(db.String(64), default="")  # 房屋床铺的配置
    deposit = db.Column(db.Integer, default=0)  # 房屋押金
    min_days = db.Column(db.Integer, default=1)  # 最少入住天数
    max_days = db.Column(db.Integer, default=0)  # 最多入住天数,0表示不限制
    order_count = db.Column(db.Integer, default=0)  # 预订完成的该房屋的订单数
    index_image_url = db.Column(db.String(256), default="")  # 房屋主图片的路径
    facilities = db.relationship("Facility", secondary=house_facility)  # 房屋的设施
    images = db.relationship("HouseImage", backref="house")  # 房屋的图片
    orders = db.relationship("Order", backref="house")  # 房屋的订单

    def to_basic_dict(self):
        """将房屋基本信息转换为字典数据"""
        house_dict = {
            "house_id":
            self.house_id,
            "title":
            self.title,
            "price":
            self.price,
            "area_name":
            self.area.area_name,
            "img_url":
            constants.QINIU_URL_DOMAIN +
            self.index_image_url if self.index_image_url else "",
            "room_count":
            self.room_count,
            "order_count":
            self.order_count,
            "address":
            self.address,
            "user_avatar":
            constants.QINIU_URL_DOMAIN +
            self.user.avatar_url if self.user.avatar_url else "",
            "ctime":
            self.create_time.strftime("%Y-%m-%d")
        }
        return house_dict

    def detail_to_dict(self):
        """将房屋详细信息转换为字典数据"""
        house_dict = {
            "hid":
            self.house_id,
            "user_id":
            self.user_id,
            "user_name":
            self.user.nickname,
            "user_avatar":
            constants.QINIU_URL_DOMAIN +
            self.user.avatar_url if self.user.avatar_url else "",
            "title":
            self.title,
            "price":
            self.price,
            "address":
            self.address,
            "room_count":
            self.room_count,
            "acreage":
            self.acreage,
            "unit":
            self.unit,
            "capacity":
            self.capacity,
            "beds":
            self.beds,
            "deposit":
            self.deposit,
            "min_days":
            self.min_days,
            "max_days":
            self.max_days,
        }

        # 房屋图片
        image_url = []
        for img in self.images:
            image_url.append(constants.QINIU_URL_DOMAIN + img.url)
        house_dict["img_urls"] = image_url

        # 房屋设施
        facilities_list = []
        for facility in self.facilities:
            facilities_list.append(facility.fac_id)
        house_dict["facilities"] = facilities_list

        # 评论信息
        comment_list = []
        try:
            orders = Order.query.filter(Order.house_id==self.house_id,Order.status=="COMPLETE",Order.comment!=None)\
                .order_by(Order.update_time.desc()).limit(constants.HOUSE_DETAIL_COMMENT_MAX_COUNTS)
            for ord in orders:
                ord_dic = {
                    "comment":
                    ord.comment,
                    "nickname":
                    "匿名用户" if ord.user.nickname == ord.user.mobile else
                    ord.user.nickname,
                    "ctime":
                    ord.update_time.strftime("%Y-%m-%d %H:%M:%S")  # 评价的时间
                }
                comment_list.append(ord_dic)
        except Exception as e:
            pass
        house_dict["comments"] = comment_list
        return house_dict