This commit is contained in:
wangxiaoxian 2026-03-04 13:03:31 +08:00
parent 25ebc0b26e
commit 79deb628b4
2 changed files with 45 additions and 9 deletions

View File

@ -40,7 +40,7 @@ const checkAndUpdateRentalStatus = async () => {
const currentDate = new Date(); const currentDate = new Date();
// 计算10天后的日期 // 计算10天后的日期
const tenDaysLater = new Date(); const tenDaysLater = new Date();
tenDaysLater.setDate(currentDate.getDate() + 10); tenDaysLater.setDate(currentDate.getDate() + 30);
// 查找所有活跃的租房记录 // 查找所有活跃的租房记录
const rentals = await Rental.findAll({ const rentals = await Rental.findAll({
@ -59,16 +59,22 @@ const checkAndUpdateRentalStatus = async () => {
// 检查是否已到期 // 检查是否已到期
if (endDate < currentDate) { if (endDate < currentDate) {
// 更新租房状态为已到期 // 更新房间附属状态为已到期
await rental.update({ status: 'expired' }); const room = await Room.findByPk(rental.roomId);
// 更新房间状态为空房 if (room && room.status === 'rented') {
if (rental.Room) { await room.update({ subStatus: 'expired' });
await rental.Room.update({ status: 'empty' });
} }
} else if (endDate <= tenDaysLater) { } else if (endDate <= tenDaysLater) {
// 更新房间状态为即将到期 // 更新房间附属状态为即将到期
if (rental.Room && rental.Room.status === 'rented') { const room = await Room.findByPk(rental.roomId);
await rental.Room.update({ status: 'soon_expire' }); if (room && room.status === 'rented') {
await room.update({ subStatus: 'soon_expire' });
}
} else {
// 更新房间附属状态为正常
const room = await Room.findByPk(rental.roomId);
if (room && room.status === 'rented') {
await room.update({ subStatus: 'normal' });
} }
} }
} }

View File

@ -52,6 +52,16 @@ const WaterBill = sequelize.define('WaterBill', {
createTime: { createTime: {
type: DataTypes.DATE, type: DataTypes.DATE,
defaultValue: DataTypes.NOW defaultValue: DataTypes.NOW
},
updateTime: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
onUpdate: DataTypes.NOW
},
isDeleted: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
} }
}, { }, {
tableName: 'water_bills', tableName: 'water_bills',
@ -109,6 +119,16 @@ const ElectricityBill = sequelize.define('ElectricityBill', {
createTime: { createTime: {
type: DataTypes.DATE, type: DataTypes.DATE,
defaultValue: DataTypes.NOW defaultValue: DataTypes.NOW
},
updateTime: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
onUpdate: DataTypes.NOW
},
isDeleted: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
} }
}, { }, {
tableName: 'electricity_bills', tableName: 'electricity_bills',
@ -174,6 +194,16 @@ const Rental = sequelize.define('Rental', {
createTime: { createTime: {
type: DataTypes.DATE, type: DataTypes.DATE,
defaultValue: DataTypes.NOW defaultValue: DataTypes.NOW
},
updateTime: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
onUpdate: DataTypes.NOW
},
isDeleted: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0
} }
}, { }, {
tableName: 'rentals', tableName: 'rentals',