微信小程序 +tp5 实现签到功能

一、使用think5.1实现签到功能

//签到
    public function block(){
        //获取用户id
        $post=input('post.');
        //查询签到状态
        $arr= Regiest::where('user_id',$post['user_id'])->whereTime('regiest_time','today')->find();
        //获取当前时间戳
        $time=time();

        if(empty($arr)){
            Regiest::create(
                ['user_id'=>1,
                    'regiest'=>1,
                    'regiest_time'=>$time,

                ]
                ,true
            );
        }

        return json(['code'=>200,'msg'=>'签到成功','data'=>null]);
    }

查询用户签到的状态

//查询用户签到的状态
    public function regin(){
        //获取用户id
        $post=input('post.');
        //查询签到状态
        $arr= Regiest::where('user_id',$post['user_id'])->whereTime('regiest_time','today')->find();

        if(empty($arr)){
            return json(['code'=>400,'msg'=>'操作成功','data'=>0]);
        }else{
            return json(['code'=>200,'msg'=>'操作成功','data'=>1]);
        }
    }

小程序端 wxml

<view class="head">
<!-- <l-avatar size="120" icon="user" /> -->
<l-avatar open-data="{{['userAvatarUrl','userNickName']}}" />
</view>

<view >
<l-grid l-class="grid" show-border="{{true}}">
    <l-grid-item >
        <view class="text" bindtap="openPage">签到</view>
    </l-grid-item>
</l-grid>
</view>

小程序js

Page({

  /**
   * 页面的初始数据
   */
  data: {
res:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that=this;
    wx.request({
      url: 'http://www.tp5.com/regin',
      data:{
        user_id:1,
      },
      method:'POST',
      success:function(res){
        console.log(res.data.data)
          that.setData({
          res:res.data.data
          })
      } 
    })
  },
  openPage(res){
    var that=this;
    var  status=this.data.res
    if(status==1){
      wx.showToast({
        title: '已经签过了',
      })
      return
    }
    console.log(status)
    wx.request({
      url: 'http://www.tp5.com/block',
      data:{
        user_id:1,
      },
      method:'POST',
      success:function(res){
          console.log(res.data)
          if(res.data.code==200){
              wx.showToast({
                title: '签到成功',
              })
          }
      } 
    })
  },


})

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值