Home > php教程 > php手册 > ThinkPHP continuous sign-in small case

ThinkPHP continuous sign-in small case

WBOY
Release: 2016-10-09 08:32:23
Original
1435 people have browsed it

A small function for continuous check-in on the website!
When you are doing website development, have you ever encountered members who sign in continuously to get points? For example, I have a rule to add points for continuous sign-ins. So when we implement this function, we face There are a few points to note: (1) The number of consecutive sign-ins must be accumulated, which involves the judgment between two timestamps. (2) Whether the sign-in is this month, of course, in this case, the judgment between the two timestamps is also That's solved, but you should also pay attention to this point (3) If it is consecutive, it will be added by 1, otherwise it will be cleared to 0. Also, if you have not signed in before, a sign-in record will be generated! Below I will post a piece of code to implement the sign-in. Everyone is welcome to learn and progress together!
Table structure:
ThinkPHP continuous sign-in small case
/**How to implement continuous check-ins*/
public function signList(){
/**First check if there is this user*/
$m_id = $_GET['m_id'];
$sign = D('Sign')->where(array("m_id"=>$m_id))->limit(0)->find();
/**If there is, judge the time difference and then process the number of check-ins.*/
if($sign){
/**Yesterday's timestamp time range*/
$t = time();
$last_start_time = mktime(0,0,0,date("m",$t),date("d",$t)-1,date("Y",$t));
$last_end_time = mktime(23,59,59,date("m",$t),date("d",$t)-1,date("Y",$t));
/**Today's timestamp time range*/
// $now_start_time = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
// $now_end_time = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
/**Determine whether the last check-in time is within yesterday's time range*/
if($last_start_time<$sign['time']&&$sign['time']<$last_end_time){
$da['time'] = time();
$da['count'] = $sign['count']+1;
/**You can also add some operations here to determine how many consecutive days you have signed in and then add points, etc.*/
D('Sign')->where(array("m_id"=>$m_id))->save($da);
}else{
/**Return to checked-in operations*/
$da['time'] = time();
$da['count'] = 0;
D('Sign')->where(array("m_id"=>$m_id))->save($da);
}
}else{
$data['m_id'] = $m_id;
$data['time'] = time();
$data['sign'] = 1;
$res = D("Sign")->add($data);
if($res){
/**Return if successful, or handle some procedures, such as adding points*/
}
}
}

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template