瀏覽代碼

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

laiguoran 3 年之前
父節點
當前提交
70fd8dcf2e

+ 81 - 27
modules/all_models/user.js

@@ -1,50 +1,85 @@
 /**
- * 用户数据模型
+ * 用户数据结构
  *
  * @author CaiAoLin
- * @date 2017/7/20
+ * @date 2017/6/28
  * @version
  */
-
-import mongoose from "mongoose";
-
+let mongoose = require("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,
     isUpgrade:Boolean,
-    remark:String,//描述:广东办刘飞 2018-06-17 启用/关闭
+    remark:String, //描述:广东办刘飞 2018-06-17 启用/关闭
     deadline: {
         type:String,
         default: '',
     },
+    lock: { // 锁信息 1:借出(借用);2:销售(购买);
+        type: Number,
+        default: 0,
+    }
 }, { _id: false })
 
+const userdList = mongoose.Schema({
+    compilationId: String
+}, {_id: false});
 
-let modelSchema = {
-    // 用户名
+// 表结构
+let schema = {
+    ssoId: {
+        type: Number,
+        unique: true
+    },
     username: String,
-    // 电子邮件
     email: String,
-    // 手机号码
-    mobile: String,
+    mobile: {
+        type: String,
+        // unique: true
+    },
     qq: {
         type: String,
         default: ''
     },
-    // 真实姓名
-    real_name: String,
-    // 公司
-    company: String,
-    // 省份
-    province: Number,
-    // 公司类型
-    company_type: {
+    real_name: {
+        type: String,
+        default: ''
+    },
+    company: {
+        type: String,
+        default: ''
+    },
+    province: {
         type: Number,
         default: -1
     },
-    // 公司规模
+    version: {
+        type: [versionSchema],
+        default: []
+    },
+    company_type: {
+        type: Number,
+        default: -1,
+    },
     company_scale: {
         type: Number,
         default: -1
@@ -56,16 +91,36 @@ let modelSchema = {
     },
     //最近使用编办
     latest_used:String,
-    // 创建时间
-    create_time: {
-        type: Number,
-        default: 0
-    },
+    create_time: Number,
     upgrade_list:[upgrade],
     user_type:{
         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
@@ -79,5 +134,4 @@ let modelSchema = {
         default: 0, // 0为普通用户,时间戳代表CLD剔除用户并按时间戳排序
     },
 };
-mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
-
+mongoose.model(collectionName, new Schema(schema, {versionKey: false}));

+ 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");

+ 51 - 2
modules/users/models/compilation_model.js

@@ -47,6 +47,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
@@ -283,7 +332,7 @@ class CompilationModel extends BaseModel {
             if (compilationData.suggestion_valuation.length <= 0 &&
                 compilationData.feasibility_valuation.length <= 0 &&
                 compilationData.rough_valuation.length <= 0 &&
-                compilationData.bill_valuation.length <= 0 && 
+                compilationData.bill_valuation.length <= 0 &&
                 compilationData.ration_valuation.length <= 0) {
                 throw '至少需要一个计价规则';
             }
@@ -395,4 +444,4 @@ class CompilationModel extends BaseModel {
 
 }
 
-export default CompilationModel;
+export default CompilationModel;

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

@@ -276,6 +276,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

@@ -70,16 +70,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();
 });
 
 //加载路由文件