<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//error_reporting(E_ALL);
//ini_set("display_errors",TRUE);
		

class Esf_center_api_zhou extends MY_Controller {

    function __construct()
    {
	  parent::__construct();
	  $this->load->model("user_model");
	  $this->load->model("userTest_model");
	  $this->load->model("ask_model");
	  $this->load->model("house_model");
	  $this->load->library("user_class");
	  $this->load->helper("template_helper");
	  $this->load->library("apply_class");
	  $this->load->model("user_statistic_model");
	  $this->load->model("push_model");
	  $this->load->model("pushzhou_model");
	  $this->city = '';
	  $this->user_id = 0;


    }



	
	/**
	* 验证验证码接口
	* @author cxf
	*/
	public function api_yzcode()
	{
		$validcode = intval($this->input->get('validcode'));
		$telno = intval($this->input->get('telno'));
		$kind = intval($this->input->get('kind'));

		//验证验证码
		$valid_isuse = $this->user_model->yzusersms($validcode,$telno,$kind);

		if($valid_isuse)
		{	
			//验证成功
			$this->user_model->updatesms($validcode,$telno);
			echo 1;
		}
		else
		{
			echo 0;
		}
		
		exit;
	}


    /**
    * 关注房源操作接口
    * @author cxf
    */
    public function api_savehouse()
    {
         $uid = $this->input->get('uid');
         $kind = $this->input->get('kind');
         $rowid = $this->input->get('rowid');
         $tbl = $kind == 3 ? 'sell' : 'rent';
         $city = $this->input->get('city');
         $city = $city ? $city : 'nj';
         $result = $this->user_model->getusercollectid($uid,$rowid,$city);

         //已关注此房源
         if( $result > 0 )
         {
            echo "2";
            exit;
         }

         if($tbl == 'sell')
         {
            $houseinfo =  $this->house_model->get_data(array('form_name' => $tbl,'where'=>array('id'=>$rowid,'esta'=>'1'),'select'=>array('infofrom','id','district','address','streetid','blockshowname','room','hall','buildarea','forward','fitment','buildyear','floor','totalfloor','subfloor','price','uid','telno','pic1','contactor','uid'),'limit'=>1),'esfhousebak');
         }
         else
         {
            $houseinfo =  $this->house_model->get_data(array('form_name' => $tbl,'where'=>array('id'=>$rowid,'esta'=>'1'),'select'=>array('infofrom','id','district','address','streetid','blockshowname','room','hall','buildarea','forward','fitment','buildyear','floor','totalfloor','subfloor','price','uid','telno','pic1','contactor','uid','priceunit','renttype'),'limit'=>1),'esfhousebak');
         }

         //判断经纪人房源多查一次经纪人姓名
         if( $houseinfo[0]['infofrom'] == '5' && $houseinfo[0]['uid'] > 0 && $houseinfo[0]['contactor'] == '')
         {
            $broker_data = $this->house_model->get_data(array('form_name'=>'broker','where'=>array('uid'=>$houseinfo[0]['uid']),'select'=>array('uid','truename'),'limit'=>1),'esfhousebak');

            //查询经纪人姓名
            $houseinfo[0]['contactor'] = $broker_data[0]['truename'];
         }

         $searchcond = serialize($houseinfo[0]);
         $this->user_model->addcollect( $uid , $rowid , $kind , $searchcond,$city,1);

         echo "1";
         exit;
    }


    /**
     * 关注房源操作接口，移动专用
     * @author cxf
    */
    public function api_savehousemobile()
    {
     $return ='';
     $uid = $this->input->get('uid');
     if(empty($uid))
      {
        $telno = $this->input->get('telno');
        $uid = $this->user_model->yztelno($telno);
      }
      $flag = $this->input->get('flag');
     if(empty($flag))
      {
        $flag = 2;
      }
     if($uid==0)
     {
     $return = 'N_USER';
     }
     $kind = $this->input->get('kind');
     $rowid = $this->input->get('rowid');
     $city = $this->input->get('city');
     $city = $city?$city:'nj';
     $tbl=$kind==3?'sell':'rent';
     $result = $this->user_model->getusercollectid($uid,$rowid,$city);
     //已关注此房源
     if($result['id']>0)
     {
      $return = 'N_COL';
     }
     if($tbl == 'sell'){
     $houseinfo =  $this->house_model->get_data(array('form_name' => $tbl,'where'=>array('id'=>$rowid,'esta'=>'1'),'select'=>array('infofrom','id','district','address','streetid','blockshowname','room','hall','buildarea','forward','fitment','buildyear','floor','totalfloor','subfloor','price','uid','telno','pic1','contactor','uid'),'limit'=>1),'esfhousebak');
     }else{
      $houseinfo =  $this->house_model->get_data(array('form_name' => $tbl,'where'=>array('id'=>$rowid,'esta'=>'1'),'select'=>array('infofrom','id','district','address','streetid','blockshowname','room','hall','buildarea','forward','fitment','buildyear','floor','totalfloor','subfloor','price','uid','telno','pic1','contactor','uid','priceunit','renttype'),'limit'=>1),'esfhousebak');
     }
        if(empty($houseinfo[0]) && $city=='nj')
        {
         $return = 'N_HOU';
        }elseif($return != 'N_COL'){
            if(!empty($houseinfo[0]))
            {
             $searchcond = serialize($houseinfo[0]);
            }else{
            $searchcond = '';
            }
          $return = $this->user_model->addcollect($uid,$rowid,$kind,$searchcond,$city,$flag);
        }


     if($return == 'N_COL'){
          $result = 2;
          $msg = '已收藏此房源';
     }elseif($return == 'N_HOU'){
          $result = 3;
          $msg = '无此房源';
     }elseif($return == 'N_USER'){
          $result = 4;
          $msg = '无此用户';
     }elseif($return > 0){
          $result = 1;
          $msg = '收藏成功';
		   //验证不在白名单，不在推送库，不在推送历史库
			$result2 = $this->push_model->yzpush($telno);
			if($result2<=0  && $city=='nj'){
				//加入备选库
				$this->push_model->addalternatives($uid,$telno);
			}
     }elseif($return == 0){
          $result = 0;
          $msg = '收藏失败';
     }

     $return_array = array('result'=>$result,'msg'=>$msg);
     echo serialize($return_array);
    }



     /**
     * 查询关注房源操作接口
     * @author cxf
    */
    public function api_yzsavehouse()
    {
     $return ='';
     $telno = $this->input->get('telno');
     $uid = $this->user_model->yztelno($telno);
     if($uid==0)
     {
     $return = 'N_USER';
     }
     $kind = $this->input->get('kind');
     $rowid = $this->input->get('rowid');
     $city = $this->input->get('city');
     $city = $city?$city:'nj';

	 if($uid){
		 $result = $this->user_model->getusercollectid($uid,$rowid);
	 }else{
		$result['id']=0;
	 }

     echo $result['id']>0?'1':'0';
    }

	/**
     * 查询我的已经关注房源uid接口
     * @author bsw
    */
    public function getCollectHouseId(){
		 $return ='';
         $uid = $this->input->get('uid');
         if(empty($uid))
         {
          $telno = $this->input->get('telno');
          $uid = $this->user_model->yztelno($telno);
         }
		 if($uid==0){
			return json_encode(array());;
		 }
		 $kind = $this->input->get('kind');
		 $city = $this->input->get('city');
		 $city = $city?$city:'nj';
		 $result = $this->user_model->getCollectHouseId($uid,$kind,$city);
		 echo json_encode($result);
    }
	

	/**
	* 查询关注房源操作接口
	* @author cxf
	*/
	public function api_user_login()
	{
		$uid = $this->input->get('uid');
		$code = $this->input->get('code');
		$md5_code = md5(md5('myhouse365'.$uid.date("Y-m-d",time()).$_COOKIE['interface_msg']));

		if( $code == $md5_code )
		{
			$user_array = $this->user_model->getuserdetail($uid);

			if(is_array($user_array) && !empty($user_array) )
			{
				$this->user_class->user_login($uid,$user_array['password'],$user_array['telno'],$user_array['username']);
				jumpto(USER_CENTER.'user');
			}
			else
			{
				echo '用户不存在或已失效';
			}
		}
		else
		{
			echo '来源不正确或请再试一次!';
		}
	}

     /**
     * 取消关注房源操作接口
     * @author cxf
    */
    public function api_delsavehouse()
    {
     $telno = $this->input->get('telno');
     $uid = $this->user_model->yztelno($telno);
     if($uid==0)
     {
     $return = 'N_USER';
     }
     $kind = $this->input->get('kind');
     $rowid = $this->input->get('rowid');
     $city = $this->input->get('city');
     $tbl=$kind==3?'sell':'rent';
     $id = $this->user_model->getcollectdetail($kind,$uid,$rowid,$city);

     if($id==0)
     {
     $return = 'N_COL';
     }else{
     $return = $this->user_model->delcollect($id);

     }
         if($return == 'N_COL'){
          $result = 2;
          $msg = '无此收藏';
        }elseif($return == 'N_USER'){
          $result = 3;
          $msg = '无此用户';
        }elseif($return > 0){
          $result = 1;
          $msg = '取消收藏';
        }elseif($return == 0){
          $result = 0;
          $msg = '取消失败';
        }
        $return_array = array('result'=>$result,'msg'=>$msg);
        echo serialize($return_array);
    }


	/**
	* 获取用户关注房源操作接口
	* @author cxf
	*/
	public function api_getsavehouse()
	{
		$telno = $this->input->get('telno');
		$uid = $this->user_model->yztelno($telno);

		if($uid==0)
		{
			echo serialize(array());exit;
		}

		$kind = $this->input->get('kind');
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');
		$page = $page ? $page:1;
		$pagesize = $pagesize?$pagesize : 20;
		$offset = $pagesize * ($page-1);

		$this->load->model("userTest_model");
	
		$collect_array = $this->userTest_model->getcollect($kind,$uid,$offset,$pagesize,$city);


		if(!empty($collect_array) && is_array($collect_array))
		{
			foreach($collect_array as $key=>$value)
			{
				$arr[$key]['id'] = $value['collect_id'];
			}
		}
		else
		{
			$arr=array();
		}
		
		echo serialize($arr);
	}

	/**
	* 获取用户关注房源操作接口
	* @author cxf
	*/
	public function api_getsavehouse_data()
	{
		
		$telno = $this->input->get('telno');
		$uid = $this->user_model->yztelno($telno);

		if($uid==0)
		{
			echo serialize(array());exit;
		}
		
		$kind = $this->input->get('kind');
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');
		$page = $page ? $page:1;
		$pagesize = $pagesize?$pagesize : 20;
		$offset = $pagesize * ($page-1);

		$this->load->model("userTest_model");
		
		$collect_array = $this->userTest_model->getcollect($kind,$uid,$offset,$pagesize,$city);

		
		if(!empty($collect_array) && is_array($collect_array))
		{
			foreach($collect_array as $key=>$value)
			{
				$arr[$key]['value'] = $value['collect_value'];
			}
		}
		else
		{
			$arr=array();
		}
		
		echo serialize($arr);
	}
	

	/**
	* 获得用户id接口
	* @author cxf
	*/
	public function api_getuidbytelno()
	{
		$telno = $this->input->get('telno');
		$userinfo =  $this->user_model->get_data(array('form_name' => 'personal_user','where'=>array('telno'=>$telno,'is_use'=>'1'),'select'=>array('id'),'limit'=>1),'esfbak');
		echo isset($userinfo[0]['id']) ? $userinfo[0]['id'] : 0 ;
		exit;
	}

	/**
	* 获得用户id接口
	* @author cxf
	*/
	public function api_get_userinfo_by_telno()
	{
		$telno = $this->input->get('telno');
		$userinfo =  $this->user_model->get_data(array('form_name' => 'personal_user','where'=>array('telno'=>$telno,'is_use'=>'1'),'select'=>array('id','username','cityname','infofrom'),'limit'=>1),'esfbak');
		//print_r($userinfo[0]);
		echo isset($userinfo[0]) ? serialize($userinfo[0]) : serialize(array());
		exit;
	}
	

	/**
	* 关注小区操作接口
	* @author cxf
	*/
    public function api_saveblock()
    {
		$uid = $this->input->get('uid');
		$kind = $this->input->get('kind');
		$blockid = $this->input->get('id');
		$city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		$result = $this->user_model->getusercollectid($uid,$blockid,$city);

		//已关注此房源
		if( $result > 0 )
		{
			echo "2";
			exit;
		}

		$blockinfo =  $this->user_model->get_data(array('form_name' => 'block','where'=>array('id'=>$blockid,'esta'=>'2'),'limit'=>1),'esfhousebak');
		$searchcond = serialize($blockinfo[0]);
		$this->user_model->addcollect($uid,$blockid,$kind,$searchcond,$city);

		echo "1";
		exit;
    }


    /**
     * 关注小区操作接口(手机端提交)
     * @author bsw
    */
    public function apiAddCollectBlock()
	{
		 $city = $this->input->get('city');
		 $city = $city ? $city : 'nj';
		 $telno = $this->input->get('telno');
		 $uid = $this->user_model->yztelno($telno);
		 if(!$uid)
		 {
			echo 3;
			die;
		 }
		 $blockid = $this->input->get('id');
		 $result = $this->user_model->getusercollectid($uid,$blockid);

		 //已关注此房源
		 if($result>0)
		 {
			echo "2";
			exit;
		 }
		 $blockinfo =  $this->user_model->get_data(array('form_name' => 'block','where'=>array('id'=>$blockid,'esta'=>'2'),'limit'=>1),'esfhousebak');
		 $searchcond = serialize($blockinfo[0]);
		 $this->user_model->addcollect($uid,$blockid,2,$searchcond,$city,2);
		 //验证不在白名单，不在推送库，不在推送历史库
        $result = $this->push_model->yzpush($uid);

        if($result<=0)
		{
			//加入备选库
			$result = $this->push_model->addalternatives($uid,$telno);
        }

		echo "1";
		exit;
    }


	/**
     * 关注学校操作接口
     * @author xue
    */
    public function api_save_school()
    { 
        $uid = $this->input->get('uid');
		$kind = $this->input->get('kind');
		$schoolid = $this->input->get('id');
		$city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		$result = $this->user_model->getusercollectid($uid,$schoolid,$city,$kind);	
		//var_dump($result);exit;
		//已关注此房源
		if($result>0)
		{
			echo "2";
			exit;
		}
  
		$schoolinfo =  $this->user_model->get_data(array('form_name' => 'school','where'=>array('id'=>$schoolid),'select'=>array('id','schoolname','district','streetid','schooltype','blockid','features','address','schooltype','telno','ispublic','rank','coverphoto'),'limit'=>1),'esfhousebak');		
		$this->load->model("block_model");
		$schoolinfo[0]['streetname'] = $this->block_model->getstreetname($schoolinfo[0]['streetid']);		
		$searchcond = serialize($schoolinfo[0]);
		
		$this->user_model->addcollect($uid,$schoolid,$kind,$searchcond,$city);
		echo "1";exit;
    }

    /**
    * 获取验证码
    * @author cxf
    */
    public function api_getyzm()
    {
        //验证是否已经通过验证
        $validcode = random(6);
        $tt = array();
        $tt['validcode'] = $validcode;
        $tt['telno'] = $this->input->get('telno');
        $tt['kind'] = $this->input->get('kind');
        $tt['dateline'] = time();
        //验证此号码55秒内是否已经发送过验证码,防止刷短信
        $result=$this->user_model->yzusersmstime(55,$tt['telno'],$tt['kind']);
		if($result>0)
		{
			echo '7';
			exit;
		}
        //设置表
        $this->user_model->set_table('personal_sms');
        //过滤表结构
        $tt = $this->user_model->create($tt,'db_esf');
        $result = $this->user_model->add($tt,'db_esf');
        if($result) {
            $msg   = '尊敬的365网友，您操作的验证码为'.$validcode.'，请在收到后两分钟内提交。';
            sendsms($tt['telno'],$msg,'sx');
            echo '1';
        }else{
            echo '2';//发送失败
        }

    }

    /**
    * 问答有回复提醒
    * @author cxf
    */
    public function api_ask_sms()
    {
       $telno = $this->input->get('telno');
       $msg   = '你提的问题有新答案，请登录365个人会员中心进行查看。';
       sendsms($telno,$msg,'sx');
    }


	/**
	* 发送站内信接口
	* @author cxf
	*/
	public function api_sendmessage()
	{
		$uid = $this->input->get('uid');
		$msg = $this->input->get('msg');
		$subject = $this->input->get('subject');
		$city = $this->input->get('city');
		$kind = $this->input->get('kind');
		$kind = !empty($kind)?$kind:'1';
		$msg = urldecode($msg);
		$subject = urldecode($subject);

		if(empty($city))
		{
			$city = GB_CITY;
		}

		$result = $this->apply_class->send_systemmsg($uid,$subject,$msg,$kind,$city);
		echo $result;
	}
	

    /**
    * 用户添加接口
    * @author cxf
    */
    public function api_adduser()
    {
		$telno = $this->input->get('telno');
		$paasword = $this->input->get('paasword');
		$city = $this->input->get('city');
		$infofrom = $this->input->get('infofrom');

		if (!preg_match('/^[_0-9a-z]{6,16}$/i',$paasword))
		{
			//密码格式不对
			$return = 'N_PASS';
		}

		//验证此号码是否已经注册
		$result = $this->user_model->yztelno($telno);
		if( $result > 0 )
		{
			//已经注册
			$return = 'N_REG';
		}
		else if($return != 'N_PASS')
		{
			$result = $this->user_model->adduser($telno,$paasword,$city,$infofrom);
			$return = $result;
		}

		//密码格式不对
		if($return == 'N_PASS')
		{
			$result = 2;
			$msg = '密码格式不对';
		}
		else if($return == 'N_REG')
		{
			$result = 3;
			$msg = '号码已被注册';
		}
		else if($return > 0)
		{
			$result = 1;
			$msg = '注册成功';
		}
		else if($return == 0)
		{
			$result = 0;
			$msg = '注册失败';
		}

		$return_array = array('result'=>$result , 'msg'=>$msg);

		echo serialize($return_array);
    }

    /**
    * 用户验证接口
    * @author cxf
    */
    public function api_yztelno()
    {
		$telno = $this->input->get('telno');
		$result = $this->user_model->yztelno($telno);
		echo $result;
    }

    /**
    * 验证用户是否可以登陆接口
    * @author cxf
    */
    public function api_yzlogin()
    {
      $telno = $this->input->get('telno');
      $password = $this->input->get('password');
      $result = $this->user_model->yzlogintelno($telno,$password);

      echo $result;
    }

    /**
    * 验证用户是否可以登陆接口移动专用
    * @author cxf
    */
    public function api_yzloginmobile()
    {
      $telno = $this->input->get('telno');
      $password = $this->input->get('password');
      $return = $this->user_model->yzlogintelno($telno,md5($password));

      if($return > 0){
          $result = 1;
          $msg = '登陆成功';
        }elseif($return == 0){
          $result = 0;
          $msg = '登陆失败';
        }
      $return_array = array('result'=>$result,'msg'=>$msg);
      echo serialize($return_array);
    }

	 /**
    * 提交登陆信息
    * @author cxf
    */
    public function api_sub_login_log_mobile()
    {
		$device_array = $this->user_statistic_model->get_device();

		$telno = $this->input->get('telno');
		$uid = $this->user_model->yztelno($telno);
		$city = $this->input->get('city');
		$device = $this->input->get('device');
		//初始化用户信息
		$this->user_statistic_model->set_uid($uid);
		$this->user_statistic_model->set_city($city);
		//提交登录信息
		$result = $this->user_statistic_model->sub_login_log('mobile',$device_array[$device]);
		echo serialize($result);
	}

        /**
    * 提交登陆操作接口
    *
    * @access public
    * @param  无
    * @return void
    */
    function api_sub_login_log()
    {
		$this->load->model('user_statistic_model');
		$login_from = $this->input->get('login_from');
		$device = $this->input->get('device');
		$uid = $this->input->get('uid');
		$code = $this->input->get('code');
		$city = $this->input->get('city');
		if( $code != md5('my365house'.$uid) )
		{
			exit;
		}

 		$this->user_statistic_model->set_city($city);
		$this->user_statistic_model->set_uid($uid);
		$result = $this->user_statistic_model->sub_login_log($login_from,$device);
        echo 1;
    }

    /**
    * 验证用户是否可以登陆接口
    * @author cxf
    */
    public function api_editpassword()
    {
      $telno = $this->input->get('telno');
      $password = $this->input->get('password');
      $return = '';
      if (!preg_match('/^[_0-9a-z]{6,16}$/i',$password)){
       //密码格式不对
       $return = 'N_PASS';
      }

      $result = $this->user_model->yztelno($telno);
      if($result==0)
        {
        //无此用户
        $return = 'N_REG';
        }elseif($return != 'N_PASS'){
         $result = $this->user_model->updatepassowrd($telno,$password);
         $return = $result;
        }

        //密码格式不对
        if($return == 'N_PASS')
        {
          $result = 2;
          $msg = '密码格式不正确';
        }elseif($return == 'N_REG')
        {
          $result = 3;
          $msg = '号码未被注册';
        }elseif($return > 0){
          $result = 1;
          $msg = '修改密码成功';
        }elseif($return == 0){
          $result = 0;
          $msg = '修改密码失败';
        }
        $return_array = array('result'=>$result,'msg'=>$msg);
        echo serialize($return_array);
    }

    //判断房源标签类型
    public function getState($istag, $isreal, $nofee) 
	{
        if ($istag == 1) {
            $state = 1;
        } else if ($isreal == 1) {
            $state = 2;
        } else if ($nofee == 1) {
            $state = 3;
        } else {
            $state = 0;
        }
        return $state;
    }

   /**
    * 提交房源操作接口
    *
    * @access public
    * @param  无
    * @return void
    */
    public function api_sub_operate_log()
    {
		$this->load->model('house_statistic_model');
		$this->load->model('house_statistic_zhou_model');
		$tbl = $this->input->get('tbl');
		$rowid = $this->input->get('rowid');
		$operate_type = $this->input->get('operate_type');
		$uid = $this->input->get('uid');
		$city = $this->input->get('city');
        $device = $this->input->get('device');
		$code = $this->input->get('code');

        //验证
		if( $code != md5('my365house'.$uid) )
		{
		    $result = array ('is_ok' => 1 , 'msg' => '参数不正确');
		}
        else
        {
            $this->house_statistic_model->set_city($city);
		    $this->house_statistic_model->set_uid( $uid );

		    $result = $this->house_statistic_model->sub_operate_log( $tbl , $rowid , $operate_type , $device );
        }

        echo serialize($result);
    }


	/**
    * 提交房源点击量接口
    *
    * @access public
    * @param  无
    * @return void
    */
	public function api_sub_house_click()
	{
		$result = array();

		//GET参数
		$city	= $this->input->get('city');
		$uid	= $this->input->get('uid');
		$tbl	= $this->input->get('tbl');
		$rowid	= $this->input->get('rowid');
		$district	= $this->input->get('district');
		$blockid	= $this->input->get('blockid');
		$streetid	= $this->input->get('streetid');
		$room		= $this->input->get('room');
		$price		= $this->input->get('price');
		$buildarea	= $this->input->get('buildarea');
		$client_ip	= $this->input->get('client_ip');
        $device = $this->input->get('device');
		$device = isset($device) ? $device : '1' ;
		$sub_key = $this->input->get('sub_key');

		if(  in_array($tbl,array('sell','rent')) && $rowid > 0 && $uid > 0 )
		{
			//验证秘钥
			if( $sub_key != md5('house_click_'.$uid.'_'.$tbl.'_'.$rowid) )
			{
				 $result = array ('is_ok' => 1 , 'msg' => '参数不正确');
			}
            else
            {
                $this->load->model('house_statistic_model');
			    $this->house_statistic_model->set_city( $city );
			    $this->house_statistic_model->set_uid( $uid );
			    $this->house_statistic_model->set_ip( $client_ip );

			    $result = $this->house_statistic_model->sub_house_click( $tbl , $rowid , $district , $blockid , $streetid , $room , $price , $buildarea , $device );
            }
		}
        else
        {
           $result = array ('is_ok' => 1 , 'msg' => '参数不正确');
        }

		echo serialize($result);
	}

	/**
    * 获取消息数接口
    *
    * @access public
    * @param  无
    * @return void
    */
    public function api_getmessagenumbyuid()
	{
		//GET参数
		$city	= $this->input->get('city');
		$uid	= $this->input->get('uid');

        $return = $this->user_model->getmessagenumbyuidwd($uid,$city);

         echo $return;
    }

    /**
    * 获取未读匹配数接口
    *
    * @access public
    * @param  无
    * @return void
    */
    public function api_getmatchnumbyuid()
	{
		//GET参数
		$uid	= $this->input->get('uid');

        $return = $this->user_model->get_match_num_byuid($uid);

         echo $return;
    }
	
	
	/**
    * 获取未读回答数接口
    *
    * @access public
    * @param  无
    * @return void
    */
    public function api_getnewanswerbyuid()
	{
		//GET参数
		$uid	= $this->input->get('uid');

        $return = $this->ask_model->getnewanswerbyuid($uid);

         echo $return;
    }
	
	
    /**
    * 提交可刷新次数接口
    *
    * @access public
    * @param  无
    * @return void
    */
    function api_add_refresh_num()
    {
        $this->load->model('house_model');
        $uid = $this->input->get("uid");
        $id = $this->input->get("id");
        $tbl = $this->input->get("tbl");
        $num = $this->input->get("num");
        $city_name = $this->input->get("city");
        $code = $this->input->get("code");
        $flag = $this->input->get("flag");
        if(empty($flag)){
          $flag=1;
        }
		if($code != md5('my365house'.$uid))
		{
			exit;
		}

        $this->house_model->addrefrshnum($uid,$id,$tbl,$num,$city_name,$flag);
        echo 1;
		exit;
    }
	

	/**
    * 获取个人出售&出租房源总刷新次数&已经刷新次数
    * @author bsw
    */
	function getRefreshHousePerson($type,$id)
	{
	    //验证刷新可用次数
		$num = $this->house_model->yzrefrshnum($this->user_id,$id,$type);
        var_dump($num);die();
		//获取今日已刷新次数
		$this->house_statistic_model->set_uid($this->user_id);
		$this->house_statistic_model->set_city($this->city);
		$this->house_statistic_model->set_nocache(1);
		$arr = $this->house_statistic_model->get_operate_list(2,$id,date("Y-m-d"));
		return array('total'=>$num,'haveRef'=>count($arr));
	}

	/**
    * 批量获取个人出售&出租房源总刷新次数&已经刷新次数
    * @author bsw
    */
	function getRefreshHousePersonBatch(){
        $type = $this->input->get_post('type');
		$this->user_id = $this->input->get_post('uid');
		$this->city = $this->input->get_post('city');
		$tmp = $arr_ids = $this->input->get_post('arr_ids');
		$arr_ids = json_decode($arr_ids,1);
		$arr_ids = array(4112782);
		$result = array();
        if(is_array($arr_ids) && $arr_ids){
			foreach($arr_ids as $val){
				$result[$val] = $this->getRefreshHousePerson($type,$val);
			}
		}

	    echo json_encode($result);
	}

	/**
    * 刷新个人出售房源
    * @author bsw
    */
	function refreshSellPerson(){
		$id = $this->input->get_post('id');
		$telno = $this->input->get_post('telno');
		$this->user_id = $this->user_model->yztelno($telno);
		$this->city = $this->input->get_post('city');

		$device = $this->input->get_post('device');
		  
		if(!$id || !$this->city || !$this->user_id){
			//参数错误
			$arr1['res'] = 0;
			$arr1['num'] = 0;
			echo json_encode($arr1);exit;
		}
        
		//获得实际可刷新次数
        $refreshInfo = $this->getRefreshHousePerson('sell',$id);
		$num = $refreshInfo['total'] - $refreshInfo['haveRef'];
		if($num>0){
			//更新房源刷新时间
			$result = $this->house_model->updatehouse($id,'sell',array('updatetime'=>time()));
			//记录刷新操作
			$this->house_statistic_model->set_uid($this->user_id);
			$this->house_statistic_model->set_city($this->city);
			$result = $this->house_statistic_model->sub_operate_log('sell' , $id , 2 ,$device);
			if($result['is_ok'] == 1){
				 //发送消息
				 $subject='您的房源刷新成功';
				 $msg='您编号为"'.$id.'"房源刷新成功。如有疑问，请联系客服。';
				 $this->apply_class->send_systemmsg($this->user_id,$subject,$msg,1,GB_CITY);
				 //刷新成功
				 $arr1['res'] = 1;
				 $arr1['num'] = $num-1;
				 echo json_encode($arr1);exit;
			}else{
				 //刷新失败
				 $arr1['res'] = 2;
				 $arr1['num'] = $num;
				 echo json_encode($arr1);exit;
			}
		}else{
			//刷新次数不足
			$arr1['res'] = 3;
			$arr1['num'] = $num;
			echo json_encode($arr1);exit;
		}
    }

	/**
    * refreshSellPerson
    * 刷新APP个人房源（出售）
    */
	function refreshSellPersonApp()
	{
		$id = $this->input->get_post('id');
		$telno = $this->input->get_post('telno');
		$this->user_id = $this->user_model->yztelno($telno);
		
		$this->city = $this->input->get_post('city');
		
		$device = $this->input->get_post('device');
		  
		if(!$id || !$this->city || !$this->user_id){
			//参数错误
			$arr1['res'] = 0;
			$arr1['num'] = 0;
			echo json_encode($arr1);exit;
		}

		//获得实际可刷新次数
        $refreshInfo = $this->getRefreshHousePerson('sell',$id);
		//获取 app端刷新的房源数据

		$num = $refreshInfo['total'] - $refreshInfo['haveRef']+1;
		if($num>0){
			//更新房源刷新时间
			$result = $this->house_model->updatehouse($id,'sell',array('updatetime'=>time()));
			//记录刷新操作
			$this->house_statistic_model->set_uid($this->user_id);
			$this->house_statistic_model->set_city($this->city);
			$result = $this->house_statistic_model->sub_operate_log('sell' , $id , 2 ,$device);
			if($result['is_ok'] == 1){
				 //发送消息
				 $subject='您的房源刷新成功';
				 $msg='您编号为"'.$id.'"房源刷新成功。如有疑问，请联系客服。';
				 $this->apply_class->send_systemmsg($this->user_id,$subject,$msg,1,GB_CITY);
				 //刷新成功
				 $arr1['res'] = 1;
				 $arr1['num'] = $num-1;
				 echo json_encode($arr1);exit;
			}else{
				 //刷新失败
				 $arr1['res'] = 2;
				 $arr1['num'] = $num;
				 echo json_encode($arr1);exit;
			}
		}else{
			//刷新次数不足
			$arr1['res'] = 3;
			$arr1['num'] = $num;
			echo json_encode($arr1);exit;
		}
		
	}

	/**
    * 刷新个人出租房源
    * @author bsw
    */
	function refreshRentPerson(){
		$id = $this->input->get_post('id');
		$telno = $this->input->get_post('telno');
		$this->user_id = $this->user_model->yztelno($telno);
		$this->city = $this->input->get_post('city');

		$device = $this->input->get_post('device');
		  
		if(!$id || !$this->city || !$this->user_id){
			//参数错误
			$arr1['res'] = 0;
			$arr1['num'] = 0;
			echo json_encode($arr1);exit;
		}
        
		//获得实际可刷新次数
        $refreshInfo = $this->getRefreshHousePerson('rent',$id);
		$num = $refreshInfo['total'] - $refreshInfo['haveRef'];
		if($num>0){
			//更新房源刷新时间
			$result = $this->house_model->updatehouse($id,'rent',array('updatetime'=>time()));
			//记录刷新操作
			$this->house_statistic_model->set_uid($this->user_id);
			$this->house_statistic_model->set_city($this->city);
			$result = $this->house_statistic_model->sub_operate_log('rent' , $id , 2 ,$device);
			if($result['is_ok'] == 1){
				 //发送消息
				 $subject='您的房源刷新成功';
				 $msg='您编号为"'.$id.'"房源刷新成功。如有疑问，请联系客服。';
				 $this->apply_class->send_systemmsg($this->user_id,$subject,$msg,1,GB_CITY);
				 //刷新成功
				 $arr1['res'] = 1;
				 $arr1['num'] = $num-1;
				 echo json_encode($arr1);exit;
			}else{
				 //刷新失败
				 $arr1['res'] = 2;
				 $arr1['num'] = $num;
				 echo json_encode($arr1);exit;
			}
		}else{
			//刷新次数不足
			$arr1['res'] = 3;
			$arr1['num'] = $num;
			echo json_encode($arr1);exit;
		}
    }


	/**
    * 刷新APP端个人出租房源
    * @author bsw
    */
	function refreshRentPersonApp(){
		$id = $this->input->get_post('id');
		$telno = $this->input->get_post('telno');
		$this->user_id = $this->user_model->yztelno($telno);
		$this->city = $this->input->get_post('city');

		$device = $this->input->get_post('device');
		  
		if(!$id || !$this->city || !$this->user_id){
			//参数错误
			$arr1['res'] = 0;
			$arr1['num'] = 0;
			echo json_encode($arr1);exit;
		}
        
		//获得实际可刷新次数
        $refreshInfo = $this->getRefreshHousePerson('rent',$id);
		$num = $refreshInfo['total'] - $refreshInfo['haveRef'] +1;
		if($num>0){
			//更新房源刷新时间
			$result = $this->house_model->updatehouse($id,'rent',array('updatetime'=>time()));
			//记录刷新操作
			$this->house_statistic_model->set_uid($this->user_id);
			$this->house_statistic_model->set_city($this->city);
			$result = $this->house_statistic_model->sub_operate_log('rent' , $id , 2 ,$device);
			if($result['is_ok'] == 1){
				 //发送消息
				 $subject='您的房源刷新成功';
				 $msg='您编号为"'.$id.'"房源刷新成功。如有疑问，请联系客服。';
				 $this->apply_class->send_systemmsg($this->user_id,$subject,$msg,1,GB_CITY);
				 //刷新成功
				 $arr1['res'] = 1;
				 $arr1['num'] = $num-1;
				 echo json_encode($arr1);exit;
			}else{
				 //刷新失败
				 $arr1['res'] = 2;
				 $arr1['num'] = $num;
				 echo json_encode($arr1);exit;
			}
		}else{
			//刷新次数不足
			$arr1['res'] = 3;
			$arr1['num'] = $num;
			echo json_encode($arr1);exit;
		}
    }

	public function get_operate_list_api() {
		$id = $this->input->get_post('id');
		$telno = intval($this->input->get_post('telno'));
	    
	    $city = $this->input->get('city');
		$this->load->model('house_statistic_model');
		$this->house_statistic_model->set_uid($uid);
		$this->house_statistic_model->set_city($city);

		echo serialize($this->house_statistic_model->get_operate_list(5 , $id,date('Y-m-d',time()))) ;
	}

	
	/**
    * 添加个人的推送信息接口
    *
    * @access public
    * @param  无
    * @return void
    */
    public function addpush() {
    $telno = $this->input->get_post('telno');
    $uid = $this->user_model->yztelno($telno);
    $city = $this->input->get_post('city');
	$city = isset($city)?$city:'nj';
	$code = $this->input->get_post('code');
	if($code != md5('my365house'.$telno) || empty($telno))
	{    
		echo 'N_CHECK';exit;
	}
        //$msg = "*********************************************** \n";
		//$msg .= date('y-m-d H:i:s')."::telno-".$telno." \n";
		//$log = 'log/addpushlog'.date('Y-m-d');
		//@file_put_contents($log,$msg,FILE_APPEND );

	//验证不在白名单，不在推送库，不在推送历史库
	$result = $this->push_model->yzpush($telno);
    
	    //added by bianshiwu 临时日志
		$data['sendtime'] = date('Y-m-d H:i:s');
		$data['telno'] = $telno;
		$data['desc'] = $result;
		$this->push_model->setPushLogTemp($data);

		//$msg = date('y-m-d H:i:s')."::result-".$result." \n";
		//$log = 'log/addpushlog'.date('Y-m-d');
		//@file_put_contents($log,$msg,FILE_APPEND );

    if($result>0){
	 echo 'N_CHECK_Y';exit;
	}
    //如果有推送历史，只推送上次推送之后一个月的行为
    $sendtime = $this->push_model->getpushlogbytelno($telno);
	$sendtime = 86400*30;

    //读取求购
	$result = $this->push_model->addbuy($uid,$city,$sendtime);
	if($result>0){
     //加入成功，删除备选库
     $this->push_model->delalternatives($telno);
	 echo 'Y';exit;
	}
    //读取求租
	$result = $this->push_model->addrentwanted($uid,$city,$sendtime);
    if($result>0){
     //加入成功，删除备选库
     $this->push_model->delalternatives($telno);
	 echo 'Y';exit;
	}
    //预约看房
	$result = $this->push_model->addseehouse($uid,$telno,$sendtime);
    if($result>0){
     //加入成功，删除备选库
     $this->push_model->delalternatives($telno);
	 echo 'Y';exit;
	}
    

    //关注房源
    $result = $this->push_model->addcollecthouse($uid,$telno,$sendtime);
    if($result>0){
     //加入成功，删除备选库
     $this->push_model->delalternatives($telno);
	 echo 'Y';exit;
	}
	

    //发送到手机
    $result = $this->push_model->addsmshouse($uid,$telno,$sendtime);
    if($result>0){
     //加入成功，删除备选库
     $this->push_model->delalternatives($telno);
	 echo 'Y';exit;
	}	
	
    //关注小区
    $result = $this->push_model->addcollectblock($uid,$telno,$sendtime);
    if($result>0){
     //加入成功，删除备选库
     $this->push_model->delalternatives($telno);
	 echo 'Y';exit;
	}	
	

    echo 'N';exit;
    }


    /**
    * 添加个人的进入备选库接口
    *
    * @access public
    * @param  无
    * @return void
    */
    public function addalternatives() {
        $telno = $this->input->get_post('telno');
        $sendkind = $this->input->get_post('sendkind');
        $tbl = $this->input->get_post('tbl');
        $uid = $this->user_model->yztelno($telno);
        $code = $this->input->get_post('code');
        $city = $this->input->get_post('city');
        $city = !empty($city)?$city:GB_CITY; 
        if($code != md5('my365house'.$telno) or empty($uid) or empty($telno))
        {
        echo 'N_CHECK';exit;
        }
        //验证不在白名单，不在推送库，不在推送历史库最近一个月
        $result = $this->push_model->yzpush($telno);
        if($result>0){
         echo 'N_CHECK_Y';exit;
        }
        //加入备选库
        $result = $this->push_model->addalternatives($uid,$telno,$city,$sendkind,$tbl);
        if($result>0){
         echo 'Y';exit;
        }	
	
        echo 'N';exit;
    }
	
    /**
    * 获取推送信息接口
    *
    * @access public
    * @param  无
    * @return void
    */
    public function Getpush()
	{   
		//当前方法执行会锁定该方法，防止重复执行
		$key  = "Job::Getpush";
		$check = $this->memcached_class->get($key);
		if($check !== false){
			echo json_encode('N_LOCKED');exit;
		}
		$this->memcached_class->add($key,true,1200);
 
		$time1=strtotime(date("Y-m-d "."8:30",time()));
		$time2=strtotime(date("Y-m-d "."21:30",time()));
		if(time()<$time1 || time()>$time2){
			echo json_encode('N_TIMEOUT');exit;
		}
		$code = $this->input->get_post('code');
		if($code != md5("my365house::ADMINPUSH")){
			echo json_encode('N_CHECK');exit;
		}
		$remainNum = $this->input->get_post('remainNum');
		if(intval($remainNum) <= 0){
			echo json_encode('N_REMAINNUM');exit;
		}
		$result = $this->push_model->getpusharray($remainNum);
		echo json_encode($result);
	}
	
	/**
    * 根据经纪人id获取未抢完用户推送列表
    *
    * @param  ctime 开始时间，$is_buy是否购买
    * @access public
    * @return void
    */
    public function Getpushbybrokerid()
	{
	
	$brokerid = $this->input->get_post('brokerid');
	if(empty($brokerid)){echo json_encode(0);exit;}
	$ctime = $this->input->get_post('ctime');
    $ctime = $ctime>(time()-60*60*24*30)?$ctime:(time()-60*60*24*30);
    $is_buy = $this->input->get_post('is_buy');
    $is_buy= !empty($is_buy)?$is_buy:0;
	$page = $this->input->get_post('page');
	$pagesize = $this->input->get_post('pagesize');
    $code = $this->input->get_post('code');

	//2016-11-2添加城市参数
	$city = $this->input->get_post('city');
	if(empty($city))
	{
		$city ='nj';
	}
	
	
	if($code != md5('my365house'.$brokerid))
	{
	echo 'N_CHECK';exit;
	}
	$result = $this->pushzhou_model->Getpushnumbybrokerid($city,$brokerid,$ctime,$is_buy,$page,$pagesize);
    echo json_encode($result);
	}
	
    /**
    * 根据经纪人id获取已经推送的数量
    *
    * @param  ctime 开始时间，$is_buy是否购买
    * @access public
    * @return void
    */
    public function Getpushnumbybrokerid()
	{
	$brokerid = $this->input->get_post('brokerid');
	if(empty($brokerid)){echo json_encode(0);exit;}
	$ctime = $this->input->get_post('ctime');
    $ctime = $ctime>(time()-60*60*24*30)?$ctime:(time()-60*60*24*30);
    $is_buy = $this->input->get_post('is_buy');
    $is_buy= !empty($is_buy)?$is_buy:0;
    $code = $this->input->get_post('code');
	if($code != md5('my365house'.$brokerid))
	{
	echo 'N_CHECK';exit;
	}
    
	$result = $this->push_model->Getpushnumbybroker($brokerid,$ctime,$is_buy);
    echo json_encode($result);
	}
	
    /**
    * 获取推送信息的详细信息
    *
    * @access public
    * @param  telno
    * @return void
    */
    public function Getsellnumbypush()
	{
		$telno = $this->input->get_post('telno');
		$sendid = $this->input->get_post('sendid');
		$sendkind = $this->input->get_post('sendkind');
		if(empty($telno)){echo json_encode(0);exit;}
		$code = $this->input->get_post('code');

		if($code != md5('my365house'.$telno))
		{
			echo 'N_CHECK';exit;
		}

		$result = $this->push_model->Getsellnumbypush($telno,$sendid,$sendkind);
		echo json_encode($result);
	}
	
	/**
    * 修改经纪人出售或者查看
    *
    * @access public
    * @param  $type 1,更新是否电话，2更新是否购买
    * @return void
    */
    public function Updatebrokerpush()
	{
	$brokerid = $this->input->get_post('brokerid');
	$pushid = $this->input->get_post('pushid');
	if(empty($brokerid)){echo json_encode(0);exit;}
    $type = $this->input->get_post('type');
    $type= !empty($type)?$type:1;
    $code = $this->input->get_post('code');
    $code_yz = $type==1?md5('my365house'.'::'.$brokerid):md5('my365house'.'::'.$brokerid.'::'.$pushid);
	if($code != $code_yz)
	{
	echo 'N_CHECK';exit;
	}	
	$result = $this->push_model->Updatebrokerpush($brokerid,$type,$pushid);
    echo json_encode($result);
	}
	

	/**
	* 根据用户行为修改用户的城市
	*
	* @access public
	* @param  $city,$telno,$uid
	* @return void
	*/
	public function Updateusercity()
	{
		$uid = $this->input->get_post('uid');

		if(empty($uid))
		{
			$telno = $this->input->get_post('telno');
			$uid = $this->user_model->yztelno($telno);
		}

		if(empty($uid))
		{
			return 0;
		}

		$city = $this->input->get_post('city');
		$city = !empty($city)?$city:GB_CITY;
		$result = $this->user_model->Updateusercity($uid,$city);

		echo json_encode($result);
	}

	/**
	* 全站会员中心获取用户关注房源接口 xue 2015-01-27
	* @param string $kind 房源类型
	* @param string $passportId 用户全站个人会员中心uid
	* @param int $page 页数
	* @param int $pagesize
	* @param string $city 城市
	* @author xue
	*/
	public function get_collect_house()
	{
		GLOBAL $house;
	
		$passportId = $this->input->get('passport_uid');
		//获取
		$uid = $this->userTest_model->getUidByPassportId($passportId);
   
		if($uid==0)
		{
			echo json_encode(array('result'=>'0','msg'=>strIconv("参数错误")));exit;
		}

		$kind = $this->input->get('kind');
		$kind = $kind == 'rent' ? 4 : 3;
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');
		$my_city = array('nj','hf','wh','sz','cz','wx','hz','cq','xa','ks'); 
		$jmz = 0;
		if(!in_array($city,$my_city)){
		  $jmz = 1;		
		}
		$test = $this->input->get('test');
		$city = $city ? $city : 'nj';
		$page = $page ? $page : 1;
		$pagesize = $pagesize ? $pagesize : 20;
		$offset = $pagesize * ($page-1);
        //获取关注数据数组
		if($jmz==1){
		   $collect_array = $this->user_model->getcollectjmz($kind,$passportId,$offset,$pagesize,$city);	
		}else{
		   $collect_array = $this->user_model->getcollect($kind,$uid,$offset,$pagesize,$city);	

		}

		
		//获取关注数据统计量
		$collect_num = $this->user_model->getusercollect($uid,$kind,$city,$jmz);
		$this->load->model("block_model");
		if(!empty($collect_array) && is_array($collect_array))
		{
			foreach($collect_array as $key=>$value)
			{
				
				$collect_value = unserialize($value['collect_value']);	
				if($test==1){
					var_dump($collect_value);
				}
				//var_dump($collect_value);
				$arr[$key]['id'] = $value['id'];	//add by kingj,2015-03-13
                $arr[$key]['house_id'] = $collect_value['id'];
                $arr[$key]['house_title'] =  strIconv($collect_value['address'],"GBK","UTF-8");	
				//房源链接
				$arr[$key]['house_link'] = $kind==4 ? get_rentinfo_url($collect_value['id']) : get_sellinfo_url($collect_value['id']);
				$arr[$key]['m_link'] = $kind==4 ? "http://m.house365.com/nj/renthouse/".$arr[$key]['house_id'].".html":"http://m.house365.com/nj/sellhouse/".$arr[$key]['house_id'].".html";
			    $arr[$key]['house_pic'] = $collect_value['pic1'] ? $collect_value['pic1'] : USER_CENTER.'images/no_img_small.gif';
				$arr[$key]['district'] = strIconv($collect_value['district'],"GBK","UTF-8");				
				$streetname	=$this->block_model->getstreetname($collect_value['streetid']);
				$arr[$key]['street'] = strIconv($streetname['streetname'],"GBK","UTF-8");				
				$arr[$key]['block'] = strIconv($collect_value['blockshowname'],"GBK","UTF-8");
				$arr[$key]['room'] = $collect_value['room'];
				$arr[$key]['hall'] = $collect_value['hall'];
				$arr[$key]['buildarea'] = $collect_value['buildarea'];
				$arr[$key]['forward'] = strIconv($collect_value['forward'],"GBK","UTF-8");
				$arr[$key]['fitment'] = strIconv($collect_value['fitment'],"GBK","UTF-8");
				$arr[$key]['floor'] = $collect_value['floor'];
				$arr[$key]['totalfloor'] = $collect_value['totalfloor'];
				$arr[$key]['subfloor'] = $collect_value['subfloor'];
				$arr[$key]['buildyear'] = $collect_value['buildyear'];
				$arr[$key]['price'] = $collect_value['price'];				
				$arr[$key]['price_unit'] = $kind==4 ? strIconv($house['priceunit'][$collect_value['priceunit']],"GBK","UTF-8") : strIconv("万元","GBK","UTF-8");		
				$arr[$key]['telno'] = $collect_value['telno'];
				$arr[$key]['contactor'] = strIconv($collect_value['contactor'],"GBK","UTF-8");
				if($collect_value['infofrom']==5){
					$arr[$key]['contactor_url'] = GB_SELL_URL."/agent_bk".$collect_value['uid']."/";
                    $this->load->model("broker_model");
					$broker = $this->broker_model->getbrokerdetail($collect_value['uid']);
				    $arr[$key]['shop'] = strIconv($broker['agentshortname'],"GBK","UTF-8");
                    $arr[$key]['shop_url'] = GB_SELL_URL."/shop_ac".$broker['agid']."/";
				
				}
			}
			$return_arr = array('total'=>$collect_num,'value'=>$arr);

		}
		else
		{
			$return_arr=array();
		}

		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr));
	}
	
	/**
	* @Func			全站会员中心删除用户关注房源接口
	* @author		kingj
	* @CreateTime	2015-04-16
	*/
	public function delete_myfav_house()
	{
		$passportId = $this->input->get('passport_uid');
		$actionid = $this->input->get('actionid');
		$code = $this->input->get('code');
		/*
        $city = $this->input->get('city');
		$my_city = array('nj','hf','wh','sz','cz','wx','hz','cq','xa','ks'); 
		$jmz = 0;
		if(!in_array($city,$my_city)){
		  $jmz = 1;		
		}
        */
		if( md5($actionid.'house365') != $code ) {
			echo json_encode(array('result'=>'0','msg'=>strIconv("参数错误")));exit;
		} else {
			//获取
			$uid = $this->userTest_model->getUidByPassportId($passportId);
			if($uid==0)
			{
				echo json_encode(array('result'=>'0','msg'=>strIconv("参数错误")));exit;
			}
		   
			$result = $this->user_model->delcollect($actionid);
			echo json_encode(array('result'=>$result,'msg'=>strIconv("删除成功")));exit;
			exit;
		}
	}

	/**
	* 全站会员中心获取用户关注小区接口 xue 2015-01-27	
	* @param string $passportId 用户全站个人会员中心uid
	* @param int $page 页数
	* @param int $pagesize
	* @param string $city 城市
	* @author xue
	*/
	public function get_collect_block(){
		$passportId = $this->input->get('passport_uid');
		//获取
		$uid = $this->userTest_model->getUidByPassportId($passportId);
   
		if($uid==0)
		{
			echo json_encode(array('result'=>'0','msg'=>strIconv("参数错误")));exit;
		}
    
		//小区的类别是2
		$kind = 2;
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		$page = $page ? $page:1;
		$pagesize = $pagesize?$pagesize : 20;
		$offset = $pagesize * ($page-1);
        //获取关注数据数组
		$collect_array = $this->user_model->getcollect($kind,$uid,$offset,$pagesize,$city);	
		//获取关注数据统计量
		$collect_num = $this->user_model->getusercollect($uid,$kind,$city);		
		if(!empty($collect_array) && is_array($collect_array))
		{
			foreach($collect_array as $key=>$value)
			{
				
				$collect_value = unserialize($value['collect_value']);		
				$arr[$key]['id'] = $value['id'];	//add by kingj,2015-03-13
                $arr[$key]['block_id'] = $collect_value['id'];
                $arr[$key]['block_name'] =  strIconv($collect_value['blockname'],"GBK","UTF-8");	
				//小区链接
				$arr[$key]['block_link'] = get_blockinfo_url($collect_value['id']);
			    $arr[$key]['block_pic'] = $collect_value['b_img'] ? $collect_value['b_img'] : USER_CENTER.'images/no_img_small.gif';
				$arr[$key]['district'] = strIconv($collect_value['district'],"GBK","UTF-8");
				$streetname	=$this->block_model->getstreetname($collect_value['streetid']);
				$arr[$key]['street'] = strIconv($streetname['streetname'],"GBK","UTF-8");	
				$arr[$key]['address'] = strIconv($collect_value['address'],"GBK","UTF-8");
				//获取小区的房源套数
				$house_num = $this->block_model->getBlockHouseNumById($collect_value['id']);				
				$arr[$key]['sell_num'] = isset($house_num[0]['sellcount']) ? $house_num[0]['sellcount'] : 0;
				$arr[$key]['rent_num'] = isset($house_num[0]['rentcount']) ? $house_num[0]['rentcount'] : 0;
				$arr[$key]['sell_link'] = get_blockinfo_url($value['collect_id']).'sell.html';
				$arr[$key]['rent_link'] = get_blockinfo_url($value['collect_id']).'rent.html';
				$arr[$key]['price'] = $collect_value['averprice'];	
				//获取小区最新的房源
				$laset_detail = $this->user_model->getblockhouse($collect_value['id']);
			
				if($laset_detail['ID']){
					$laset_house['house_id'] = $laset_detail['ID'];
					//最新房源的链接
					$laset_house['house_link'] = get_sellinfo_url($laset_detail['ID']);
					$laset_house['room'] = $laset_detail['ROOM'];
					$laset_house['hall'] = $laset_detail['HALL'];
					$laset_house['buildarea'] = $laset_detail['BUILDAREA'];
					$laset_house['buildyear'] = $laset_detail['BUILDYEAR'];
					$laset_house['floor'] = $laset_detail['FLOOR'];
					$laset_house['totalfloor'] = $laset_detail['TOTALFLOOR'];
					$laset_house['subfloor'] = $laset_detail['SUBFLOOR'];
					$laset_house['forward'] = strIconv($laset_detail['FORWARD'],"GBK","UTF-8");
					$laset_house['fitment'] = strIconv($laset_detail['FITMENT'],"GBK","UTF-8");
					$laset_house['update_time'] = strIconv($laset_detail['time'],"GBK","UTF-8");
				}else{
				    $laset_house = array();
				}
		
				$arr[$key]['lastest'] = $laset_house;				
				
			}
			$return_arr = array('total'=>$collect_num,'value'=>$arr);
		}
		else
		{
			$return_arr=array();
		}		

		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr));
	}


	/**
	* 全站会员中心获取用户关注学区接口 xue 2015-01-27	
	* @param string $passportId 用户全站个人会员中心uid
	* @param int $page 页数
	* @param int $pagesize
	* @param string $city 城市
	* @author xue
	*/
	public function get_collect_school(){		
		
		$passportId = $this->input->get('passport_uid');		
		//获取
		$uid = $this->userTest_model->getUidByPassportId($passportId);
   
		if($uid==0)
		{
			echo json_encode(array('result'=>'0','msg'=>strIconv("参数错误")));exit;
		}

		//学校的类别是7
		$kind = 7;
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		$page = $page ? $page : 1;
		$pagesize = $pagesize?$pagesize : 20;
		$offset = $pagesize * ($page-1);
        //关注数据数组
		$collect_array = $this->user_model->getCollectSchoolList($kind,$uid,$offset,$pagesize,$city);	
		//关注数据统计
		$collect_num = $this->user_model->getusercollect($uid,$kind,$city);	

		if(!empty($collect_array) && is_array($collect_array))
		{
			foreach($collect_array as $key=>$value)
			{
				$arr[$key]['id'] = $value['id'];	//add by kingj,2015-03-13
				$arr[$key]['school_id'] = $value['collect_id'];
				$collect_value = unserialize($value['collect_value']);
				$arr[$key]['school_name'] = strIconv($collect_value['schoolname'],"GBK","UTF-8");				
                $arr[$key]['school_link'] = get_school_url($value['collect_id']);
                $arr[$key]['school_pic'] =  $collect_value['coverphoto'] ? $collect_value['coverphoto'] : USER_CENTER.'images/no_img_small.gif';	
				$arr[$key]['district'] =  strIconv($collect_value['district'],"GBK","UTF-8");
				$arr[$key]['street'] =  strIconv($collect_value['streetname']['streetname'],"GBK","UTF-8");
				$arr[$key]['address'] =  strIconv($collect_value['address'],"GBK","UTF-8");
				$arr[$key]['telno'] =  isset($collect_value['telno']) ? $collect_value['telno'] : "";
                $feature =  $this->user_model->getSchoolFeature($collect_value['features']);
                $arr[$key]['feature'] = strIconv($feature,"GBK","UTF-8");
				//学校下属小区
				$blockArr = $this->user_model->getSchoolBlock($value['collect_id']);
				//学区下的二手房数量
			    $sellNum = $this->user_model->getSchoolHouseNum($value['collect_id'],$blockArr,'sell');
				$arr[$key]['sell_num']= $sellNum ? $sellNum : 0;
				//学区下的租房数量
				$rentNum = $this->user_model->getSchoolHouseNum($value['collect_id'],$blockArr,'rent');
				$arr[$key]['rent_num'] = $rentNum ? $rentNum : 0;
				//学区二手房链接
				$arr[$key]['sell_link'] = get_schoolsell_url($value['collect_id']);
				//学区租房链接
				$arr[$key]['rent_link'] = get_schoolrent_url($value['collect_id']);
				$arr[$key]['block_num'] = count($blockArr);
				$arr[$key]['block_link'] = get_schoolblock_url($value['collect_id']);
				//最新房源
				$laset_detail = $this->user_model->getSchoolLastestHouse($value['collect_id']);
				//var_dump($laset_detail);exit;
				if(isset($laset_detail['ID'])){
					$laset_house['house_id'] = $laset_detail['ID'];
					//最新房源的链接
					$laset_house['house_link'] = get_sellinfo_url($laset_detail['ID']);
					$laset_house['price'] =  strIconv($laset_detail['PRICE']."万元","GBK","UTF-8");
					$laset_house['room'] = $laset_detail['ROOM'];
					$laset_house['hall'] = $laset_detail['HALL'];
					$laset_house['buildarea'] = $laset_detail['BUILDAREA'];
					$laset_house['buildyear'] = $laset_detail['BUILDYEAR'];
					$laset_house['floor'] = $laset_detail['FLOOR'];
					$laset_house['totalfloor'] = $laset_detail['TOTALFLOOR'];
					$laset_house['subfloor'] = $laset_detail['SUBFLOOR'];
					$laset_house['forward'] = strIconv($laset_detail['FORWARD'],"GBK","UTF-8");
					$laset_house['fitment'] = strIconv($laset_detail['FITMENT'],"GBK","UTF-8");
					$laset_house['update_time'] = strIconv($laset_detail['time'],"GBK","UTF-8");
				}else{
				    $laset_house = array();
				}				
		
				$arr[$key]['lastest'] = $laset_house;
				$arr[$key]['price'] = $value['price'];
			}
			$return_arr = array('total'=>$collect_num,'value'=>$arr);

		}
		else
		{
			$return_arr=array();
		}		

		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr));
	}


	/**
	* 全站会员中心获取用户关注二手房找房条件接口 xue 2015-01-28
	* @param string $passportId 用户全站个人会员中心uid
	* @param int $page 页数
	* @param int $pagesize
	* @param string $city 城市
	* @author xue
	*/
	public function get_sell_condition(){		
		
		
		$passportId = $this->input->get('passport_uid');		
		//获取
		$uid = $this->userTest_model->getUidByPassportId($passportId);
   
		if($uid==0)
		{
			echo json_encode(array('result'=>'0','msg'=>strIconv("参数错误")));exit;
		}

		//二手房的类别是1
		$kind = 1;
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		$page = $page ? $page : 1;
		$pagesize = $pagesize?$pagesize : 20;
		$offset = $pagesize * ($page-1);
        //关注数据数组
		$collect_array = $this->user_model->getcollect($kind,$uid,$offset,$pagesize,$city);	
		$collect_num = $this->user_model->getusercollect($uid,$kind,$city);	
		$collect_data = $this->user_model->getSeachcondStr($collect_array);
		$collect_url = $this->user_model->getSeachcondUrl($collect_array, 1);	
		if(!empty($collect_array) && is_array($collect_array))
		{
			foreach($collect_array as $key=>$value)
			{
				$arr[$key]['id'] = $collect_data[$key]['id'];	
				$arr[$key]['searchcond'] = strip_tags(strIconv($collect_data[$key]['searchcond'],"GBK","UTF-8"));
				$arr[$key]['url'] = strIconv($collect_url[$key],"GBK","UTF-8");
				
			    //最新房源
				$collect_detail = $this->user_model->getconditionhouse(unserialize($value['collect_value']));
				if(isset($collect_detail['ID'])){
					$laset_house['house_id'] = $collect_detail['ID'];
					//最新房源的链接
					$laset_house['house_link'] = get_sellinfo_url($collect_detail['ID']);
					$laset_house['room'] = $collect_detail['ROOM'];
					$laset_house['hall'] = $collect_detail['HALL'];
					$laset_house['buildarea'] = $collect_detail['BUILDAREA'];
					$laset_house['buildyear'] = $collect_detail['BUILDYEAR'];
					$laset_house['floor'] = $collect_detail['FLOOR'];
					$laset_house['totalfloor'] = $collect_detail['TOTALFLOOR'];
					$laset_house['subfloor'] = $collect_detail['SUBFLOOR'];
					$laset_house['forward'] = strIconv($collect_detail['FORWARD'],"GBK","UTF-8");
					$laset_house['fitment'] = strIconv($collect_detail['FITMENT'],"GBK","UTF-8");
					$laset_house['update_time'] = strIconv($collect_detail['time'],"GBK","UTF-8");
				}else{
				    $laset_house = array();
				}			
		
				$arr[$key]['lastest'] = $laset_house;
				
			}
			$return_arr = array('total'=>$collect_num,'value'=>$arr);

		}
		else
		{
			$return_arr=array();
		}		

		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr));
		
	}


	/**
	* 全站会员中心获取用户关注租房找房条件接口 xue 2015-01-28	
	* @param string $passportId 用户全站个人会员中心uid
	* @param int $page 页数
	* @param int $pagesize
	* @param string $city 城市
	* @author xue
	*/
	public function get_rent_condition(){		
		
		$passportId = $this->input->get('passport_uid');		
		//获取
		$uid = $this->userTest_model->getUidByPassportId($passportId);
   
		if($uid==0)
		{
			echo json_encode(array('result'=>'0','msg'=>strIconv("参数错误")));exit;
		}

		//租房的类别是1
		$kind = 5;
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		$page = $page ? $page : 1;
		$pagesize = $pagesize?$pagesize : 20;
		$offset = $pagesize * ($page-1);

		$collect_array = $this->user_model->getcollect($kind,$uid,$offset,$pagesize,$city);	
		$collect_num = $this->user_model->getusercollect($uid,$kind,$city);	
		$collect_data = $this->user_model->getSeachcondStr($collect_array);
		$collect_url = $this->user_model->getSeachcondUrl($collect_array, 2);	
		if(!empty($collect_array) && is_array($collect_array))
		{
			foreach($collect_array as $key=>$value)
			{
				$arr[$key]['id'] = $collect_data[$key]['id'];	
				$arr[$key]['searchcond'] = strip_tags(strIconv($collect_data[$key]['searchcond'],"GBK","UTF-8"));
				$arr[$key]['url'] = strIconv($collect_url[$key],"GBK","UTF-8");

				
			    //最新房源
				$collect_detail = $this->user_model->getconditionhouse(unserialize($value['collect_value']));
				if(isset($collect_detail['ID'])){
					$laset_house['house_id'] = $collect_detail['ID'];
					//最新房源的链接
					$laset_house['house_link'] = get_rentinfo_url($collect_detail['ID']);
					$laset_house['room'] = $collect_detail['ROOM'];
					$laset_house['hall'] = $collect_detail['HALL'];
					$laset_house['buildarea'] = $collect_detail['BUILDAREA'];
					$laset_house['buildyear'] = $collect_detail['BUILDYEAR'];
					$laset_house['floor'] = $collect_detail['FLOOR'];
					$laset_house['totalfloor'] = $collect_detail['TOTALFLOOR'];
					$laset_house['subfloor'] = $collect_detail['SUBFLOOR'];
					$laset_house['forward'] = strIconv($collect_detail['FORWARD'],"GBK","UTF-8");
					$laset_house['fitment'] = strIconv($collect_detail['FITMENT'],"GBK","UTF-8");
					$laset_house['update_time'] = strIconv($collect_detail['time'],"GBK","UTF-8");
				}else{
				    $laset_house = array();
				}			
		
				$arr[$key]['lastest'] = $laset_house;
				
			}
			$return_arr = array('total'=>$collect_num,'value'=>$arr);

		}
		else
		{
			$return_arr=array();
		}		

		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr));
		
	}

	 /**
     * 关注房源操作接口，触屏版专用
     * @author xue 2015-02-06
    */
    public function api_save_house_touch()
    {
		$return ='';
        $passportId = $this->input->get('passport_uid');		
	    //获取
	    $uid = $this->userTest_model->getUidByPassportId($passportId);   
	    if($uid==0)
	    {
		  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
        }
    
        $flag = $this->input->get('flag');
        if(empty($flag))
        {
          $flag = 2;
        }

        $kind = $this->input->get('kind');
        $rowid = $this->input->get('rowid');
        $city = $this->input->get('city');
        $city = $city?$city:'nj';
        $tbl=$kind==3?'sell':'rent';
        $result = $this->user_model->getusercollectid($uid,$rowid,$city);
        //已关注此房源
        if($result['id']>0)
        {
           echo json_encode(array('result'=>'2','msg'=>strIconv("关注失败，此房源已关注！")));exit;
        }
        if($tbl == 'sell'){
           $houseinfo =  $this->house_model->get_data(array('form_name' => $tbl,'where'=>array('id'=>$rowid,'esta'=>'1'),'select'=>array('infofrom','id','district','address','streetid','blockshowname','room','hall','buildarea','forward','fitment','buildyear','floor','totalfloor','subfloor','price','uid','telno','pic1','contactor','uid'),'limit'=>1),'esfhousebak');
        }else{
           $houseinfo =  $this->house_model->get_data(array('form_name' => $tbl,'where'=>array('id'=>$rowid,'esta'=>'1'),'select'=>array('infofrom','id','district','address','streetid','blockshowname','room','hall','buildarea','forward','fitment','buildyear','floor','totalfloor','subfloor','price','uid','telno','pic1','contactor','uid','priceunit','renttype'),'limit'=>1),'esfhousebak');
        }
        if(empty($houseinfo[0]))
        {
           echo json_encode(array('result'=>'3','msg'=>strIconv("关注失败，无此房源！")));exit;
        }else{
             if(!empty($houseinfo[0])){
                 $searchcond = serialize($houseinfo[0]);
             }else{
                 $searchcond = '';
             }
             $return = $this->user_model->addcollect($uid,$rowid,$kind,$searchcond,$city,$flag);
        }


        if($return > 0)
		{
           $result = 1;
           $msg = '收藏成功';
		   //验证不在白名单，不在推送库，不在推送历史库
			$result2 = $this->push_model->yzpush($telno);
			if($result2<=0  && $city=='nj')
			{
				//加入备选库
				$this->push_model->addalternatives($uid,$telno);
			}
			echo json_encode(array('result'=>'1','msg'=>strIconv("收藏成功！")));exit;
        }elseif($return == 0){
           echo json_encode(array('result'=>'0','msg'=>strIconv("收藏失败！")));exit;
        }
    }

	/**
     * 取消关注房源操作接口
     * @author xue 2015-02-06
    */
    public function api_del_save_touch()
    {

		$passportId = $this->input->get('passport_uid');		
	    //获取
	    $uid = $this->userTest_model->getUidByPassportId($passportId);   
	    if($uid==0)
	    {
		  echo json_encode(array('result'=>'3','msg'=>strIconv("无此用户")));exit;
        }
   
		 $kind = $this->input->get('kind');
		 $rowid = $this->input->get('rowid');
		 $city = $this->input->get('city');
		 $tbl=$kind==3?'sell':'rent';
		 $id = $this->user_model->getcollectdetail($kind,$uid,$rowid,$city);

		 if($id==0)
		 {
		    echo json_encode(array('result'=>'2','msg'=>strIconv("无此收藏")));exit;
		 }else{
		    $return = $this->user_model->delcollect($id);

		 }
		 if($return > 0){
			 echo json_encode(array('result'=>'1','msg'=>strIconv("取消收藏")));exit;
		}elseif($return == 0){
		     echo json_encode(array('result'=>'0','msg'=>strIconv("取消失败")));exit;
		}
    }


   /**
    ** 我的求购接口
    ** @author xue 2015-03-17
	**
    */
    function my_sell()
    {		   
               
		$passportId = $this->input->get('passport_uid');		
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');

		$city = $city ? $city : 'nj';
		$page = $page ? $page : 1;
		$pagesize = $pagesize ? $pagesize : 8;
		$offset = $pagesize * ($page-1);

	    //获取用户id
	    $uid = $this->userTest_model->getUidByPassportId($passportId);   
	    if($uid==0)
	    {
		  echo json_encode(array('result'=>'3','msg'=>strIconv("无此用户")));exit;
        }  
		$this->user_id = $uid;
		$total_num = $this->house_model->gethousenumbyuid($uid,'sell');
		
		//获取房源
		$house_array = $this->house_model->gethousebyuid($uid,'sell',array('id','address','blockid','buildarea','price','updatetime','creattime','esta','ischarge','pic1','district','streetid','blockshowname','infotype','room','hall','buildarea'),$offset,$pagesize);

		if(is_array($house_array)&&!empty($house_array)){
			foreach($house_array as $key=>$value){
				$house_array[$key]['block_url'] = get_blockinfo_url($value['blockid']);
				$house_array[$key]['address'] = strIconv($value['address']);			  
				$house_array[$key]['district'] = strIconv($value['district']);
				$house_array[$key]['blockshowname'] = strIconv($value['blockshowname']);
				$house_array[$key]['fitment'] = strIconv($value['fitment']); 
				$house_array[$key]['click'] = $this->house_statistic_model->get_house_clicknum_by_id($value['id'],'sell');
				//$house_array[$key]['pic1'] = $value['pic1'] ? str_replace('thumb/','',$value['pic1']):USER_CENTER.'images/no_img_small.gif';
				$house_array[$key]['pic1'] = $value['pic1'] ? get_big_pic_new($value['pic1']):USER_CENTER.'images/no_img_small.gif';
				//xue 2015-04-08
				$this->house_statistic_model->set_city(GB_CITY);
				$this->house_statistic_model->set_uid($uid);
				//房源今日是否刷新
				$is_refresh = $this->house_statistic_model->get_operate_list(2 , $value['id'],date('Y-m-d',time()));
				//房源今日是否再发布
				$is_oper = $this->house_statistic_model->get_operate_list(5 , $value['id'],date('Y-m-d',time()));
				//搜索是否有相同条件的已激活房源，有的话就不能再发布
				$arr=array('blockshowname'=>$value['blockshowname'],'buildarea'=>$value['buildarea'],'price'=>$value['price'],'floor'=>$value['floor'],'subfloor'=>$value['subfloor'],'totalfloor'=>$value['totalfloor']);
				$telno = $value['telno'];
				$is_esta = $this->house_model->yzsamehouse($telno,$arr,'sell');
				$click_num = $this->house_statistic_model->get_house_clicknum_by_id($value['id'],'sell');
				$refresh_num = $this->user_model->getRefreshByid('sell',$value['id']);

				if($value['esta'] == 1){
				   $house_array[$key]['esta_arr']['house_url']= get_sellinfo_url($value['id']).'?update=1';
				   $house_array[$key]['esta_arr']['updatetime'] = strIconv(time_tran($value['updatetime']));
				   $house_array[$key]['esta_arr']['refresh_num'] = $refresh_num;
				   $house_array[$key]['esta_arr']['refresh_str'] = strIconv("刷新");
				   $house_array[$key]['esta_arr']['refresh_str2'] = strIconv("可刷新次数").$refresh_num.strIconv("次");
				   $house_array[$key]['esta_arr']['modify_url'] = GB_PUBLISH_URL."?kind=". (isset($value['priceunit'])?'2':'1')."&id=".$value['id']."&code=".md5($value['id'].'house365')."&tbl=sell";
                   $house_array[$key]['esta_arr']['modify_str'] = strIconv("修改");
				   if(empty($is_oper[0])){
				       $house_array[$key]['esta_arr']['delete_str'] = strIconv("删除");
				   }

				   if(GB_CITY=='nj' && $value['ischarge']==2){
					   $house_array[$key]['esta_arr']['refresh_promot'] = strIconv("推广申请中");
				   }elseif(GB_CITY=='nj' && $value['ischarge']==0){
					   $house_array[$key]['esta_arr']['refresh_promot'] = strIconv("推广");
				   }elseif(GB_CITY=='nj' && $value['ischarge']==1){
					   $house_array[$key]['esta_arr']['refresh_promot'] = strIconv("付费推广中");
				   }
				
				}else if($value['esta'] == 2){
					$house_array[$key]['esta_arr']['esta_str'] = strIconv("已删除");
					$house_array[$key]['esta_arr']['republish'] = strIconv("再发布");
				}else if($value['esta'] == 0 || $value['esta'] == 5 || $value['esta'] == -10){
					$house_array[$key]['esta_arr']['esta_str'] = strIconv("审核中");				
				}else if($value['esta'] == 3 || $value['esta'] == 4){
					$house_array[$key]['esta_arr']['esta_str'] = strIconv("已删除");
					if($value['ischarge'] != 1 && empty($is_esta)){ 
                        $house_array[$key]['esta_arr']['republish'] = strIconv("再发布");
                    }	
				}else if($value['esta'] < 0 && $value['esta'] > -9){
					$house_array[$key]['esta_arr']['esta_str'] = strIconv("审核未通过");
					$house_array[$key]['esta_arr']['esta_info'] = strIconv("了解详情，请拨打客服电话：").TEL;
				}

                //点击量下提示
				if(($value['ischarge']==0 || $value['ischarge']==2) && empty($value['pic1'])){
					$house_array[$key]['prompt'] = strIconv("上传图片就可以获得一次刷新了哦。");
				}elseif(($value['ischarge']==0 || $value['ischarge']==2) && !empty($value['pic1']) && empty($is_refresh)){
                    $house_array[$key]['prompt'] = strIconv("刷新一下，就立马排到前面去了哦。");
                }elseif(($value['ischarge']==0 || $value['ischarge']==2) && GB_CITY=='nj' && !empty($value['pic1']) && !empty($is_refresh)){ 
                    $house_array[$key]['prompt'] = strIconv("付费推广效果更佳哦。");
                }elseif($value['ischarge']==1){
                    $house_array[$key]['prompt'] = strIconv("记得每天刷新哦。");
                }
			}	
		}
		$return_arr = array('total'=>$total_num,'value'=>$house_array);

		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr,'tel'=>TEL));
   }

   /**
    ** 我的二手房刷新接口
    ** @author xue 2015-03-17
	**
    */
	public function my_sell_refresh(){

		$code = $this->input->get('code');//简易验证码
		$passportId = $this->input->get('passport_uid');
		$house_id = $this->input->get('house_id');
        $city = $this->input->get('city');       
        $city = $city ? $city : 'nj';

        if(md5($house_id.'house365')==$code)
		{
			//获取
			$uid = $this->userTest_model->getUidByPassportId($passportId);   
			if($uid==0)
			{
			  echo json_encode(array('result'=>'3','msg'=>strIconv("无此用户")));exit;
			}
			$this->user_id = $uid;
			
			//验证刷新可用次数
			$num = $this->house_model->yzrefrshnum($uid,$house_id,'sell');

			//获取今日已刷新次数
			$this->house_statistic_model->set_uid($uid);
			$this->house_statistic_model->set_city($city);
			$this->house_statistic_model->set_nocache(1);
			$arr = $this->house_statistic_model->get_operate_list(2,$house_id,date("Y-m-d"));

			//获得实际可刷新次数
			$num = $num - count($arr);
			if($num>0)
			{
				//更新房源刷新时间
				$result = $this->house_model->updatehouse($house_id,'sell',array('updatetime'=>time()));
				//记录刷新操作
				$this->house_statistic_model->set_uid($uid);
				$this->house_statistic_model->set_city($city);
				$result = $this->house_statistic_model->sub_operate_log('sell' , $house_id , 2 );
				if($result['is_ok'] == 1)
				{
					//发送消息
					$subject='您的房源刷新成功';
					$msg='您编号为"'.$id.'"房源刷新成功。如有疑问，请联系客服。';
					$this->apply_class->send_systemmsg($uid,$subject,$msg,1,$city);
					//刷新成功					
					$arr1['num'] = $num-1;
					echo json_encode(array('result'=>'1','msg'=>strIconv("刷新成功")));exit;   
				}else{
					//刷新失败					
					$arr1['num'] = $num;
					echo json_encode(array('result'=>'4','msg'=>strIconv("刷新失败")));exit;   
				}
			}else{
				//刷新次数不足				
				$arr1['num'] = $num;
				echo json_encode(array('result'=>'5','msg'=>strIconv("刷新次数不足")));exit;   
			}
		}else{
		
		   //验证不通过，来源不正确
            echo json_encode(array('result'=>'2','msg'=>strIconv("验证不通过，来源不正确")));exit;   
		}  
	}

   /**
    ** 我的二手房推广接口
    ** @author xue 2015-03-17
	**
    */
	public function my_sell_tg()
	{
		$payday = $this->input->get('payday');
        $paytype = $this->input->get('paytype');
		$code = $this->input->get('code');//简易验证码
		$passportId = $this->input->get('passport_uid');
		$house_id = $this->input->get('house_id');
        $city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		$payday = $payday ? $payday : 1;
		$paytype = $paytype ? $paytype : 1;
		if(md5($house_id.'house365')==$code)
		{
			//获取
			$uid = $this->userTest_model->getUidByPassportId($passportId);   
			if($uid==0)
			{
			  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
			}
			$this->user_id = $uid;
			//更新房源状态,改为有意向
            $result = $this->house_model->updatehouse($house_id,'sell',array('ischarge'=>'2'));
            //记录客户意向
            $result1 = $this->user_model->addusercharge($house_id, $paytype , $payday,$uid );
            if($result1>0)
            {
				//发送消息
                $subject='您的房源推广申请已提交。';
                $msg='您编号为"'.$id.'"的房源推广申请正在审核中，请耐心等待。';
                $this->apply_class->send_systemmsg($uid,$subject,$msg,1,$city);
                //添加成功
                echo json_encode(array('result'=>'1','msg'=>strIconv("添加成功")));exit;               
            }else{
                //添加失败
				echo json_encode(array('result'=>'2','msg'=>strIconv("添加失败")));exit;     
                 
            }
		}else{
		   //验证不通过，来源不正确
          echo json_encode(array('result'=>'3','msg'=>strIconv("验证不通过，来源不正确")));exit;   
		}
	}


   /**
    ** 我的二手房删除接口
    ** @author xue 2015-03-17
	**
    */
	public function my_sell_delete(){
		$code = $this->input->get('code');//简易验证码
		$passportId = $this->input->get('passport_uid');
		$house_id = $this->input->get('house_id');
        $city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		if(md5($house_id.'house365')==$code)
		{
			//获取
			$uid = $this->userTest_model->getUidByPassportId($passportId);   
			if($uid==0)
			{
			  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
			}
			$this->user_id = $uid;
			//更新房源状态,相当于失效状态
            $result = $this->house_model->updatehouse($house_id,'sell',array('esta'=>'2'));
            //记录再发布操作
            $this->house_statistic_model->set_uid($uid);
            $this->house_statistic_model->set_city($city);
            $result1 = $this->house_statistic_model->sub_operate_log('sell' , $house_id , 3 );
            if($result>0)
            {
				//删除成功
                echo json_encode(array('result'=>'1','msg'=>strIconv("删除成功")));exit;
            }else{
                //删除失败                
                echo json_encode(array('result'=>'2','msg'=>strIconv("删除失败")));exit;
            }
		}else{
		     //验证不通过，来源不正确
             echo json_encode(array('result'=>'3','msg'=>strIconv("验证不通过，来源不正确")));exit; 
		}
	}

	/**
    ** @Func		我的二手房再发布接口
    ** @author		kingj 
	** @CreateTime	2015-04-16
    */
	public function my_sell_agianpublish(){
		$code = $this->input->get('code');	//简易验证码
		$passportId = $this->input->get('passport_uid');
		$house_id = $this->input->get('house_id');
		$infotype = $this->input->get('infotype');
        $city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		if(md5($house_id.'house365')==$code) {
			$uid = $this->userTest_model->getUidByPassportId($passportId);   
			if($uid==0) {
			  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
			}
			$this->user_id = $uid;
			//更新房源状态
			if($city == 'nj') {
				if($infotype==1 or $infotype==2) {
					$expiretime = strtotime("+45 day");
				} else if($infotype==3 or  $infotype==4 or $infotype==5 or $infotype==6) {
					$expiretime = strtotime("+60 day");
				}
			} else {
				$expiretime = strtotime("+90 day");
			}

			$result = $this->house_model->republishhouse($house_id,'sell',array('esta'=>'1','creattime'=>time(),'updatetime'=>time(),'expiretime'=>$expiretime));

			//记录再发布操作
			$this->house_statistic_model->set_uid($uid);
			$this->house_statistic_model->set_city($city);
			$result1 = $this->house_statistic_model->sub_operate_log('sell' , $house_id , 5 ,1);
			if($result>0) {
				echo json_encode(array('result'=>'1','msg'=>strIconv("再发布成功")));exit; 
			} else {
				echo json_encode(array('result'=>'3','msg'=>strIconv("验证不通过，来源不正确")));exit;
			}
		} else {
		     //验证不通过，来源不正确
             echo json_encode(array('result'=>'2','msg'=>strIconv("验证不通过，来源不正确")));exit; 
		}
	}

   /**
    ** 我的租房接口
    ** @author xue 2015-03-22
	**
    */
    function my_rent()
    {
        global $house;

		$passportId = $this->input->get('passport_uid');		
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');

		$city = $city ? $city : 'nj';
		$page = $page ? $page : 1;
		$pagesize = $pagesize ? $pagesize : 8;
		$offset = $pagesize * ($page-1);

	    //获取用户id
	    $uid = $this->userTest_model->getUidByPassportId($passportId);   
	    if($uid==0)
	    {
		  echo json_encode(array('result'=>'3','msg'=>strIconv("无此用户")));exit;
        }  
		$this->user_id = $uid;
        $total_num = $this->house_model->gethousenumbyuid($uid,'rent');
      
		//获取房源
		$house_array = $this->house_model->gethousebyuid($uid,'rent',array('id','address','buildarea','price','updatetime','creattime','esta','ischarge','pic1','district','streetid','blockshowname','infotype','room','hall','fitment','buildarea','priceunit','ischarge','telno','floor ','subfloor','totalfloor'),$offset,$pagesize);
		
        if(is_array($house_array)&&!empty($house_array)){
			foreach($house_array as $key=>$value){
			   $house_array[$key]['address'] = strIconv($value['address']);
			   $house_array[$key]['priceunit'] = strIconv($house['priceunit'][$value['priceunit']]);
			   $house_array[$key]['district'] = strIconv($value['district']);
			   $house_array[$key]['blockshowname'] = strIconv($value['blockshowname']);
			   $house_array[$key]['fitment'] = strIconv($value['fitment']); 
			   $house_array[$key]['click'] = $this->house_statistic_model->get_house_clicknum_by_id($value['id'],'rent');
			   //$house_array[$key]['pic1'] = $value['pic1'] ? str_replace('thumb/','',$value['pic1']):USER_CENTER.'images/no_img_small.gif';
			   $house_array[$key]['pic1'] = $value['pic1'] ? get_big_pic_new($value['pic1']):USER_CENTER.'images/no_img_small.gif';

				$this->house_statistic_model->set_city(GB_CITY);
				$this->house_statistic_model->set_uid($uid);
				//房源今日是否刷新
				$is_refresh = $this->house_statistic_model->get_operate_list(2 , $value['id'],date('Y-m-d',time()));
				//房源今日是否再发布               
				$is_oper = $this->house_statistic_model->get_operate_list(5 , $value['id'],date('Y-m-d',time()));
				//搜索是否有相同条件的已激活房源，有的话就不能再发布
				$arr=array('blockshowname'=>$value['blockshowname'],'buildarea'=>$value['buildarea'],'price'=>$value['price'],'floor'=>$value['floor'],'subfloor'=>$value['subfloor'],'totalfloor'=>$value['totalfloor'],'priceunit'=>$value['priceunit']);
				$telno = $value['telno'];
                $is_esta = $this->house_model->yzsamehouse($telno,$arr,'rent');
				
				$click_num = 0;
				$click_num = $this->house_statistic_model->get_house_clicknum_by_id($value['id'],'rent');
				$refresh_num = $this->user_model->getRefreshByid('rent',$value['id']);
				
				if($value['esta'] == 1){
				   $house_array[$key]['esta_arr']['house_url']= get_rentinfo_url($value['id']).'?update=1';
				   $house_array[$key]['esta_arr']['updatetime'] = strIconv(time_tran($value['updatetime']));
				   $house_array[$key]['esta_arr']['refresh_num'] = $refresh_num;
				   $house_array[$key]['esta_arr']['refresh_str'] = strIconv("刷新");
				   $house_array[$key]['esta_arr']['refresh_str2'] = strIconv("可刷新次数").$refresh_num.strIconv("次");
				   $house_array[$key]['esta_arr']['modify_url'] = GB_PUBLISH_URL."?kind=". (isset($value['priceunit'])?'2':'1')."&id=".$value['id']."&code=".md5($value['id'].'house365')."&tbl=sell";
                   $house_array[$key]['esta_arr']['modify_str'] = strIconv("修改");
				   if(empty($is_oper[0])){
				       $house_array[$key]['esta_arr']['delete_str'] = strIconv("删除");
				   }

				   if(GB_CITY=='nj' && $value['ischarge']==2){
					   $house_array[$key]['esta_arr']['refresh_promot'] = strIconv("推广申请中");
				   }elseif(GB_CITY=='nj' && $value['ischarge']==0){
					   $house_array[$key]['esta_arr']['refresh_promot'] = strIconv("推广");
				   }elseif(GB_CITY=='nj' && $value['ischarge']==1){
					   $house_array[$key]['esta_arr']['refresh_promot'] = strIconv("付费推广中");
							
				   }
				
				}else if($value['esta'] == 2){
					$house_array[$key]['esta_arr']['esta_str'] = strIconv("已删除");
					$house_array[$key]['esta_arr']['republish'] = strIconv("再发布");
				}else if($value['esta'] == 0 || $value['esta'] == 5 || $value['esta'] == -10){
					$house_array[$key]['esta_arr']['esta_str'] = strIconv("审核中");				
				}else if($value['esta'] == 3 || $value['esta'] == 4){
					$house_array[$key]['esta_arr']['esta_str'] = strIconv("已删除");
					if($value['ischarge'] != 1 && empty($is_esta)){ 
                        $house_array[$key]['esta_arr']['republish'] = strIconv("再发布");
                    }						
					
				}else if($value['esta'] < 0 && $value['esta'] > -9){
					$house_array[$key]['esta_arr']['esta_str'] = strIconv("审核未通过");
					$house_array[$key]['esta_arr']['esta_info'] = strIconv("了解详情，请拨打客服电话：").TEL;
				}

                //点击量下提示
				if(($value['ischarge']==0 || $value['ischarge']==2) && empty($value['pic1'])){
					$house_array[$key]['prompt'] = strIconv("上传图片就可以获得一次刷新了哦。");
				}elseif(($value['ischarge']==0 || $value['ischarge']==2) && !empty($value['pic1']) && empty($is_refresh)){
                    $house_array[$key]['prompt'] = strIconv("刷新一下，就立马排到前面去了哦。");
                }elseif(($value['ischarge']==0 || $value['ischarge']==2) && GB_CITY=='nj' && !empty($value['pic1']) && !empty($is_refresh)){ 
                    $house_array[$key]['prompt'] = strIconv("付费推广效果更佳哦。");
                }elseif($value['ischarge']==1){
                    $house_array[$key]['prompt'] = strIconv("记得每天刷新哦。");
                }
			}	
		}
		$return_arr = array('total'=>$total_num,'value'=>$house_array);
		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr, 'tel'=>TEL));
    }

	/**
    ** 我的租房刷新接口
    ** @author xue 2015-03-22
	**
    */
	public function my_rent_refresh(){

		$code = $this->input->get('code');//简易验证码
		$passportId = $this->input->get('passport_uid');
		$house_id = $this->input->get('house_id');
        $city = $this->input->get('city');       
        $city = $city ? $city : 'nj';

        if(md5($house_id.'house365')==$code)
		{
			//获取
			$uid = $this->userTest_model->getUidByPassportId($passportId);   
			if($uid==0)
			{
			  echo json_encode(array('result'=>'3','msg'=>strIconv("无此用户")));exit;
			}
			$this->user_id = $uid;
			//验证刷新可用次数
			$num = $this->house_model->yzrefrshnum($uid,$house_id,'rent');

			//获取今日已刷新次数
			$this->house_statistic_model->set_uid($uid);
			$this->house_statistic_model->set_city($city);
			$this->house_statistic_model->set_nocache(1);
			$arr = $this->house_statistic_model->get_operate_list(2,$house_id,date("Y-m-d"));

			//获得实际可刷新次数
			$num = $num - count($arr);
			if($num>0)
			{
				//更新房源刷新时间
				$result = $this->house_model->updatehouse($house_id,'sell',array('updatetime'=>time()));
				//记录刷新操作
				$this->house_statistic_model->set_uid($uid);
				$this->house_statistic_model->set_city($city);
				$result = $this->house_statistic_model->sub_operate_log('rent' , $house_id , 2 ,1);
				if($result['is_ok'] == 1)
				{
					//发送消息
					$subject='您的房源刷新成功';
					$msg='您编号为"'.$id.'"房源刷新成功。如有疑问，请联系客服。';
					$this->apply_class->send_systemmsg($uid,$subject,$msg,1,$city);
					//刷新成功					
					$arr1['num'] = $num-1;
					echo json_encode(array('result'=>'1','msg'=>strIconv("刷新成功")));exit;   
				}else{
					//刷新失败					
					$arr1['num'] = $num;
					echo json_encode(array('result'=>'4','msg'=>strIconv("刷新失败")));exit;   
				}
			}else{
				//刷新次数不足				
				$arr1['num'] = $num;
				echo json_encode(array('result'=>'5','msg'=>strIconv("刷新次数不足")));exit;   
			}
		}else{
		
		   //验证不通过，来源不正确
            echo json_encode(array('result'=>'2','msg'=>strIconv("验证不通过，来源不正确")));exit; 
		}  
	}
	
   /**
    ** 我的租房推广接口
    ** @author xue 2015-03-22
	**
    */
	public function my_rent_tg()
	{
		$payday = $this->input->get('payday');
        $paytype = $this->input->get('paytype');
		$code = $this->input->get('code');//简易验证码
		$passportId = $this->input->get('passport_uid');
		$house_id = $this->input->get('house_id');
        $city = $this->input->get('city');
		$city = $city ? $city : 'nj';
        $payday = $payday ? $payday : 1;
		$paytype = $paytype ? $paytype : 1;

		if(md5($house_id.'house365')==$code)
		{
			//获取
			$uid = $this->userTest_model->getUidByPassportId($passportId);   
			if($uid==0)
			{
			  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
			}
			$this->user_id = $uid;
			//更新房源状态,改为有意向
            $result = $this->house_model->updatehouse($house_id,'rent',array('ischarge'=>'2'));
            //记录客户意向
            $result1 = $this->user_model->addusercharge($house_id, $paytype , $payday,$uid ,'rent');
            if($result1>0)
            {
				//发送消息
                $subject='您的房源推广申请已提交。';
                $msg='您编号为"'.$id.'"的房源推广申请正在审核中，请耐心等待。';
                $this->apply_class->send_systemmsg($uid,$subject,$msg,1,$city);
                //添加成功
                echo json_encode(array('result'=>'1','msg'=>strIconv("添加成功")));exit;               
            }else{
                //添加失败
				echo json_encode(array('result'=>'2','msg'=>strIconv("添加失败")));exit;                 
            }
		}else{
		   //验证不通过，来源不正确
          echo json_encode(array('result'=>'3','msg'=>strIconv("验证不通过，来源不正确")));exit;   
		}
	}

	/**
    ** 我的租房删除接口
    ** @author xue 2015-03-22
	**
    */
	public function my_rent_delete(){
		$code = $this->input->get('code');//简易验证码
		$passportId = $this->input->get('passport_uid');
		$house_id = $this->input->get('house_id');
        $city = $this->input->get('city');
		$city = $city ? $city : 'nj';
		if(md5($house_id.'house365')==$code)
		{
			//获取
			$uid = $this->userTest_model->getUidByPassportId($passportId);   
			if($uid==0)
			{
			  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
			}
			$this->user_id = $uid;
			//更新房源状态,相当于失效状态
            $result = $this->house_model->updatehouse($house_id,'rent',array('esta'=>'2'));
            //记录再发布操作
            $this->house_statistic_model->set_uid($uid);
            $this->house_statistic_model->set_city($city);
            $result1 = $this->house_statistic_model->sub_operate_log('rent' , $house_id , 3 );
            if($result>0)
            {
				//删除成功
                echo json_encode(array('result'=>'1','msg'=>strIconv("删除成功")));exit;
            }else{
                //删除失败                
                echo json_encode(array('result'=>'2','msg'=>strIconv("删除失败")));exit;
            }
		}else{
		     //验证不通过，来源不正确
             echo json_encode(array('result'=>'3','msg'=>strIconv("验证不通过，来源不正确")));exit; 
		
		}
	}

	/**
    ** @Func		我的租房再发布接口
    ** @author		kingj 
	** @CreateTime	2015-04-16
    */
	public function my_rent_agianpublish(){
		$code = $this->input->get('code');	//简易验证码
		$passportId = $this->input->get('passport_uid');
		$house_id = $this->input->get('house_id');
		$infotype = $this->input->get('infotype');
        $city = $this->input->get('city');
		$city = $city ? $city : 'nj';

		if(md5($house_id.'house365')==$code) {
			$uid = $this->userTest_model->getUidByPassportId($passportId);   
			if($uid==0) {
			  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
			}
			$this->user_id = $uid;
			//更新房源状态
			if($city == 'nj') {
				if($infotype==1 or $infotype==2) {
					$expiretime = strtotime("+35 day");
				} else if($infotype==3 or  $infotype==4 or $infotype==5 or $infotype==6) {
					$expiretime = strtotime("+60 day");
				}
			} else {
				$expiretime = strtotime("+90 day");
			}

			$result = $this->house_model->republishhouse($house_id,'rent',array('esta'=>'1','creattime'=>time(),'updatetime'=>time(),'expiretime'=>$expiretime));

			//记录再发布操作
			$this->house_statistic_model->set_uid($uid);
			$this->house_statistic_model->set_city($city);
			$result1 = $this->house_statistic_model->sub_operate_log('rent' , $house_id , 5);

			if($result>0) {
				echo json_encode(array('result'=>'1','msg'=>strIconv("再发布成功")));exit; 
			} else {
				echo json_encode(array('result'=>'3','msg'=>strIconv("验证不通过，来源不正确")));exit;
			}
		} else {
		     //验证不通过，来源不正确
             echo json_encode(array('result'=>'2','msg'=>strIconv("验证不通过，来源不正确")));exit; 
		}
	}

    /**
    ** 我的求购接口
    ** @author xue 2015-03-22
	**
    */

	 public function my_want_buy()
    {
		 global $house;

		$passportId = $this->input->get('passport_uid');		
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');

		$city = $city ? $city : 'nj';
		$page = $page ? $page : 1;
		$pagesize = $pagesize ? $pagesize : 10;
		$offset = $pagesize * ($page-1);

		//获取
		$uid = $this->userTest_model->getUidByPassportId($passportId);   
		if($uid==0)
		{
		  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
		}       
		$this->user_id = $uid;
        //符合条件的总行数
        $total_num = $this->user_model->get_buynum_by_uid($uid,1);   
    
        //获取数据源
        $statistic_data = $this->user_model->get_buy_by_uid($uid,$offset,$pagesize); 
		//var_dump($statistic_data);exit();
		if(is_array($statistic_data)&&!empty($statistic_data)){
			foreach($statistic_data as $key=>$value){
				$statistic_data[$key]['infotype'] = strIconv($house['infotype'][$value['infotype']]);
				$statistic_data[$key]['infofrom'] = strIconv($house['infofrom'][$value['infofrom']]);
				$statistic_data[$key]['address'] = strIconv($value['address']);
				$statistic_data[$key]['remark'] = strIconv($value['remark']);
				$statistic_data[$key]['buy_url'] = GB_SELL_URL."/buyinfo.php?id=".$value['id'];

				if($value['esta'] == 1){
				    if($value['allow_match'] == 1 && GB_CITY=='nj'){
						 $statistic_data[$key]['esta_arr']['show_matched_str'] = 1;
					     $statistic_data[$key]['esta_arr']['matched_num'] = $value['new_matched_num'];
						 $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("条新房源");
				    }elseif(GB_CITY=='nj'){
				         $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("未参与匹配");
				    }else{
				         $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("已激活");
				    }
				}else if( $value['esta'] == 0 || $value['esta'] == '-10' ){
				    $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("审核中");
				}else if( $value['esta'] == 2 || $value['esta'] == 3 || $value['esta'] == 4 ){ 
				    $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("已删除");
				}else{
				    $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("审核未通过");
				}

			    if( $value['esta'] == 1 && $value['allow_match'] == 1 && $value['matched_num'] >= 1 && GB_CITY=='nj'){ 
                    $statistic_data[$key]['esta_arr']['matched_look_str'] = strIconv("查看匹配");
					$statistic_data[$key]['esta_arr']['matched_del_str'] = strIconv("删除");
				    $statistic_data[$key]['esta_arr']['matched_look_str_click'] = 1;
					$statistic_data[$key]['esta_arr']['matched_del_str_click'] = 1;
                }elseif($value['esta']==1 && GB_CITY=='nj'){
					$statistic_data[$key]['esta_arr']['matched_look_str'] = strIconv("查看匹配");
					$statistic_data[$key]['esta_arr']['matched_del_str'] = strIconv("删除");
				    $statistic_data[$key]['esta_arr']['matched_look_str_click'] = 0;
					$statistic_data[$key]['esta_arr']['matched_del_str_click'] = 1;
                }elseif(GB_CITY=='nj'){
                    $statistic_data[$key]['esta_arr']['matched_look_str'] = strIconv("查看匹配");					
				    $statistic_data[$key]['esta_arr']['matched_look_str_click'] = 0;
                }elseif(GB_CITY!='nj' && $value['esta']==1){
					$statistic_data[$key]['esta_arr']['matched_del_str'] = strIconv("删除");
					$statistic_data[$key]['esta_arr']['matched_del_str_click'] = 1;
			    }elseif(GB_CITY!='nj' && $value['esta']!=1){
					$statistic_data[$key]['esta_arr']['matched_del_str'] = strIconv("删除");
					$statistic_data[$key]['esta_arr']['matched_del_str_click'] = 0;
			    }
			}	
		}
        $return_arr = array('total'=>$total_num,'value'=>$statistic_data);
		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr));
      
    }

	/**
    ** 我的求租接口
    ** @author xue 2015-03-22
	**
    */

	 public function my_want_rent()
    {
		 global $house;

		$passportId = $this->input->get('passport_uid');		
		$page = $this->input->get('page');
		$pagesize = $this->input->get('pagesize');
		$city = $this->input->get('city');

		$city = $city ? $city : 'nj';
		$page = $page ? $page : 1;
		$pagesize = $pagesize ? $pagesize : 10;
		$offset = $pagesize * ($page-1);

		//获取
		$uid = $this->userTest_model->getUidByPassportId($passportId);   
		if($uid==0)
		{
		  echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
		}
		$this->user_id = $uid;
        //符合条件的总行数
        $total_num = $this->user_model->get_rent_wantnum_by_uid($uid,1);   
    
        //获取数据源
        $statistic_data = $this->user_model->get_rentwant_by_uid($uid,$offset,$pagesize); 
		if(is_array($statistic_data)&&!empty($statistic_data)){
			foreach($statistic_data as $key=>$value){
			   $statistic_data[$key]['infotype'] = strIconv($house['infotype'][$value['infotype']]);
			   $statistic_data[$key]['infofrom'] = strIconv($house['infofrom'][$value['infofrom']]);
			   $statistic_data[$key]['address'] = strIconv($value['address']);
			   $statistic_data[$key]['remark'] = strIconv($value['remark']);
			   $statistic_data[$key]['renttype'] = strIconv($house['renttype'][$value['renttype']]);
			   $statistic_data[$key]['buy_url'] = GB_SELL_URL."/rentwantedinfo.php?id=".$value['id'];

			   if($value['esta'] == 1){
				    if($value['allow_match'] == 1 && GB_CITY=='nj'){
					     $statistic_data[$key]['esta_arr']['matched_num'] = strIconv($value['new_matched_num']."条新房源");
				    }elseif(GB_CITY=='nj'){
				         $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("未参与匹配");
				    }else{
				         $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("已激活");
				    }
				}else if( $value['esta'] == 0 || $value['esta'] == '-10' ){
				    $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("审核中");
				}else if( $value['esta'] == 2 || $value['esta'] == 3 || $value['esta'] == 4 ){ 
				    $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("已删除");
				}else{
				    $statistic_data[$key]['esta_arr']['matched_str'] = strIconv("审核未通过");
				}

			    if( $value['esta'] == 1 && $value['allow_match'] == 1 && $value['matched_num'] >= 1 && GB_CITY=='nj'){ 
                    $statistic_data[$key]['esta_arr']['matched_look_str'] = strIconv("查看匹配");
					$statistic_data[$key]['esta_arr']['matched_del_str'] = strIconv("删除");
				    $statistic_data[$key]['esta_arr']['matched_look_str_click'] = 1;
					$statistic_data[$key]['esta_arr']['matched_del_str_click'] = 1;
                }elseif($value['esta']==1 && GB_CITY=='nj'){
					$statistic_data[$key]['esta_arr']['matched_look_str'] = strIconv("查看匹配");
					$statistic_data[$key]['esta_arr']['matched_del_str'] = strIconv("删除");
				    $statistic_data[$key]['esta_arr']['matched_look_str_click'] = 0;
					$statistic_data[$key]['esta_arr']['matched_del_str_click'] = 1;
                }elseif(GB_CITY=='nj'){
                    $statistic_data[$key]['esta_arr']['matched_look_str'] = strIconv("查看匹配");					
				    $statistic_data[$key]['esta_arr']['matched_look_str_click'] = 0;
                }elseif(GB_CITY!='nj' && $value['esta']==1){
					$statistic_data[$key]['esta_arr']['matched_del_str'] = strIconv("删除");
					$statistic_data[$key]['esta_arr']['matched_del_str_click'] = 1;
			    }elseif(GB_CITY!='nj' && $value['esta']!=1){
					$statistic_data[$key]['esta_arr']['matched_del_str'] = strIconv("删除");
					$statistic_data[$key]['esta_arr']['matched_del_str_click'] = 0;
			    }	 
			}	
		}
		
        $return_arr = array('total'=>$total_num,'value'=>$statistic_data);

		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr));
      
    }

	/**
    ** 我的求购求租删除接口
    ** @author xue 2015-03-22
	**tbl:rentwanted|buy
    */
    function my_want_delete()
    {

        $id = $this->input->get('house_id');      
        $code = $this->input->get('code');
	    $city = $this->input->get('city');		
        $tbl = $this->input->get('tbl');
	    $passportId = $this->input->get('passport_uid');	
	    $city = $city ? $city : 'nj';
        if(md5($id.'house365')==$code&&in_array($tbl,array("rentwanted","buy")))
        {
			//获取
		    $uid = $this->userTest_model->getUidByPassportId($passportId);   
		    if($uid==0)
		    {
				echo json_encode(array('result'=>'4','msg'=>strIconv("无此用户")));exit;
		    }
			$this->user_id = $uid;
		    //更新房源状态,相当于失效状态
		    $result = $this->user_model->updatewant($id,$tbl,array('esta'=>4));
		    //记录再发布操作
		    $this->house_statistic_model->set_uid($uid);
		    $this->house_statistic_model->set_city($city);
		    $result1 = $this->house_statistic_model->sub_operate_log($tbl , $id , 3 );
		    if($result>0)
			{
				//删除成功
			    echo json_encode(array('result'=>'1','msg'=>strIconv("删除成功")));exit;
			}else{
			    //删除失败			             
                echo json_encode(array('result'=>'2','msg'=>strIconv("删除失败")));exit;
			}            
        
        }else{
			 //删除失败			             
             echo json_encode(array('result'=>'3','msg'=>strIconv("验证失败")));exit;
		}
	}

	function get_house_clicknum_by_id()
	{
		$this->load->model('house_statistic_zhou_model');
		$rowid = $this->input->get('rowid');
	    $tbl = $this->input->get('tbl');
		$uid = $this->input->get('uid');

        $this->house_statistic_zhou_model->set_uid( $uid );
        $click_num = $this->house_statistic_zhou_model->get_house_clicknum_by_id($rowid,$tbl);
		
		echo $click_num;
		exit();
		
	}

	function sms_check_state()
	{
		$this->load->model('house_statistic_zhou_model');
		$telno = $this->input->get('telno');
		$status = $this->house_statistic_zhou_model->get_telno_state($telno);
		echo $status;exit;
		
	}


	function check_validcode_state()
	{
		$this->load->model('house_statistic_zhou_model');
		$telno = $this->input->get('telno');
		$validcode = $this->input->get('validcode');
		$status = $this->house_statistic_zhou_model->check_validcode_state($telno,$validcode);
	
		echo $status;exit;
	}

	function update_validcode_state()
	{
		$this->load->model('house_statistic_zhou_model');
		$telno = $this->input->get('telno');
		$validcode = $this->input->get('validcode');
		$status = $this->house_statistic_zhou_model->update_validcode_state($telno,$validcode);
		echo $status;exit;
	}


	//获取求购求租匹配数据
	public function get_want_match(){
		//error_reporting(E_ALL);
          //  ini_set("display_errors",TRUE);

		 global $house;
        //获取表单数据
        $want_id = $this->input->get('want_id',TRUE);
        $want_type = strip_tags($this->input->get('want_type',TRUE));
        //$page = $this->input->get('page',TRUE);
        $data['priceunit'] = $house['priceunit'];

		$this->_limit = 10;

        if( $want_id > 0 && in_array( $want_type , array('buy','rentwant') ))
        {
            //加载房源操作统计类
            $this->load->model('want_house_model');

            $want_arr = array ('buy'=> array('house_tbl'=>'sell','match_tbl'=>'buy_match'),'rentwant'=> array('house_tbl'=>'rent','match_tbl'=>'rentwanted_match'));

            //设置房源表
            $this->want_house_model->set_tbl_house($want_arr[$want_type]['house_tbl']);

            //设置匹配表
            $this->want_house_model->set_tbl_match($want_arr[$want_type]['match_tbl']);
            if($want_type=='buy')
            {
            $fields_base = array('id','district','streetid','blockshowname','infotype','infofrom','buildarea','price','room','hall','fitment','floor','subfloor','totalfloor');
            }else{
            $fields_base = array('id','district','streetid','blockshowname','infotype','infofrom','buildarea','price','room','hall','fitment','floor','subfloor','totalfloor','priceunit');           
            }
            $fields_t['buy'] = array('buildyear');
            $fields_t['rentwant'] = array('renttype');
            $fields = array_merge( $fields_base , $fields_t[$want_type]);
            $this->want_house_model->set_house_fields($fields);

            //符合条件的总行数
            $this->_total_count = $this->want_house_model->get_matched_num_by_id( $want_id );
            //计算总页数
            $pages  = $this->_total_count > 0 ? ceil( $this->_total_count / 6 ) : 0;

            if($page>$pages)
            {
             $page=$pages;
            }

            //获取数据源

            $statistic_data = $this->want_house_model->get_matched_by_id( $want_id , $this->_offset , $this->_limit );

			if(is_array($statistic_data)&&!empty($statistic_data)){
				foreach($statistic_data as $key=>$value){
				    $statistic_data[$key]['url'] = $want_type == 'buy' ? get_sellinfo_url($value['id']) : get_rentinfo_url($value['id']);
                    $statistic_data[$key]['price'] = $want_type == 'buy' ? $value['price']."万元" : $value['price'].$house['priceunit'][$value['priceunit']];
				}
			
			}
        }
        else
        {
            $this->_total_count = 0;
            $pages  = 0;
            $statistic_data = array();
        }
      

        $return_arr = array('total'=>$this->_total_count,'value'=>strIconv($statistic_data));
		echo json_encode(array('result'=>'1','msg'=>'success','data'=>$return_arr));
    
        
     
		
	}






	//删除求购求租匹配数据
	function deleteWantMatch(){

		//加载房源操作统计类
	   $match_type = $this->input->get('want_type');
	   $ids =$this->input->get('ids');

       $this->load->model('want_house_model');
      
       $tbl = $match_type=='buy'?'buy_match':'rentwanted_match';
	   $ask_tbl=$match_type=='buy'?'buy':'rentwanted';
	
	
	   if(!empty($ids))
	   {
			$id_array=explode(',',$ids);

			foreach($id_array as $value)
			{

				$arr = array('id'=>$value);
				
				$up = array('esta'=>'4','isread'=>'1');
				$this->want_house_model->set_table($tbl);
				$result = $this->want_house_model->save($arr,$up,'esfhouse');
				//更新匹配数目
				$result = $this->user_model->updatematched_num($id,$ask_tbl);
				
			}
		}
		echo $result;
		
	}


	/**
	 *commitintention
	 *经纪人对用户的意向提交接口
	 *parms  int  $brokerid  经纪人id
	 *parms  int  $pid  pushuserid
	 *parms  int  $intention  意向
	 */

	function commitintention()
	{
		$brokerid = $this->input->get_post('brokerid');
		if(empty($brokerid)){echo json_encode(0);exit;}
		$pushuserid = $this->input->get_post('pushuserid');
		
		$intention = $this->input->get_post('intention');
		
		$code = $this->input->get_post('code');
		
		
		if($code != md5('my365house'.$brokerid))
		{
			//echo 'N_CHECK';exit;
		}
		$result = $this->pushzhou_model->commitintention($brokerid,$pushuserid,$intention);
		echo json_encode($result);
	
	}


	
}