98 lines
2.0 KiB
JavaScript
98 lines
2.0 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
||
const sequelize = require('../config/db');
|
||
const Room = require('./Room');
|
||
|
||
const Rental = sequelize.define('Rental', {
|
||
id: {
|
||
type: DataTypes.INTEGER,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '租赁记录ID'
|
||
},
|
||
roomId: {
|
||
type: DataTypes.INTEGER,
|
||
allowNull: false,
|
||
references: {
|
||
model: Room,
|
||
key: 'id'
|
||
},
|
||
comment: '房间ID'
|
||
},
|
||
tenantName: {
|
||
type: DataTypes.STRING(50),
|
||
allowNull: false,
|
||
comment: '租客姓名'
|
||
},
|
||
startDate: {
|
||
type: DataTypes.DATE,
|
||
allowNull: false,
|
||
comment: '开始日期'
|
||
},
|
||
endDate: {
|
||
type: DataTypes.DATE,
|
||
allowNull: false,
|
||
comment: '结束日期'
|
||
},
|
||
rent: {
|
||
type: DataTypes.DECIMAL(10, 2),
|
||
allowNull: false,
|
||
comment: '租金'
|
||
},
|
||
deposit: {
|
||
type: DataTypes.DECIMAL(10, 2),
|
||
allowNull: true,
|
||
comment: '押金'
|
||
},
|
||
refundedDeposit: {
|
||
type: DataTypes.DECIMAL(10, 2),
|
||
allowNull: true,
|
||
defaultValue: 0,
|
||
comment: '已退押金'
|
||
},
|
||
status: {
|
||
type: DataTypes.ENUM('active', 'expired'),
|
||
allowNull: false,
|
||
defaultValue: 'active',
|
||
comment: '租赁状态(active:在租,expired:已过期)'
|
||
},
|
||
remark: {
|
||
type: DataTypes.TEXT,
|
||
allowNull: true,
|
||
comment: '备注'
|
||
},
|
||
createBy: {
|
||
type: DataTypes.INTEGER,
|
||
allowNull: true,
|
||
comment: '创建人ID'
|
||
},
|
||
createTime: {
|
||
type: DataTypes.DATE,
|
||
defaultValue: DataTypes.NOW,
|
||
comment: '创建时间'
|
||
},
|
||
updateBy: {
|
||
type: DataTypes.INTEGER,
|
||
allowNull: true,
|
||
comment: '修改人ID'
|
||
},
|
||
updateTime: {
|
||
type: DataTypes.DATE,
|
||
defaultValue: DataTypes.NOW,
|
||
onUpdate: DataTypes.NOW,
|
||
comment: '更新时间'
|
||
},
|
||
isDeleted: {
|
||
type: DataTypes.INTEGER,
|
||
allowNull: false,
|
||
defaultValue: 0,
|
||
comment: '删除状态(0:未删除,1:已删除)'
|
||
}
|
||
}, {
|
||
tableName: 'rentals',
|
||
timestamps: false
|
||
});
|
||
|
||
// 建立关联
|
||
Rental.belongsTo(Room, { foreignKey: 'roomId' });
|
||
|
||
module.exports = Rental; |