2026-03-02 12:36:41 +00:00
|
|
|
|
const { DataTypes } = require('sequelize');
|
|
|
|
|
|
const sequelize = require('../config/db');
|
|
|
|
|
|
const Apartment = require('./Apartment');
|
|
|
|
|
|
|
|
|
|
|
|
const Room = sequelize.define('Room', {
|
|
|
|
|
|
id: {
|
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
primaryKey: true,
|
2026-03-05 15:26:13 +00:00
|
|
|
|
autoIncrement: true,
|
|
|
|
|
|
comment: '房间ID'
|
2026-03-02 12:36:41 +00:00
|
|
|
|
},
|
|
|
|
|
|
apartmentId: {
|
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
allowNull: false,
|
|
|
|
|
|
references: {
|
|
|
|
|
|
model: Apartment,
|
|
|
|
|
|
key: 'id'
|
2026-03-05 15:26:13 +00:00
|
|
|
|
},
|
|
|
|
|
|
comment: '所属公寓ID'
|
2026-03-02 12:36:41 +00:00
|
|
|
|
},
|
|
|
|
|
|
roomNumber: {
|
|
|
|
|
|
type: DataTypes.STRING(20),
|
2026-03-05 15:26:13 +00:00
|
|
|
|
allowNull: false,
|
|
|
|
|
|
comment: '房间编号'
|
2026-03-02 12:36:41 +00:00
|
|
|
|
},
|
|
|
|
|
|
area: {
|
|
|
|
|
|
type: DataTypes.DECIMAL(10, 2),
|
2026-03-05 15:26:13 +00:00
|
|
|
|
allowNull: true,
|
|
|
|
|
|
comment: '房间面积'
|
2026-03-02 12:36:41 +00:00
|
|
|
|
},
|
2026-03-03 15:36:48 +00:00
|
|
|
|
monthlyPrice: {
|
|
|
|
|
|
type: DataTypes.DECIMAL(10, 2),
|
2026-03-05 15:26:13 +00:00
|
|
|
|
allowNull: true,
|
|
|
|
|
|
comment: '月租金'
|
2026-03-03 15:36:48 +00:00
|
|
|
|
},
|
|
|
|
|
|
yearlyPrice: {
|
2026-03-02 12:36:41 +00:00
|
|
|
|
type: DataTypes.DECIMAL(10, 2),
|
2026-03-05 15:26:13 +00:00
|
|
|
|
allowNull: true,
|
|
|
|
|
|
comment: '年租金'
|
2026-03-02 12:36:41 +00:00
|
|
|
|
},
|
|
|
|
|
|
status: {
|
2026-03-07 11:40:53 +00:00
|
|
|
|
type: DataTypes.ENUM('empty', 'reserved', 'rented'),
|
2026-03-02 12:36:41 +00:00
|
|
|
|
allowNull: false,
|
2026-03-05 15:26:13 +00:00
|
|
|
|
defaultValue: 'empty',
|
2026-03-07 11:40:53 +00:00
|
|
|
|
comment: '房间状态(empty:空房,reserved:预订,rented:在租)'
|
2026-03-02 12:36:41 +00:00
|
|
|
|
},
|
2026-03-03 15:36:48 +00:00
|
|
|
|
subStatus: {
|
|
|
|
|
|
type: DataTypes.ENUM('normal', 'soon_expire', 'expired'),
|
|
|
|
|
|
allowNull: false,
|
2026-03-05 15:26:13 +00:00
|
|
|
|
defaultValue: 'normal',
|
|
|
|
|
|
comment: '附属状态(normal:正常,soon_expire:即将到期,expired:已到期)'
|
2026-03-03 15:36:48 +00:00
|
|
|
|
},
|
|
|
|
|
|
otherStatus: {
|
|
|
|
|
|
type: DataTypes.ENUM('', 'cleaning', 'maintenance'),
|
|
|
|
|
|
allowNull: false,
|
2026-03-05 15:26:13 +00:00
|
|
|
|
defaultValue: '',
|
|
|
|
|
|
comment: '其他状态(cleaning:打扫中,maintenance:维修中)'
|
2026-03-03 15:36:48 +00:00
|
|
|
|
},
|
2026-03-08 16:28:33 +00:00
|
|
|
|
createBy: {
|
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
allowNull: true,
|
|
|
|
|
|
comment: '创建人ID'
|
|
|
|
|
|
},
|
2026-03-02 12:36:41 +00:00
|
|
|
|
createTime: {
|
|
|
|
|
|
type: DataTypes.DATE,
|
2026-03-05 15:26:13 +00:00
|
|
|
|
defaultValue: DataTypes.NOW,
|
|
|
|
|
|
comment: '创建时间'
|
2026-03-03 15:36:48 +00:00
|
|
|
|
},
|
2026-03-08 16:28:33 +00:00
|
|
|
|
updateBy: {
|
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
allowNull: true,
|
|
|
|
|
|
comment: '修改人ID'
|
|
|
|
|
|
},
|
2026-03-03 15:36:48 +00:00
|
|
|
|
updateTime: {
|
|
|
|
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
defaultValue: DataTypes.NOW,
|
2026-03-05 15:26:13 +00:00
|
|
|
|
onUpdate: DataTypes.NOW,
|
|
|
|
|
|
comment: '更新时间'
|
2026-03-03 15:36:48 +00:00
|
|
|
|
},
|
|
|
|
|
|
isDeleted: {
|
|
|
|
|
|
type: DataTypes.INTEGER,
|
|
|
|
|
|
allowNull: false,
|
2026-03-05 15:26:13 +00:00
|
|
|
|
defaultValue: 0,
|
|
|
|
|
|
comment: '删除状态(0:未删除,1:已删除)'
|
2026-03-02 12:36:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
}, {
|
|
|
|
|
|
tableName: 'rooms',
|
|
|
|
|
|
timestamps: false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 建立关联
|
|
|
|
|
|
Room.belongsTo(Apartment, { foreignKey: 'apartmentId' });
|
|
|
|
|
|
Apartment.hasMany(Room, { foreignKey: 'apartmentId' });
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Room;
|