<?php
/**
 * 经纪人活跃度
 * 功能：去除第7天的登陆状态
 * 需要在服务器时间过12点后准时执行
 */
require('path.inc.php');

$sql ="select * from fke_member where user_type=1";
//$sql ="select * from fke_member where user_type=1 order by last_login desc limit 50, 10";
$query->open($sql);
while ($rs = $query->next()) {
	//取得前六天的登陆情况
	$dateNow = mktime(0,0,0,date('m'),date('d'),date('Y'));
	
	//$dateNow = MyDate::transform('timestamp','2009-04-30');
	$dateBefore =  $dateNow -518400;
	$loginlog = $query_mysql->select("select add_time from fke_member_loginlog where username = '".$rs['username']."' and add_time>=".$dateBefore." order by add_time asc");
	$active_arr = array_fill(0, 7, 0);
	$activeRate = 0;
	foreach($loginlog as $item){
		for($i=0;$i<=6;$i++){
			if($dateBefore+$i*86400 == $item ){
				//print_rr('$dateBefore='.($dateBefore+$i*86400));
				//print_rr('$item='.$item);
				$activeRate += 1000+pow(2, $i);
				$active_arr[$i]=1;
				break;
			}
		}
	}
	//print_rr($active_arr);
	//print_rr($activeRate);
	if($active_arr){
		$active_str = implode('|',$active_arr);
	}else{
		$active_str = '';
	}
	$total_loginday = $query_mysql->getValue("select count(*) from fke_member_loginlog where username = '".$rs['username']."'");
	$registe_day = (time() - $rs['add_time'])/86400;
	$total_rate = $total_loginday/$registe_day;
	//print_rr("update fke_member set active_str ='".$active_str."' , active_rate='".$activeRate."' , active_total='".$total_rate."' where id = ".$rs['id']);
	$query_mysql->execute("update fke_member set active_str ='".$active_str."' , active_rate='".$activeRate."' , active_total='".$total_rate."' where id = ".$rs['id']);
}


echo "经纪人活跃度更新完成";

?>