admin.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const moment = require('moment');
  4. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  5. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  6. // 管理员表
  7. const admin = {
  8. name: { type: String }, // 名称
  9. phone: { type: String }, // 手机
  10. passwd: { type: Secret, select: false }, // 注册密码
  11. openid: { type: String }, // 微信openid
  12. role: { type: String }, // 角色: 0:超级管理员;1:管理员;2:机构管理员;3:业务管理员
  13. menus: { type: [ String ] }, // 菜单
  14. pid: { type: String }, // 上级id
  15. deptname: { type: String }, // 机构名称
  16. code: { type: String }, // 邀请码
  17. isdel: { type: Boolean, default: false }, // 是否删除
  18. remark: { type: String, maxLength: 200 },
  19. create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
  20. };
  21. const schema = new Schema(admin, { toJSON: { virtuals: true } });
  22. schema.index({ id: 1 });
  23. schema.index({ name: 1 });
  24. schema.index({ phone: 1 });
  25. schema.index({ role: 1 });
  26. schema.index({ pid: 1 });
  27. schema.index({ code: 1 });
  28. schema.index({ 'meta.createdAt': 1 });
  29. schema.plugin(metaPlugin);
  30. module.exports = app => {
  31. const { mongoose } = app;
  32. return mongoose.model('Admin', schema, 'admin');
  33. };