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

class Usertest extends MY_Controller
{

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

      $this->load->model("user_model");
      $this->load->model("test_model");
      $this->load->model("broker_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);
    }



  


   






   /**
    * 我的关注学区页面
    * @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_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->test_model->getCollectSchoolList(7,$this->user_id,$data['offset'],$data['pagesize']);  
		//获取你可能感兴趣的二手房
        $data['likesell'] = $this->test_model->getLikeSchoolHouse($this->user_id);		
        $this->load->view('my_attention_school',$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'];
         $this->load->view('myhouserenttest',$data);
    }
    
	
  
	

}