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

业务背景

老年大学是“空巢”老人更新知识的课堂,健身养心的场所,开心娱乐的园地,广交朋友的平台,智力开发的基地!在手机网络普及今天,广大老年人足不出户,就可以通过小程序的方式了解培训班级和课程,登记资料,查看报名结果,后台工作人员也可以通过电子化的手段收集报名资料,大大节省老年人奔波的劳顿时间,也提高老年大学的工作效率。

功能规划

主要功能包括公告通知,课堂风采,培训班列表,培训课程介绍,我的报名,后台培训项目管理,报名名单管理,后台通知管理,后台管理员管理等功能
image.png

报名模块

  • 报名项目管理:开始/截止时间/是否审核/是否可取消/是否可修改/人数等参数均可灵活设置,并可以自定义老人报名填写的数据项
  • 报名审核:可以设定报名名单是否审核,审核不通过可提示用户完善资料
  • 我的报名记录:可以修改,取消我的报名记录
  • 详尽的报名数据:支持报名名单数据导出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设计

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

后台实现

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

代码

代码

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

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

CC同学呀

有意思,小程序还可以一键生成App!
说到小程序,大部分同学的第一反应,可能是微信小程序、支付宝小程序,确实,小程序的概念深入人心,并且已经被约定俗成的绑定到某些互联网公司的 APP 上。

chokcoco4阅读 765评论 2

微信小程序之聊天室(多人聊天室)总结
实现方式一:使用nodejs + socket.io实现缺点:引用weapp.socket.io.js 大小100kb实现方式二:使用小程序云开发- 数据库实时监听 来实现缺点:目前不可以跨端,只能在当前小程序聊天预览效果:未完待续..来源:[...

jigsaw1阅读 5k

NutUI 京东小程序发布了!
NutUI 是一套京东风格的轻量级移动端组件库,目前已有 70+ 高质量组件,覆盖移动端主流场景。NutUI 3.1 版本上线后,增加了多端小程序适配能力,在微信小程序平台取得了很好的效果。而现在,NutUI 支持京东小程序...

京东设计中心JDC2阅读 1.2k

封面图
2022,「倾城之链」运营第 6 年感记
转眼间,距离「倾城之链」诞生之时,已有六年之久。如今(2022.10.25),倾城收录网站已突破 1000 款,值此之时,有必要督促自己深入思考,不仅是「倾城」过往的总结、未来之设想,更要确立后续业余项目方向、乃...

jeffjade1阅读 601

封面图
微信小程序归结
是的,在这个框架满天飞的年代,我既然有有幸使用了原生小程序开发项目,除了麻烦些,倒也不是一无所获,耕耘总有收货嘛,写博客本身不是为了炫技还是什么,单纯的是记性不好,有些知识点 自己是花了时间去查找的...

HappyCodingTop1阅读 970

封面图
魔方带壳截图:让你的截图看起来更加高大上
我们在日常工作和生活中,往往需要截图去做汇报或分享。普通人的做法:手机或电脑截图,然后就拿去汇报或分享。这样你的截图显得平平无奇,没有给人眼前一亮的感觉。但是,如果我们给这张截图穿上一件“衣服”,把...

老人羽海阅读 1.2k

封面图

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

18 声望
2 粉丝
宣传栏