1
This commit is contained in:
@@ -377,6 +377,70 @@ class TaskQueue {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查账号授权状态(剩余天数)
|
||||
* @param {string} sn_code - 设备SN码
|
||||
* @returns {Promise<{authorized: boolean, remaining_days: number, message: string}>}
|
||||
*/
|
||||
async checkAccountAuthorization(sn_code) {
|
||||
try {
|
||||
const pla_account = db.getModel('pla_account');
|
||||
const account = await pla_account.findOne({
|
||||
where: {
|
||||
sn_code: sn_code,
|
||||
is_delete: 0
|
||||
},
|
||||
attributes: ['authorization_date', 'authorization_days']
|
||||
});
|
||||
|
||||
if (!account) {
|
||||
return {
|
||||
authorized: false,
|
||||
remaining_days: 0,
|
||||
message: '账号不存在'
|
||||
};
|
||||
}
|
||||
|
||||
const accountData = account.toJSON();
|
||||
const authDate = accountData.authorization_date;
|
||||
const authDays = accountData.authorization_days || 0;
|
||||
|
||||
// 使用工具函数计算剩余天数
|
||||
const { calculateRemainingDays } = require('../../utils/account_utils');
|
||||
const remaining_days = calculateRemainingDays(authDate, authDays);
|
||||
|
||||
// 如果没有授权信息或剩余天数 <= 0,不允许创建任务
|
||||
if (!authDate || authDays <= 0 || remaining_days <= 0) {
|
||||
if (!authDate || authDays <= 0) {
|
||||
return {
|
||||
authorized: false,
|
||||
remaining_days: 0,
|
||||
message: '账号未授权,请购买使用权限后使用'
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
authorized: false,
|
||||
remaining_days: 0,
|
||||
message: '账号使用权限已到期,请充值续费后使用'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
authorized: true,
|
||||
remaining_days: remaining_days,
|
||||
message: `授权有效,剩余 ${remaining_days} 天`
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`[任务队列] 检查账号授权状态失败:`, error);
|
||||
return {
|
||||
authorized: false,
|
||||
remaining_days: 0,
|
||||
message: '检查授权状态失败'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加任务到队列
|
||||
* @param {string} sn_code - 设备SN码
|
||||
@@ -390,6 +454,12 @@ class TaskQueue {
|
||||
throw new Error(`账号未启用,无法添加任务`);
|
||||
}
|
||||
|
||||
// 检查账号授权状态(剩余天数)
|
||||
const authResult = await this.checkAccountAuthorization(sn_code);
|
||||
if (!authResult.authorized) {
|
||||
throw new Error(authResult.message);
|
||||
}
|
||||
|
||||
// 检查是否已有相同类型的任务在队列中或正在执行
|
||||
const existingTask = await this.findExistingTask(sn_code, taskConfig.taskType);
|
||||
if (existingTask) {
|
||||
|
||||
Reference in New Issue
Block a user