'use strict'; /** * 平台管理员(admin_members) * * 一行 = 一个平台管理员账号(`user_id` 唯一): * - `role`:1 超级管理员 / 2 管理员(目前权限一样,留字段给以后细分) * - `status`:1 启用 / 0 停用(停用等价于移除,但保留记录便于审计) * - 软删除:paranoid(`deleted_at`) * * ⚠️ 与 `wechat_gateway_bindings` 同理:软删的行仍然占着 `uk_admin_members_user` 唯一索引, * 所以「查重 / 重新添加同一个人」必须带 `paranoid: false`(见 service/admin_member.js)。 */ module.exports = (app) => { const { BIGINT, STRING, TINYINT, DATE } = app.Sequelize; const AdminMember = app.model.define('admin_member', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, userId: { type: BIGINT.UNSIGNED, allowNull: false, unique: true, comment: '平台管理员的账号 users.id' }, name: { type: STRING(32), allowNull: false, defaultValue: '', comment: '显示名(不填就用账号昵称/用户名)' }, role: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '角色:1 超级管理员 2 管理员' }, status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1 启用 0 停用' }, remark: { type: STRING(255), comment: '备注' }, }, { tableName: 'admin_members', paranoid: true, comment: '平台管理员表', }); AdminMember.associate = function() { app.model.AdminMember.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' }); }; return AdminMember; };