const { DataTypes } = require('sequelize'); const sequelize = require('../config/db'); const Room = require('./Room'); const WaterBill = sequelize.define('WaterBill', { 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 }, updateTime: { type: DataTypes.DATE, defaultValue: DataTypes.NOW, onUpdate: DataTypes.NOW }, isDeleted: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 } }, { tableName: 'water_bills', timestamps: false }); // 建立关联 WaterBill.belongsTo(Room, { foreignKey: 'roomId' }); module.exports = WaterBill;