tp5项目每日签到
public function sign()
{
$id = input('id');
$data = db('sign')->where('uid',$id)->select();
$pro = db('login')->where('id',$id)->select();
$pro1 = $pro[0]['pro'] + 1000;
if(count($data) == 0) //没有该用户的签到记录
{
$aa = db('sign')->insert(['time'=>date('Y-m-d H:i:s'),'uid'=>$id]);
db('sign')->alias("a")->join('login b', 'a.uid = b.id')->where('b.id',$id)->update(['b.pro'=>$pro1]);
$this->success('签到成功',url('index/user',['id'=>$id]));//签到成功并返回个人中心
}
else
{
//判断今天是否签到
$todayb=date('Y-m-d'." 00:00:00");
$todaye= date('Y-m-d'." 23:59:59");
$isexit = db('sign')->field('time')->where(['uid'=>$id])->where('time','between',[$todayb,$todaye])->select();
if(count($isexit) == 1) {
$this->error('今日已签到',url('index/user',['id'=>$id])); //今日已签到
}
else //今日未签到
{
$query4 = db('sign')->where('uid',$id)->update(['time'=>date('Y-m-d H:i:s')]);
db('sign')->alias("a")->join('login b', 'a.uid = b.id')->where('b.id',$id)->update(['b.pro'=>$pro1]);
$this->success('签到成功',url('index/user',['id'=>$id]));
}
}
}