signIn.json
{
"navigationBarTitleText": "签到",
"usingComponents": {
}
}
signIn.wxss
/* 签到顶部背景信息 */
.signBkImg{
width: 100%;
height: 241rpx;
position: relative;
}
.signBkImg>image{
width: 100%;
height: 100%;
}
.sign-con{
width: 92%;
height: 213rpx;
padding: 0 30rpx;
display: flex;
justify-content: space-between;
align-items: center;
position: absolute;
top: 0;
}
.sign-con>navigator{
width: 167rpx;
height: 67rpx;
line-height: 67rpx;
text-align: center;
border-radius: 34rpx;
color: #33998C;
background-color: #fff;
font-size: 30rpx;
}
.headNews-left{
display: flex;
align-items: center;
flex-wrap: nowrap;
}
.headNews-left>image{
width: 133rpx;
height: 133rpx;
border: 6rpx solid rgb(255,255,255);
border-radius: 50%;
}
.nikeNme{
color: rgb(254,254,254);
margin-left: 26rpx;
}
.nikeNme>view:nth-child(1){
font-size: 40rpx;
font-weight: bold;
}
.nikeNme>view:nth-child(2){
font-size: 26rpx;
margin-top: 12rpx;
}
/* 积分,积分明细 */
.points-con{
margin: 50rpx 0;
display: flex;
}
.points-con>view,.points-con>navigator{
width: 50%;
height: 61rpx;
line-height: 61rpx;
text-align: center;
color: rgb(119,119,119);
font-size: 30rpx;
}
.points-con>view{
border-right: 2rpx solid rgb(235,235,235);
}
.points-num{
font-size: 38rpx;
color: #33998C;
}
/* 日历签到 */
/**index.wxss**/
.t_red{
color: red;
}
.t_blue{
color: royalblue;
}
.calendar{
background-color: white;
box-shadow: 2px 2px 5px 2px #e6e6e6;
padding:30rpx;
width: 85%;
margin-left: 4%;
border-radius: 50rpx;
display: block
}
.time{
padding: 16rpx 20rpx;
background-color: wheat;
display: flex;
}
.time{
font-family: '黑体';
font-size: 40rpx;
color: white;
text-align: center;
padding: 16rpx 20rpx;
height:80rpx;
line-height:80rpx;
border-radius:12rpx;
background-color: #f9634b;
display: flex;
margin-bottom: 29rpx;
}
.time view{
flex: 1;
font-size: 30rpx;
}
.time view text{
font-size: 38rpx;
}
.weekName{
font-size: 36rpx;
color: #333;
width: 100%;
display: flex;
padding: 16rpx 0;
}
.weekName view{
flex: 1;
text-align: center;
}
.sunday,.saturday{
color: #33998C;
}
.week{
width: 100%;
}
.week view{
width: 14.2%;
height: 90rpx;
line-height: 80rpx;
display: inline-block;
margin: 10rpx 0;
font-size: 34rpx;
text-align: center;
}
.week view text{
width: 100%;
height: 100%;
display: inline-block;
}
.calendarSign{
margin: 40rpx auto;
}
.selDate{
font-size: 28rpx;
border-bottom: 1px solid #33998C;
}
.selDateItem{
color:#33998C;
font-weight: bold;
font-size:22rpx;
border-radius: 50%;
}
/* 前后时间 */
.preNext-path{
margin: 28rpx 0;
display: flex;
align-items: center;
justify-content: center;
}
.preNext-path>image{
width: 11rpx;
height: 21rpx;
}
.preNext-path>text{
color: #33998C;
font-size: 28rpx;
margin: 0 54rpx;
}
/* 签到按钮 */
.signInBtn{
width: 235rpx;
height: 77rpx;
line-height: 77rpx;
text-align: center;
border-radius: 10rpx;
font-size: 34rpx;
color: #fff;
background:#33998C;
}
signIn.wxml
{{userInfo.nickname}}
本月已签到 {{calendarSignDay}} 天
兑换商品
我的积分:
{{userInfo.integral}}
积分明细 >
{{year}}年{{month}}月
日
一
二
三
四
五
六
\n
已签到
{{item+1}}
已签到
{{date}}
{{item+date+1}}
签到
今日已签到
signIn.js
js中导入了requestUtil 为请求工具类,改为自己的就行
import requestUtil from '../../../utils/requestUtil';
//获取应用实例
var calendarSignData = [];
var date;
Page({
data: {
calendarSignData: [],
calendarSignDay:'',
month: "",
year: "",
userInfo: '',
show: false
},
onShow: function () {
this.a();
this.getUserByOpenid();
},
//获取用户
getUserByOpenid: function () {
var that = this;
var openId = wx.getStorageSync("openId");
if (openId) {
var url = "integral/getUserByOpenid";
requestUtil._get_param(url, {
openid: openId
}, function (res) {
console.log(res);
if (res.data.status == 200) {
var d = res.data.data;
var currentDate = new Date();
if (d.calendarSignDay > 0) {
var a = new Date(d.calendarSignTime);
var day = a.getDate();
if (currentDate.getDate() == day) {
calendarSignData[day] = day;
}
}
that.setData({
userInfo: d
// calendarSignData: calendarSignData
})
}
})
} else {
this.setData({
show: true
})
}
},
a(){
var openId = wx.getStorageSync("openId");
//过去签到过的天数
var that = this;
var url = "integral/queryUserMonthSign";
requestUtil._get_param(url, {
openid:openId
}, function (res) {
console.log(res);
if (res.data.status == 200) {
that.setData({
calendarSignData: res.data.data.calendarSignData,
calendarSignDay:res.data.data.calendarSignDay,
})
}else{
wx.showToast({
title: '查询本月签到的数据失败',
icon: 'none',
})
}
})
},
//事件处理函数
calendarSign: function () {
var openId = wx.getStorageSync("openId");
console.log(openId)
if (openId) {
var that = this;
var id = this.data.userInfo.id
var url = "integral/sign";
requestUtil._get_param(url, {
openid:openId
}, function (res) {
console.log(res);
if (res.data.status == 200) {
wx.showToast({
title: '签到成功',
icon: 'success',
duration: 2000
})
that.onShow();
}else{
wx.showToast({
title: '今日已签到,请勿重复签到',
icon: 'none',
})
}
})
} else {
this.setData({
show: true
})
}
},
sign_prev: function () {
var year = this.data.year;
var month = this.data.month;
if (month == "1") {
var month = "12";
var year = parseInt(this.data.year) - 1;
} else {
var month = parseInt(this.data.month) - 1;
var showYear = this.data.year;
}
this.setData({
month: month,
year: year
})
},
sign_next: function () {
var year = this.data.year;
var month = this.data.month;
if (month == "12") {
var month = "1";
var year = parseInt(this.data.year) + 1;
} else {
var month = parseInt(this.data.month) + 1;
var showYear = this.data.year;
}
this.setData({
month: month,
year: year
})
},
onLoad: function () {
var mydate = new Date();
var year = mydate.getFullYear();
var month = mydate.getMonth() + 1;
date = mydate.getDate();
console.log("date", date)
var day = mydate.getDay();
var nbsp;
if ((date - day) <= 0) {
nbsp = day - date + 1;
} else {
nbsp = 7 - ((date - day) % 7) + 1;
}
console.log("nbsp" + nbsp);
console.log(day)
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;
}
};
this.setData({
year: year,
month: month,
nbsp: nbsp,
monthDaySize: monthDaySize,
date: date,
calendarSignData: calendarSignData
})
}
})
后台 Java代码
/**
* 根据用户openid获取用户签到信息(月签到信息)
* @param openid
* @return
*/
@RequestMapping("queryUserMonthSign")
public ShopResult queryUserMonthSign(String openid,String data) {
MapretMap = new ConcurrentHashMap<>();
ListintegralDetails = shopIntegralDetailService.queryUserMonthSign(openid,data);
//获取本月的天数
int monthDay = DateUtils.getCurrentMonthDay();
int[] i = new int[monthDay+1];
int calendarSignDay = 0;
for (int j = 0; j < monthDay; j++) {
for (ShopIntegralDetail shopIntegralDetail:
integralDetails) {
int day = Integer.valueOf(DateUtils.formatDate(shopIntegralDetail.getCreateDate(),"dd"));
if(j==day){
i[j] = day;
calendarSignDay += 1 ;
}
}
}
retMap.put("calendarSignData", i);//本月签到天数
retMap.put("calendarSignDay", calendarSignDay);//本月签到数据 为数组【0,1,2,3】
System.out.println(i);
return ShopResult.ok(retMap);
}
我这边是每次积分签到成功之后在积分记录表中添加一条信息,所以在积分详情表中查用户签到信息
SELECT
FROM shop_integral_detail a
where
a.openid = #{openid}
AND
DATE_FORMAT(a.create_date,'%Y-%m') = DATE_FORMAT(NOW(),'%Y-%m')
AND
a.integral_type=4
shop_integral_detail表 字段
idvarchar32
integralvarchar20积分
integral_typechar 类型0:系统赠送,1:购物送,2:邀请好友送,3:消费 4签到
openidvarchar64 微信openid
create_datedatetime时间