1
This commit is contained in:
@@ -69,6 +69,7 @@ module.exports = {
|
||||
"POST /user/login": async (ctx) => {
|
||||
|
||||
const { sn_code, device_id } = ctx.getBody();
|
||||
const dayjs = require('dayjs');
|
||||
|
||||
const { pla_account,device_status} = await Framework.getModels();
|
||||
|
||||
@@ -79,6 +80,26 @@ module.exports = {
|
||||
return ctx.fail('用户不存在');
|
||||
}
|
||||
|
||||
// 检查授权状态
|
||||
const userData = user.toJSON();
|
||||
const authDate = userData.authorization_date;
|
||||
const authDays = userData.authorization_days || 0;
|
||||
|
||||
if (authDate && authDays > 0) {
|
||||
const startDate = dayjs(authDate);
|
||||
const endDate = startDate.add(authDays, 'day');
|
||||
const now = dayjs();
|
||||
const remaining = endDate.diff(now, 'day', true);
|
||||
const remaining_days = Math.max(0, Math.ceil(remaining));
|
||||
|
||||
if (remaining_days <= 0) {
|
||||
return ctx.fail('账号授权已过期,请联系管理员续费');
|
||||
}
|
||||
} else {
|
||||
// 如果没有授权信息,检查是否允许登录(可以根据业务需求决定是否允许)
|
||||
// 这里暂时允许登录,但可以添加配置项控制
|
||||
}
|
||||
|
||||
// 更新设备状态
|
||||
|
||||
const device = await device_status.findOne({ where: { sn_code } });
|
||||
@@ -99,7 +120,20 @@ module.exports = {
|
||||
device_id: user.device_id
|
||||
});
|
||||
|
||||
return ctx.success({ token, user: user.toJSON() });
|
||||
// 计算剩余天数并返回
|
||||
let remaining_days = 0;
|
||||
if (authDate && authDays > 0) {
|
||||
const startDate = dayjs(authDate);
|
||||
const endDate = startDate.add(authDays, 'day');
|
||||
const now = dayjs();
|
||||
const remaining = endDate.diff(now, 'day', true);
|
||||
remaining_days = Math.max(0, Math.ceil(remaining));
|
||||
}
|
||||
|
||||
const userInfo = user.toJSON();
|
||||
userInfo.remaining_days = remaining_days;
|
||||
|
||||
return ctx.success({ token, user: userInfo });
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user