user.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * 用户数据结构
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/6/28
  6. * @version
  7. */
  8. let mongoose = require("mongoose");
  9. let Schema = mongoose.Schema;
  10. // 表名
  11. let collectionName = 'user';
  12. const invalidSchema = new Schema({
  13. invalid: Boolean,
  14. invalidDate: String,
  15. invalidBy: String //管理者名
  16. });
  17. const versionSchema = new Schema({
  18. compilationId: String,
  19. activateCode: String,
  20. activatedDate: String,
  21. activatedBy: String,
  22. invalidInfo: [invalidSchema]
  23. });
  24. let upgrade = mongoose.Schema({
  25. compilationID:String,// 编办ID
  26. upgrade_time:Number,
  27. isUpgrade:Boolean,
  28. remark:String,// 描述:广东办刘飞 2018-06-17 启用/关闭
  29. deadline: {
  30. type:String,
  31. default: '',
  32. },
  33. lock: { // 锁信息 1:借出;2:销售;
  34. type: Number,
  35. default: 0
  36. }
  37. }, { _id: false })
  38. const userdList = mongoose.Schema({
  39. compilationId: String
  40. }, {_id: false});
  41. // 表结构
  42. let schema = {
  43. ssoId: {
  44. type: Number,
  45. unique: true,
  46. },
  47. username: String,
  48. email: String,
  49. mobile: {
  50. type: String,
  51. // unique: true,
  52. },
  53. qq: {
  54. type: String,
  55. default: ''
  56. },
  57. real_name: {
  58. type: String,
  59. default: ''
  60. },
  61. company: {
  62. type: String,
  63. default: ''
  64. },
  65. province: {
  66. type: Number,
  67. default: -1
  68. },
  69. version: {
  70. type: [versionSchema],
  71. default: []
  72. },
  73. company_type: {
  74. type: Number,
  75. default: -1,
  76. },
  77. company_scale: {
  78. type: Number,
  79. default: -1
  80. },
  81. // 最后登录时间
  82. latest_login: {
  83. type: Number,
  84. default: 0
  85. },
  86. //最近使用编办
  87. latest_used:String,
  88. create_time: Number,
  89. upgrade_list:[upgrade],
  90. user_type:{
  91. type:String,
  92. default:'normal'// normal : 普通用户,test:测试用户
  93. },
  94. //使用过的费用定额,主要目的拷贝用户在该费用定额下的一些数据模板 eg:用户第一次进入该费用定额的补充定额库时,拷贝补充定额的章节树
  95. used_list: {
  96. type: [userdList],
  97. default: []
  98. },
  99. // 联系人
  100. contacts: {
  101. type: Array,
  102. default: []
  103. },
  104. // 是否邮箱已通过验证
  105. isUserActive: Number,
  106. // 是否只允许短信登录
  107. isSmsLogin: {
  108. type: Number,
  109. default: 0
  110. },
  111. // 登录异常短信通知
  112. isLoginValid: {
  113. type: Number,
  114. default: 0
  115. },
  116. welcomeShowTime:String,
  117. token: String,
  118. online_times: {//最近一天的登录时长累计
  119. type: Number,
  120. default: 0
  121. },
  122. all_online_times: {//所有登录时长累计
  123. type: Number,
  124. default: 0
  125. },
  126. is_cld: {
  127. type: Number,
  128. default: 0, // 0为普通用户,时间戳代表CLD剔除用户并按时间戳排序
  129. },
  130. };
  131. mongoose.model(collectionName, new Schema(schema, {versionKey: false}));