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