首页 > 作文

TP5框架实现签到功能的方法分析

更新时间:2023-04-08 16:37:48 阅读: 评论:0

本文实例讲述了tp5框架实现签到功能的方法。分享给大家供大家参考,具体如下:

基于tp5 模型的一个签到功能;

由于存储所有的签到日期数据库会非常庞大,所以签到日期只存储近三个月的。

具体功能:

1、记录最近一次的签到时间

2、每次签到都会添加15积分

3、有连续签到的记录

create table `sp_林甸教育信息中心sign` ( `id` int(11) not null auto_increment comment '主键', `times` datetime default null comment '最近一次签到时间', `urid` int(11) default null comment '用户id', `days` tiny秋水原文及翻译int(6) not null default '0' comment '连续签到的天数', `number` decimal(10,0) not null default '0' comment '当月签到给的积分', `one` varchar(255) default null comment '当月签到的日期,用“,”隔开', `two` varchar(255) default null comment '上个月签到的日期,用“,”隔开', `three` varchar(255) default null comment '上上个月签到的日期,用“,”隔开', primary key (`id`)) engine=innodb auto_increment=4 default chart=utf8;
/**   * 用户签到   * @param array $urid 用户id   */  public function add($urid)  {      $data = db::name('sign')->where('urid',$urid)->lect();      if(count($data) == 0) //没有该用户的签到记录      {        $query4 = db::name('sign')->inrt(['times'=>date('y-m-d h:i:s'),'urid'=>$urid,'days'=>1,'number'=>'15','one'=>date('d',time())]);        return 1;      }      el      {        //判断今天是否签到        $todaybegin=date('y-m-d'." 00:00:00");        $todayend= date('y-m-d'." 23:59:59");        $ixit = db::name('sign')->field('times')->where(['urid'=>$urid])->where('times','between',[$todaybegin,$todayend])->lect();        if(count($ixit) == 1)  //今日已签到        {          return 0;        }        el  //今日未签到        {          $times = db::name('sign')->where('urid',$urid)->field('times')->lect();          $time = strtotime($times[0]['times']);           if((time()-$time > 24*60*60))    //上次签到时间大于24小时,连续签到天数清零          {            $query = db::name('sign')->where('urid',$urid)->update(['days'=>1]);          }          el   //上次签到时间小于24小时,连续签到次数加1          {            $query = db::name('sign')->where('urid',$urid)->tinc('days');          }          //更新上次签到时间和签到积分          $query1 = db::name('sign')->where('urid',$urid)->update(['times'=>date('y-m-d h:i:s')]);          $query2 = db::name('sign')->where('urid',$urid)->tinc('number', 15);           $sqldate = date('m',$time);  //上次签到日期的月份          $nowdate = date('m',time()); //当前月份          //记录本次签到日期          if($sqldate != $nowdate) //上次签到日期与本次签到日期月份不一样          {            $oldtime = $times[0]['times'];            $onetime=date("y-m-d h:i:s", strtotime("-1 month")); //获取前1个月的时间,获取格式为2016-12-30 13:26:13            $two印象主题time=date("y-m-d h:i:s", strtotime("-2 month")); //获取前2个月的时间            $threetime=date("y-m-世界十大化妆品品牌d h:i:s", strtotime("-3 month")); //获取前3个月的时间             $rs = db::name('sign')->where('urid',$urid)->field('one,two,three')->lect();             if($oldtime < $onetime && $oldtime >= $twotime)   //月份间隔 大于1个月,小于2个月            {              $one = date('d',time());              $two = $rs[0]['one'];              $three = $rs[0]['two'];            }            elif($oldtime < $twotime && $oldtime >= $threetime) //月份间隔 大于2个月,小于3个月            {              $one = date('d',time());              $two = '';              $three = $rs[0]['one'];            }            elif($oldtime < $threetime) //月份间隔 大于3个月            {              $one = date('d',time());              $two = '';              $three = '';            }    嫦娥五号月球探测器在我国哪里发射        $query3 = db::name('sign')->where('urid',$urid)->update(['one'=>$one,'two'=>$two,'three'=>$three]);          }          el //上次签到日期与本次签到日期月份一样          {            $one = db::name('sign')->where('urid',$urid)->field('one')->lect();            $arr[] = $one[0]['one'];            $arr[] = date('d',time());            $newones = implode(",",$arr);            $query3 = db::name('sign')->where('urid',$urid)->update(['one'=>$newones]);          }        return 1;        }      }  }

本文发布于:2023-04-08 16:37:46,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/a892d0407bb67c8b5bd09b5120bcb629.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:TP5框架实现签到功能的方法分析.doc

本文 PDF 下载地址:TP5框架实现签到功能的方法分析.pdf

标签:个月   日期   时间   间隔
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图