背景
在日常生活中,大家也经常有组织活动,比如体育、才艺比赛报名,户外、聚餐、出游报名,休闲小聚,会议报名,创业聚会,校友聚会,公益活动,培训报名等需求。如果一个个收集就非常费时间和人力成本,这个时候只需要一款在线报名小程序就可以快速搞定,报名、签到、活动收集一气呵成!
概要设计
包括公告通知,活动分类,活动列表,活动报名,活动评价,我的活动报名,后台活动项目管理,后台报名记录管理,后台报名审核,后台报名数据导出等功能,组织方可以自定义要填写的内容,比如姓名、性别、年龄,身份证、手机号等
数据库设计
ActivityJoinModel.DB_STRUCTURE = {
_pid: 'string|true',
ACTIVITY_JOIN_ID: 'string|true',
ACTIVITY_JOIN_ACTIVITY_ID: 'string|true|comment=报名PK',
ACTIVITY_JOIN_IS_ADMIN: 'int|true|default=0|comment=是否管理员添加 0/1',
ACTIVITY_JOIN_CODE: 'string|true|comment=核验码15位',
ACTIVITY_JOIN_IS_CHECKIN: 'int|true|default=0|comment=是否签到 0/1 ',
ACTIVITY_JOIN_CHECKIN_TIME: 'int|false|default=0|签到时间',
ACTIVITY_JOIN_USER_ID: 'string|true|comment=用户ID',
ACTIVITY_JOIN_FORMS: 'array|true|default=[]|comment=表单',
ACTIVITY_JOIN_OBJ: 'object|true|default={}',
ACTIVITY_JOIN_STATUS: 'int|true|default=1|comment=状态 0=待审核 1=报名成功, 99=审核未过',
ACTIVITY_JOIN_REASON: 'string|false|comment=审核拒绝或者取消理由',
ACTIVITY_JOIN_ADD_TIME: 'int|true',
ACTIVITY_JOIN_EDIT_TIME: 'int|true',
ACTIVITY_JOIN_ADD_IP: 'string|false',
ACTIVITY_JOIN_EDIT_IP: 'string|false',
};
核心实现
async statActivityJoin(id) {
let where = {
ACTIVITY_JOIN_ACTIVITY_ID: id,
ACTIVITY_JOIN_STATUS: ['in', [ActivityJoinModel.STATUS.WAIT, ActivityJoinModel.STATUS.SUCC]]
}
let cnt = await ActivityJoinModel.count(where);
where = {
ACTIVITY_JOIN_ACTIVITY_ID: id,
ACTIVITY_JOIN_STATUS: ActivityJoinModel.STATUS.SUCC
}
let joinParams = {
from: UserModel.CL,
localField: 'ACTIVITY_JOIN_USER_ID',
foreignField: 'USER_MINI_OPENID',
as: 'user',
};
let orderBy = {
ACTIVITY_JOIN_ADD_TIME: 'desc'
}
let list = await ActivityJoinModel.getListJoin(joinParams, where, 'ACTIVITY_JOIN_ADD_TIME,user.USER_MINI_OPENID,user.USER_NAME,user.USER_PIC', orderBy, 1, 6, false, 0);
list = list.list;
for (let k = 0; k < list.length; k++) {
list[k] = list[k].user;
}
await ActivityModel.edit(id, { ACTIVITY_JOIN_CNT: cnt, ACTIVITY_USER_LIST: list });
}
/** 报名前获取关键信息 */
async detailForActivityJoin(userId, activityId) {
let fields = 'ACTIVITY_JOIN_FORMS, ACTIVITY_TITLE';
let where = {
_id: activityId,
ACTIVITY_STATUS: ActivityModel.STATUS.COMM
}
let activity = await ActivityModel.getOne(where, fields);
if (!activity)
this.AppError('该活动不存在');
// 取出本人最近一次的填写表单
let whereMy = {
ACTIVITY_JOIN_USER_ID: userId,
}
let orderByMy = {
ACTIVITY_JOIN_ADD_TIME: 'desc'
}
let joinMy = await ActivityJoinModel.getOne(whereMy, 'ACTIVITY_JOIN_FORMS', orderByMy);
let myForms = joinMy ? joinMy.ACTIVITY_JOIN_FORMS : [];
activity.myForms = myForms;
return activity;
}
/** 取消我的报名 只有成功和待审核可以取消 取消即为删除记录 */
async cancelMyActivityJoin(userId, activityJoinId) {
let where = {
ACTIVITY_JOIN_USER_ID: userId,
_id: activityJoinId,
ACTIVITY_JOIN_STATUS: ['in', [ActivityJoinModel.STATUS.WAIT, ActivityJoinModel.STATUS.SUCC]]
};
let activityJoin = await ActivityJoinModel.getOne(where);
if (!activityJoin) {
this.AppError('未找到可取消的报名记录');
}
if (activityJoin.ACTIVITY_JOIN_IS_CHECKIN == 1)
this.AppError('该活动已经签到,无法取消');
let activity = await ActivityModel.getOne(activityJoin.ACTIVITY_JOIN_ACTIVITY_ID);
if (!activity)
this.AppError('该活动不存在');
if (activity.ACTIVITY_END <= this._timestamp)
this.AppError('该活动已经结束,无法取消');
if (activity.ACTIVITY_CANCEL_SET == 0)
this.AppError('该活动不能取消');
if (activity.ACTIVITY_CANCEL_SET == 2 && activity.ACTIVITY_STOP < this._timestamp)
this.AppError('该活动已经截止报名,不能取消');
await ActivityJoinModel.del(where);
// 统计
await this.statActivityJoin(activityJoin.ACTIVITY_JOIN_ACTIVITY_ID);
}