小程序
小游戏
企业微信
微信支付
小程序签到打卡逻辑分析
~
最近在实现小程序的积分签到打卡的功能,连续签到5天以上下发的积分是不一样的,所以有几个难点就是
1、用户进来后如何判断今天是连续第几题签到;
2、如果超过7天,后面怎么展示;
小程序签到打卡逻辑分析~
最下面的图是支付宝的
支付宝积分签到
它1到7天,分别1到7积分,然后后边签到都是7积分
后面我会联系签到7天,每天在评论处打卡,还望各位提醒监督
8 个评论
加粗
标红
插入代码
插入链接
插入图片
上传视频
<!--index.wxml--> <view class="calendar"> <view class='bcfff'> <view class="weekName"> <view class="monday">一</view> <view class="tuesday">二</view> <view class="wednesday">三</view> <view class="thursday">四</view> <view class="friday">五</view> <view class="saturday">六</view> <view class="sunday">日</view> </view> <view class="week"> <!--填补空格--> <view wx:for="{{nbsp}}">\n</view> <!--循环日期--> <!-- 当天以前 --> <view wx:for="{{date-1}}" style="color:gainsboro;"> <text wx:if="{{item+1==calendarSignData[item+1]}}" style="color: #2ccecb;">{{item+1}}</text> <text wx:else="">{{item+1}}</text> </view> <!-- 当天 --> <view style=""> <text wx:if="{{is_qd}}" style="color: #2ccecb;">{{date}}</text> <text wx:else="" style="">{{date}}</text> </view> <!-- 以后 --> <view wx:for="{{monthDaySize-date}}">{{item+date+1}}</view> </view> </view> <view class="calendarSign"> <image bindtap="calendarSign" class='btnimg' src='https://jpadmin.99dudesign.com/public/img/source/btn_icon_wodekaoqin1.png'></image> <!-- wx:if="{{date!=calendarSignData[date]}}" --> </view> </view> <!-- 签到成功 --> <view class='zhegai hide {{qdView?"block":""}}' bindtap='quxiaoQd'></view> <view class='successqd hide {{qdView?"block":""}}'> <view class='qdtitle'>签到成功</view> <view class='qdcontent' wx:if="{{is_qd}}">今天已经签过了~</view> <view class='qdcontent' wx:else>签到成功,获得{{integral}}积分,您已连续签到{{rule}}天!</view> <view class='queding' bindtap='quxiaoQd'>确定</view> </view>
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
var app = getApp(); var calendarSignData; var date; var calendarSignDay; var is_qd; Page({ /** * 页面的初始数据 */ data: { qdView: false, calendarSignData: "", calendarSignDay: "", is_qd: false, }, quxiaoQd: function (e) { var that = this; that.setData({ qdView: false, is_qd: true }) }, //事件处理函数 calendarSign: function (e) { var that = this; that.setData({ qdView: true }) calendarSignData[date] = date; console.log(calendarSignData); calendarSignDay = calendarSignDay + 1; var today = new Date().getDate() wx.request({ url: getApp().data.host + '后台的接口', method: "POST", data: { "user_id": wx.getStorageSync('user_id'), "sign_num": today }, header: { 'content-type': 'application/x-www-form-urlencoded' //通过post传值,所以要加header }, success: function (res) { that.setData({ rule: res.data.rule, integral: res.data.integral, }) } }) wx.setStorageSync("calendarSignData", calendarSignData); wx.setStorageSync("calendarSignDay", calendarSignDay); this.setData({ calendarSignData: calendarSignData, calendarSignDay: calendarSignDay }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { var that = this; var mydate = new Date(); var year = mydate.getFullYear(); var month = mydate.getMonth() + 1; date = mydate.getDate(); console.log("date" + date) var day = mydate.getDay(); console.log(day) var nbsp = 7 - ((date - day) % 7); console.log("nbsp" + nbsp); var monthDaySize; if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { monthDaySize = 31; } else if (month == 4 || month == 6 || month == 9 || month == 11) { monthDaySize = 30; } else if (month == 2) { // 计算是否是闰年,如果是二月份则是29天 if ((year - 2000) % 4 == 0) { monthDaySize = 29; } else { monthDaySize = 28; } }; // 传ajax wx.request({ url: getApp().data.host + 'index.php?g=api&m=output&a=sign_list', method: "POST", data: { "user_id": wx.getStorageSync('user_id') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { // 判断是否签到过 if (res.data == null) { calendarSignData = new Array(monthDaySize) wx.setStorageSync("calendarSignData", calendarSignData); } else { var is_qd; for (var i in res.data) { parseInt(res.data[i]) calendarSignData = new Array(monthDaySize) calendarSignData[parseInt(res.data[i])] = parseInt(res.data[i]) wx.setStorageSync("calendarSignData", calendarSignData); console.log(date) console.log(parseInt(res.data[i])) if (parseInt(res.data[i]) == date) { console.log(1) wx.setStorageSync("calendarSignDay", 1); is_qd = true } else { wx.setStorageSync("calendarSignDay", 0); } } } console.log(is_qd) calendarSignData = wx.getStorageSync("calendarSignData") calendarSignDay = wx.getStorageSync("calendarSignDay") console.log(calendarSignData); console.log(calendarSignDay) that.setData({ is_qd: is_qd, year: year, month: month, nbsp: nbsp, monthDaySize: monthDaySize, date: date, calendarSignData: calendarSignData, calendarSignDay: calendarSignDay }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { wx.removeStorageSync("calendarSignData") wx.removeStorageSync("calendarSignDay") }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })
打卡签到第八天
打卡第六天
打卡第五天
签到第四天
打卡第四天
实现该功能用到二个集合和一个触发器
1、一个集合记录打卡明细,用以记录每天的打卡明细;
2、一个集合记录连续签到的天数和更新时间
触发器,每天0时跑下数据看看今天有没有签到,如无签到就重置签到天数字段
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
<!--index.wxml--> <view class="calendar"> <view class='bcfff'> <view class="weekName"> <view class="monday">一</view> <view class="tuesday">二</view> <view class="wednesday">三</view> <view class="thursday">四</view> <view class="friday">五</view> <view class="saturday">六</view> <view class="sunday">日</view> </view> <view class="week"> <!--填补空格--> <view wx:for="{{nbsp}}">\n</view> <!--循环日期--> <!-- 当天以前 --> <view wx:for="{{date-1}}" style="color:gainsboro;"> <text wx:if="{{item+1==calendarSignData[item+1]}}" style="color: #2ccecb;">{{item+1}}</text> <text wx:else="">{{item+1}}</text> </view> <!-- 当天 --> <view style=""> <text wx:if="{{is_qd}}" style="color: #2ccecb;">{{date}}</text> <text wx:else="" style="">{{date}}</text> </view> <!-- 以后 --> <view wx:for="{{monthDaySize-date}}">{{item+date+1}}</view> </view> </view> <view class="calendarSign"> <image bindtap="calendarSign" class='btnimg' src='https://jpadmin.99dudesign.com/public/img/source/btn_icon_wodekaoqin1.png'></image> <!-- wx:if="{{date!=calendarSignData[date]}}" --> </view> </view> <!-- 签到成功 --> <view class='zhegai hide {{qdView?"block":""}}' bindtap='quxiaoQd'></view> <view class='successqd hide {{qdView?"block":""}}'> <view class='qdtitle'>签到成功</view> <view class='qdcontent' wx:if="{{is_qd}}">今天已经签过了~</view> <view class='qdcontent' wx:else>签到成功,获得{{integral}}积分,您已连续签到{{rule}}天!</view> <view class='queding' bindtap='quxiaoQd'>确定</view> </view>
var app = getApp(); var calendarSignData; var date; var calendarSignDay; var is_qd; Page({ /** * 页面的初始数据 */ data: { qdView: false, calendarSignData: "", calendarSignDay: "", is_qd: false, }, quxiaoQd: function (e) { var that = this; that.setData({ qdView: false, is_qd: true }) }, //事件处理函数 calendarSign: function (e) { var that = this; that.setData({ qdView: true }) calendarSignData[date] = date; console.log(calendarSignData); calendarSignDay = calendarSignDay + 1; var today = new Date().getDate() wx.request({ url: getApp().data.host + '后台的接口', method: "POST", data: { "user_id": wx.getStorageSync('user_id'), "sign_num": today }, header: { 'content-type': 'application/x-www-form-urlencoded' //通过post传值,所以要加header }, success: function (res) { that.setData({ rule: res.data.rule, integral: res.data.integral, }) } }) wx.setStorageSync("calendarSignData", calendarSignData); wx.setStorageSync("calendarSignDay", calendarSignDay); this.setData({ calendarSignData: calendarSignData, calendarSignDay: calendarSignDay }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { var that = this; var mydate = new Date(); var year = mydate.getFullYear(); var month = mydate.getMonth() + 1; date = mydate.getDate(); console.log("date" + date) var day = mydate.getDay(); console.log(day) var nbsp = 7 - ((date - day) % 7); console.log("nbsp" + nbsp); var monthDaySize; if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { monthDaySize = 31; } else if (month == 4 || month == 6 || month == 9 || month == 11) { monthDaySize = 30; } else if (month == 2) { // 计算是否是闰年,如果是二月份则是29天 if ((year - 2000) % 4 == 0) { monthDaySize = 29; } else { monthDaySize = 28; } }; // 传ajax wx.request({ url: getApp().data.host + 'index.php?g=api&m=output&a=sign_list', method: "POST", data: { "user_id": wx.getStorageSync('user_id') }, header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { // 判断是否签到过 if (res.data == null) { calendarSignData = new Array(monthDaySize) wx.setStorageSync("calendarSignData", calendarSignData); } else { var is_qd; for (var i in res.data) { parseInt(res.data[i]) calendarSignData = new Array(monthDaySize) calendarSignData[parseInt(res.data[i])] = parseInt(res.data[i]) wx.setStorageSync("calendarSignData", calendarSignData); console.log(date) console.log(parseInt(res.data[i])) if (parseInt(res.data[i]) == date) { console.log(1) wx.setStorageSync("calendarSignDay", 1); is_qd = true } else { wx.setStorageSync("calendarSignDay", 0); } } } console.log(is_qd) calendarSignData = wx.getStorageSync("calendarSignData") calendarSignDay = wx.getStorageSync("calendarSignDay") console.log(calendarSignData); console.log(calendarSignDay) that.setData({ is_qd: is_qd, year: year, month: month, nbsp: nbsp, monthDaySize: monthDaySize, date: date, calendarSignData: calendarSignData, calendarSignDay: calendarSignDay }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { wx.removeStorageSync("calendarSignData") wx.removeStorageSync("calendarSignDay") }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })
打卡签到第八天
打卡第六天
打卡第五天
签到第四天
打卡第四天
实现该功能用到二个集合和一个触发器
1、一个集合记录打卡明细,用以记录每天的打卡明细;
2、一个集合记录连续签到的天数和更新时间
触发器,每天0时跑下数据看看今天有没有签到,如无签到就重置签到天数字段