const { DataTypes } = require('sequelize'); const sequelize = require('../config/db'); const TenantBillingDetail = sequelize.define('TenantBillingDetail', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, comment: '明细ID' }, tenantId: { type: DataTypes.INTEGER, allowNull: false, comment: '租户ID' }, billingPeriodStart: { type: DataTypes.DATEONLY, allowNull: false, comment: '计费周期开始' }, billingPeriodEnd: { type: DataTypes.DATEONLY, allowNull: false, comment: '计费周期结束' }, baseAmount: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0, comment: '基础费用' }, overageApartmentCount: { type: DataTypes.INTEGER, defaultValue: 0, comment: '超额公寓数' }, overageApartmentAmount: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0, comment: '超额公寓费用' }, overageRoomCount: { type: DataTypes.INTEGER, defaultValue: 0, comment: '超额房间数' }, overageRoomAmount: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0, comment: '超额房间费用' }, overageUserCount: { type: DataTypes.INTEGER, defaultValue: 0, comment: '超额用户数' }, overageUserAmount: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0, comment: '超额用户费用' }, totalOverageAmount: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0, comment: '超额费用合计' }, totalAmount: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0, comment: '总费用' }, status: { type: DataTypes.ENUM('calculated', 'billed', 'paid', 'waived'), defaultValue: 'calculated', comment: '状态' }, orderId: { type: DataTypes.INTEGER, allowNull: true, comment: '关联订单ID' } }, { tableName: 'tenant_billing_details', timestamps: false, indexes: [ { name: 'idx_tenant_period', fields: ['tenantId', 'billingPeriodStart', 'billingPeriodEnd'] }, { name: 'idx_status', fields: ['status'] } ], comment: '租户计费明细表' }); module.exports = TenantBillingDetail;