<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 房源类型发布规则
 *
 * 
 */
class house_publish_rule_wang_model extends MY_Model {

    /**
     * 表名
     * @var type 表名
     */
    private $table;

    public function __construct() 
	{
        //parent::__construct(0,1,0);
		
		parent::__construct(1,1,1);
	
		//parent::__construct();

        $this->table = 'house_publish_rule';
    }
	
	/**
	 * 获取房源类型发布规则
	 *
	 */
    public function getHouseRuleOneData($searchCrond = array(),$showCoulumn = array()) 
	{
		$result = array();

        if(empty($searchCrond))
		{
			return $result;
		}
			
		$coulmnVal = '*';
		if(!empty($showCoulumn))
		{
			$coulmnVal = implode(',',$showCoulumn);
		}

		$sql = "select ".$coulmnVal." from ".$this->table." where ".implode(' and ',$searchCrond)." limit 1";

        $result = $this->dbback->query($sql)->row_array($sql);

		return $result;
    }

	/**
	 * 获取查房价
	 *
	 */
	public function getHousePrice($argumentData = array())
	{
		$cacheKey = 'nj_block_assess_price_'.$argumentData['blockId'].'_'.$argumentData['buildArea'].'_'.$argumentData['floor'].'_'.$argumentData['forward'].'_'.$argumentData['room'].'_'.$argumentData['totalFloor'];

		$data = $this->mc->get($cacheKey);
		
		if(empty($data))
		{
			//$url = 'http://hmc.house365.com:8012/house365-cm-web/rest/interface/?blockId='.$argumentData['blockId'].'&blockName='.$argumentData['blockName'].'&buildArea='.$argumentData['buildArea'].'&city='.$argumentData['city'].'&client=tf&floor='.$argumentData['floor'].'&forward='.$argumentData['forward'].'&livingRoom='.$argumentData['livingRoom'].'&room='.$argumentData['room'].'&serviceCode=Hmc&serviceName=saveAssess&totalFloor='.$argumentData['totalFloor'];

			$url = 'http://xxxapi.house365.com:92/sell-price/price/calculate_price?city='.$argumentData['city'].'&blockid='.$argumentData['blockId'].'&forward='.$argumentData['forward'].'&room='.$argumentData['room'].'&buildarea='.$argumentData['buildArea'].'&floor='.$argumentData['floor'].'&totalfloor='.$argumentData['totalFloor'];

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_TIMEOUT, 3);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
			$data = curl_exec($ch);
			curl_close($ch);
			
			if(!empty($data))
			{
				$this->mc->add($cacheKey,$data,3600);
			}

			//file_put_contents('testapi.log',$url."\n".var_export($data,true)."\n\n",FILE_APPEND);
		}

		return $data;
	}
}
?>
