E企盈营销工具技术服务商 热线:4006-838-530

微信小程序(看文档写实北仑区E企盈小程序例六)微信小程序课堂宝APP实现签到逻辑

继上篇博文,这篇写下签到实现的逻辑。一、实现逻辑发起签到1、先上传当前自己的定位经纬度2、学生查询老师的最后一次签到记录,如果发现签到记录signComplete为false说明有新的签到3、得到签到的第几次课4、系统获得学生的定位经纬度5、判断两点经纬度转换成距离是否在100米以内,如果是则可以签到否则不能签到签到完成1、老师端选择结束签到2、老师更新最后一次签到signComplete为true二、服务器签到表服务器签到表在上篇获取签到列表已经给出,主要就是一个签到次数和签到是是否完成及用户的信息。三、代码实现由于前端在前面已经提到,因此现在直接写上代码,有详细注释。// 签到sign:function(){wx.showToast({title: ‘正在获取位置信息..’,icon:’loading’,duration:10000});// 1、获取位置wx.getLocation({type: ‘wgs84’,success: function (resLocation) {// 2、设置当前用户的经纬度信息var queryUser = Bmob.Query(‘_User’);queryUser.get(app.globalData.currentUser.objectId).then(resUser => {var point = Bmob.GeoPoint({ latitude: resLocation.latitude, longitude: resLocation.longitude })resUser.set(‘location’, point);resUser.save();//3、查询签到表老师最近一次签到var queryTeacher = Bmob.Query开通苹果/Apple小程序电话:4006-838-530(‘_User’);queryTeacher.equalTo(“userType”, ‘==’, 1);queryTeacher.find().then(resTeacher => {var teacher = resTeacher[0];var teacherPointer = Bmob.Pointer(‘_User’)var teacherPoiID = teacherPointer.set(teacher.objectId)var teacherQuerySign = Bmob.Query(‘sign_record’);//userId 字段名称关联用户表 ,类型PointerteacherQuerySi开通描红本小程序电话:4006-838-530gn.equalTo(“userId”, “==”, teacherPoiID);teacherQuerySign.order(“-numberNo”);teacherQuerySign.limit(1);teacherQuerySign.find().then(resTeacherSign => {wx.hideToast();// 如果没有记录,说明学生当前不用签到,老师可以发起签到if (resTeacherSign.length==0){// 如果当前用户是老师if(app.globalData.currentUser.userType==1){wx.showModal({title: ‘提示’,content: ‘您确定发起签到吗’,success: function (resModal) {if (resModal.confirm) {wx.showToast({title: ‘发起中..’,icon: ‘loading’,duration: 10000});teacherQuerySign.set(‘numberNo’,1);teacherQuerySign.set(‘signComplete’, false);teacherQuerySign.save().then(resTeacherSignSave => {teacherQuerySign.get(resTeacherSignSave.objectId).then(resSignSaveUser => {var userIdPointer = Bmob.Pointer(‘_User’);var pointerUserId = userIdPointer.set(app.globalData.currentUser.objectId);resSignSaveUser.set(‘userId’, pointerUserId);resSignSaveUser.save();// 签到结束刷新签到记录that.getSignRecord();wx.hideToast();});}).catch(err => {console.log(err)});}}});}// 如果是学生else{wx.showToast({title: ‘当前无需签到~’,duration:2500});return;}}//有签到记录else{var teacherSignRecordItem = resTeacherSign[0];if (app.globalData.currentUser.userType == 1) {wx.hideToast();wx.showModal({title: ‘提示’,content: ‘您确定发起签到吗’,success: function (resModal) {if (resModal.confirm) {wx.showToast({title: ‘发起中..’,icon: ‘loading’,duration: 10000});teacherQuerySign.set(‘numberNo’, teacherSignRecordItem.numberNo + 1);teacherQuerySign.set(‘signComplete’, false);teacherQuerySign.save().then(resTeacherSignSave => {teacherQuerySign.get(resTeacherSignSave.objectId).then(resSignSaveUser => {var userIdPointer = Bmob.Pointer(‘_User’);var pointerUserId = userIdPointer.set(app.globalData.currentUser.objectId);resSignSaveUser.set(‘userId’, pointerUserId);resSignSaveUser.save();// 签到结束刷新签到记录that.getSignRecord();wx.hideToast();});}).catch(err => {console.log(err)});}}})}// 如果是学生else {// 如果最后一次签到已经结束则提示最近一次签到结束if (teacherSignRecordItem.signComplete == true){wx.showToast({title: ‘最新签到已结束~’,duration: 2500});return;}else{wx.showToast({title: ‘查询是否签到中..’,icon: ‘loading’,duration: 10000});// 查询是不是已经签到过了var queryHaveSign = Bmob.Query(‘sign_record’);var pointerHaveSign = Bmob.Pointer(‘_User’)var poiIDHaveSign = pointerHaveSign.set(app.globalData.currentUser.objectId);queryHaveSign.equalTo(“userId”, ‘==’, poiIDHaveSign);queryHaveSign.equalTo(“numberNo”, ‘==’, teacherSignRecordItem.numberNo);queryHaveSign.find().then(resHaveSign => {wx.hideToast();// 如果最新一次课已经签到if (resHaveSign.length>0){wx.showToast({title: ‘您已签到过了~’,duration: 2500});return;}// 如果最新一次课没有签到else{wx.showToast({title: ‘获取老师位置中..’,icon: ‘loading’,duration: 10000});// 判断和老师端的距离,小于100米才能签到var teacherLocation = teacher.location;var distance = Util.getDistance(resLocation.latitude, resLocation.longitude, teacherLocation.latitude, teacherLocation.longitude);//距离老师签到点100米内可以签到否则不能if (distance < 100) {teacherQuerySign.set(‘numberNo’, teacherSignRecordItem.numberNo);teacherQuerySign.set(‘signComplete’, false);teacherQuerySign.save().then(resTeacherSignSave => {teacherQuerySign.get(resTeacherSignSave.objectId).then(resSignSaveUser => {var 开通西装小程序电话:4006-838-530userIdPointer = Bmob.Pointer(‘_User’);var pointerUserId = userIdPointer.set(app.globalData.currentUser.objectId);resSignSaveUser.set(‘userId’, pointerUserId);resSignSaveUser.save();// 签到结束刷新签到记录that.getSignRecord();wx.hideToast();wx.showToast({title: ‘恭喜你完成签到啦~’,duration: 2500});});}).catch(err => {console.log(err)});} else {wx.hideToast();wx.showToast({title: ‘您距离老师太远啦~’,duration: 2500});return;}}}).catch(err=>{});}}}}).catch(err => { });}).catch(err=>{});});}});},签到完成功能在“我的”tab中,只有教师用户才能看到并对本次签到结束,结束后学生将不能再签到,后面在设计“我的”模块时实现。微信小程序

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信小程序(看文档写实北仑区E企盈小程序例六)微信小程序课堂宝APP实现签到逻辑
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

模王系统开发

联系我们升级日志

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏