/* * 200 签到成功 (第一次签到提示) * 201 恭喜您签到成功 (连续签到提示) * 202 请勿重复签到(当天已经签过到了) * 203 您已断签 已为您重新签到 * */ public function sign(){ $uid = session('id');//获取用户id //查询当前用户是否签到 $res = Db::table('signs')->where(['uid'=>$uid])->find(); if ($res){ //获取用户签到时间 $signtime = $res['signtime']; //获取当天 12:00 时间 $date = date( " Y-m-d"); //转为时间戳 $dateTime = strtotime($date); //获取昨天 整点 $homeTime = $dateTime-86400; //获取明天 整点 $endTime = $dateTime+86400; //判断当天是否签到 if ($signtime>$dateTime && $signtime<$endTime){ return json(['code'=>202,'msg'=>'请勿重复签到']); } //如果昨天未签到 if ($signtime<$homeTime){ //如果没有连续签到 也就是断签 那就在原来的积分之上 累加初值 $count = $res['count'] + 10; //签到天数 改为1 $day = 1; $signtime = time(); //修改数据 Db::table('signs')->where(['uid'=>$uid])->update(['count'=>$count,'signtime'=>$signtime,'day'=>$day]); return json(['code'=>203,'msg'=>'您已断签 已为您重新签到']); } //连续签到 if ($signtime>$homeTime && $signtime<$dateTime){ //如果连续签到 原本积分 = 签到天数 × 10 $count_a = $res['count']; $count_b = $res['day']*10; $count =$count_a + $count_b; //签到天数 + 1 $day = $res['day'] + 1; $signtime = time(); Db::table('signs')->where(['uid'=>$uid])->update(['count'=>$count,'signtime'=>$signtime,'day'=>$day]); return json(['code'=>201,'msg'=>'恭喜您签到成功']); } }else{ $data['signtime'] = time(); $data['count'] = 10; $data['uid'] = $uid; $data['day'] = 1; $SignRes = Db::table('signs')->insert($data); if ($SignRes){ return json(['code'=>200,'msg'=>'签到成功']); } } }