乐趣区

关于小程序:基于微信小程序的老年大学招生报名小程序开发笔记

业务背景

老年大学是“空巢”老人更新常识的课堂,健身养心的场合,开心娱乐的园地,广交朋友的平台,智力开发的基地!在手机网络遍及明天,宽广老年人足不出户,就能够通过小程序的形式理解培训班级和课程,注销材料,查看报名后果,后盾工作人员也能够通过电子化的伎俩收集报名材料,大大节俭老年人奔走的劳顿工夫,也进步老年大学的工作效率。

性能布局

次要性能包含布告告诉,课堂风采,培训班列表,培训课程介绍,我的报名,后盾培训项目管理,报名名单治理,后盾告诉治理,后盾管理员治理等性能

报名模块

  • 报名项目管理:开始 / 截止工夫 / 是否审核 / 是否可勾销 / 是否可批改 / 人数等参数均可灵便设置,并能够自定义老人报名填写的数据项
  • 报名审核:能够设定报名名单是否审核,审核不通过可提醒用户欠缺材料
  • 我的报名记录:能够批改,勾销我的报名记录
  • 详尽的报名数据:反对报名名单数据导出 Excel,打印

技术选型

  • 本我的项目应用微信小程序平台进行开发。
  • 应用腾讯专门的小程序云开发技术,云资源蕴含云函数,数据库,带宽,存储空间,定时器等,资源配额价格低廉,无需域名和服务器即可搭建。
  • 小程序自身的即用即走,适宜小工具的应用场景,也适宜疾速开发迭代。
  • 云开发技术采纳腾讯外部链路,没有被黑客攻击的危险,不会 DDOS 攻打,节俭防火墙费用,安全性高且免保护。
  • 资源承载力可依据业务倒退须要随时弹性扩大。

数据库设计

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_USER_ID: 'string|true|comment= 用户 ID', 
    ENROLL_JOIN_FORMS: 'array|true|default=[]|comment= 表单',

    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',
};

UserModel.DB_STRUCTURE = {
    _pid: 'string|true',
    USER_ID: 'string|true',

    USER_MINI_OPENID: 'string|true|comment= 小程序 openid',
    USER_STATUS: 'int|true|default=1|comment= 状态 0= 待审核,1= 失常,8= 审核未过,9= 禁用',
    USER_CHECK_REASON: 'string|false|comment= 审核未过的理由',

    USER_NAME: 'string|false|comment= 用户昵称',
    USER_MOBILE: 'string|false|comment= 联系电话',

    USER_FORMS: 'array|true|default=[]',
    USER_OBJ: 'object|true|default={}',

    USER_LOGIN_CNT: 'int|true|default=0|comment= 登陆次数',
    USER_LOGIN_TIME: 'int|false|comment= 最近登录工夫',


    USER_ADD_TIME: 'int|true',
    USER_ADD_IP: 'string|false',

    USER_EDIT_TIME: 'int|true',
    USER_EDIT_IP: 'string|false',
}


外围实现

class EnrollService extends BaseProjectService {

    // 获取以后注销状态
    getJoinStatusDesc(enroll) {
        let timestamp = this._timestamp;

        if (enroll.ENROLL_STATUS == 0)
            return '已进行';
        else if (enroll.ENROLL_START > timestamp)
            return '未开始';
        else if (enroll.ENROLL_END <= timestamp)
            return '已截止';
        else if (enroll.ENROLL_MAX_CNT > 0
            && enroll.ENROLL_JOIN_CNT >= enroll.ENROLL_MAX_CNT)
            return '人数已满';
        else
            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_MAX_CNT,ENROLL_START,ENROLL_END,ENROLL_ORDER,ENROLL_STATUS,ENROLL_CATE_NAME,ENROLL_OBJ';

        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 getMyEnrollJoinList(userId, {
        search, // 搜寻条件
        sortType, // 搜寻菜单
        sortVal, // 搜寻菜单
        orderBy, // 排序 
        page,
        size,
        isTotal = true,
        oldTotal
    }) {
        orderBy = orderBy || {'ENROLL_JOIN_ADD_TIME': 'desc'};
        let fields = '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;
    }

    /** 获得我的注销详情 */
    async getMyEnrollJoinDetail(userId, enrollJoinId) {

        let fields = '*';

        let where = {
            _id: enrollJoinId,
            ENROLL_JOIN_USER_ID: userId
        };
        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, forms) {

        // 注销是否完结
        let whereEnroll = {
            _id: enrollId,
            ENROLL_STATUS: EnrollModel.STATUS.COMM
        }
        let enroll = await EnrollModel.getOne(whereEnroll);
        if (!enroll)
            this.AppError('该' + ENROLL_NAME + '不存在或者曾经进行');

        // 是否注销开始
        if (enroll.ENROLL_START > this._timestamp)
            this.AppError('该' + ENROLL_NAME + '尚未开始');

        // 是否过了注销截止期
        if (enroll.ENROLL_END < this._timestamp)
            this.AppError('该' + ENROLL_NAME + '曾经截止');


        // 人数是否满
        if (enroll.ENROLL_MAX_CNT > 0) {
            let whereCnt = {
                ENROLL_JOIN_ENROLL_ID: enrollId,
                ENROLL_JOIN_STATUS: ['in', [EnrollJoinModel.STATUS.WAIT, EnrollJoinModel.STATUS.SUCC]]
            }
            let cntJoin = await EnrollJoinModel.count(whereCnt);
            if (cntJoin >= enroll.ENROLL_MAX_CNT)
                this.AppError('该' + ENROLL_NAME + '人数已满');
        }

        // 本人是否曾经有注销
        let whereMy = {
            ENROLL_JOIN_USER_ID: userId,
            ENROLL_JOIN_ENROLL_ID: enrollId,
            ENROLL_JOIN_STATUS: ['in', [EnrollJoinModel.STATUS.WAIT, EnrollJoinModel.STATUS.SUCC]]
        }
        let my = await EnrollJoinModel.getOne(whereMy);
        if (my) {if (my.ENROLL_JOIN_STATUS == EnrollJoinModel.STATUS.WAIT)
                this.AppError('您曾经填报,正在期待审核,毋庸反复填报');
            else
                this.AppError('您曾经填报胜利,毋庸反复填报');
        }

        // 入库
        let data = {
            ENROLL_JOIN_USER_ID: userId,
            ENROLL_JOIN_ENROLL_ID: enrollId,
            ENROLL_JOIN_STATUS: (enroll.ENROLL_CHECK_SET == 0) ? EnrollJoinModel.STATUS.SUCC : EnrollJoinModel.STATUS.WAIT,
            ENROLL_JOIN_FORMS: 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 == 2 && enroll.ENROLL_END < this._timestamp)
            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_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);
        }
        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 == 2 && enroll.ENROLL_END < this._timestamp)
            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);

    }

}

UI 设计

后盾实现

代码

代码

退出移动版