user.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const Schema = require('mongoose').Schema;
  3. const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
  4. const { Secret } = require('naf-framework-mongoose/lib/model/schema');
  5. // 用户表
  6. const UserSchema = {
  7. name: { type: String, required: false, maxLength: 200 }, // 名称
  8. mobile: { type: String, required: true, maxLength: 64 }, // 手机
  9. passwd: { type: Secret, select: false }, // 注册密码
  10. openid: { type: String, required: false }, // 微信openid
  11. appopenid: { type: String, required: false }, // 微信小程序openid
  12. unionid: { type: String, required: false }, // 微信unionid
  13. remark: { type: String, required: false }, // 备注
  14. type: { type: String, required: false, maxLength: 200 }, // 身份,0、中心管理元1、班主任用户2、学校用户3、教师4、学生
  15. uid: { type: String, required: false, maxLength: 200 }, // 关联用户信息id
  16. status: { type: String, required: false, default: '0' }, // 注册状态,0注册;1正在使用;2冻结
  17. };
  18. const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
  19. schema.index({ openid: 1 });
  20. schema.index({ mobile: 1 });
  21. schema.plugin(metaPlugin);
  22. module.exports = app => {
  23. const { mongoose } = app;
  24. return mongoose.model('User', schema, 'user');
  25. };