rentease-backend/models/ElectricityBill.js

97 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const Room = require('./Room');
const ElectricityBill = sequelize.define('ElectricityBill', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '电费账单ID'
},
roomId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: Room,
key: 'id'
},
comment: '房间ID'
},
startDate: {
type: DataTypes.DATE,
allowNull: false,
comment: '开始日期'
},
endDate: {
type: DataTypes.DATE,
allowNull: false,
comment: '结束日期'
},
startReading: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
comment: '起始读数'
},
endReading: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
comment: '结束读数'
},
usage: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
comment: '用电量'
},
unitPrice: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
comment: '单价'
},
amount: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
comment: '金额'
},
status: {
type: DataTypes.ENUM('unpaid', 'paid'),
allowNull: false,
defaultValue: 'unpaid',
comment: '状态unpaid未支付paid已支付'
},
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: 'electricity_bills',
timestamps: false
});
// 建立关联
ElectricityBill.belongsTo(Room, { foreignKey: 'roomId' });
module.exports = ElectricityBill;