<?php
/**
 * 计算A+房源（租房）
 * 推荐到首页（时间可根据具体情况定）每天更新
 */

require('path.inc.php');

$borough_avgprice = $query->getValue("select stat_value from fke_statistics where stat_index = 'avgprice'");

$query->execute("update fke_housesell set order_weight=0");
$housesell =  new HouseSell($query);
$borough = new Borough($query);
//计算二手房A+房源的单价比
$sql ="select * from fke_housesell where status=1 and (house_drawing<>'' or drawing_id<>'') and  house_price<200";
$query->open($sql);
while ($rs = $query->next()) {
	$img_num = $housesell->getImgNum($rs['id']);
	if($img_num<3){
		continue;
	}
	
	if(!$rs['borough_id']){
		//小区信息不对
		continue;
	}
	if(!$rs['house_age']){
		//没有填房龄
		continue;
	}
	if(!$rs['house_totalarea']){
		//没有填面积
		continue;
	}
	if(strpos('0',$rs['house_age']) === 0){
		$rs['house_age'] = '20' .$rs['house_age'];
	}elseif(intval($rs['house_age']) >= 80 && intval($rs['house_age']) < 100){
		$rs['house_age'] = '19'.$rs['house_age']; 
	}elseif(intval($rs['house_age']) <= 20){
		$rs['house_age'] = 2009 - $rs['house_age'];
	}
	$rs['house_age'] = intval($rs['house_age']);
	
	$house_age = date('Y') - $rs['house_age'];
	if($house_age == 0){
		continue;
	}
	
	$regional = ($borough_avgprice*1.5 - $rs['house_price']*10000/$rs['house_totalarea']);
	echo $regional."<br/>";
	$order_weight = $regional/(pow($rs['house_totalarea'],1/5)*2) + $regional/(pow($house_age,1/3) *0.5);
	$query_mysql->execute('update fke_housesell set order_weight='.$order_weight.' where id='.$rs['id']);
}


echo "A+房源更新完成";

?>