基于微信小程序的会议室预定平台开发笔记

业务背景

会议室是一个单位或部门的共用资源,但在使用的时候往往会遇到时间冲突、预约困难、不方便协调等问题。目前大部分公司是统一在公司群聊中预约,每次预约时,都需要翻一下聊天记录,了解是否有人预定以及预定时间等。如果冲突则需要找到相关联系人进行沟通。查找历史预约记录麻烦。而现在员工人人都有微信,基于微信环境下的小程序,不用安装独立APP,访问方便。所以我们可以基于小程序,借助于会议室预约系统改善这种情况,实现会议室资源的最优使用

需求分析

image.png

数据库设计

EnrollModel.DB_STRUCTURE = {
    _pid: 'string|true',
    ENROLL_ID: 'string|true',

    ENROLL_TITLE: 'string|true|comment=标题',
    ENROLL_STATUS: 'int|true|default=1|comment=状态 0=未启用,1=使用中',

    ENROLL_CATE_ID: 'string|true|default=0|comment=分类',
    ENROLL_CATE_NAME: 'string|false|comment=分类冗余',

    ENROLL_CANCEL_SET: 'int|true|default=1|comment=取消设置 0=不允,1=允许,2=仅截止前可取消,3=审核后不可取消',
    ENROLL_EDIT_SET: 'int|true|default=1|comment=修改 0=不允,1=允许,2=仅截止前可,3=审核后不可修改',
    ENROLL_CHECK_SET: 'int|true|default=0|comment=审核 0=不需要审核,1=需要审核',

 

    ENROLL_ORDER: 'int|true|default=9999',
    ENROLL_VOUCH: 'int|true|default=0',

    ENROLL_FORMS: 'array|true|default=[]',
    ENROLL_OBJ: 'object|true|default={}',

    ENROLL_JOIN_FORMS: 'array|true|default=[]',

    ENROLL_QR: 'string|false',
    ENROLL_VIEW_CNT: 'int|true|default=0',
    ENROLL_JOIN_CNT: 'int|true|default=0',

    ENROLL_ADD_TIME: 'int|true',
    ENROLL_EDIT_TIME: 'int|true',
    ENROLL_ADD_IP: 'string|false',
    ENROLL_EDIT_IP: 'string|false',
};

EnrollJoinModel.DB_STRUCTURE = {
    _pid: 'string|true',
    ENROLL_JOIN_ID: 'string|true',
    ENROLL_JOIN_ENROLL_ID: 'string|true|comment=报名PK',

    ENROLL_JOIN_IS_ADMIN: 'int|true|default=0|comment=是否管理员添加 0/1',

    ENROLL_JOIN_DAY: 'string|false|comment=预约日期',
    ENROLL_JOIN_START: 'string|false|comment=开始时间',
    ENROLL_JOIN_END: 'string|false|comment=结束时间',
    ENROLL_JOIN_END_POINT: 'string|false|comment=结束时间末尾',

    ENROLL_JOIN_USER_ID: 'string|true|comment=用户ID', 
    ENROLL_JOIN_FORMS: 'array|true|default=[]|comment=表单',
    ENROLL_JOIN_OBJ: 'object|true|default={}',

    ENROLL_JOIN_STATUS: 'int|true|default=1|comment=状态 0=待审核 1=报名成功, 99=审核未过',
    ENROLL_JOIN_REASON: 'string|false|comment=审核拒绝或者取消理由',

    ENROLL_JOIN_LAST_TIME: 'int|true|default=0', 
    
    ENROLL_JOIN_ADD_TIME: 'int|true',
    ENROLL_JOIN_EDIT_TIME: 'int|true',
    ENROLL_JOIN_ADD_IP: 'string|false',
    ENROLL_JOIN_EDIT_IP: 'string|false',
};

UI设计

image.png
image.png
image.png
image.png
image.png
image.png

核心代码

class EnrollService extends BaseProjectService {

    // 获取当前登记状态
    getJoinStatusDesc(enroll) {

        return '进行中';
    }

    /** 浏览信息 */
    async viewEnroll(userId, id) {

        let fields = '*';

        let where = {
            _id: id,
            ENROLL_STATUS: EnrollModel.STATUS.COMM
        }
        let enroll = await EnrollModel.getOne(where, fields);
        if (!enroll) return null;

        EnrollModel.inc(id, 'ENROLL_VIEW_CNT', 1);

        // 判断是否有登记
        let whereJoin = {
            ENROLL_JOIN_USER_ID: userId,
            ENROLL_JOIN_ENROLL_ID: id,
            ENROLL_JOIN_STATUS: ['in', [EnrollJoinModel.STATUS.WAIT, EnrollJoinModel.STATUS.SUCC]]
        }
        let enrollJoin = await EnrollJoinModel.getOne(whereJoin);
        if (enrollJoin) {
            enroll.myEnrollJoinId = enrollJoin._id;
            enroll.myEnrollJoinTag = (enrollJoin.ENROLL_JOIN_STATUS == EnrollJoinModel.STATUS.WAIT) ? '待审核' : '已预约';
        }
        else {
            enroll.myEnrollJoinId = '';
            enroll.myEnrollJoinTag = '';
        }

        return enroll;
    }


    /** 取得分页列表 */
    async getEnrollList({
        search, // 搜索条件
        sortType, // 搜索菜单
        sortVal, // 搜索菜单
        orderBy, // 排序 
        page,
        size,
        isTotal = true,
        oldTotal
    }) {

        orderBy = orderBy || {
            'ENROLL_ORDER': 'asc',
            'ENROLL_ADD_TIME': 'desc'
        };
        let fields = 'ENROLL_STOP,ENROLL_JOIN_CNT,ENROLL_OBJ,ENROLL_VIEW_CNT,ENROLL_TITLE,ENROLL_ORDER,ENROLL_STATUS,ENROLL_CATE_NAME';

        let where = {};
        where.and = {
            _pid: this.getProjectId() //复杂的查询在此处标注PID
        };

        where.and.ENROLL_STATUS = EnrollModel.STATUS.COMM; // 状态  

        if (util.isDefined(search) && search) {
            where.or = [{
                ENROLL_TITLE: ['like', search]
            },];
        } else if (sortType && util.isDefined(sortVal)) {
            // 搜索菜单
            switch (sortType) {
                case 'cateId': {
                    if (sortVal) where.and.ENROLL_CATE_ID = String(sortVal);
                    break;
                }
                case 'sort': {
                    orderBy = this.fmtOrderBySort(sortVal, 'ENROLL_ADD_TIME');
                    break;
                }

            }
        }

        return await EnrollModel.getList(where, fields, orderBy, page, size, isTotal, oldTotal);
    }

    // 获取某天某会议室预约情况
    async getEnrollJoinByDay(enrollId, day) {
        let where = {
            ENROLL_JOIN_DAY: day,
            ENROLL_JOIN_ENROLL_ID: enrollId,
        };
        return EnrollJoinModel.getAll(where);
    }


    /** 取得我的登记分页列表 */
    async getMyEnrollJoinList(userId, {
        search, // 搜索条件
        sortType, // 搜索菜单
        sortVal, // 搜索菜单
        orderBy, // 排序 
        page,
        size,
        isTotal = true,
        oldTotal
    }) {
        orderBy = orderBy || {
            'ENROLL_JOIN_ADD_TIME': 'desc'
        };
        let fields = 'ENROLL_JOIN_OBJ,ENROLL_JOIN_DAY,ENROLL_JOIN_START,ENROLL_JOIN_END,ENROLL_JOIN_END_POINT,ENROLL_JOIN_LAST_TIME,ENROLL_JOIN_REASON,ENROLL_JOIN_ENROLL_ID,ENROLL_JOIN_STATUS,ENROLL_JOIN_ADD_TIME,enroll.ENROLL_TITLE,enroll.ENROLL_EDIT_SET,enroll.ENROLL_CANCEL_SET';

        let where = {
            ENROLL_JOIN_USER_ID: userId
        };

        if (util.isDefined(search) && search) {
            where['enroll.ENROLL_TITLE'] = {
                $regex: '.*' + search,
                $options: 'i'
            };
        } else if (sortType) {
            // 搜索菜单
            switch (sortType) {
                case 'timedesc': { //按时间倒序
                    orderBy = {
                        'ENROLL_JOIN_ADD_TIME': 'desc'
                    };
                    break;
                }
                case 'timeasc': { //按时间正序
                    orderBy = {
                        'ENROLL_JOIN_ADD_TIME': 'asc'
                    };
                    break;
                }
                case 'succ': {
                    where.ENROLL_JOIN_STATUS = EnrollJoinModel.STATUS.SUCC;
                    break;
                }
                case 'wait': {
                    where.ENROLL_JOIN_STATUS = EnrollJoinModel.STATUS.WAIT;
                    break;
                }
                case 'cancel': {
                    where.ENROLL_JOIN_STATUS = EnrollJoinModel.STATUS.ADMIN_CANCEL;
                    break;
                }
            }
        }

        let joinParams = {
            from: EnrollModel.CL,
            localField: 'ENROLL_JOIN_ENROLL_ID',
            foreignField: '_id',
            as: 'enroll',
        };

        let result = await EnrollJoinModel.getListJoin(joinParams, where, fields, orderBy, page, size, isTotal, oldTotal);

        return result;
    }

    /**
     * 获取从某天开始有预约的日期
     * @param {*} fromDay  日期 Y-M-D
     */
    async getEnrollJoinHasDaysFromDay(fromDay) {
        let where = {
            ENROLL_JOIN_DAY: ['>=', fromDay],
        };

        let fields = 'ENROLL_JOIN_DAY';
        let list = await EnrollJoinModel.distinct(where, fields);
 
        return list;
    }

    /** 按天获取所有预定项目 */
    async getEnrollJoinAllListByDay(day) {
        let where = {
            ENROLL_JOIN_STATUS: EnrollJoinModel.STATUS.SUCC,
            ENROLL_JOIN_DAY: day,
        };

        let orderBy = {
            'ENROLL_JOIN_START': 'asc',
            'ENROLL_JOIN_ADD_TIME': 'desc'
        };

        let fields = 'ENROLL_JOIN_START,ENROLL_JOIN_END_POINT,ENROLL_JOIN_OBJ';

        let list = await EnrollJoinModel.getAll(where, fields, orderBy);

        let retList = [];

        for (let k = 0; k < list.length; k++) {
            console.log(list[k])
            let node = {};
            node.timeDesc = list[k].ENROLL_JOIN_START;
            node.title = list[k].ENROLL_JOIN_OBJ.name; 
            node._id = list[k]._id;
            retList.push(node);

        }
        return retList;
    }

    /** 取得我的登记详情 */
    async getMyEnrollJoinDetail(enrollJoinId) {

        let fields = '*';

        let where = {
            _id: enrollJoinId
        };
        let enrollJoin = await EnrollJoinModel.getOne(where, fields);
        if (enrollJoin) {
            enrollJoin.enroll = await EnrollModel.getOne(enrollJoin.ENROLL_JOIN_ENROLL_ID, 'ENROLL_TITLE');
        }

        return enrollJoin;
    }

    //################## 登记 
    // 登记 
    async enrollJoin(userId, enrollId, start, end, endPoint, day, forms) {

        // 登记是否结束
        let whereEnroll = {
            _id: enrollId,
            ENROLL_STATUS: EnrollModel.STATUS.COMM
        }
        let enroll = await EnrollModel.getOne(whereEnroll);
        if (!enroll)
            this.AppError('该' + ENROLL_NAME + '不存在或者已经停止');



        // 时段是否冲突 TODO


        // 入库
        let data = {
            ENROLL_JOIN_USER_ID: userId,
            ENROLL_JOIN_ENROLL_ID: enrollId,

            ENROLL_JOIN_START: start,
            ENROLL_JOIN_END: end,
            ENROLL_JOIN_END_POINT: endPoint,
            ENROLL_JOIN_DAY: day,

            ENROLL_JOIN_STATUS: (enroll.ENROLL_CHECK_SET == 0) ? EnrollJoinModel.STATUS.SUCC : EnrollJoinModel.STATUS.WAIT,

            ENROLL_JOIN_FORMS: forms,
            ENROLL_JOIN_OBJ: dataUtil.dbForms2Obj(forms),
        }

        let enrollJoinId = await EnrollJoinModel.insert(data);

        // 统计数量
        this.statEnrollJoin(enrollId);

        let check = enroll.ENROLL_CHECK_SET;

        return { enrollJoinId, check }

    }


    // 修改登记 
    async enrollJoinEdit(userId, enrollId, enrollJoinId, forms) {
        let whereJoin = {
            _id: enrollJoinId,
            ENROLL_JOIN_USER_ID: userId,
            ENROLL_JOIN_ENROLL_ID: enrollId,
            ENROLL_JOIN_STATUS: ['in', [EnrollJoinModel.STATUS.WAIT, EnrollJoinModel.STATUS.SUCC]],
        }
        let enrollJoin = await EnrollJoinModel.getOne(whereJoin);
        if (!enrollJoin)
            this.AppError('该' + ENROLL_NAME + '记录不存在或者已经被系统取消');

        // 登记是否结束
        let whereEnroll = {
            _id: enrollId,
            ENROLL_STATUS: EnrollModel.STATUS.COMM
        }
        let enroll = await EnrollModel.getOne(whereEnroll);
        if (!enroll)
            this.AppError('该' + ENROLL_NAME + '不存在或者已经停止');


        if (enroll.ENROLL_EDIT_SET == 0)
            this.AppError('该' + ENROLL_NAME + '不允许修改资料');


        if (enroll.ENROLL_EDIT_SET == 3
            && enroll.ENROLL_CHECK_SET == 1
            && enrollJoin.ENROLL_JOIN_STATUS == EnrollJoinModel.STATUS.SUCC
        )
            this.AppError('该' + ENROLL_NAME + '已通过审核,不能修改资料');


        let data = {
            ENROLL_JOIN_FORMS: forms,
            ENROLL_JOIN_OBJ: dataUtil.dbForms2Obj(forms),
            ENROLL_JOIN_LAST_TIME: this._timestamp,
        }
        await EnrollJoinModel.edit(whereJoin, data);

    }

    async statEnrollJoin(id) {
        let where = {
            ENROLL_JOIN_ENROLL_ID: id,
            ENROLL_JOIN_STATUS: ['in', [EnrollJoinModel.STATUS.WAIT, EnrollJoinModel.STATUS.SUCC]]
        }
        let cnt = await EnrollJoinModel.count(where);

        await EnrollModel.edit(id, { ENROLL_JOIN_CNT: cnt });
    }

    /**  登记前获取关键信息 */
    async detailForEnrollJoin(userId, enrollId, enrollJoinId = '') {
        let fields = 'ENROLL_JOIN_FORMS, ENROLL_TITLE';

        let where = {
            _id: enrollId,
            ENROLL_STATUS: EnrollModel.STATUS.COMM
        }
        let enroll = await EnrollModel.getOne(where, fields);
        if (!enroll)
            this.AppError('该' + ENROLL_NAME + '不存在');



        let joinMy = null;
        if (enrollJoinId) {
            // 编辑
            let whereMy = {
                ENROLL_JOIN_USER_ID: userId,
                _id: enrollJoinId
            }
            joinMy = await EnrollJoinModel.getOne(whereMy);
            enroll.join = {
                start: joinMy.ENROLL_JOIN_START,
                end: joinMy.ENROLL_JOIN_END,
                endPoint: joinMy.ENROLL_JOIN_END_POINT,
                day: joinMy.ENROLL_JOIN_DAY,
            }
        }
        else {
            // 取出本人最近一次的填写表单 
            /*
            let whereMy = {
                ENROLL_JOIN_USER_ID: userId,
            }
            let orderByMy = {
                ENROLL_JOIN_ADD_TIME: 'desc'
            }
            joinMy = await EnrollJoinModel.getOne(whereMy, 'ENROLL_JOIN_FORMS', orderByMy);*/
        }

        let myForms = joinMy ? joinMy.ENROLL_JOIN_FORMS : [];
        enroll.myForms = myForms;

        return enroll;
    }

    /** 取消我的登记 只有成功和待审核可以取消 取消即为删除记录 */
    async cancelMyEnrollJoin(userId, enrollJoinId) {
        let where = {
            ENROLL_JOIN_USER_ID: userId,
            _id: enrollJoinId,
            ENROLL_JOIN_STATUS: ['in', [EnrollJoinModel.STATUS.WAIT, EnrollJoinModel.STATUS.SUCC]]
        };
        let enrollJoin = await EnrollJoinModel.getOne(where);

        if (!enrollJoin) {
            this.AppError('未找到可取消的记录');
        }

        let enroll = await EnrollModel.getOne(enrollJoin.ENROLL_JOIN_ENROLL_ID);
        if (!enroll)
            this.AppError('该' + ENROLL_NAME + '不存在');

        if (enroll.ENROLL_CANCEL_SET == 0)
            this.AppError('该' + ENROLL_NAME + '不能取消');


        if (enroll.ENROLL_CANCEL_SET == 3
            && enroll.ENROLL_CHECK_SET == 1
            && enrollJoin.ENROLL_JOIN_STATUS == EnrollJoinModel.STATUS.SUCC
        )
            this.AppError('该' + ENROLL_NAME + '已通过审核,不能取消');

        await EnrollJoinModel.del(where);

        this.statEnrollJoin(enrollJoin.ENROLL_JOIN_ENROLL_ID);

    }

}

后台管理

image.png

image.png
image.png
image.png

git代码

git代码

鹅厂程序猿一枚,交流v: cclinux0730

18 声望
2 粉丝
0 条评论
推荐阅读
从0到1:健身房私教预约小程序开发笔记
在当代“瘦身热”的带动下,到健身房运动和瘦身的人员也在不断增加,一定程度上加大了健身房的管理难度,因此,开发一款属于健身房预约的小程序这时候正好可以派上用场

CC同学呀

从零搭建 Node.js 企业级 Web 服务器(十五):总结与展望
总结截止到本章 “从零搭建 Node.js 企业级 Web 服务器” 主题共计 16 章内容就更新完毕了,回顾第零章曾写道:搭建一个 Node.js 企业级 Web 服务器并非难事,只是必须做好几个关键事项这几件必须做好的关键事项就...

乌柏木66阅读 6.2k评论 16

从零搭建 Node.js 企业级 Web 服务器(一):接口与分层
分层规范从本章起,正式进入企业级 Web 服务器核心内容。通常,一块完整的业务逻辑是由视图层、控制层、服务层、模型层共同定义与实现的,如下图:从上至下,抽象层次逐渐加深。从下至上,业务细节逐渐清晰。视图...

乌柏木44阅读 7.4k评论 6

从零搭建 Node.js 企业级 Web 服务器(二):校验
校验就是对输入条件的约束,避免无效的输入引起异常。Web 系统的用户输入主要为编辑与提交各类表单,一方面校验要做在编辑表单字段与提交的时候,另一方面接收表单的接口也要做足校验行为,通过前后端共同控制输...

乌柏木33阅读 6.2k评论 9

从零搭建 Node.js 企业级 Web 服务器(五):数据库访问
回顾 从零搭建 Node.js 企业级 Web 服务器(一):接口与分层,一块完整的业务逻辑是由视图层、控制层、服务层、模型层共同定义与实现的,控制层与服务层实现了业务处理过程,模型层定义了业务实体并以 对象-关系...

乌柏木34阅读 4.6k评论 9

从零搭建 Node.js 企业级 Web 服务器(十三):断点调试与性能分析
Node.js 官方提供了断点调试机制,出于安全性考虑默认为关闭状态,可以通过 node 参数 --inspect 或 --inspect-brk 开启,配合 IDE 能够非常方便地调试代码,本章就上一章已完成的项目 licg9999/nodejs-server-ex...

乌柏木31阅读 3.9k评论 9

从零搭建 Node.js 企业级 Web 服务器(八):网络安全
计算机网络依据 TCP/IP 协议栈分为了物理层、网络层、传输层、应用层,通常基础设施供应商会解决好前三层的网络安全问题,需要开发者自行解决应用层的网络安全问题,本章将着重表述应用层常见的网络安全问题及处...

乌柏木33阅读 5.8k评论 1

鹅厂程序猿一枚,交流v: cclinux0730

18 声望
2 粉丝
宣传栏