'use strict'; const Schema = require('mongoose').Schema; const moment = require('moment'); const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin'); const { Secret } = require('naf-framework-mongoose/lib/model/schema'); // 办卡表 const card = { mobile: { type: String, required: true, maxLength: 11, unique: true }, // 电话 password: { type: Secret, required: true, select: false }, // 密码 province: { type: String, required: true }, // 省份 city: { type: String }, // 省份 set: { type: String, required: true }, // 169/129 套餐 pay_type: { type: String }, // 支付方式 name: { type: String, required: true }, // 姓名 id_card: { type: String, required: true, lowercase: true }, // 身份证 level: { type: Number, required: true, default: 1 }, // 等级 points: { type: Number, default: 0 }, // 积分 recommend: { type: String }, // 推荐人 r_mobile: { type: String }, // 推荐人电话 car_show: { type: Boolean, default: false }, // 车奖 stockholder: { type: Boolean, default: false }, // 股东 wxaccount: { type: String }, // 微信号(支付账号) create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss'), }, // 创建/办卡 时间 status: { type: String, default: '1' }, // 审核状态:0=>可以使用;1=>禁止使用,需要审核 admin: { type: Boolean, default: false }, }; const schema = new Schema(card, { toJSON: { virtuals: true } }); schema.index({ id: 1 }); schema.index({ status: 1 }); schema.index({ 'meta.createdAt': 1 }); schema.plugin(metaPlugin); module.exports = app => { const { mongoose } = app; return mongoose.model('Card', schema, 'card'); };