Browse Source

修正user配置项和其它bug无法获取接口信息

laiguoran 3 years ago
parent
commit
a9b5daf503

+ 63 - 3
modules/all_models/user.js

@@ -10,6 +10,21 @@ import mongoose from "mongoose";
 
 let Schema = mongoose.Schema;
 let collectionName = 'users';
+
+const invalidSchema = new Schema({
+    invalid: Boolean,
+    invalidDate: String,
+    invalidBy: String   //管理者名
+});
+
+const versionSchema = new Schema({
+    compilationId: String,
+    activateCode: String,
+    activatedDate: String,
+    activatedBy: String,
+    invalidInfo: [invalidSchema]
+});
+
 let upgrade = mongoose.Schema({
     compilationID:String,//编办ID
     upgrade_time:Number,
@@ -21,8 +36,16 @@ let upgrade = mongoose.Schema({
     },
 }, { _id: false })
 
+const userdList = mongoose.Schema({
+    compilationId: String
+}, {_id: false});
+
 
 let modelSchema = {
+    ssoId: {
+        type: Number,
+        unique: true,
+    },
     // 用户名
     username: String,
     // 电子邮件
@@ -35,11 +58,24 @@ let modelSchema = {
         default: ''
     },
     // 真实姓名
-    real_name: String,
+    real_name: {
+        type: String,
+        default: ''
+    },
     // 公司
-    company: String,
+    company: {
+        type: String,
+        default: ''
+    },
     // 省份
-    province: Number,
+    province: {
+        type: Number,
+        default: -1
+    },
+    version: {
+        type: [versionSchema],
+        default: []
+    },
     // 公司类型
     company_type: {
         type: Number,
@@ -67,6 +103,30 @@ let modelSchema = {
         type:String,
         default:'normal'//  normal : 普通用户,test:测试用户
     },
+    //使用过的费用定额,主要目的拷贝用户在该费用定额下的一些数据模板 eg:用户第一次进入该费用定额的补充定额库时,拷贝补充定额的章节树
+    used_list: {
+        type: [userdList],
+        default: []
+    },
+    // 联系人
+    contacts: {
+        type: Array,
+        default: []
+    },
+    // 是否邮箱已通过验证
+    isUserActive: Number,
+    // 是否只允许短信登录
+    isSmsLogin: {
+        type: Number,
+        default: 0
+    },
+    // 登录异常短信通知
+    isLoginValid: {
+        type: Number,
+        default: 0
+    },
+    welcomeShowTime:String,
+    token: String,
     online_times: {
         type: Number,
         default: 0

+ 2 - 1
modules/users/controllers/cld_controller.js

@@ -8,7 +8,8 @@
  * @version
  */
 
-const CLDModel = require("../models/cld_model");
+// const CLDModel = require("../models/cld_model");
+import CLDModel from "../models/cld_model";
 import UserModel from "../models/user_model";
 import CompilationModel from "../models/compilation_model";
 // const UserModel = require("../models/user_model");

+ 50 - 1
modules/users/models/compilation_model.js

@@ -44,6 +44,55 @@ class CompilationModel extends BaseModel {
     }
 
     /**
+     * 获取编办列表
+     *
+     * @return {Promise}
+     */
+    async getList() {
+        // 筛选字段
+        let field = {_id: 1, name: 1, is_release: 1, description: 1, categoryID: 1};
+        let compilationData = await this.findDataByCondition({name: {$ne: ''}, is_release: true}, field, false);
+
+        return compilationData === null ? [] : compilationData;
+    }
+
+    /**
+     * 根据id获取可用的编办数据
+     *
+     * @param {String} id
+     * @return {Promise}
+     */
+    async getCompilationById(id) {
+        let condition = {_id: id, is_release: true};
+        let compilationData = await this.findDataByCondition(condition);
+        if (!compilationData  || compilationData.bill_valuation === undefined) {
+            return compilationData;
+        }
+
+        if (compilationData.bill_valuation.length > 0) {
+            let enableValuation = [];
+            for (let index in compilationData.bill_valuation) {
+                if (compilationData.bill_valuation[index].enable) {
+                    enableValuation.push(compilationData.bill_valuation[index]);
+                }
+            }
+            compilationData.bill_valuation = enableValuation;
+        }
+
+        if (compilationData.ration_valuation.length > 0) {
+            let enableValuation = [];
+            for (let index in compilationData.ration_valuation) {
+                if (compilationData.ration_valuation[index].enable) {
+                    enableValuation.push(compilationData.bill_valuation[index]);
+                }
+            }
+            compilationData.ration_valuation = enableValuation;
+        }
+
+        return compilationData;
+    }
+
+    /**
      * 设置场景
      *
      * @param {string} scene
@@ -377,4 +426,4 @@ class CompilationModel extends BaseModel {
 
 }
 
-export default CompilationModel;
+export default CompilationModel;

+ 41 - 0
modules/users/models/user_model.js

@@ -281,6 +281,47 @@ class UserModel extends BaseModel {
         return "success";
     }
 
+    /**
+     * 根据用户名查找数据
+     *
+     * @param {string} username
+     * @return {object}
+     */
+    async findDataByName(username) {
+        return await this.db.findOne({username: username});
+    }
+
+    /**
+     * 根据ssoID查找数据
+     *
+     * @param {string} ssoId
+     * @return {object}
+     */
+    async findDataBySsoId(ssoId) {
+        return await this.db.findOne({ssoId: ssoId});
+    }
+
+    /**
+     * 根据手机号查找数据
+     *
+     * @param {string} mobile
+     * @return {object}
+     */
+    async findDataByMobile(mobile) {
+        return await this.db.findOne({mobile: mobile});
+    }
+
+    /**
+     * 根据userId查找数据
+     *
+     * @param {string} ssoId
+     * @return {object}
+     */
+    async findDataById(id, fields) {
+        const objId = mongoose.Types.ObjectId(id);
+        return fields ? await this.db.findOne({_id: objId}, fields) : await this.db.findOne({_id: objId});
+    }
+
 }
 
 export default UserModel;

+ 12 - 8
operation.js

@@ -67,16 +67,20 @@ app.use(session({
 
 app.use(function (req, res, next) {
     let referer = '';
-    if (!(/^\/cld\/(?!getCategoryStaff)/.test(req.originalUrl) || /^\/login/.test(req.originalUrl)) && !req.session.managerData) {
-        if (req.headers["x-requested-with"] != null
-            && req.headers["x-requested-with"] == "XMLHttpRequest"
-            && req.url != "/login") {
-            return res.json({ret_code: 99, ret_msg: '登录信息失效,请您重新登录'});
-        } else{
-            return res.redirect('/login');
+    if(/\.map|\.ico$/.test(req.originalUrl) || /^\/cld\/(?!getCategoryStaff)/.test(req.originalUrl)) {
+        next();
+    } else {
+        if (!/^\/login/.test(req.originalUrl) && !req.session.managerData) {
+            if (req.headers["x-requested-with"] != null
+                && req.headers["x-requested-with"] == "XMLHttpRequest"
+                && req.url != "/login") {
+                return res.json({ret_code: 99, ret_msg: '登录信息失效,请您重新登录'});
+            } else {
+                return res.redirect('/login');
+            }
         }
+        next();
     }
-    next();
 });
 
 //加载路由文件