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 }, roomId: { type: DataTypes.INTEGER, allowNull: false, references: { model: Room, key: 'id' } }, startDate: { type: DataTypes.DATE, allowNull: false }, endDate: { type: DataTypes.DATE, allowNull: false }, startReading: { type: DataTypes.DECIMAL(10, 2), allowNull: false }, endReading: { type: DataTypes.DECIMAL(10, 2), allowNull: false }, usage: { type: DataTypes.DECIMAL(10, 2), allowNull: false }, unitPrice: { type: DataTypes.DECIMAL(10, 2), allowNull: false }, amount: { type: DataTypes.DECIMAL(10, 2), allowNull: false }, status: { type: DataTypes.ENUM('unpaid', 'paid'), allowNull: false, defaultValue: 'unpaid' }, createTime: { type: DataTypes.DATE, defaultValue: DataTypes.NOW } }, { tableName: 'electricity_bills', timestamps: false }); // 建立关联 ElectricityBill.belongsTo(Room, { foreignKey: 'roomId' }); module.exports = ElectricityBill;