class User(db.Model, TimestampMixin, IDMixin): __tablename__ = 'users' is_active = db.Column(db.Boolean, default=True) username = db.Column(db.VARCHAR(255), nullable=False) email = db.Column(db.VARCHAR(255), nullable=False) password_hash = db.Column(db.VARCHAR(255), nullable=False) role_id = db.Column( db.Integer, db.ForeignKey('roles.id', name='FK_roles__id', ondelete='SET NULL', onupdate='CASCADE'), ) role = db.relationship('Role', back_populates='users') @property def password(self): raise AttributeError('password: write-only field') @password.setter def password(self, password): self.password_hash = bcrypt.generate_password_hash(password).decode( 'utf-8') def check_password(self, password): return bcrypt.check_password_hash(self.password_hash, password) def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class Administrator(db.Model): __table_args__ = { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8mb4' } admin_id = db.Column(db.Integer, primary_key=True, autoincrement=True) admin_name = db.Column( db.String(20), unique=True, nullable=False) admin_passwd = db.Column(db.String(20), unique=True, nullable=False) def __init__(self, admin_name, admin_passwd): self.admin_name = admin_name self.admin_passwd = admin_passwd def __repr__(self): return '<admin_name %r>' % self.admin_name def save(self): db.session.add(self) db.session.commit() return self def update(self): db.session.commit() return self
class Permission(db.Model, TimestampMixin, IDMixin): __tablename__ = 'permissions' is_active = db.Column(db.Boolean, default=True) name = db.Column(db.VARCHAR(255), nullable=False) code = db.Column(db.VARCHAR(20), nullable=False) roles = db.relationship('Role', secondary='role_permissions') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class PaymentInformation(db.Model, TimestampMixin, IDMixin): __tablename__ = 'payment_informations' bank_code = db.Column(db.Enum(Bank), nullable=False) account_number = db.Column(db.VARCHAR(255), nullable=False) account_name = db.Column(db.VARCHAR(255), nullable=False) hotel_id = db.Column( db.Integer, db.ForeignKey('hotels.id', name='FK_hotels__id', ondelete='RESTRICT', onupdate='CASCADE')) hotel = db.relationship('Hotel', back_populates='payment_informations') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class User(db.Model): __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8mb4'} id = db.Column(db.Integer, primary_key=True, autoincrement=True) stu_id = db.Column(db.String(20), unique=True, nullable=False) stu_name = db.Column(db.String(20), unique=True, nullable=False) def __init__(self, stu_id, stu_name): self.stu_id = stu_id self.stu_name = stu_name def __repr__(self): return '<id %r>' % self.id def save(self): db.session.add(self) db.session.commit() return self def update(self): db.session.commit() return self
class Hotel(db.Model, TimestampMixin, IDMixin): __tablename__ = 'hotels' is_active = db.Column(db.Boolean, default=True) name = db.Column(db.VARCHAR(255), nullable=False) description = db.Column(db.VARCHAR(255), nullable=False) city_or_province = db.Column(db.VARCHAR(255), nullable=False) address = db.Column(db.VARCHAR(255), nullable=False) phone_number = db.Column(db.VARCHAR(255), nullable=False) email = db.Column(db.VARCHAR(255), nullable=False) room_types = db.Column(db.VARCHAR(255), nullable=False) utilities = db.Column(db.VARCHAR(255), nullable=False) checkin = db.Column(db.TIME(), nullable=False) checkout = db.Column(db.TIME(), nullable=False) image = db.Column(db.VARCHAR(255), nullable=False) longitude = db.Column(db.FLOAT, nullable=False) latitude = db.Column(db.FLOAT, nullable=False) price_standard = db.Column(db.INTEGER, nullable=True) available_room_standard = db.Column(db.INTEGER, nullable=True) tax_standard = db.Column(db.FLOAT, nullable=True) image_standard = db.Column(db.VARCHAR(255), nullable=True) price_deluxe = db.Column(db.INTEGER, nullable=True) available_room_deluxe = db.Column(db.INTEGER, nullable=True) tax_deluxe = db.Column(db.FLOAT, nullable=True) image_deluxe = db.Column(db.VARCHAR(255), nullable=True) payment_informations = db.relationship('PaymentInformation', back_populates='hotel') hotel_bookings = db.relationship('HotelBooking', back_populates='hotel') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class TourBooking(db.Model, TimestampMixin, IDMixin): __tablename__ = 'tour_bookings' status = db.Column(db.Enum(BookingStatus), nullable=False) start_date = db.Column(db.DATE(), nullable=False) user_id = db.Column(db.VARCHAR(255), nullable=False) guests = db.Column(db.INTEGER, nullable=True) price_per_participant = db.Column(db.INTEGER, nullable=False) guest_name = db.Column(db.VARCHAR(255), nullable=False) guest_phone_number = db.Column(db.VARCHAR(255), nullable=False) guest_email = db.Column(db.VARCHAR(255), nullable=False) note = db.Column(db.VARCHAR(255), nullable=True) image_witness = db.Column(db.VARCHAR(255), nullable=True) grand_total = db.Column(db.INTEGER, nullable=False) tour_id = db.Column( db.Integer, db.ForeignKey('tours.id', name='FK_tours__booking__id', ondelete='RESTRICT', onupdate='CASCADE')) tour = db.relationship('Tour', back_populates='tour_bookings') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class Tour(db.Model, TimestampMixin, IDMixin): __tablename__ = 'tours' is_active = db.Column(db.Boolean, default=True) name = db.Column(db.VARCHAR(255), nullable=False) description = db.Column(db.VARCHAR(5000), nullable=False) city_or_province = db.Column(db.VARCHAR(255), nullable=False) common_address = db.Column(db.VARCHAR(255), nullable=False) duration = db.Column(db.Integer, nullable=False) min_size = db.Column(db.Integer, nullable=False) max_size = db.Column(db.Integer, nullable=False) price_per_participant = db.Column(db.Integer, nullable=False) transportations = db.Column(db.VARCHAR(255), nullable=False) images = db.Column(db.VARCHAR(500), nullable=False) organizer_name = db.Column(db.VARCHAR(255), nullable=False) organizer_email = db.Column(db.VARCHAR(255), nullable=False) organizer_phone_number = db.Column(db.VARCHAR(255), nullable=False) organizer_avatar = db.Column(db.VARCHAR(255), nullable=False) tour_payment_informations = db.relationship('TourPaymentInformation', back_populates='tour') tour_bookings = db.relationship('TourBooking', back_populates='tour') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class Wo(db.Model): __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8mb4'} ''' id: 记录编号 stu_id: 学号 stu_name: 姓名 tel_number: 手机号码 brand: 电脑品牌 ishandle: 是否处理(0未处理,1已处理) problem: 问题 scheduled: 预约时间 sn码 admin_name: 维修人员 evaluation: 维修评价(1-5分) remark: 备注 admin_remark regtime: 提交时间 ''' id = db.Column(db.Integer, primary_key=True, autoincrement=True) stu_id = db.Column(db.String(20), nullable=False) stu_name = db.Column(db.String(20), nullable=False) tel_number = db.Column(db.String(20), nullable=False) brand = db.Column(db.String(20), nullable=False) ishandle = db.Column(db.Integer, default=0, nullable=False) problem = db.Column(db.String(20), nullable=False) scheduled = db.Column(db.String(20), nullable=False) admin_name = db.Column(db.String(20), nullable=True) sn = db.Column(db.String(20), nullable=True) evaluation = db.Column(db.Integer, default=0, nullable=False) remark = db.Column(db.String(200), nullable=True) admin_remark = db.Column(db.String(200), nullable=True) regtime = db.Column(db.DateTime, default=datetime.now, nullable=False) def __init__(self, stu_id, stu_name, tel_number, problem, brand, scheduled, remark): self.stu_id = stu_id self.stu_name = stu_name self.tel_number = tel_number self.remark = remark self.problem = problem self.brand = brand self.scheduled = scheduled def __repr__(self): return '<stu_id %r>' % self.stu_id def save(self): db.session.add(self) db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit() return self def update(self): db.session.commit() return self
class HotelBooking(db.Model, TimestampMixin, IDMixin): __tablename__ = 'hotel_bookings' status = db.Column(db.Enum(BookingStatus), nullable=False) checkin_date = db.Column(db.DATE(), nullable=False) checkout_date = db.Column(db.DATE(), nullable=False) room_type = db.Column(db.VARCHAR(255), nullable=False) note = db.Column(db.VARCHAR(255), nullable=True) user_id = db.Column(db.VARCHAR(255), nullable=False) rooms = db.Column(db.INTEGER, nullable=True) guests = db.Column(db.INTEGER, nullable=True) room_price = db.Column(db.INTEGER, nullable=False) room_tax = db.Column(db.FLOAT, nullable=False) guest_name = db.Column(db.VARCHAR(255), nullable=False) guest_phone_number = db.Column(db.VARCHAR(255), nullable=False) guest_email = db.Column(db.VARCHAR(255), nullable=True) bank_code = db.Column(db.Enum(Bank), nullable=True) paided = db.Column(db.INTEGER, nullable=True) image_witness = db.Column(db.VARCHAR(255), nullable=True) grand_total = db.Column(db.INTEGER, nullable=False) hotel_id = db.Column( db.Integer, db.ForeignKey('hotels.id', name='FK_hotels__booking__id', ondelete='RESTRICT', onupdate='CASCADE')) hotel = db.relationship('Hotel', back_populates='hotel_bookings') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}