const { DataTypes } = require('sequelize'); const sequelize = require('../config/db'); const User = sequelize.define('User', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, comment: '用户ID' }, username: { type: DataTypes.STRING(50), allowNull: false, unique: true, comment: '用户名' }, password: { type: DataTypes.STRING(255), allowNull: false, comment: '密码(加密存储)' }, nickname: { type: DataTypes.STRING(50), allowNull: true, comment: '昵称' }, avatar: { type: DataTypes.STRING(255), allowNull: true, comment: '头像URL' }, roleId: { type: DataTypes.INTEGER, allowNull: true, comment: '角色ID' }, tenantId: { type: DataTypes.INTEGER, allowNull: false, comment: '租户ID' }, userType: { type: DataTypes.ENUM('super_admin', 'tenant_admin', 'user'), allowNull: false, defaultValue: 'user', comment: '用户类型:super_admin-系统管理员,tenant_admin-租户管理员,user-普通用户' }, status: { type: DataTypes.ENUM('active', 'inactive'), defaultValue: 'active', comment: '状态:active-启用,inactive-禁用' }, lastLoginTime: { type: DataTypes.DATE, allowNull: true, comment: '最后登录时间' }, lastLoginIp: { type: DataTypes.STRING(50), allowNull: true, comment: '最后登录IP' }, createBy: { type: DataTypes.INTEGER, allowNull: true, comment: '创建人ID' }, updateBy: { type: DataTypes.INTEGER, allowNull: true, comment: '修改人ID' }, isDeleted: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: '删除状态(0:未删除,1:已删除)' }, createTime: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, comment: '创建时间' }, updateTime: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, comment: '更新时间' } }, { tableName: 'users', timestamps: false, comment: '用户表' }); module.exports = User;