小程序:
sign.wxml:
{{data.nickname}}
已签到 {{data.days}} 天
兑换商品
我的积分:
{{data.scores}}
积分明细 >
{{data.created_at}}月
日
一
二
三
四
五
六
n
sign.js:
Page({
data: {
data:""
},
onLoad: function (options) {
var that = this
wx.request({
url: 'http://www.week3.com/api/show',
data: {
},
header: {
token:wx.getStorageSync('token')
},
success (res) {
console.log(res.data)
that.setData({
data:res.data.data
})
}
})
},
sign(e){
var that = this
wx.request({
url: 'http://www.week3.com/api/sign',
data: {
},
header: {
token:wx.getStorageSync('token')
},
method:"POST",
success (res) {
console.log(res.data)
if(res.data.code==200){
wx.showToast({
title: '首次签到成功',
})
}
if(res.data.code==100){
wx.showToast({
title: '今天已经签到过了',
})
}
if(res.data.code==300){
wx.showToast({
title: '今天已断签',
})
}
if(res.data.code==400){
wx.showToast({
title: '连续签到成功',
})
}
}
})
},
})
sign:json
{
"navigationBarTitleText": "签到",
"usingComponents": {
"l-button":"/miniprogram_npm/lin-ui/button"
}
}
sign.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;
}
.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;
}
后端php
first(); $uid = $login['id']; //查询是否签到过 $data = Sign::where('uid',$uid)->first(); if (empty($data)){ //用户没有签到过 $day = 1; //查询第一天的签到所得积分 $score = Score::where('day',$day)->first(); //添加签到记录 $arr = [ 'uid'=>$uid, 'mouth_week_day'=>date('Y-m-d 00:00:00'), ]; $userSgin =[ 'uid'=>$uid, 'days'=>$score['day'], 'scores'=>$score['score'] ]; $user = Login::where('id',$uid)->first(); $sign = Sign::create($arr,true);//添加签到记录 $score_sign = User_Sign::create($userSgin,true);//添加签到积分 $upuser = Login::where('id',$uid)->update(['days'=>$score['day'],'scores'=>$user['scores']+$score['score']]); if ($sign && $score_sign && $upuser!==false){ DB::commit(); return ['code'=>200,'msg'=>'签到成功','data'=>$user]; }else{ DB::rollBack(); return ['code'=>500,'msg'=>'签到失败','data'=>null]; } } //如果用户签到过 if (!empty($data)){ //查询用户最近的签到记录 $signTime = Sign::where('uid',$uid)->orderBy('mouth_week_day','desc')->first(); $time = $signTime['mouth_week_day']; $prevTime = strtotime($time);//获取最近一天的签到时间 $nowTime = time();//当前时间 //判断用户今日是否签到过 if ($nowTime-$prevTime<24*3600){ return ['code'=>100,'msg'=>'您今天已经签到过了','data'=>null]; } //判断用户是否断签 if ($nowTime-$prevTime>48*3600){ //如果断签了还是从第一天算起 $day = 1; //断签从第一天开始算起 $score = Score::where('day',$day)->first(); //添加签到记录 $arr = [ 'uid'=>$uid, 'mouth_week_day'=>date('Y-m-d 00:00:00'), ]; $userSgin =[ 'uid'=>$uid, 'days'=>$score['day'], 'scores'=>$score['score'] ]; $user = Login::where('id',$uid)->first(); $sign = Sign::create($arr,true);//添加签到记录 $score_sign = User_Sign::create($userSgin,true);//添加签到积分 $upuser = Login::where('id',$uid)->update(['days'=>$score['day'],'scores'=>$user['scores']+$score['score']]); if ($sign && $score_sign && $upuser!==false){ DB::commit(); return ['code'=>300,'msg'=>'今日已断签','data'=>$user]; }else{ DB::rollBack(); return ['code'=>500,'msg'=>'签到失败','data'=>null]; } } //判断用户今天是否签到 if (24*3600<$nowTime-$prevTime && $nowTime-$prevTime<48*3600){ $user = Login::where('id',$uid)->first();//获取出连续签到天数 //查询出连续签到所得积分 $score = Score::where('day',$user['days']+1)->first(); //添加签到记录 $arr = [ 'uid'=>$uid, 'mouth_week_day'=>date('Y-m-d 00:00:00'), ]; $userSgin =[ 'uid'=>$uid, 'days'=>$score['day'], 'scores'=>$score['score'] ]; $user = Login::where('id',$uid)->first(); $sign = Sign::create($arr,true);//添加签到记录 $score_sign = User_Sign::create($userSgin,true);//添加签到积分 $upuser = Login::where('id',$uid)->update(['days'=>$score['day'],'scores'=>$user['scores']+$score['score']]); if ($sign && $score_sign && $upuser!==false){ DB::commit(); return ['code'=>400,'msg'=>'连续签到成功','data'=>$user]; }else{ DB::rollBack(); return ['code'=>500,'msg'=>'签到失败','data'=>null]; } } } } public function showSign(request $request) { $openid = $request['uid']; $login = Login::where('openid',$openid)->first(); $uid = $login['id']; $data = Login::where('id',$uid)->first(); return ['code'=>200,'msg'=>'用户签到展示成功','data'=>$data]; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)