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

class User_xue extends MY_Controller
{

    function __construct()
    {
      parent::__construct();

      $this->load->model("user_model");

      $this->load->model("broker_model");
	  $this->load->model("pic_model");
      
	  $this->load->model("block_model");

      $this->load->model("ask_model");
      $this->load->model("house_model");
      $this->load->model("house_statistic_model");
      $this->load->library("user_class");
      $this->load->library("apply_class");
      $this->user_id = checklogin();

       if( $this->user_id <= 0 )
       {
            jumpto( USER_CENTER.'login');
            exit();
       }

        //关注各项数量
        $this->num_1 = $this->user_model->getusercollect($this->user_id,1);
        $this->num_2 = $this->user_model->getusercollect($this->user_id,2);
        $this->num_3 = $this->user_model->getusercollect($this->user_id,3);
        $this->num_4 = $this->user_model->getusercollect($this->user_id,4);
        $this->num_5 = $this->user_model->getusercollect($this->user_id,5);
		$this->num_7 = $this->user_model->getusercollect($this->user_id,7);
    }


    /**
    * 用户中心首页
    * @author cxf
    */
    public function index()
    {
        global $house;
         
        $data['conf_where'] = 'index';
        $data['title'] = '会员中心';
        $data['priceunit'] = $house['priceunit'];
        $data['sell_num'] = $this->house_model->gethousenumbyuid($this->user_id,'sell',1);
        $data['rent_num'] = $this->house_model->gethousenumbyuid($this->user_id,'rent',1);
        $data['want_num'] = $this->user_model->get_rent_wantnum_by_uid($this->user_id,1);
        $data['buy_num'] = $this->user_model->get_buynum_by_uid($this->user_id,1);
        $data['user_detail'] = $this->user_model->get_userdetail($this->user_id,array('email','telno'));

         //获取最新2条房源
        $newhouse           = $this->user_model->newhouse( $this->user_id , 2 );
		
		$data['newhouse']   = $newhouse;

		$count_newhouse     =count($newhouse);
		$active_num  =0;
		$active_sell_num =0;
		for($i=0;$i<$count_newhouse;$i++)
        {
			if($newhouse[$i]['esta']==1)
			{
				if($newhouse[$i]['tbl']=='sell')
				{
					$active_sell_num++;
				}
				$active_num++;
			}
			
		}


        $sell_collect_house = $this->user_model->getcollect(3,$this->user_id,0,8);				//网友关注的二手房房源
		$rent_collect_house = $this->user_model->getcollect(4,$this->user_id,0,8);				//网友关注的租房房源
		$sell_collect_block = $this->user_model->getcollect(2,$this->user_id,0,8);				//网友关注的小区
		$data['sell_collect_house'] = $sell_collect_house;
		$data['rent_collect_house'] = $rent_collect_house;
		$data['sell_collect_block'] = $sell_collect_block;

		
       //获取你可能感兴趣的二手房
        $data['likesell'] = $this->user_model->getlikehousebyrule($active_num,$active_sell_num,$newhouse,$sell_collect_house,$sell_collect_block,$this->user_id,'sell',$active_sell_num,4);

		
		
		//获取你可能感兴趣的租房
        $data['likerent'] = $this->user_model->getlikehousebyrule($active_num,$active_sell_num,$newhouse,$rent_collect_house,$sell_collect_block,$this->user_id,'rent',$active_sell_num,4);
		
		//获取你可能感兴趣的小区
        $data['likeblock'] = $this->user_model->getlikehousebyrule($active_num,$active_sell_num,$newhouse,$sell_collect_house,$sell_collect_block,$this->user_id,'block',4);


		//中奖通知  5.25-8.31
		$data['is_win'] = $this->_get_is_win();
		
		//BI统计 ----- start----->
		$data['isa_website'] = '2,19,46';
	    $data['isa_city'] = GB_CITY;
	    $data['isa_addones'] = '';
	    $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
		//BI统计 ----- ent----->
        $this->load->view('index',$data);
    }
	
	/**
    * 会员中心切换城市
    * @author cxf
    */
    public function changecity()
    {
	 $city = $this->input->get('city');
     $city = !empty($city)?$city:'nj';
     setcoandsess('website_jumpto_city',$city);
     jumpto(USER_CENTER.'user');
    }



        /**
    * 我的关注二手房页面
    * @author cxf
    */
    public function selllist()
    {
		
        $data['conf_where'] = 'selllist';
        $data['title'] = '会员中心';
		$this->load->model("user_xue_model");
        //删除操作
        if(isset($_POST['muldel']) && $_POST['muldel']=='del')
        {
			
			$esfuserid =$_SESSION['esfuserid'];
            $result = $this->user_xue_model->delcollect($_POST['actionid'],$esfuserid);
            echo $result;exit;
        }

        //分页开始
        $data['collect_num'] = $this->num_3;
        $data['pagesize'] = 8;//设定每一页显示的记录数
        $data['pages'] = $data['collect_num'] ? ceil($data['collect_num']/$data['pagesize']) : 0 ;  //计算总页数
        $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
        $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page'];  //判断跳转页数
        $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量
        $data['collect'] = $this->user_model->getcollect(3,$this->user_id,$data['offset'],$data['pagesize']);
		

		if(is_array($data['collect'])&&!empty($data['collect'])){
			
			foreach($data['collect'] as $key=>$value){				
				 $isChoice = $this->user_xue_model->isCheckPriceRemind($this->user_id,$value['collect_id']);
				 $infofrom_data=$this->user_xue_model->get_infofrom_by_id($value['collect_id']);
				 $data['collect'][$key]['infofrom'] =$infofrom_data[0]['infofrom'];
				
                 $data['collect'][$key]['is_remind'] = isset($isChoice[0]['status'])&&($isChoice[0]['status']==1) ? 1:0;
			
			}
		
		}
	
		//var_dump($data['collect']);
		//获取你可能感兴趣的二手房
        $data['likesell'] = $this->user_model->getlikehouse($this->user_id,'sell',4);
		
		//BI统计 ----- start----->
		 
		 $data['isa_website'] = '2,19,79';
	     $data['isa_city'] = GB_CITY;
	     $data['isa_addones'] = '';
	     $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
		//BI统计 ----- ent----->
	
        $this->load->view('my_attention_sell_xue',$data);
    }


    /**
    * 我的关注租房页面
    * @author cxf
    */
    public function rentlist()
    {
        GLOBAL $house;

        $data['conf_where'] = 'selllist';
        $data['title'] = '我的关注';

        //删除操作
        if(isset($_POST['muldel']) && $_POST['muldel']=='del')
        {
            $result = $this->user_model->delcollect($_POST['actionid']);
            echo $result;exit;
        }

        //分页开始
        $data['collect_num'] = $this->num_4;
        $data['pagesize'] = 8;//设定每一页显示的记录数
        $data['pages'] = $data['collect_num'] ? ceil($data['collect_num']/$data['pagesize']) : 0 ;  //计算总页数
        $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
        $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page'];  //判断跳转页数
        $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量
        $data['collect'] = $this->user_model->getcollect(4,$this->user_id,$data['offset'],$data['pagesize']);
        $data['priceunit'] = $house['priceunit'];
        //获取你可能感兴趣的租房
        $data['likerent'] = $this->user_model->getlikehouse($this->user_id,'rent',4);
		
        $this->load->view('my_attention_rent',$data);
    }


    /**
    * 我的关注小区页面
    * @author cxf
    */
    public function blocklist()
    {
        $data['conf_where'] = 'blocklist';
        $data['title'] = '我的关注';

        //删除操作
        if(isset($_POST['muldel']) && $_POST['muldel']=='del')
        {
            $result = $this->user_model->delcollect($_POST['actionid']);
            echo $result;
            exit;
        }

        //分页开始
        $data['collect_num'] = $this->num_2;
        $data['pagesize'] = 8;//设定每一页显示的记录数
        $data['pages'] = $data['collect_num'] ? ceil($data['collect_num']/$data['pagesize']) : 0 ;  //计算总页数
        $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
        $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page'];  //判断跳转页数
        $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量

        $data['collect'] = $this->user_model->getcollect(2,$this->user_id,$data['offset'],$data['pagesize']);
        //获取你可能感兴趣的小区
        $data['likeblock'] = $this->user_model->getlikehouse($this->user_id,'block',4);

		//BI统计 ----- start----->
		 
		 $data['isa_website'] = '2,19,80';
	     $data['isa_city'] = GB_CITY;
	     $data['isa_addones'] = '';
	     $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
		//BI统计 ----- ent----->
        $this->load->view('my_attention_block',$data);
    }

   /**
    * 我的关注学区页面
    * @author xue
    */
    public function schoollist()
    {

        $data['conf_where'] = 'schoollist';
        $data['title'] = '会员中心';

        //删除操作
        if(isset($_POST['muldel']) && $_POST['muldel']=='del')
        {
            $result = $this->user_model->delcollect($_POST['actionid']);
            echo $result;exit;
        }

        //分页开始
        $data['collect_num'] = $this->num_7;
        $data['pagesize'] = 8;//设定每一页显示的记录数
        $data['pages'] = $data['collect_num'] ? ceil($data['collect_num']/$data['pagesize']) : 0 ;  //计算总页数
        $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
        $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page'];  //判断跳转页数
        $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量
        $data['collect'] = $this->user_model->getCollectSchoolList(7,$this->user_id,$data['offset'],$data['pagesize']);  
		//获取你可能感兴趣的二手房
        $data['likesell'] = $this->user_model->getLikeSchoolHouse($this->user_id);		
        $this->load->view('my_attention_school',$data);
    }


    /**
     * 我的二手房关注条件页面
     * @author cxf
    */
    public function sell_condition()
    {

        $data['conf_where'] = 'sell_condition';
        $data['title'] = '我的关注';

        $muldel = $this->input->post('muldel');
        $actionid	= $this->input->post('actionid');

        //删除操作
        if( isset( $muldel ) && $muldel == 'del')
        {
            $result = $this->user_model->delcollect($actionid);
            echo $result;
            exit;
        }

        //分页开始
        $data['collect_num'] = $this->num_1;
        $data['pagesize'] = 5;//设定每一页显示的记录数
		//计算总页数
        $data['pages'] = $data['collect_num'] ? ceil($data['collect_num']/$data['pagesize']) : 0 ;
		//获取当前页数
        $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) : 1 ;
		//判断跳转页数
        $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page']; 
		//计算记录偏移量
        $data['offset'] = $data['pagesize']*($data['page']-1);
        $data['collect'] = $this->user_model->getcollect(1,$this->user_id,$data['offset'],$data['pagesize']);
        $data['sarr'] = $this->user_model->getSeachcondStr($data['collect']);
        $data['surl'] = $this->user_model->getSeachcondUrl($data['collect'], 1);
        //获取你可能感兴趣的二手房
        $data['likesell'] = $this->user_model->getlikehouse($this->user_id,'sell',4);


		//BI统计 ----- start----->
		 
		$data['isa_website'] = '2,19,78';
	    $data['isa_city'] = GB_CITY;
	    $data['isa_addones'] = '';
	    $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
		//BI统计 ----- ent----->
        $this->load->view('my_sell_condition',$data);
    }


    /**
    * 我的关注条件页面
    * @author cxf
    */
    public function rent_condition()
    {
		global $house;
        $data['conf_where'] = 'sell_condition';
        $data['title'] = '我的关注';
		$data['priceunit'] = $house['priceunit'];

        //删除操作
        if(isset($_POST['muldel']) && $_POST['muldel']=='del')
        {
            $result = $this->user_model->delcollect($_POST['actionid']);
            echo $result;exit;
        }

        //分页开始
        $data['collect_num'] = $this->num_5;
        $data['pagesize'] = 5;//设定每一页显示的记录数
        $data['pages'] = $data['collect_num'] ? ceil($data['collect_num']/$data['pagesize']) : 0 ;  //计算总页数
        $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
        $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page'];  //判断跳转页数
        $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量
        $data['collect'] = $this->user_model->getcollect(5,$this->user_id,$data['offset'],$data['pagesize']);
        $data['sarr'] = $this->user_model->getSeachcondStr($data['collect']);
        $data['surl'] = $this->user_model->getSeachcondUrl($data['collect'], 5);
        //获取你可能感兴趣的租房
        $data['likerent'] = $this->user_model->getlikehouse($this->user_id,'rent',4);
        $this->load->view('my_rent_condition',$data);
    }


    /**
    * 用户退出
    * @author cxf
    */
    public function logout()
    {
        vbsetcookie("esfuserid","",1);
        vbsetcookie("esfpassword","",1);
        vbsetcookie("esfusername","",1);
        vbsetcookie("esfusertelno","",1);
        vbsetcookie("esfshowname","",1);
        vbsetcookie("esfusercity","",1);

        unset($_SESSION['esfuserid']);
        unset($_SESSION['esfpassword']);
        unset($_SESSION['esfusername']);
        unset($_SESSION['esfusertelno']);
        unset($_SESSION['esfusercity']);
        unset($_SESSION['esfshowname']);
        if(isset($_SERVER['HTTP_REFERER']))
        {
        $url = substr($_SERVER['HTTP_REFERER'], 0, 35);
        $url1 = substr($_SERVER['HTTP_REFERER'], 0, 40);
        if($url==USER_CENTER.'user' || $url1==USER_CENTER.'statistic' || $url==USER_CENTER.'want')
        {
            //jumptotk(GB_SELL_URL,"退出成功!将返回二手房首页！",3000,'tips');
            jumpto(GB_SELL_URL);
        }else{
            //jumptotk($_SERVER['HTTP_REFERER'],"退出成功!将返回之前的页面！",3000,'tips');
            jumpto($_SERVER['HTTP_REFERER']);
        }
        }else{
            //jumptotk(GB_SELL_URL,"退出成功!将返回二手房首页！",3000,'tips');
            jumpto(GB_SELL_URL);
        }
        exit();
    }


    /**
    * 修改个人资料
    * @author cxf
    */
    function edit_profile()
    {
         $data['js'] = '<script type="text/javascript" src="'.USER_CENTER.'js/jquery.Jcrop.min.js"></script>';
         $data['conf_where'] = 'edit_profile';

         $data['title'] = '修改资料';
         $data['user_detail_old'] = $this->user_model->get_userdetail($this->user_id,array('username','email','sex','birthdate'));
         if($_POST)
         {
            $arr['email'] = $this->input->post('email');
            $arr['sex'] = $this->input->post('sex');
            $arr['birthdate'] = strtotime($this->input->post('year')."-".$this->input->post('month')."-".$this->input->post('day'));
            //var_dump($arr['birthdate']);exit;
            $result = $this->user_model->updateuser($this->user_id,$arr);
         }

         $data['user_detail'] = $this->user_model->get_userdetail($this->user_id,array('username','email','sex','birthdate','head_pic'));


		 //BI统计 ----- start----->
		 
		 $data['isa_website'] = '2,19,83';
	     $data['isa_city'] = GB_CITY;
	     $data['isa_addones'] = '';
	     $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
		 //BI统计 ----- ent----->
         $this->load->view('edit_profile',$data);
    }


    /**
    * 修改密码
    * @author cxf
    */
    function edit_password()
    {
        $data['js']= '<script type="text/javascript" src="'.USER_CENTER.'js/Validform_v5.3.2_ncr_min.js"></script>';
        $select = array('telno');
        $data['user'] = $this->user_model->get_userdetail($this->user_id,$select);
        $data['conf_where'] = 'edit_password';
        $data['title'] = '修改密码';

        if($_POST)
        {
            $newpassword = $this->input->post('newpassword');
            $againpassword = $this->input->post('againpassword');
            $password = $this->input->post('password');

            if($newpassword == $againpassword)
            {
                $result = $this->user_model->yzloginuser($this->user_id,md5($password));

                if( $result > 0 )
                {
                    $result_pass = $this->user_model->updatepassowrdbyuid($this->user_id,$newpassword);
                    echo $result_pass ? 1 : 4;
                    exit;
                }else{
                    echo 3;
                    exit;
                }
            }
            else
            {
                echo 2;
                exit;
            }
        }

        $this->load->view('edit_password',$data);
    }


    /**
    * 修改电话号码
    * @author cxf
    */
    function edit_telno()
    {
        $data['conf_where'] = 'edit_telno';
        $data['title'] = '修改手机号码';
        $data['js']= '<script type="text/javascript" src="'.USER_CENTER.'js/code.js"></script><script type="text/javascript" src="'.USER_CENTER.'js/Validform_v5.3.2_ncr_min.js"></script>';
        $select = array('telno');
        $data['user'] = $this->user_model->get_userdetail($this->user_id,$select);

        if($_POST)
        {
            $telno = $this->input->post('telnoold');
            $telnonew = $this->input->post('telno');
            $validcode = $this->input->post('validcode');
            $kind = $this->input->post('kind');

            //验证手机号是否存在
            $result2 = $this->user_model->yztelnolt($telnonew);

            if($result2[0]['id']>0 && $result2[0]['infofrom'] !=2)
            {
                echo 3;
                exit;
            }

            //验证短信验证码是否正确
            $result = $this->user_model->yzusersms($validcode,$telnonew,$kind);

            if($result>0)
            {
                $result_pass = $this->user_model->updatetelnobyuid($this->user_id,$telnonew);

				if($result_pass)
				{
					//修改已经绑定的400号码
					$this->load->model("esf_400_model");
					$this->esf_400_model->update_telno($this->user_id , $telnonew ,$telno);
				}

                echo $result_pass ? 1 : 0;

                if($result2[0]['id']>0 && $result2[0]['infofrom']==2)
                {
                    //对原有账号进行失效操作
                    $this->user_model->updateuser($result2[0]['id'],array('is_use'=>0));

                    //对原有房源进行id修改
                    $this->house_model->updatehouseuid($result2[0]['id'],$this->user_id,'sell');
                    $this->house_model->updatehouseuid($result2[0]['id'],$this->user_id,'rent');
                }

                exit;
            }
            else
            {
                echo 2;
                exit;
            }
        }

        $this->load->view('edit_telno',$data);
    }


    /**
    * 编辑头像文件
    * @author cxf
    */
    function edit_headfile()
    {
        if($this->input->post("action") == 'headfile')
        {
            $fileurl = common_file_upload("headfile", false, false, 340, 220);
            if($fileurl)
            {
                echo "<script>window.parent.setHeadimgsrc('".$fileurl."');window.parent.document.getElementById('headpic').value='".$fileurl."';window.parent.jcSetImage();window.parent.changeShowPic('headShowPic');</script>";
            }
            else
            {
                echo "<script>window.parent.document.getElementById('jsUploadHeadPortrait').style.display = 'none';window.parent.document.getElementById('jsDialogE_msg').innerHTML='图片上传失败，请重试！';window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1000);</script>";
            }

            exit;
        }
        else if( $this->input->post("action") == 'savehead' )
        {
            $headpic = trim($this->input->post("headpic"));
            $x = floatval($this->input->post("x"));
            $y = floatval($this->input->post("y"));
            $w = floatval($this->input->post("w"));
            $h = floatval($this->input->post("h"));

            $picfile = curl_get_contents($headpic);

            if( $picfile )
            {
                $targ_w = $w;
                $targ_h = $h;
                $jpeg_quality = 100;

                //FISHER 2013-6-22
                //获取远程图片再裁剪处理，然后还要FTP上传到图片服务器，目前只能在本地创建临时文件，想不出其他办法了。
                $filename = GB_CITY.'_'.md5($headpic).".jpg";
                $cachefile = APPPATH."/cache/".$filename;

                if($handle = fopen($cachefile, "wb") && $targ_w > 0 && $targ_h > 0)
                {
                    $img_r = imagecreatefromstring($picfile);
                    $dst_r = ImageCreateTrueColor($targ_w, $targ_h);

                    imagecopyresampled($dst_r,$img_r,0,0,$x,$y,$targ_w,$targ_h,$w,$h);
                    imagejpeg($dst_r, $cachefile, $jpeg_quality);

                    @fclose($handle);

                    $_FILES['headfile']['nocheck'] = "house365";//uploadfile 类会检查这个文件是否是POST提交的文件，没办法啊绕过去。
                    $_FILES['headfile']['name'] = $filename;
                    $_FILES['headfile']['type'] = 'image/pjpeg';
                    $_FILES['headfile']['tmp_name'] = $cachefile;
                    $_FILES['headfile']['error'] = 0;
                    $_FILES['headfile']['size'] = @filesize($cachefile);
                    $this->load->library('uploadfile_class',array('filename'=>"headfile"));

                    $this->uploadfile_class->setFileType("jpg");
                    $this->uploadfile_class->setMaxSize(5120);
                    $this->uploadfile_class->setUploadType("ftp");
                    $this->uploadfile_class->setSaveDir("/".GB_CITY."house/");
                    $this->uploadfile_class->setWatermark(false);
                    $this->uploadfile_class->setImageCut(false);

                    if ($this->uploadfile_class->upload() == "success")
                    {
                        $headpicurl = $this->uploadfile_class->getSaveFileURL(); //图片地址
                    }
                    else
                    {
                        $headpicurl = "";
                    }

                    @unlink($cachefile);

                    if($headpicurl != "")
                    {
                        //更新用户头像
                        $id = $this->user_model->updateheadpic($this->user_id,$headpicurl);

                        if($id > 0)
                        {
                            echo "<script>window.parent.openWin('upfile-ok');</script>";
                        }
                        else
                        {
                            echo "<script>window.parent.openWin('warning');</script>";
                        }
                    }
                    else
                    {
                        echo "<script>window.parent.openWin('warning');</script>";
                    }
                }
                else
                {
                    echo "<script>window.parent.openWin('warning');setTimeout(function(){window.parent.location.reload();},1000);</script>";
                }
            }
            else
            {
                echo "<script>window.parent.openWin('warning');setTimeout(function(){window.parent.location.reload();},1000);</script>";
            }

            exit;
         }
    }


    /**
     * 我的问答
     * @author cxf
    */
    function myask()
    {
         $data['conf_where'] = 'ask';
         $data['title'] = '我的问答';

         //分页开始
         $data['ask_num'] = $this->ask_model->getquelistnum($this->user_id);
         $data['pagesize'] = 8;//设定每一页显示的记录数
         $data['pages'] = $data['ask_num'] ? ceil($data['ask_num']/$data['pagesize']) : 0 ;  //计算总页数

         $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
         $data['page'] = ($data['page'] > $data['pages']) ? $data['pages'] : $data['page'];  //判断跳转页数
         $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量

         //获取问题列表
         $data['asklist'] = $this->ask_model->getquelist($this->user_id,$data['offset'],$data['pagesize']);
         $data['expertslist'] = $this->ask_model->getexperts();

		//BI统计 ----- start----->
		 
		 $data['isa_website'] = '2,19,99';
	     $data['isa_city'] = GB_CITY;
	     $data['isa_addones'] = '';
	     $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
		//BI统计 ----- ent----->
		//print_r($data);die;
         $this->load->view('myask',$data);
    }


    /**
    * 提问详情页跳转页
    * @author cxf
    */
    function qdetail($qid)
    {
        $arr=array('a_qid'=>$qid,'a_esta'=>1,'a_read'=>0);
        $up= array('a_read'=>1);
        $this->user_model->set_table('qa_answer');
        $result = $this->user_model->save($arr,$up,'esfhouse');
        //更新问答未读的cookie
        $ask_num = $this->ask_model->getnewanswerbyuid($this->user_id);
        setcoandsess('esfasknum',$ask_num);
        echo '<script language="javascript">location= "'.get_questioninfo_url($qid).'";</script>';
    }


    /**
    * 我的消息
    * @author cxf
    */
    function mymessage()
    {
         $data['conf_where'] = 'message';
         $data['title'] = '我的消息';

        //删除操作
        if(isset($_POST['muldel']) && $_POST['muldel']=='del')
        {
            $result = $this->user_model->delmessage($_POST['actionid']);
            echo $result;
            exit;
        }
        //更新消息的点击状态
        $this->user_model->updateannounceclick($this->user_id);
        $data['num'] = $this->user_model->getmessagenumbyuid($this->user_id);
        $data['pagesize'] = 8;//设定每一页显示的记录数
        $data['pages'] = $data['num'] ? ceil($data['num']/$data['pagesize']) : 0 ;  //计算总页数
        $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
        $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page'];  //判断跳转页数
        $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量
        $data['message'] = $this->user_model->getmessagebyuid($this->user_id,$data['offset'],$data['pagesize']);


		//BI统计 ----- start----->
		 
		$data['isa_website'] = '2,19,82';
	    $data['isa_city'] = GB_CITY;
	    $data['isa_addones'] = '';
	    $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
		//BI统计 ----- ent----->
        $this->load->view('mymessage',$data);
    }


    function updateread()
    {
	  $ids = $this->input->post("ids");
	  if(!empty($ids))
	  {
        $id_arr = explode(',',$ids);
		foreach($id_arr as $value)
		{
		  $result = $this->user_model->updateannounce($value);
		}
	  }else{
        $result = $this->user_model->updateannounce($this->input->post("id"));
	  }
      echo $result;
    }


    /**
    * 我的房源二手房
    * @author cxf
    */
    function myhousesell()
    {
     $data['conf_where'] = 'housesell';
     $data['title'] = '我的房源';
     if($_POST)
      {
         $id = $this->input->post('id');
         $type = $this->input->post('type');
         $code = $this->input->post('code');
         $infotype = $this->input->post('infotype');
         $payday = $this->input->post('payday');
         $paytype = $this->input->post('paytype');
         //推广处理
         if($type =='tg'){
              //更新房源状态,改为有意向
              $result = $this->house_model->updatehouse($id,'sell',array('ischarge'=>'2'));
              //记录客户意向
              $result1 = $this->user_model->addusercharge($id, $paytype , $payday,$this->user_id );
              if($result1>0)
                {
                  //发送消息
                  $subject='您的房源推广申请已提交。';
                  $msg='您编号为"'.$id.'"的房源推广申请正在审核中，请耐心等待。';
                  $this->apply_class->send_systemmsg($this->user_id,$subject,$msg,1,GB_CITY);
                 //添加成功
                 echo '1';exit;
                }else{
                //添加失败
                 echo '3';exit;
                }
            }
         //验证
         if(md5($id.'house365')==$code)
         {
            if($type =='refresh')
            {
              //验证刷新可用次数
                $num = $this->house_model->yzrefrshnum($this->user_id,$id,'sell');

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

                //获得实际可刷新次数
                $num = $num - count($arr);
                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(GB_CITY);
                 $result = $this->house_statistic_model->sub_operate_log('sell' , $id , 2 );
                    if($result['is_ok'] == 1)
                    {
                     //发送消息
                     $subject='您的房源刷新成功';
                     $msg='您编号为"'.$id.'"房源刷新成功。如有疑问，请联系客服。';
                     $this->apply_class->send_systemmsg($this->user_id,$subject,$msg,1,GB_CITY);
                     //刷新成功
                     $arr1['msg'] = 1;
                     $arr1['num'] = $num-1;
                     print json_encode($arr1);exit;
                    }else{
                      //刷新失败
                     $arr1['msg'] = 4;
                     $arr1['num'] = $num;
                     print json_encode($arr1);exit;
                    }
                }else{
                //刷新次数不足
                     $arr1['msg'] = 3;
                     $arr1['num'] = $num;
                     print json_encode($arr1);exit;
                }

            }elseif($type =='del'){
              //更新房源状态,相当于失效状态
              $result = $this->house_model->updatehouse($id,'sell',array('esta'=>'2'));
              //记录再发布操作
              $this->house_statistic_model->set_uid($this->user_id);
              $this->house_statistic_model->set_city(GB_CITY);
              $result1 = $this->house_statistic_model->sub_operate_log('sell' , $id , 3 );
              if($result>0)
                {
                 //删除成功
                 echo '1';
				 exit;
                }else{
                //删除失败
                 echo '3';
				 exit;
                }
            }
			elseif($type =='again_pub')
			{
				//更新房源状态
				if(GB_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($id,'sell',array('esta'=>'1','creattime'=>time(),'updatetime'=>time(),'expiretime'=>$expiretime));

				//记录再发布操作
				$this->house_statistic_model->set_uid($this->user_id);
				$this->house_statistic_model->set_city(GB_CITY);
				$result1 = $this->house_statistic_model->sub_operate_log('sell' , $id , 5 ,1);
              if($result>0)
                {
                 //再发布成功
                 echo '1';exit;
                }else{
                //再发布失败
                 echo '3';exit;
                }
            }else{
            //验证不通过，来源不正确
            echo '2';exit;
            }
           }else{
           //验证不通过，来源不正确
           echo '2';exit;
           }
      }
     $data['num'] = $this->house_model->gethousenumbyuid($this->user_id,'sell');
     $data['pagesize'] = 8;//设定每一页显示的记录数
     $data['pages'] = $data['num'] ? ceil($data['num']/$data['pagesize']) : 0 ;  //计算总页数
     $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
     $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page'];  //判断跳转页数
     $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量
     //获取房源
     $data['house_array'] = $this->house_model->gethousebyuid($this->user_id,'sell',array('id','address','buildarea','price','updatetime','creattime','esta','ischarge','pic1','district','streetid','blockshowname','infotype','room','hall','fitment','buildarea','ischarge','telno','floor ','subfloor','totalfloor'),$data['offset'],$data['pagesize']);
	
     //中奖通知  5.25-8.31
	 $data['is_win'] = $this->_get_is_win();

	 //BI统计 ----- start----->
		 
	 $data['isa_website'] = '2,19,72';
	 $data['isa_city'] = GB_CITY;
	 $data['isa_addones'] = '';
	 $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
	 //BI统计 ----- ent----->

     $this->load->view('myhousesell',$data);
     }


    /**
    * 我的房源二手房
    * @author cxf
    */
    function myhouserent()
    {
         global $house;
         $data['conf_where'] = 'houserent';
         $data['title'] = '我的房源';
          if($_POST)
          {
             $id = $this->input->post('id');
             $type = $this->input->post('type');
             $code = $this->input->post('code');
             $infotype = $this->input->post('infotype');
             $payday = $this->input->post('payday');
             $paytype = $this->input->post('paytype');
             //推广处理
             if($type =='tg'){
                  //更新房源状态,改为有意向
                  $result = $this->house_model->updatehouse($id,'rent',array('ischarge'=>'2'));
                  //记录客户意向
                  $result1 = $this->user_model->addusercharge($id, $paytype , $payday,$this->user_id,'rent' );
                  if($result1>0)
                    {
                      //发送消息
                      $subject='您的房源推广申请已提交。';
                      $msg='您编号为"'.$id.'"的房源推广申请正在审核中，请耐心等待。';
                      $this->apply_class->send_systemmsg($this->user_id,$subject,$msg,1,GB_CITY);
                     //添加成功
                     echo '1';exit;
                    }else{
                    //添加失败
                     echo '3';exit;
                    }
                }
             //验证
             if(md5($id.'house365')==$code)
               {
                if($type =='refresh')
                {
                   //验证刷新可用次数
                    $num = $this->house_model->yzrefrshnum($this->user_id,$id,'rent');
                    //获取今日已刷新次数
                    $this->house_statistic_model->set_uid($this->user_id);
                    $this->house_statistic_model->set_city(GB_CITY);
                    $this->house_statistic_model->set_nocache(1);
                    $arr = $this->house_statistic_model->get_operate_list(2,$id,date("Y-m-d"));
                    //获得实际可刷新次数
                    $num = $num - count($arr);
                    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(GB_CITY);
                     $result = $this->house_statistic_model->sub_operate_log('rent' , $id , 2,1);
                            if($result['is_ok'] == 1)
                            {
                             //发送消息
                             $subject='您的房源刷新成功';
                             $msg='您编号为"'.$id.'"房源刷新成功。如有疑问，请联系客服。';
                             $this->apply_class->send_systemmsg($this->user_id,$subject,$msg,1,GB_CITY);
                              //刷新成功
                             $arr1['msg'] = 1;
                             $arr1['num'] = $num-1;
                             print json_encode($arr1);exit;
                            }else{
                              //刷新失败
                             $arr1['msg'] = 4;
                             $arr1['num'] = $num;
                             print json_encode($arr1);exit;
                            }
                        }else{
                        //刷新次数不足
                             $arr1['msg'] = 3;
                             $arr1['num'] = $num;
                             print json_encode($arr1);exit;
                        }

                }elseif($type =='del'){
                  //更新房源状态
                  $result = $this->house_model->updatehouse($id,'rent',array('esta'=>2));
                  //记录再发布操作
                  $this->house_statistic_model->set_uid($this->user_id);
                  $this->house_statistic_model->set_city(GB_CITY);
                  $result1 = $this->house_statistic_model->sub_operate_log('rent' , $id , 3 );
                  if($result>0)
                    {
                     //删除成功
                     echo '1';exit;
                    }else{
                    //删除失败
                     echo '3';exit;
                    }
                }
				elseif($type =='again_pub')
				{
                  //更新房源状态
				  if(GB_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($id,'rent',array('esta'=>1,'creattime'=>time(),'updatetime'=>time(),'expiretime'=>$expiretime));

                  //记录再发布操作
                  $this->house_statistic_model->set_uid($this->user_id);
                  $this->house_statistic_model->set_city(GB_CITY);
                  $result1 = $this->house_statistic_model->sub_operate_log('rent' , $id , 5 );
                  if($result>0)
                    {
                     //再发布成功
                     echo '1';exit;
                    }else{
                    //再发布失败
                     echo '3';exit;
                    }
                }else{
                //验证不通过，来源不正确
                echo '2';exit;
                }
               }else{
               //验证不通过，来源不正确
               echo '2';exit;
               }
          }
         $data['num'] = $this->house_model->gethousenumbyuid($this->user_id,'rent');
         $data['pagesize'] = 8;//设定每一页显示的记录数
         $data['pages'] = $data['num'] ? ceil($data['num']/$data['pagesize']) : 0 ;  //计算总页数
         $data['page'] = $this->uri->segment(3) ? intval($this->uri->segment(3)) :1 ; // 获取当前页数
         $data['page'] = ($data['page']>$data['pages'] && $data['pages']!=0) ? $data['pages'] : $data['page'];  //判断跳转页数
         $data['offset'] = $data['pagesize']*($data['page']-1);   //计算记录偏移量
         //获取房源
         $data['house_array'] = $this->house_model->gethousebyuid($this->user_id,'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'),$data['offset'],$data['pagesize']);
         $data['priceunit'] = $house['priceunit'];

         //中奖通知  5.25-8.31
	     $data['is_win'] = $this->_get_is_win();

		 //BI统计 ----- start----->
		 
		 $data['isa_website'] = '2,19,73';
		 $data['isa_city'] = GB_CITY;
		 $data['isa_addones'] = '';
		 $data['isa_url'] = 'isa.house365.com/js/analyze.js?v=2.1';
		 //BI统计 ----- ent----->

         $this->load->view('myhouserent',$data);
    }
	
    /**
     * 获取当前会员是否获取奖品
	 *
	 */
    private function _get_is_win()
	{
		$result = false;

		if(GB_CITY == 'nj'){
			$time = time();
			$start_date = mktime(0,0,0,5,25,date('Y'));
			$end_date = mktime(23,59,59,12,23,date('Y'));
			
			if($start_date <= $time && $time <= $end_date)
			{
				$user_data = $this->user_model->get_user_data($this->user_id);
				
				if(!empty($user_data) && !empty($user_data['telno']))
				{
					$result = $this->user_model->check_is_win($this->user_id,$user_data['telno'],$start_date,$end_date);						
				}
			}
		}

		return $result;
	}

    //价格提醒处理ajax
	function price_remind_ajax(){
		error_reporting(7);
            ini_set("display_errors",true);
      $this->load->model("user_xue_model");
		
		 $houseid = $this->input->post('houseid');
		 $type = $this->input->post('type');
		 $flag = $this->input->post('flag');
		 $priceRemindNum = $this->user_xue_model->getPriceRemindNum($this->user_id);
		
		 if($priceRemindNum>=5&&$flag==1){//满4条提示
			 $result = 3;		 
		 }else{
			 $isChoice = $this->user_xue_model->isCheckPriceRemind($this->user_id,$houseid);
			 //var_dump($isChoice);exit();
			 if(is_array($isChoice)){
				
				 if(empty($isChoice)&&$flag==1){
					 $result = $this->user_xue_model->addPriceRemind($houseid,$this->user_id);	
					 //echo "444";
				 }elseif($isChoice[0]['status']==1&&$flag==0){
					 $result = $this->user_xue_model->updatePrcieRemind($houseid,$this->user_id,0);	
					
				 }elseif($isChoice[0]['status']==0&&$flag==1){
					$result = $this->user_xue_model->updatePrcieRemind($houseid,$this->user_id,1);		 
				 }
			 
			 }
		 
		 
		 }
		
		 
		 echo $result = $result ? $result :0;

	}




	function test(){
	
	teste();
	}
}