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, 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: true, comment: '结束日期' }, startReading: { type: DataTypes.DECIMAL(10, 2), allowNull: false, comment: '起始读数' }, endReading: { type: DataTypes.DECIMAL(10, 2), allowNull: true, comment: '结束读数' }, usage: { type: DataTypes.DECIMAL(10, 2), allowNull: true, comment: '用水量' }, unitPrice: { type: DataTypes.DECIMAL(10, 2), allowNull: false, comment: '单价' }, amount: { type: DataTypes.DECIMAL(10, 2), allowNull: true, comment: '金额' }, status: { type: DataTypes.ENUM('unbilled', 'unpaid', 'paid'), allowNull: false, defaultValue: 'unpaid', comment: '状态(unbilled:未出账,unpaid:未支付,paid:已支付)' }, createTime: { type: DataTypes.DATE, defaultValue: DataTypes.NOW, comment: '创建时间' }, updateTime: { type: DataTypes.DATE, defaultValue: DataTypes.NOW, onUpdate: DataTypes.NOW, comment: '更新时间' }, isDeleted: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: '删除状态(0:未删除,1:已删除)' } }, { tableName: 'water_bills', timestamps: false }); // 建立关联 WaterBill.belongsTo(Room, { foreignKey: 'roomId' }); module.exports = WaterBill;