Browse Source

cld剔除用户页面和权限

laiguoran 4 years ago
parent
commit
62b7c2ac81

+ 5 - 1
modules/all_models/user.js

@@ -70,7 +70,11 @@ let modelSchema = {
     online_times: {
         type: Number,
         default: 0
-    } //最近一天的登录时长累计
+    }, //最近一天的登录时长累计
+    is_cld: {
+        type: Number,
+        default: 0, // 0为普通用户,时间戳代表CLD剔除用户并按时间戳排序
+    },
 };
 mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
 

+ 106 - 0
modules/users/controllers/user_controller.js

@@ -7,6 +7,7 @@
  */
 import BaseController from "../../common/base/base_controller";
 import UserModel from "../models/user_model";
+const CLDModel = require("../models/cld_model");
 import Config from "../../../config/config";
 import CompilationModel from "../models/compilation_model";
 let config = require("../../../config/config.js");
@@ -172,6 +173,90 @@ class UserController extends BaseController {
         response.render('users/views/user/test_user', renderData);
     }
 
+    /**
+     * 最近注册列表(最近登录前台用户列表)
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+    async cldUsers(request, response) {//取普通用户
+        let userModel = new UserModel();
+        let total = 0;
+        let pageData = {};
+        let userList = [];
+        let compilationList =[];
+        let compilationString ='';
+        let compilationMap = {};
+        let filter = request.query;
+        try {
+            //获取编办列表
+            let  compilationModel = new CompilationModel();
+            compilationList = await compilationModel.getCompilationList({_id: 1, name: 1, is_release: 1});
+            compilationString = JSON.stringify(compilationList);
+            compilationMap = _.keyBy(compilationList,'_id');//4.17后的版本没有indexBy方法,改成了keyBy
+            let condition = userModel.getFilterCondition(request);
+            //设置搜索普通用户:
+            condition.user_type = 'normal';
+            condition.is_cld = {$exists:true, $ne: 0};
+
+            //获取注册时间
+            let regtime = request.query.regtime;
+            if(regtime !== '' && regtime !== undefined){
+                filter.regtimeMsg = userModel.getDayMsg(regtime);
+            }
+
+            //获取注册时间
+            let loginTime = request.query.loginTime;
+            if(loginTime !== '' && loginTime !== undefined){
+                filter.loginMsg = userModel.getDayMsg(loginTime);
+            }
+
+            // 获取用户总数
+            total = await userModel.count(condition);
+
+            // 分页数据
+            let page = request.query.page === undefined ? 1 : request.query.page;
+            pageData = {
+                current: page,
+                total: Math.ceil(total / Config.pageSize),
+                queryData: response.locals.urlQuery
+            };
+            // console.log("取用户信息=========================");
+            // console.log(condition);
+            // 获取用户列表
+            userList = await userModel.getList(condition, page, Config.pageSize, {is_cld:-1});
+            // await online_facade.setOnlineTimes(userList,condition);
+            // console.log(userList)
+        } catch (error) {
+            console.log(error);
+        }
+
+        // 用户管理二级菜单独立出来
+        let secondMenu = response.locals.secondMenu;
+        let userMenu = [];
+        for (let second in secondMenu) {
+            userMenu.push(secondMenu[second]);
+        }
+
+        // 渲染数据
+        let renderData = {
+            compilationList:compilationList,
+            compilationString:compilationString,
+            compilationMap:compilationMap,
+            adminName:request.session.managerData?request.session.managerData.real_name:'',
+            userList: userList,
+            pages: pageData,
+            total: total,
+            filter: filter,
+            model: userModel,
+            userMenu: userMenu,
+            layout: 'users/views/layout/layout',
+            LicenseKey:config.getLicenseKey(process.env.NODE_ENV)
+        };
+        response.render('users/views/user/cld', renderData);
+    }
+
 
     /**
      * 获取搜索用户json
@@ -288,6 +373,27 @@ class UserController extends BaseController {
         response.json(responseData);
     }
 
+    async updateCldUser(request, response) {
+        let userModel = new UserModel();
+        let responseData = {
+            error: 0,
+            msg: '',
+            data: null
+        };
+        try{
+            let cldModel = new CLDModel();
+            let cldUserList = await cldModel.getAllStaff();
+            cldUserList = JSON.parse(cldUserList);
+            await userModel.updateAllStaff(cldUserList);
+            responseData.data = true;
+        } catch (error) {
+            console.log(error);
+            responseData.error = error.code;
+            responseData.msg = error.err;
+        }
+        response.json(responseData);
+    }
+
     /**
      * 根据用户id列表获取用户信息列表 json
      *

+ 45 - 0
modules/users/models/cld_model.js

@@ -0,0 +1,45 @@
+'use strict';
+
+/**
+ * cld接口模型
+ *
+ * @author EllisRan.
+ * @date 2020/12/4
+ * @version
+ */
+const Request = require("request");
+
+class CLDModel {
+
+    CLDUrl = 'http://cld.smartcost.com.cn';
+
+    /**
+     * 获取cld所有员工信息
+     *
+     * @return {Promise}
+     */
+    async getAllStaff() {
+        let postData = {
+            url: this.CLDUrl + '/api/building/staff/list',
+            encoding: 'utf8'
+        };
+        return new Promise(function (resolve, reject) {
+            try {
+                // 请求接口
+                Request.post(postData, function (err, postResponse, body) {
+                    if (err) {
+                        throw '请求错误';
+                    }
+                    if (postResponse.statusCode !== 200) {
+                        throw 'CLD通讯失败!';
+                    }
+                    resolve(body);
+                });
+            } catch (error) {
+                reject([]);
+            }
+        });
+    }
+}
+
+module.exports = CLDModel;

+ 14 - 3
modules/users/models/user_model.js

@@ -103,10 +103,10 @@ class UserModel extends BaseModel {
      * @param {Number} pageSize
      * @return {promise}
      */
-    async getList(condition = null, page = 1, pageSize = 30) {
+    async getList(condition = null, page = 1, pageSize = 30, sort = {_id:-1}) {
         page = parseInt(page);
         page = page <= 1 ? 1 : page;
-        let option = {pageSize: pageSize, offset: parseInt((page - 1) * pageSize), sort: {_id:-1}};
+        let option = {pageSize: pageSize, offset: parseInt((page - 1) * pageSize), sort: sort};
 
         let userList = await this.db.find(condition, null, option);
         userList = userList.length > 0 ? userList : [];
@@ -230,6 +230,17 @@ class UserModel extends BaseModel {
         return "success";
     }
 
+
+    async updateAllStaff(userList) {
+        for (const user of userList) {
+            const users = await this.findDataByCondition({ mobile: user.telephone });
+            if(users && users.is_cld === 0) {
+                await this.db.model.updateMany({"_id":users._id},{"is_cld":Date.parse(new Date())/1000});
+            }
+        }
+        return "success";
+    }
+
 }
 
-export default UserModel;
+export default UserModel;

+ 3 - 1
modules/users/routes/user_route.js

@@ -15,11 +15,13 @@ module.exports =function (app) {
     // action定义区域
     router.get('/', userController.auth, userController.init, userController.normalUsers);
     router.get('/testUser', userController.auth, userController.init, userController.testUsers);
+    router.get('/cldUser', userController.auth, userController.init, userController.cldUsers);
     router.get('/search', userController.auth, userController.init, userController.search);
     router.post('/findByID', userController.auth, userController.init, userController.findByID);
     router.post('/getOnlineInfo', userController.auth, userController.init, userController.getOnlineInfo);
     router.post('/getUserList', userController.auth, userController.init, userController.getUserList);
     router.post('/updateUser', userController.auth, userController.init, userController.updateUser);
+    router.post('/updateCldUser', userController.auth, userController.init, userController.updateCldUser);
     router.post('/deleteUser', userController.auth, userController.init, userController.deleteUser);
     app.use("/user", router);
-};
+};

+ 55 - 4
web/users/js/user.js

@@ -40,6 +40,26 @@ $(document).ready(function() {
             }
         }
     });
+    $('#remove-cldUser').click(async function () {
+        const id = $(this).attr('data-uid');
+        if(id !== '') {
+            try {
+                await ajaxPost("/user/updateUser",{ID:id,updateData:{is_cld:0}});
+                window.location.reload();
+            }catch (err){
+                console.log(err);
+            }
+        }
+    });
+
+    $('#add-allCldUser').click(async function () {
+        try {
+            await ajaxPost("/user/updateCldUser", {});
+            window.location.reload();
+        }catch (err){
+            console.log(err);
+        }
+    })
 });
 let cacheUser = null;
 
@@ -59,13 +79,12 @@ async function getOnlineInfo(filter) {
 
 async function getUserInfo(ID) {
     let user = await ajaxPost("/user/findByID",{ID:ID});
-    let infoString = `<tr><th>注册时间</th><td>${user.create_time}</td><th>最近登录</th><td>${user.last_login}</td></tr>
+    let infoString = `<tr><th>注册时间</th><td>${user.create_time}</td><th>最近登录</th><td>${moment(user.latest_login).format('YYYY-MM-DD HH:mm:ss')}</td></tr>
                       <tr><th>手机</th><td >${user.mobile}</td><th>邮箱</th><td>${user.email}</td></tr>
                       <tr><th>姓名</th><td colspan="3" id>${user.real_name}</td></tr>
-                      <tr><th>企业名称</th><td colspan="3">${user.company}</td></tr>
-                      <tr><th>企业地区</th><td>${user.province}</td><th>企业类型</th><td>${user.company_type}</td></tr>
-                      <tr><th>企业规模</th><td colspan="3">${user.company_scale}</td></tr>`;
+                      <tr><th>企业名称</th><td colspan="3">${user.company}</td></tr>`;
     $('#userInfoTable').html(infoString);
+    $('#remove-cldUser').attr('data-uid', ID);
 }
 
 function deleteUser(userID) {
@@ -73,7 +92,39 @@ function deleteUser(userID) {
     $("#userID").val(userID);
 }
 
+function searchUser() {
+    const keyword = $.trim($('#search_keyword').val());
+    if (keyword === '') {
+        alert("请输出查询用户信息!");
+    }
+    CommonAjax.get(`/user/search?keyword=` + keyword, function (result) {
+        if (result.error === 0) {
+            let html = '';
+            for (const user of result.data) {
+                html += `<tr><td>${user.real_name}</td><td>${user.email}</td><td>${user.mobile}</td><td>` + (user.is_cld === 0 ? `<a href="javascript:void(0);" onclick="addCldUser(this, '${user._id}')">添加</a>` : '已添加') + `</td></tr>`;
+            }
+            $('#search_user_list').html(html);
+        } else {
+            alert(result.msg);
+        }
+    });
+    return false;
+}
+
+async function addCldUser($this, id) {
+    try {
+        await ajaxPost("/user/updateUser",{ID:id,updateData:{is_cld:Date.parse(new Date())/1000}});
+        const _self = $($this).parents('td');
+        $this.remove();
+        _self.text('已添加');
+    }catch (err){
+        console.log(err);
+    }
+}
 
+async function removeCldUser() {
+
+}
 
 async function getUserUpgradeInfo(ID){
     try {

+ 122 - 0
web/users/views/user/cld.html

@@ -0,0 +1,122 @@
+<div class="panel-content">
+    <div class="panel-title fluid">
+        <div class="title-main">
+            <% for (let menu of userMenu) { %>
+            <% if (menu.title === secondMenu[action].title) { %>
+            <%= menu.title %>
+            <% } else { %>
+            <a href="<%= menu.url %>" class="btn btn-primary btn-link" style="margin-left: 0;margin-right: 12px"><%= menu.title %></a>
+            <% } %>
+            <% } %>
+            <a href="#news-add" data-toggle="modal" data-target="#news-add" class="btn btn-primary btn-sm pull-right">添加用户</a></h2>
+            <a href="javascript:void(0)" id="add-allCldUser" class="btn btn-warning btn-sm pull-right">一键增加所有CLD员工用户</a></h2>
+        </div>
+    </div>
+    <div class="content-wrap">
+        <div class="c-header">
+            <form class="form-inline" method="get" action="" id="searchUser">
+                <!--结果-->
+                <div class="btn-group">
+                    &nbsp;共 <%= total %> 条结果
+                </div>
+                <!--搜索-->
+                <div class="btn-group">
+                    <div class="input-group">
+                        <input type="text" name="keyword" class="form-control input-sm" value="<%= filter.keyword === undefined ? '' : filter.keyword %>" placeholder="手机/邮箱/姓名/公司">
+                        <span class="input-group-btn">
+                        <button class="btn btn-default btn-sm" type="submit">
+                            <i class="glyphicon glyphicon-search"></i>
+                        </button>
+                    </span>
+                    </div>
+                </div>
+            </form>
+        </div>
+        <div class="c-body">
+            <table class="table">
+                <thead>
+                <tr>
+                    <th width="350">注册手机/QQ</th>
+                    <th>姓名</th>
+                    <th>企业名称</th>
+                    <th>最近使用 </th>
+                    <th width="180">最近登录</th>
+                    <th>详细</th>
+                </tr>
+                </thead>
+                <tbody>
+                <% userList.forEach(function (user){ %>
+                <tr>
+                    <td><%= user.mobile %><br><%= user.qq %></td>
+                    <td><%= user.real_name %></td>
+                    <td><%= user.company %></td>
+                    <td><%= compilationMap[user.latest_used]?compilationMap[user.latest_used].name:""%></td>
+                    <td><%= user.latest_login?moment(user.latest_login).tz("Asia/Shanghai").format('YYYY-MM-DD HH:mm:ss'):"" %></td>
+                    <td><a role="button" data-toggle="modal" data-target="#view" onclick='getUserInfo("<%= user._id.toString()%>")'>详细</a></td>
+                </tr>
+                <% }) %>
+                </tbody>
+            </table>
+            <nav aria-label="Page navigation">
+                <%include ../layout/page.html %>
+            </nav>
+        </div>
+    </div>
+</div>
+
+
+<!-- 弹窗查看用户详情-->
+<div class="modal fade" id="view" tabindex="-1" role="dialog">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                <h4 class="modal-title" >用户信息</h4>
+            </div>
+            <div class="modal-body">
+                <table class="table table-bordered">
+                    <tbody id="userInfoTable">
+                    </tbody>
+                </table>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-danger" id="remove-cldUser" data-uid="">移除该账号</button>
+                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
+            </div>
+        </div>
+    </div>
+</div>
+
+<!-- 弹窗添加-->
+<div class="modal fade" id="news-add" tabindex="-1" role="dialog">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                <h4 class="modal-title" >添加剔除用户</h4>
+            </div>
+            <div class="modal-body">
+                <form class="input-group" method="get" action="/user/search" onsubmit="searchUser(); return false;" style="margin-bottom:10px">
+                    <input class="form-control input-sm" placeholder="手机/邮箱/姓名" type="text" name="keyword" id="search_keyword">
+                    <span class="input-group-btn">
+			        <button class="btn btn-default btn-sm" type="submit"><i class="glyphicon glyphicon-search"></i></button>
+			      </span>
+                </form>
+                <table class="table table-sm table-bordered">
+                    <tr><th>姓名</th><th>邮箱</th><th>手机</th><th>添加</th></tr>
+                    <tbody id="search_user_list">
+                    </tbody>
+                </table>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script type="text/javascript">
+    let compilationList = JSON.parse('<%- compilationString %>');
+    let adminName = '<%- adminName %>';
+</script>
+<script type="text/javascript" src="/web/users/js/user.js"></script>

+ 0 - 1
web/users/views/user/index.html

@@ -8,7 +8,6 @@
             <a href="<%= menu.url %>" class="btn btn-primary btn-link" style="margin-left: 0;margin-right: 12px"><%= menu.title %></a>
             <% } %>
             <% } %>
-            <!--<h2><%= secondMenu[action].title %><a href="/user/testUser" class="btn btn-primary btn-link">测试用户</a></h2>-->
         </div>
     </div>
     <div class="content-wrap">