<?php
	set_time_limit(0);
	error_reporting(7);
	ini_set("display_errors",true);
	$conf_basedir = "../../../../"; //相对主目录的位置
	define('WEB_ROOT', $conf_basedir);
	$conf_where = "admin"; //选择调用相应模块
	$directory = basename(dirname(__FILE__)); //定义当前所在的目录，引入模块公用函数
	include_once(  "./base.inc.php");
	require_once '../function_crontab.php';


	$nowDate = date('Y-m-d');


	$sql = "select count(*) as num, uid, max(id) as maxid from reserve_refresh_deal_log where tbl='rent' and ymd = '$nowDate' group by uid ";
	$broker = $db->getAll($sql);
	$brokerNum = count($broker);
	if (intval($brokerNum) > 0) {
		$sql = '';
		$gcwp = new GrowthCreditWayPackage();
		$gewp = new GrowthExpWayPackage();
		for($i = 0 ; $i < $brokerNum; $i++ ) {
			/**
			$content = file_get_contents("growth.log");
			if ($content) {
				echo 'over';
				die();
			}***/
			$uid = $broker[$i]['uid'];
			$sql = "select * from broker where uid = $uid";
			$memkey = "growth_" . $sql;
			$BrokerInfo = $mc->get($memkey);
			if ($BrokerInfo === false) {
				$BrokerInfo = $dbback->getRow($sql);
				$mc->set($memkey, $BrokerInfo, 3600);
			}

			$arrBroker = array(
				'id' => $BrokerInfo['uid'],
				'groupid' => $BrokerInfo['groupid'],
			); 
			
			$gbc  = new GrowthBrokerCredit($arrBroker); 
			$gbe  = new GrowthBrokerExp($arrBroker);	
			$sum = $broker[$i]['num'];
			$refrshDescription = "预约刷新".$sum."条房源";
			//echo $refrshDescription;
			$score = $gcwp->getScoreByWayAliasAndPackageId('refreshHouse',$arrBroker['groupid']);                
			$inCreditStatus = $gbc->increase('refreshHouse',$refrshDescription,$score*$sum);			   
			//成长值			
			$exp = $gewp->findScoreByWayAliasAndPackageId('refreshHouse',$arrBroker['groupid']);					 
			$inExpStatus = $gbe->increase('refreshHouse',$refrshDescription,$exp*$sum);

			if ($broker[$i]['maxid'] > $lastInCreaseId) {
				$lastInCreaseId = $broker[$i]['maxid'];
			}
			//sleep(1);
		}
	}
	echo 'over';
