一个连续登录的方法

今天看了一个同事写的连续登录的方法,功能可以实现

 

 

/**

 *

 * int $topc 连续次数封顶值,int $uid 用户id,int $mul连续次数

 * 判断连续第几次领取积分

 * return int $mul 0为当日已点击,n已为连续n天点击

 *

*/

 

function get_levellxdl($topc,$uid,$mul) {

 

$nowdate = strtotime(date('Y-m-d',time()-86400*($mul-1)));

$ldate = strtotime(date('Y-m-d',time()-86400*$mul));

 

if(empty($mul)) {

/* 查询用户今日是否点击 */

$sql = "SELECT count(*)".

" FROM ".DB::table('buynow_lxdl').

" WHERE uid='".$uid."'".

" AND lonclick BETWEEN $ldate AND $nowdate-1".

" limit 0,1";

 

$lxdlres = DB::result_first($sql);

if($lxdlres) {

return $mul=0;

} else {

$mul=1;

return get_levellxdl($topc,$uid,$mul);

}

} else {

$sql = "SELECT *".

" FROM ".DB::table('buynow_lxdl').

" WHERE uid='".$uid."' AND lonclick BETWEEN $ldate AND $nowdate";

 

$resql = DB::result_first($sql);

if($resql && $mul != $topc) {

$mul += 1;

return get_levellxdl($topc,$uid,$mul);

} else {

 

return $mul;

}

}

}

 

你可能感兴趣的:(sql,table,date)