PHP TP5 实现用户签到
//获取Session中的用户ID
$where['userid'] = session('user.id') ; $result = Sigins::getOne($where); if(!$result){ $data['userid'] = session('user.id') ; $data['sign'] = 1; //初始连续签到天数 $data['num'] = 10; //初始签到积分 $data['addtime'] = time(); $model=new Sigins(); $res = $model->insert($data); if($res){ $this->success('恭喜您完成首次签到获得10积分!!'); } }else{ $sigin_time = $result['addtime']; //获取上次签到的时间 $atNow = date('y-m-d'); //当天0点 $newNow = strtotime($atNow); //转化为时间戳 $prevDay = $newNow - 86400; //昨天0点 $nextDay = $newNow + 86400; //明天0点 if($sigin_time>$newNow && $sigin_time<$nextDay){ $this->error('您今天已经签到过了!!当天不能重复签到'); } if($sigin_time>$prevDay && $sigin_time<$newNow){ $id['userid'] = $result['userid'] ;// $request->session()->get('U')['user_id']; $data['sign'] = $result['sign']+1; $data['num'] = $result['num']+10*($result['sign']+1); $data['addtime'] = time(); $model=new Sigins(); $res=$model->where($id)->update($data); if($res){ $this->success('第'.($result['sign']+1).'天签到获得'.(10*($result['sign']+1)).'积分'); } } if($sigin_time<$prevDay){ $id['userid'] = $result['userid'] ;//$request->session()->get('U')['user_id']; $data['sign'] = 1; //初始连续签到天数 $data['num'] = $result['num']+10; //初始签到积分 $data['addtime'] = time(); $model=new Sigins(); $res=$model->where($id)->update($data); if($res){ $this->success('由于你中途断签,此次签到获得10积分'); // echo "<Script>alert('签到成功');location.href='sign'</Script>";die; } } }