const { DataTypes } = require('sequelize'); const sequelize = require('../config/db'); const Apartment = require('./Apartment'); const Room = sequelize.define('Room', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, comment: '房间ID' }, apartmentId: { type: DataTypes.INTEGER, allowNull: false, references: { model: Apartment, key: 'id' }, comment: '所属公寓ID' }, roomNumber: { type: DataTypes.STRING(50), allowNull: false, comment: '房间编号' }, floor: { type: DataTypes.INTEGER, allowNull: true, comment: '楼层' }, roomType: { type: DataTypes.STRING(50), allowNull: true, comment: '户型(如一室一厅、两室一厅等)' }, area: { type: DataTypes.DECIMAL(10, 2), allowNull: true, comment: '房间面积' }, orientation: { type: DataTypes.STRING(20), allowNull: true, comment: '朝向' }, monthlyPrice: { type: DataTypes.DECIMAL(10, 2), allowNull: true, comment: '月租金' }, yearlyPrice: { type: DataTypes.DECIMAL(10, 2), allowNull: true, comment: '年租金' }, deposit: { type: DataTypes.DECIMAL(10, 2), allowNull: true, comment: '押金' }, description: { type: DataTypes.TEXT, allowNull: true, comment: '描述' }, sortOrder: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: '排序字段' }, status: { type: DataTypes.ENUM('empty', 'reserved', 'rented'), allowNull: false, defaultValue: 'empty', comment: '房间状态(empty:空房,reserved:预定,rented:在租)' }, rentalStatus: { type: DataTypes.ENUM('normal', 'soon_expire', 'expired'), allowNull: false, defaultValue: 'normal', comment: '租房标识(normal:正常,soon_expire:即将到期,expired:已到期)' }, tenantId: { type: DataTypes.INTEGER, allowNull: false, comment: '租户ID' }, createBy: { type: DataTypes.INTEGER, allowNull: true, comment: '创建人ID' }, updateBy: { type: DataTypes.INTEGER, allowNull: true, comment: '修改人ID' }, isDeleted: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: '删除状态(0:未删除,1:已删除)' }, createTime: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, comment: '创建时间' }, updateTime: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, comment: '更新时间' } }, { tableName: 'rooms', timestamps: false, comment: '房间表' }); // 建立关联 Room.belongsTo(Apartment, { foreignKey: 'apartmentId' }); Apartment.hasMany(Room, { foreignKey: 'apartmentId' }); module.exports = Room;