<?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 increase_id from growth_reserve_increase_job where id = 1";

	$increaseId = $dbback->getOne($sql);

	$sql = "select count(*) as num, uid, max(id) as maxid from reserve_refresh_deal_log where id > $increaseId  and ymd = '$nowDate' group by uid ";
	$broker = $db->getAll($sql);
	$brokerNum = count($broker);
	$lastInCreaseId = 1;
	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);
		}
	}
	if ($lastInCreaseId != 1) {
		$sql = "update growth_reserve_increase_job set increase_id = $lastInCreaseId where id = 1";
		$db->execute($sql);
	}
	echo 'over';
