<?php

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


class House_Zhou_model extends MY_Model
{

    function __construct()
    {
       parent::__construct();
       $this->load->model("house_statistic_model");
    }

     /**
     * 验证房源的可刷新次数
     * @param type $uid，房源id  $id
     * @return array
     */
    function yzrefrshnum($uid,$id,$tbl='sell')
    {
		 //获得可刷新次数
		$num1 =  $this->get_data(array('form_name' => 'personal_refresh','where'=>array('uid'=>$uid,'rowid'=>$id,'tbl'=>$tbl,'flag'=>1,'esta'=>1),'select'=>array('refresh_num')),'esfbak');

		$num2 =  $this->get_data(array('form_name' => 'personal_refresh','where'=>array('rowid'=>$id,'tbl'=>$tbl,'flag'=>2,'esta'=>1,'begin_time <'=>time(),'end_time >'=>time()),'select'=>array('refresh_num')),'esfbak');
		  if(!empty($num1[0]['refresh_num']) && !empty($num2[0]['refresh_num']))
			{
			 $num = $num1[0]['refresh_num']+$num2[0]['refresh_num'];
			}elseif(!empty($num1[0]['refresh_num']))
			{
			 $num = $num1[0]['refresh_num'];
			}elseif(!empty($num2[0]['refresh_num']))
			{
			 $num = $num2[0]['refresh_num'];
			}
			if(!empty($num))
			{
			 return $num;
			}else{
			 return 0;
			}
    }

         /**
     * 验证房源的可刷新次数
     * @param type $uid，房源id  $id
     * @return array
     */
    function yzrefrsh($uid,$id,$tbl='sell',$flag=1)
    {
     //获得可刷新次数
    $result =  $this->get_data(array('form_name' => 'personal_refresh','where'=>array('uid'=>$uid,'rowid'=>$id,'tbl'=>$tbl,'flag'=>$flag,'esta'=>1),'select'=>array('id')),'esfbak');

    
        if(!empty($result))
        {
         return $result;
        }else{
         return 0;
        }
    }


    
     /**
     * 验证房源的可刷新次数
     * @param $telno 手机号,$arr 匹配信息,$tbl 表
     * @return array
     */
    function yzsamehouse($telno , $arr , $tbl = 'sell')
     {
        $total_num = 0;
        if( in_array( $tbl , array('sell','rent') ) && !empty($telno) )
        {
            $sql = "SELECT id FROM $tbl ";
            $where_cond = " WHERE esta = '1' AND infofrom = '1' AND ischarge = '0' AND telno='".$telno."'";

			if(is_array($arr) && !empty($arr))
			{
				foreach($arr as $key=>$value)
				{	
					$value = addslashes(strip_tags($value));
					$where_cond .= " AND ".$key." = '".$value."'";
				}
			}
			//echo '<!--'.$sql . $where_cond.'-->';
			$query = $this->db_esfhousebak->query($sql . $where_cond);
			$result = $query->result_array();

            if( isset($result[0]['id']) )
            {
                $return = 1;
            }else{
                $return = 0;
            }
        }

        return $return;
     }

     /**
     * 添加房源的可刷新次数
     * @param type $uid，房源id  $id,添加刷新次数 $num,城市 $city_name
     * @return array
     */
    function addrefrshnum($uid,$id,$tbl='sell',$num,$city_name,$flag=1)
    {
      //验证是否有刷新次数
      $result =  $this->yzrefrsh($uid,$id,$tbl,$flag);

      if($result >0 )
      {
        $this->updaterefrshnum($uid,$id,$num,$tbl,$flag);
      }
      else
      {
        $arr['uid'] = $uid;
        $arr['rowid'] = $id;
        $arr['tbl'] = $tbl;
        $arr['refresh_num'] = $num;
        $arr['cityname'] = $city_name;

        //设置表
        $this->house_model->set_table('personal_refresh');

        //过滤表结构
        $result = $this->house_model->add($arr,'esf');
      }

    }


    /**
    * 刷新房源更新时间
    * @param type $telno 手机号码 $validcode 验证码
    * @return string
    */
    function updatehouse($id,$tbl,$up)
    {

		//echo "http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=4";die;
        if( $id > 0)
        {
            $arr = array( 'id' => $id );
            $this->set_table($tbl);
            $result = $this->save($arr,$up,'esfhouse');
			if($tbl=='rent')
			{

				$housedetail =  $this->get_data(array('form_name' => $tbl,'where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('telno')),'esfhousebak');
				$telno =$housedetail[0]['telno'];
				$ip    =get_ip();


				if(isset($up) && $up['esta']==2)
				{

					$arr = array( 'rowid' => $id );
					$this->set_table('rent_of_zhizu');
					$this->save($arr,array('status'=>2),'esfhouse');
					//echo "http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=2";die;
					get_api("http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=2");
				}
				else
				{
					get_api("http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip);
				}
			}


        }
        return $result;
    }
	
	/**
    * 再发布房源
    * @param type $telno 手机号码 $validcode 验证码
    * @return string
    */
    function republishhouse($id,$tbl,$up)
    {
		
		
        if( $id > 0)
        {
			// 2017-3-28 添加再发布匹配小区图片 功能 --- start ----->
			$housedetail_pic_info =  $this->get_data(array('form_name' => $tbl,'where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('pic1','blockid')),'esfhousebak');
			
			if(empty($housedetail_pic_info['0']['pic1']))
			{
				$blockid    =$housedetail_pic_info['0']['blockid'];
				$pic_url_lm = $this->get_block_pic_by_type($blockid , 52);
				
				if( $pic_url_lm != '')
				{
					$filename = $pic_url_lm;
				}
				else
				{
					$filename = $this->get_block_pic_by_type( $blockid , 0);
				}
				
				if( $filename != '')
				{
					$title = '';
					$sort  = 1;
					$blockid = $blockid;
					$createtime = time();
					$upload_name = get_upload_tblname($tbl,$id);
					
					$sql = "INSERT INTO $upload_name(`tbl`,`rowid`,`position`,`filename`,`title` ,`blockid`,`sort`,`createtime`,`isfrom`) VALUES('$tbl',$id,'pic1','$filename','$title','$blockid','$sort','$createtime','1')";

					//echo $sql;die;
					$this->db_esfhouse->query($sql);

					
					$sql = "UPDATE $tbl SET pic1 = '".$filename."',lucupdatetime=lucupdatetime+1 WHERE id = '".$id."' ";
					//echo $sql;die;
					$this->db_esfhouse->query($sql);
					
				}
				
			}
			
			// 2017-3-28 添加再发布匹配小区图片 功能 --- end ----->

            $arr = array( 'id' => $id );
            $this->set_table($tbl);
            $result = $this->save($arr,$up,'esfhouse');

			if($tbl=='rent')
			{

				$housedetail =  $this->get_data(array('form_name' => $tbl,'where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('telno')),'esfhousebak');
				$telno =$housedetail[0]['telno'];
				$ip    =get_ip();


				if(isset($up) && $up['esta']==1)
				{
					$arr = array( 'rowid' => $id );
					$this->set_table('rent_of_zhizu');
					$this->save($arr,array('status'=>0),'esfhouse');
					get_api("http://mtapi.house365.com/?method=zhizu.rentRefreshHouse&city=".GB_CITY."&id=".$id."&telno=".$telno."&fromzhizu=2&ip=".$ip."&sell_status=0");
				}
				
			}
        }
		//再发布更新已经激活的同样条件的房源
		$housedetail =  $this->get_data(array('form_name' => $tbl,'where'=>array('id'=>$id,'infofrom'=>'1'),'select'=>array('blockshowname','buildarea','price','floor','telno')),'esfhousebak');

       if(!empty($housedetail[0]['telno']))
        {
        //更新此条件下其他房源
        $this->db_esfhouse->query("update $tbl set esta=-5,note='系统打为重复' where telno='".$housedetail[0]['telno']."' AND esta = '1' AND infofrom = '1' AND ischarge!='1' AND id!=$id AND blockshowname='".$housedetail[0]['blockshowname']."' AND buildarea='".$housedetail[0]['buildarea']."' AND floor='".$housedetail[0]['floor']."' AND updatetime>'".strtotime(date('Y-m-d'))."'");       

        $this->db_esfhouse->query("update $tbl set esta=2,note='系统打为失效' where telno='".$housedetail[0]['telno']."' AND esta = '1' AND infofrom = '1' AND ischarge!='1' AND id!=$id AND blockshowname='".$housedetail[0]['blockshowname']."' AND buildarea='".$housedetail[0]['buildarea']."' AND floor='".$housedetail[0]['floor']."' AND updatetime<'".strtotime(date('Y-m-d'))."'"); 
        }

        return $result;
    }

	function get_block_pic_by_type($blockid , $bi_type)
	{
		$where_cond = "WHERE bi_blockid = '".$blockid."'";
		if( $bi_type > 0 )
		{
			$where_cond .= " AND bi_type = '".$bi_type."' limit 1";
		}
		else
		{
			$where_cond .= " AND bi_type IN (51,52,53) limit 1";
		}

		$sql = "SELECT bi_img as pic FROM block_img ".$where_cond .$order_cond;
		
		$query = $this->db_esfhousebak->query($sql);
		$result = $query->result_array();
		
		return $result[0]['pic'];
		
	}

     /**
     * 更新可用刷新次数
     * @param type $telno 手机号码 $validcode 验证码 $num刷新次数 $tbl 表
     * @return string
     */
    function updaterefrshnum($uid,$id,$num,$tbl='sell',$flag=1)
    {
        $query = $this->db_esf->query("UPDATE `personal_refresh` SET `refresh_num` = '$num' WHERE `rowid` =  '$id'  AND `uid` =  '$uid' AND `tbl` =  '$tbl' AND `flag` =  '$flag'");

        return 1;
    }

     /**
     * 根据用户id获取房源数量
     * @param type $uid
     * @return array
     */
    function gethousenumbyuid( $uid , $tbl='sell' , $esta=0)
    {
        if($esta == 1)
        {
          $housenum =  $this->get_data(array('form_name' => $tbl,'where'=>array('uid'=>$uid,'esta'=>'1','infofrom'=>'1'),'select'=>array('count(id) as num')),'esfhousebak');
        }else{
          $housenum =  $this->get_data(array('form_name' => $tbl,'where'=>array('uid'=>$uid,'esta !='=>'4','infofrom'=>'1'),'select'=>array('count(id) as num')),'esfhousebak');
        }
		//print_r($housenum);exit;
        return $housenum[0]['num'];
    }

    /**
    * 根据用户id获取房源信息
    * @param type $uid
    * @return array
    */
    function gethousebyuid($uid,$tbl='sell',$select,$offset=0,$pagesize=0)
    {
		
        $housearray =  $this->get_data(array('form_name' => $tbl,'where'=>array('uid'=>$uid,'infofrom'=>'1','esta !='=>4),'select'=>$select,'order_by'=>'creattime desc','limit'=>$offset,'offset'=>$pagesize),'esfhousebak');
		//获取数组的个数，再把图片的数量插入数组中
		$housearray_number =count($housearray);
		
		for($i=0;$i<$housearray_number;$i++)
		{
			$sell_house_id =$housearray[$i]['id'];
			$this->load->helper('function');
			
			$uploadtbl = get_upload_tblname($tbl,$sell_house_id);
			$pic_number = $this->pic_model->getPicNum($tbl,$sell_house_id,$uploadtbl);
			$housearray[$i]['pic_num'] =$pic_number;
			$housearray[$i]['city_name']=GB_CITY;
		}

		
        return $housearray;
    }


	/**
    * 根据用户id获取激活的房源信息
    * @param type $uid
    * @return array
    */
    function gethousebyuid_and_activate($uid,$tbl='sell',$select,$offset=0,$pagesize=0)
    {
		//esta 暂时设置为-4 等开发完成后，改为1
		
        $housearray =  $this->get_data(array('form_name' => $tbl,'where'=>array('uid'=>$uid,'infofrom'=>'1','esta'=>1),'select'=>$select,'order_by'=>'creattime desc','limit'=>$offset,'offset'=>$pagesize),'esfhousebak');
		
		
        return $housearray;
    }

    /**
    * 根据所传数组获取房源信息
    * @param type $where
    * @return array
    */
    function gethousebywhere($where,$tbl='sell',$select,$offset=0,$pagesize=0)
    {
        $housearray =  $this->get_data(array('form_name' => $tbl,'where'=>$where,'select'=>$select,'order_by'=>'updatetime desc','limit'=>$offset,'offset'=>$pagesize),'esfhousebak');
        return $housearray;
    }


	/**
    * 根据所传数组获取房源信息
    * @param type $where
    * @return array
    */
    function get_house_num_by_where($where,$tbl='sell')
    {	
        $house_info =  $this->get_data(array('form_name' => $tbl,'where'=>$where,'select'=>array('count(id) as num')),'esfhousebak');
		$house_num = isset($house_info[0]['num']) ? $house_info[0]['num'] : 0; 
        return $house_num;
    }


    /**
    * 更改房源的uid
    * @param type $uid
    * @return array
    */
    function updatehouseuid( $uid , $newuid , $tbl = 'sell')
    {
        $uid    = intval($uid);
        $newuid = intval($newuid);

        if( $uid > 0 && $newuid > 0 && in_array( $tbl , array('sell','rent') ) )
        {
            $sql = "UPDATE $tbl SET uid = '$newuid' WHERE uid = '$uid' AND infofrom = '1'";
            $this->db_esfhouse->query($sql);
            $msg = 1;
        }
        else
        {
            $msg = 0;
        }

        return  $msg;
    }


    /**
    * 添加个人房源匹配求购求租信息
    * @param string $want_type  求购求租类型(buy/rentwant)
    * @param int $want_id   求购求租信息编号
    * @param int $want_uid  求购求租人账号
    * @param int $match_id  匹配房源编号
    * @param int $uid   匹配人账号编号
    * @return array 添加结果
    */
    public function add_match_info( $want_type , $want_id , $want_uid , $match_id , $uid )
    {
        if( in_array( $want_type, array('buy','rentwanted') ) )
        {
            if( $want_type == 'buy')
            {
                $tbl_want = 'buy';
                $tbl_match = 'buy_match';
            }
            else if( $want_type == 'rentwanted' )
            {
                $tbl_want = 'rentwanted';
                $tbl_match = 'rentwanted_match';
            }

            //提交的日志数据
            $data   = array(
                'match_id'  => $match_id,
                'match_uid' => $uid,
                'want_id'   => $want_id,
                'want_uid'  => $want_uid,
                'infofrom'  => 1, //个人
                'esta'      => 0, //匹配状态
                'isread'    => 0, //是否已经查看
                'creattime' => time()
            );

            //是否已经添加过匹配
            $is_matched = $this->_check_is_matched( $tbl_match , $want_id , $want_uid , $match_id , $uid);

            if( !$is_matched )
            {
                $today_num_matched = $this->_get_matched_num_today( $tbl_match , $want_id , 1 );

                //每天10条匹配信息
                if( $today_num_matched <= 10)
                {
                    $this->set_table( $tbl_match );//插入数据
                    $insert_id  = $this->add( $data , 'esfhouse' );

                    if( $insert_id > 0 )
                    {
                        //修改求租房源新匹配个数
                        $sql = " UPDATE $tbl_want SET matched_num = matched_num + 1 WHERE id = ".$want_id;
                        $query = $this->db_esfhouse->query($sql);

                        $result['is_ok'] = 1;
                        $result['insert_id'] = $insert_id;
                        $result['msg'] = '匹配房源信息插入成功';
                    }
                    else
                    {
                        $result['is_ok'] = 0;
                        $result['msg'] = '匹配房源信息插入失败';
                    }
                }
                else
                {
                    $result['is_ok'] = 2;
                    $result['msg'] = '今日个人匹配已达到上限';
                }
            }
            else
            {
                $result['is_ok'] = 3;
                $result['msg'] = '匹配信息已经存在';
            }
        }

        return $result;
    }


    /**
    * 判断某条求购求租的匹配信息是否已经存在
    * @param string $tbl_match  房源匹配表(buy/rentwant)
    * @param int $want_id   求购求租信息编号
    * @param int $want_uid  求购求租用户编号
    * @param int $match_id  匹配房源编号
    * @param int $match_uid 匹配人账号编号
    * @param int $infofrom  匹配房源来源
    * @return boolean       是否已经添加(true-已匹配/false)
    */
    private function _check_is_matched( $tbl_match , $want_id , $want_uid , $match_id , $match_uid , $infofrom = 1)
    {
        $is_matched = false;

        if( $tbl_match != '')
        {
            $where_cond = "want_id = '".$want_id."' AND match_id = '".$match_id."'
                     AND want_uid = '".$want_uid."' AND match_uid = '".$match_uid."' AND infofrom = '".$infofrom."' ";

            $this->db_esfhouse->where( $where_cond );
            $this->db_esfhouse->from($tbl_match);
            $total_num  = $this->db_esfhouse->count_all_results();
            //echo $this->db_esfhousebak->last_query();

            if( $total_num  > 0 )
            {
               $is_matched = true;
            }
        }

        return $is_matched;
    }


    /**
    * 获得某条求购求租房源已匹配的个数
    * @param string $tbl_match  房源匹配表(buy/rentwanted)
    * @param int $want_id   求购求租信息编号
    * @param int $infofrom  匹配房源来源
    * @return boolean       是否已经添加(true-已匹配/false)
    */
    private function _get_matched_num_today( $tbl_match , $want_id , $infofrom = '')
    {
        $total_num  = 0;

        if( $tbl_match != '')
        {
            $where_cond = "want_id = '".$want_id."' ";

            if( intval($infofrom) > 0 )
            {
                $where_cond .= " AND infofrom = '".$infofrom."' ";
            }

            //$where_cond .= " AND esta = 0 ";

            $this->db_esfhouse->where( $where_cond );
            $this->db_esfhouse->from( $tbl_match );
            $total_num  = $this->db_esfhouse->count_all_results();
            //echo $this->db_esfhousebak->last_query();
        }

        return $total_num;
    }


    /**
    * 获取昨日新增个人有效房源
    * @param string $tbl  房源表('sell','rent')
    * @return int   新发布个数
    */
    function get_personal_house_num_yesterday($tbl)
    {
        $total_num = 0;
        if( in_array( $tbl , array('sell','rent') ) )
        {
            $yesterday = date('Y-m-d' , strtotime('-1 day'));
            $yesterday_time  = strtotime($yesterday);
            $yesterday_time_end = $yesterday_time + 86400;

            $sql = "SELECT id FROM $tbl";
            $where_cond = " WHERE esta = '1' AND infofrom = '1' AND creattime >= '".$yesterday_time."'
                            AND creattime <= '".$yesterday_time_end."' luc";

            if( $tbl == 'sell')
            {
                $total_info = $this->server_sell->query( $sql . $where_cond);
            }
            else if( $tbl == 'rent')
            {
                $total_info = $this->server_rent->query( $sql . $where_cond);
            }

            if( isset($total_info['TOTAL']) )
            {
                $total_num = intval($total_info['TOTAL']);
            }
        }

        return $total_num;
    }


    /**
    * 获取昨日新增个人有效房源
    * @param string $tbl  房源表('sell','rent')
    * @param string $offset 偏移量
    * @param string $limit  每次显示个数
    * @param string $order  排序
    * @return array 新发布房源数组
    */
    function get_personal_house_yesterday( $tbl , $offset , $limit , $order = 'desc' )
    {
        $houseinfo = array();

        if( in_array( $tbl , array('sell','rent') ) )
        {
            $yesterday = date('Y-m-d' , strtotime('-1 day'));
            $yesterday_time  = strtotime($yesterday);
            $yesterday_time_end = $yesterday_time + 86400;

            $where_cond = " WHERE esta = '1' AND infofrom = '1' AND creattime >= '".$yesterday_time."'
                            AND creattime <= '".$yesterday_time_end."' ";
            $order_cond =  " ORDER BY creattime " . $order ;
            $limit_cond =  " LIMIT ". $offset .",". $limit;

            if( $tbl == 'sell')
            {
                $sql = "SELECT id,uid,infotype,streetid,buildarea,price,buildyear FROM $tbl";
                $record_info = $this->server_sell->query( $sql . $where_cond . $order_cond . $limit_cond .' luc');
            }
            else if( $tbl == 'rent')
            {
                $sql = "SELECT id,uid,infotype,streetid,buildarea,price,renttype FROM $tbl";
                $record_info = $this->server_rent->query( $sql . $where_cond . $order_cond . $limit_cond .' luc');
            }

            if( isset($record_info['TOTAL']) && isset($record_info['Record']) )
            {
                $houseinfo = $record_info['Record'];
            }
        }

        return $houseinfo;
    }


    /**
    * 获取房源符合哪些求购信息
    * @param string $infotype  房源信息
    * @param string $streetid  板块
    * @param string $buildarea 建筑面积
    * @param string $price 价格
    * @param string $buildyear 建筑年代
    * @return array 符合条件的个人求购房源
    */
    function get_buy_want_by_house ( $infotype , $streetid , $buildarea , $price , $buildyear , $order ='asc')
    {
        $tbl_want = 'buy';
        $nowtime = time();

        if( $tbl_want != '')
        {
          
		   $where_cond = "esta = '1' AND allow_match = '1' AND expiretime > '".$nowtime."' AND
                    infofrom IN ('0','1') AND infotype = '".$infotype."' AND( street = '".$streetid."' OR  street1 = '".$streetid."' OR street2 = '".$streetid."' ) AND   buildarea1*0.9 <= '".$buildarea."' AND buildarea2 >= '".$buildarea."' AND price1*0.9 <= '".$price."' AND price2 >= '".$price."' AND buildyear1 <= '".$buildyear."' AND buildyear2 >= '".$buildyear."'";
		
			
			
            $this->db_esfhousebak->select('id , uid ,address');
            $this->db_esfhousebak->where($where_cond);
            $this->db_esfhousebak->order_by( 'creattime' , $order );
            $arr_data = $this->db_esfhousebak->get($tbl_want)->result_array();
        }

        return $arr_data;
    }


    /**
    * 获取房源符合哪些求租信息
    * @param string $infotype  房源信息
    * @param string $streetid  板块
    * @param string $buildarea 建筑面积
    * @param string $price 价格
    * @param string $renttype 建筑年代
    * @return array 符合条件的个人求购房源
    */
    function get_rent_want_by_house( $infotype , $streetid , $buildarea , $price , $renttype , $order ='asc')
    {
        $tbl_want = 'rentwanted';
        $nowtime = time();

        if( $tbl_want != '')
        {
		   /*
           $where_cond = "esta = '1' AND allow_match = '1' AND expiretime > '".$nowtime."' AND
                    infofrom IN ('0','1') AND infotype = '".$infotype."' AND( street = '".$streetid."' OR street1 = '".$streetid."' OR street2 = '".$streetid."' ) AND buildarea1 <= '".$buildarea."' AND buildarea2 >= '".$buildarea."' AND price1 <= '".$price."' AND price2 >= '".$price."' AND renttype = '".$renttype."' ";
			*/
			 $where_cond = "esta = '1' AND allow_match = '1' AND expiretime > '".$nowtime."' AND
                    infofrom IN ('0','1') AND infotype = '".$infotype."' AND( street = '".$streetid."' OR street1 = '".$streetid."' OR street2 = '".$streetid."' ) AND buildarea1 >= '".$buildarea*0.9."' AND buildarea2 >= '".$buildarea."' AND price1 >= '".$price*0.9."' AND price2 >= '".$price."' AND renttype = '".$renttype."' ";
			echo $where_cond;die;
            $this->db_esfhousebak->select('id , uid , address');
            $this->db_esfhousebak->where($where_cond);
            $this->db_esfhousebak->order_by( 'creattime' , $order );
            $arr_data = $this->db_esfhousebak->get($tbl_want)->result_array();
        }

        return $arr_data;
    }


    /**
    * 失效过期的求购/求租房源
    * @param void
    * @return array 符合条件的个人求购房源
    */
    function invalid_buy_rentwanted_info( $tbl )
    {
       $now_time = time();

       if( isset ( $tbl ) && in_array( $tbl , array('buy' , 'rentwanted')) )
       {
            $sql = "UPDATE $tbl SET esta = 2 WHERE expiretime <= '".$now_time."' AND esta IN (0,1)";
            $result = $this->db_esfhouse->query($sql);
       }

       if( $result )
       {
            $result['is_ok'] = 1;
            $result['msg'] = '更新完成';
       }
       else
       {
            $result['is_ok'] = 0;
            $result['msg'] = '更新失败';
       }

       return $result;
    }
}