This commit is contained in:
张成
2025-12-15 18:36:20 +08:00
parent c083494fce
commit 6e5c35f144
15 changed files with 867 additions and 8 deletions

View File

@@ -264,6 +264,39 @@ module.exports = (db) => {
})
},
// 授权相关字段
authorization_date: {
comment: '授权日期(授权开始时间)',
type: Sequelize.DATE,
allowNull: true,
defaultValue: null
},
authorization_days: {
comment: '授权天数',
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0
},
remaining_days: {
comment: '剩余天数(虚拟字段,通过计算得出)',
type: Sequelize.VIRTUAL,
get: function () {
const authDate = this.getDataValue('authorization_date');
const authDays = this.getDataValue('authorization_days') || 0;
if (!authDate || authDays <= 0) {
return 0;
}
const startDate = dayjs(authDate);
const endDate = startDate.add(authDays, 'day');
const now = dayjs();
// 计算剩余天数
const remaining = endDate.diff(now, 'day', true);
return Math.max(0, Math.ceil(remaining));
}
}
});