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