rentease-backend/models/ElectricityBill.js

97 lines
2.0 KiB
JavaScript
Raw 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 ElectricityBill = sequelize.define('ElectricityBill', {
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
},
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
},
startReading: {
type: DataTypes.DECIMAL(10, 2),
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '起始读数'
2026-03-02 12:36:41 +00:00
},
endReading: {
type: DataTypes.DECIMAL(10, 2),
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '结束读数'
2026-03-02 12:36:41 +00:00
},
usage: {
type: DataTypes.DECIMAL(10, 2),
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '用电量'
2026-03-02 12:36:41 +00:00
},
unitPrice: {
type: DataTypes.DECIMAL(10, 2),
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '单价'
2026-03-02 12:36:41 +00:00
},
amount: {
type: DataTypes.DECIMAL(10, 2),
2026-03-05 15:26:13 +00:00
allowNull: false,
comment: '金额'
2026-03-02 12:36:41 +00:00
},
status: {
type: DataTypes.ENUM('unpaid', 'paid'),
allowNull: false,
2026-03-05 15:26:13 +00:00
defaultValue: 'unpaid',
comment: '状态unpaid未支付paid已支付'
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: 'electricity_bills',
timestamps: false
});
// 建立关联
ElectricityBill.belongsTo(Room, { foreignKey: 'roomId' });
module.exports = ElectricityBill;