rentease-backend/models/Rental.js

98 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2026-03-02 12:36:41 +00:00
const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const Room = require('./Room');
const Rental = sequelize.define('Rental', {
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
},
roomId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: Room,
key: 'id'
2026-03-05 15:26:13 +00:00
},
comment: '房间ID'
2026-03-02 12:36:41 +00:00
},
2026-03-05 15:26:13 +00:00
tenantName: {
type: DataTypes.STRING(50),
2026-03-02 12:36:41 +00:00
allowNull: false,
2026-03-05 15:26:13 +00:00
comment: '租客姓名'
2026-03-02 12:36:41 +00:00
},
startDate: {
type: DataTypes.DATE,
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '开始日期'
2026-03-02 12:36:41 +00:00
},
endDate: {
type: DataTypes.DATE,
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '结束日期'
2026-03-02 12:36:41 +00:00
},
rent: {
type: DataTypes.DECIMAL(10, 2),
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '租金'
2026-03-02 12:36:41 +00:00
},
deposit: {
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-09 13:27:09 +00:00
refundedDeposit: {
type: DataTypes.DECIMAL(10, 2),
allowNull: true,
defaultValue: 0,
comment: '已退押金'
},
2026-03-02 12:36:41 +00:00
status: {
type: DataTypes.ENUM('active', 'expired'),
allowNull: false,
2026-03-05 15:26:13 +00:00
defaultValue: 'active',
comment: '租赁状态active在租expired已过期'
2026-03-02 12:36:41 +00:00
},
remark: {
type: DataTypes.TEXT,
2026-03-05 15:26:13 +00:00
allowNull: true,
comment: '备注'
2026-03-02 12:36:41 +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: 'rentals',
timestamps: false
});
// 建立关联
Rental.belongsTo(Room, { foreignKey: 'roomId' });
module.exports = Rental;