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


/**
 * 个人中心——基本资料管理
 */
class ucenter_information extends MY_Controller{
    /**
     * 解析函数
     *
     * @access public
     * @return void
     */
    public function __construct() {
        parent::__construct();
        $this->config_cityflag = 'nj';
        $this->load->model('broker_model');
        $this->growthCreditWayPackage = new GrowthCreditWayPackage();
        $this->growthExpWayPackage = new GrowthExpWayPackage();
        $this->load->model('pic_model');
		$this->load->helper('common_string');
    }
    
    public function index(){      

        /*ini_set('error_reporting',E_ALL);
        ini_set('display_errors',true);*/
        //获取个人信息        
        $session_info = $this->broker_model->get_user_session();	
 
        $groupId = $session_info['package_id'];//套餐
        $brokerType = $session_info['groupid'];//免费or付费
        
        $broker_info = $this->broker_information($session_info['uid']);//经纪人基本信息   
        $broker_info['agent_url'] = $session_info['agent_url'];//店铺url
        //套餐信息
        $broker_package_info = $this->broker_package($groupId);      
   
        //读取公司信息
        $broker_company_info = $this->broker_company_info($session_info['uid']);
		
		//$broker_company_info['agentshortname'] ='';
        //头像信息
        $smallphoto = $session_info["smallphoto"] != "" ? $session_info["smallphoto"] : 'http://esf.fz.house365.com/zsb/images/v1.0/defaultface.jpg';
        
		//2015 8-18 zhou 头像审核状态 0审核未通过 1审核通过 --------  start ---------->
		
		$statusHeadPic = $this->broker_model->statusHeadPic($session_info['uid']);
		
		//2015 8-18 zhou 头像审核状态  --------  end ---------->

		 // 2016-1-14 添加星级数据 -----------start -------->
	
		$broker_new_info =$this->broker_model->get_broker_info_by_uid($session_info['uid']);
		if(isset($_GET['test']))
		{
			echo "222";
		}
		// 2016-1-14 添加星级数据 -----------end -------->

        //经纪人等级
        $broker_level = $this->broker_levle($session_info['uid']);
        //经纪人身份证认证可以领到的房豆
        $id_cert_credit = $this->id_cert_credit($groupId);
        //经纪人身份证认证可以领到的成长值
        $id_cert_exp = $this->id_cert_exp($groupId);
        //经纪人名片认证可领到的房豆
        $bcard_cert_credit = $this->bcard_cert_credit($groupId);
        //经纪人名片认证可领到的成长值
        $bcard_cert_exp = $this->bcard_cert_exp($groupId);
        //经纪人证书认证可领到的房豆
        $occup_cert_credit = $this->occup_cert_credit($groupId);
        //经纪人证书认证可领到的成长值
        $occup_cert_exp = $this->occup_cert_exp($groupId);
        
		//判断身份证认证
        $id_certificate = $this->broker_model->get_certificate_info('idcard',$session_info['uid']);        
        //判断名片认证
        $bus_certificate = $this->broker_model->get_certificate_info('buscard',$session_info['uid']);    
        //判断职业认证
        $occup_certificate = $this->broker_model->get_certificate_info('occup',$session_info['uid']);

        //明示牌认证
        $express_certificate = $this->broker_model->get_certificate_info('express_card',$session_info['uid']);

        //房源核心数组
        $house = $this->config->item('house');
        $data = array();
        $data['page_title'] = '租售宝-个人中心-基本资料';
        $data['css'] = load_css('zsb/css/v1.0/style1.css,zsb/css/v1.0/jquery.Jcrop.css'); //需要加载的css
        $data['js'] = load_js('zsb/js/v1.0/jquery.validate.min.js,zsb/js/v1.0/messages_zh.js.js,zsb/js/v1.0/jquery.Jcrop.min.js,zsb/js/v1.0/js2.js');   //需要加载的css
        
        $data['broker_info'] = $broker_info;
		$data['broker_new_info'] = $broker_new_info;
        $data['brokerType'] = $brokerType;
        $data['broker_package_info'] = $broker_package_info;
        $data['broker_company_info'] = $broker_company_info;
        $data['id_certificate'] = $id_certificate;
        $data['bus_certificate'] = $bus_certificate;
        $data['occup_certificate'] = $occup_certificate;
        $data['smallphoto'] = $smallphoto;
        $data['broker_level'] = $broker_level;
        $data['id_cert_credit'] = $id_cert_credit;
        $data['id_cert_exp'] = $id_cert_exp;
        $data['bcard_cert_credit'] = $bcard_cert_credit;
        $data['bcard_cert_exp'] = $bcard_cert_exp;
        $data['occup_cert_credit'] = $occup_cert_credit;
        $data['occup_cert_exp'] = $occup_cert_exp;
        $data['express_certificate'] = $express_certificate;
        $data['house'] = $house;
		$data['session_info'] = $session_info;	
		$data['statusHeadPic'] = $statusHeadPic;
       // $this->load->view( 'ucenter/my_information', $data);
	    $data['google_analytics'] = get_ga_js_code('/个人中心/基本资料管理/');
        $this->view('ucenter', 'ucenter/my_information', $data);
     
        
        
        
    }
    
    
    //头像上传
    public function headUpload(){
		 
         $this->pic_model->set_filename("headfile");
         $this->pic_model->set_resize_width(340);
         $this->pic_model->set_resize_height(220);
		 
         $fileurl = $this->pic_model->common_upload();
		// echo $fileurl;die;
        //die("111");
	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.showCallbackMsg('jsDialogE_msg','pic_upload_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
	}
    }
    
    //头像保存
    public function headSave()
    {
        $headpic = trim($this->input->post('headpic',TRUE));
        $x = floatval($this->input->post('x',TRUE));
        $y = floatval($this->input->post('y',TRUE));
        $w = floatval($this->input->post('w',TRUE));
        $h = floatval($this->input->post('h',TRUE));

        $picfile = curl_get_contents($headpic);
        if($picfile)
        {
            $targ_w = $w;
            $targ_h = $h;
            $jpeg_quality = 100;		
            //获取远程图片再裁剪处理，本地创建临时文件，然后还要FTP上传到图片服务器
            $session_info = $this->broker_model->get_user_session();
            $filename = $this->config_cityflag."_".$session_info['uid']."_".md5($headpic).".jpg";
            $cachefile = "./cache/pic_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->pic_model->set_filename("headfile");
                $this->pic_model->set_resize_width(340);
                $this->pic_model->set_resize_height(220);
                $headpicurl = $this->pic_model->common_upload();
                
                @unlink($cachefile);

                if($headpicurl != "")
                {
                    //先处理待审核的
                    $this->broker_model->check_certificate($session_info['uid'],'p_1',0,2,'本人重新提交');
                    //添加记录
                    $id = $this->broker_model->add_certificate($session_info['uid'],'p_1',$headpicurl);
                    
                    if($id > 0)
                    {
                        $this->broker_model->reset_user_session();

                        echo "<script>window.parent.showCallbackMsg('jsDialogT_msg','head_set_success');window.parent.openWin('jsDialogT');</script>";
                    }
                    else
                    {
                        echo "<script>window.parent.showCallbackMsg('jsDialogE_msg','head_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
                    }
                }
                else
                {
                    echo "<script>window.parent.showCallbackMsg('jsDialogE_msg','head_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
                }
            }
            else
            {
                echo "<script>window.parent.showCallbackMsg('jsDialogE_msg','head_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
            }
        }
        else
        {
            echo "<script>window.parent.showCallbackMsg('jsDialogE_msg','head_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
        } 
    }
    
    //身份证上传
    public function idCardUpload(){        
        $this->pic_model->set_filename("idcardfile");
        $this->pic_model->set_image_width(640);
        $this->pic_model->set_image_height(480);
        $this->pic_model->set_resize_width(340);
        $this->pic_model->set_resize_height(220);
        $fileurl = $this->pic_model->common_upload();
	if($fileurl)
	{
		//$bigpicurl = str_replace("/thumb", "", $fileurl);
		$bigpicurl = pic_thumbTobig($fileurl);
		$imghtml = '<div style="width:320px;text-align:center;"><a href="'.$bigpicurl.'" target="_blank"><img src="'.$fileurl.'" /></a></div>';
		echo "<script>window.parent.document.getElementById('idCardShowPic').innerHTML='".$imghtml."';window.parent.document.getElementById('idcardpic').value='".$bigpicurl."';window.parent.changeShowPic('idCardShowPic');</script>";
	}
	else
	{
		echo "<script>window.parent.document.getElementById('jsIdentityAuthentication').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','pic_upload_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
	}

	exit;
        
    }
    
    //身份证保存
    public function idCardSave()
    {       
        $idcardno = trim($this->input->post('idcard',TRUE));
	    $idcardpic = trim($this->input->post('idcardpic',TRUE));
        $session_info = $this->broker_model->get_user_session();
        if($idcardpic == "")
        {
            echo "<script>window.parent.document.getElementById('jsBusinessCard').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','idcard_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
            exit;
        }       

        //先处理待审核的
        $this->broker_model->check_certificate($session_info['uid'],'p_2',0,2,'本人重新提交');
        //添加记录
        $id = $this->broker_model->add_certificate($session_info['uid'],'p_2',$idcardpic);

        if($id > 0)
        {
            $this->broker_model->set_broker_info($session_info['uid'],array("idno"=>$idcardno));
            $this->del_broker_cache($session_info['uid']);

            echo "<script>window.parent.showCallbackMsg('jsDialogT_msg','idcard_set_success');window.parent.openWin('jsDialogT');setTimeout(function(){window.parent.location.href='/ucenter_information/index/';}, 1500);</script>";
        }
        else
        {
            echo "<script>window.parent.document.getElementById('jsBusinessCard').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','idcard_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
        }
	
    }
    
    //名片上传
    public function busCardUpload(){
        $this->pic_model->set_filename("buscardfile");
        $this->pic_model->set_image_width(640);
        $this->pic_model->set_image_height(480);
        $this->pic_model->set_resize_width(340);
        $this->pic_model->set_resize_height(220);
        $fileurl = $this->pic_model->common_upload();
		

	if($fileurl)
	{
		//$bigpicurl = str_replace("/thumb", "", $fileurl);
		$bigpicurl = pic_thumbTobig($fileurl);
		$imghtml = '<div style="width:320px;text-align:center;"><a href="'.$bigpicurl.'" target="_blank"><img src="'.$fileurl.'" /></a></div>';
		echo "<script>window.parent.document.getElementById('buscardShowPic').innerHTML='".$imghtml."';window.parent.document.getElementById('buscardpic').value='".$bigpicurl."';window.parent.changeShowPic('buscardShowPic');</script>";
	}
	else
	{
		echo "<script>window.parent.document.getElementById('jsBusinessCard').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','pic_upload_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
	}
        
    }
    
    //名片保存
    public function busCardSave(){
        $buscardpic = trim($this->input->post('buscardpic',TRUE));
        $session_info = $this->broker_model->get_user_session();
      
	
	if($buscardpic == "")
	{
		echo "<script>window.parent.document.getElementById('jsBusinessCard').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','businessCard_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
		exit;
	}
        //先处理待审核的
        $this->broker_model->check_certificate($session_info['uid'],'p_3',0,2,'本人重新提交');
        //添加记录
        $id = $this->broker_model->add_certificate($session_info['uid'],'p_3',$buscardpic);
	if($id > 0)
	{
		echo "<script>window.parent.showCallbackMsg('jsDialogT_msg','businessCard_set_success');window.parent.openWin('jsDialogT');setTimeout(function(){window.parent.location.href='/ucenter_information/index/';}, 1500);</script>";
	}
	else
	{
		echo "<script>window.parent.document.getElementById('jsBusinessCard').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','businessCard_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
	}
        
    }
    
    //职业认证上传
     public function occupCardsUpload(){
        $this->pic_model->set_filename("accardfile");
        $this->pic_model->set_image_width(640);
        $this->pic_model->set_image_height(480);
        $this->pic_model->set_resize_width(340);
        $this->pic_model->set_resize_height(220);
        $fileurl = $this->pic_model->common_upload();
        if($fileurl)
        {
            //$bigpicurl = str_replace("/thumb", "", $fileurl);
            $bigpicurl = pic_thumbTobig($fileurl);
            $imghtml = '<div style="width:320px;text-align:center;"><a href="'.$bigpicurl.'" target="_blank"><img src="'.$fileurl.'" /></a></div>';
            echo "<script>window.parent.document.getElementById('accardShowPic').innerHTML='".$imghtml."';window.parent.document.getElementById('accardpic').value='".$bigpicurl."';window.parent.changeShowPic('accardShowPic');</script>";
        }
        else
        {
            echo "<script>window.parent.document.getElementById('jsAuthenticationProfession').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','pic_upload_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
        }
        
    }    
    
    //职业认证保存
    public function occupCardSave(){
        $accardpic = trim($this->input->post('accardpic',TRUE));
        $session_info = $this->broker_model->get_user_session();        
       
	if($accardpic == "")
	{
            echo "<script>window.parent.document.getElementById('jsAuthenticationProfession').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','accard_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
	    exit;
	}

        
         //先处理待审核的
        $this->broker_model->check_certificate($session_info['uid'],'p_4_1',0,2,'本人重新提交');
        //添加记录
        $id = $this->broker_model->add_certificate($session_info['uid'],'p_4_1',$accardpic);

	if($id > 0)
	{
	    echo "<script>window.parent.showCallbackMsg('jsDialogT_msg','accard_set_success');window.parent.openWin('jsDialogT');setTimeout(function(){window.parent.location.href='/ucenter_information/index/';}, 1500);</script>";
	}
	else
	{
	    echo "<script>window.parent.document.getElementById('jsAuthenticationProfession').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','accard_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
	}
        
    }
    
    //获取手机验证码
    public function get_phone_code(){
        $session_info = $this->broker_model->get_user_session();
        $newphone = trim($this->input->get('newphone'));
	$oldphone =  trim($this->input->get('oldphone'));

	//验证新输入的手机号和原来的手机号是否相等
	if( $newphone == $oldphone){
            echo "4";
	    exit;
	}
        
	
	
        //一天只能修改一次
	$check_today = $this->broker_model->change_phone_num($session_info['uid']); 
	if($check_today>0){
            echo "5";
	    exit;
	}
        //获得今天已经获得验证码的次数,限制每天获得验证码的次数不得超过3次
	$num_today = $this->broker_model->get_certifycode_num($session_info['uid']);
	if( $num_today < 3){
            //查看60秒内是否已经获得了随机验证码，如果有则提示稍后再试！		
	    $num_second = $this->broker_model->is_get_certifycode($newphone); 
	    if($num_second <= 0){
                /*第一步：先把用户id 、随机验证码产生，插入数据库*/
                $certifycode = random(6);//获得随机验证码
                $flag = $this->broker_model->add_certifycode($session_info['uid'],$newphone,$certifycode);
                if($flag){ 
                    /*第二步：像用户填写的手机发送短信，把验证码发送给用户*/                  
                    $message = "您操作的验证码为".$certifycode."，请在收到后两分钟内提交。";//短息内容
                    send_sms($newphone,$message,'sx',$certifycode); //发送短信
                    echo "1";//成功
                    exit;                        
                } 
            } else {
                echo "2";//每次间隔60秒
                exit;
            }
	} else {
            echo "3";//每天3次
            exit;
	}
    }


    //手机信息保存
    public function save_phone(){
        $session_info = $this->broker_model->get_user_session();
        $newphone = trim($this->input->post('newphone'));
	$oldphone = trim($this->input->post('oldphone'));
	$phonecode = trim($this->input->post('phonecode'));
	if($newphone == ""){
            echo "0";
	    exit;
	}

	if($newphone == $oldphone){
            echo "2";
	    exit;
	}

	if(!$phonecode || !preg_match("/^\\d{6}$/", $phonecode)) {
	    echo "3";exit;
	} else {            
            $result = $this->broker_model->change_phone_num($session_info['uid']);
            if($result>0){
                echo "4";//一天只能修改一次
		exit;
	    }
	   
            $row = $this->broker_model->get_certifycode($session_info['uid'],$newphone);
            
	    if(empty($row)){
                echo "5";//验证码过期
	        exit;
	    }

	    if($phonecode != $row["validcode"]){
                //echo "验证码输入错误"; 
		echo "3";exit;
	    }elseif($newphone!=$row["mobile"]){
	        echo "5";exit;
	    }else{
                $flag = $this->broker_model->set_broker_info($session_info['uid'],array("telno"=>$newphone));  
               
                if($flag){
                    //修改房源联系号码
                    $this->load->model('sell_model');
                    $this->sell_model->update_sell_mobile($session_info['uid'],$newphone);
                    $this->load->model('rent_model');
                    $this->rent_model->update_rent_mobile($session_info['uid'],$newphone);
                    //修改验证码状态
                    $this->broker_model->update_certifycode($row['id']);      
                    //失效名片认证
                    $this->broker_model->check_certificate($session_info['uid'],'p_3',1,2,'修改手机号码，名片认证失效');
                    $this->broker_model->set_broker_info($session_info['uid'],array("p_3_pic"=>""));

                    //$session_info['telno'] =  $newphone;
                    $this->del_broker_cache($session_info['uid']);
                   // $this->broker_model->reset_user_session();   //可能没用                
					//$session_key = $this->broker_model->get_appkey();
					//$this->session->set_userdata(array($session_key => $session_info));//修改session信息
                    $this->update_session_info($session_info,'telno',$newphone);
                    echo "1";exit;
                }else{
                        echo "6";exit;
                }
	   }
	}
	exit;
    }
    
    //修改登录密码
    public function save_pwd(){
        $session_info = $this->broker_model->get_user_session();
        $oldpwd = $this->input->post('oldpwd',TRUE);
        $newpwd = $this->input->post('newpwd',TRUE);
        $newpwd2 = $this->input->post('newpwd2',TRUE);     
	
	if($oldpwd == ""){
            echo "2";
	    exit;
	}

	if($newpwd == ""){
            echo "3";
	    exit;
	}

	if($newpwd != $newpwd2){
            echo "4";
	    exit;
	}

	$oldpassword = $this->encrypt_pwd($oldpwd);
	$newpassword = $this->encrypt_pwd($newpwd);
        $this->broker_model->set_uid($session_info['uid']);
        $broker_info = $this->broker_model->get_broker_detail();
        
	$oldpwd = $broker_info['password'];
	if($oldpassword == $oldpwd){
            $flag = $this->broker_model->set_broker_info($session_info['uid'],array("password"=>$newpassword));
	    if($flag){
                echo "1";

            $this->broker_model->saveChangePasswordLog($newpassword, $broker_info['uid'], $broker_info['username']);


	    }else{
                echo "2";
	    }
	}
	else{
            echo "2";
	}
	
	exit;
    }
    
    
    //修改身份证号码
    public function save_idcard(){
        return;//注释此功能
        $session_info = $this->broker_model->get_user_session();
        $idcardno = $this->input->post('idcardno',TRUE);
        $flag = $this->broker_model->set_broker_info($session_info['uid'],array("idno"=>$idcardno));
        $this->del_broker_cache($session_info['uid']);
		$this->update_session_info($session_info,'idno',$idcardno);
        if($flag){
            echo "1";
        }
        else{
            echo "2";
        }
	    exit;
    }


    public function save_alipay(){
        $session_info = $this->broker_model->get_user_session();

        $alipay_acount = '';
        if(!empty($session_info['alipay_acount'])){
            $alipay_acount = $session_info['alipay_acount'];
        }
        $before_account = $alipay_acount;

        $alipay_acount = $this->input->post('alipay_acount',TRUE);
        $flag = $this->broker_model->set_broker_info($session_info['uid'],array("alipay_acount"=>$alipay_acount));
        $this->del_broker_cache($session_info['uid']);
        $this->update_session_info($session_info,'alipay_acount',$alipay_acount);

        if($flag){
            $this->broker_model->save_alipay_log($before_account,$alipay_acount);
            echo "1";

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




    //修改email
    public function save_email(){
        $session_info = $this->broker_model->get_user_session();
        $email = $this->input->post('email',TRUE);      
        $flag = $this->broker_model->set_broker_info($session_info['uid'],array("email"=>$email));
	    $this->del_broker_cache($session_info['uid']);
	    $this->update_session_info($session_info,'email',$email);
	if($flag){
            echo "1";
	}else{
            echo "2";
	}
	exit;
    }
    
    //修改QQ
    public function save_qq(){
        $session_info = $this->broker_model->get_user_session();
        $qq = $this->input->post('qq',TRUE);  
        $flag = $this->broker_model->set_broker_info($session_info['uid'],array("qq"=>$qq));
	    $this->del_broker_cache($session_info['uid']);
		$this->update_session_info($session_info,'qq',$qq);	 
	if($flag){
            echo "1";
	}
	else{
            echo "2";
	}
	exit;
    }
    
    //修改内部编号
    public function save_intelnal_num(){
        $session_info = $this->broker_model->get_user_session();
        $internal_number = $this->input->post('internal_number',TRUE); 
        $internal_number = iconv("UTF-8","GBK", $internal_number);
	$flag = $this->broker_model->set_broker_info($session_info['uid'],array("internal_number"=>$internal_number));
	$this->del_broker_cache($session_info['uid']);
	if($flag){
            echo "1";
	}else{
            echo "2";
	}
	exit;
    }

    //修改自身描述
    public function save_self_desc(){
        $session_info = $this->broker_model->get_user_session();
        $selfdesc = $this->input->post('selfdesc',TRUE);
        $selfdesc = iconv("UTF-8","GBK", $selfdesc);
	$selfdesc = csubstr2(strip_tags($selfdesc), 1000);
        $flag = $this->broker_model->set_broker_info($session_info['uid'],array("selfdesc"=>$selfdesc));
	    $this->del_broker_cache($session_info['uid']);
		$this->update_session_info($session_info,'selfdesc',$selfdesc);	   

	if($flag){
            echo "1";
	}else{
            echo "2";
	}
	exit;
    }
    
    //修改自身技能
    public function save_skill(){
        $session_info = $this->broker_model->get_user_session();
        $skill = $this->input->post('skill',TRUE);
        $skillval = "";        
	if(is_array($skill) && !empty($skill)){
            $skillval = implode(",", $skill);
	}
       
        $flag = $this->broker_model->set_broker_info($session_info['uid'],array("skill"=>$skillval));
	    $this->del_broker_cache($session_info['uid']);
		$this->update_session_info($session_info,'skill',$skillval);	  
	if($flag){
            echo "<script>window.parent.showCallbackMsg('jsDialogT_msg','skill_set_success');window.parent.openWin('jsDialogT');</script>";
	}else{
            echo "<script>window.parent.showCallbackMsg('jsDialogT_msg','skill_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
	}
	exit;
    }


    //经纪人信息
    private function broker_information($uid){
        $key = $this->config_cityflag.'_broker_information_by_uid_'.$uid;
      
        $data = $this->mc->get($key);
        if($data['isok']!=1){            
            $this->broker_model->set_uid($uid);
            $broker_infomation = $this->broker_model->get_broker_detail();//经纪人基本信息
            $data = array('data'=>$broker_infomation,'isok'=>1);
            $this->mc->set($key,$data,60);
        }
        return $data['data'];
    }
    
    //清除个人信息缓存
    private function del_broker_cache($uid){
        $key = $this->config_cityflag.'_broker_information_by_uid_'.$uid;
        $this->mc->delete($key);
    }

	//修改session_info值
	private function update_session_info($session_info,$key,$value){
		$session_info[$key] =  $value;	
		$session_key = $this->broker_model->get_appkey();
		$this->session->set_userdata(array($session_key => $session_info));//修改session信息
		
	}
    
    //套餐信息
    private function broker_package($groupId){
        $key = $this->config_cityflag.'_broker_package_by_'.$groupId;
        $data = $this->mc->get($key);
        if($data['isok']!=1){
            $this->load->model('broker_package_model');
            $broker_package_info = $this->broker_package_model->find_by_id($groupId);
            $data = array('data'=>$broker_package_info,'isok'=>1);
            $this->mc->set($key,$data,600);
        }
        return $data['data'];
    }
    
    //所属公司信息
    private function broker_company_info($uid){
        $key = $this->config_cityflag.'_broker_company_info_'.$uid;
        $data = $this->mc->get($key);
        if($data['isok']!=1){
            $broker_company = $this->broker_model->get_broker_company($uid);
            $data = array('data'=>$broker_company,'isok'=>1);
            $this->mc->set($key,$data,600);
        }
        return $data['data'];
    }
    
    //经纪人等级
    private function broker_levle($uid){
        $key = $this->config_cityflag.'_growth_broker_level'.$uid;
        $growthExp = new GrowthExp();
	$brokerExp = $growthExp->findOneByBrokerId($uid);
	$brokerExp['exp'] = isset($brokerExp['exp']) ? $brokerExp['exp'] : 0;        
        $brokerLevel = $this->mc->get($key);
        if( $brokerLevel === false ){
            $growthLevel = new GrowthLevel();
            $brokerLevel = $growthLevel->findLevelNameByExp($brokerExp['exp']);
            $this->mc->set($key,$brokerLevel,600);	
	}
        return $brokerLevel;
    }
    
    //经纪人身份认证可领到的房豆
    private function id_cert_credit($groupId){
	$key = $this->config_cityflag.'_growth_credit_way_alias_package_idCert'.$groupId;
        $idCertCredit = $this->mc->get($key);
	if($idCertCredit === false){
            $idCertCredit = $this->growthCreditWayPackage->getScoreByWayAliasAndPackageId('idCert',$groupId);
            $this->mc->set($key,$idCertCredit,6000);
	}
        return $idCertCredit;
    }
    //经纪人身份认证可领到的成长值
    private function id_cert_exp($groupId){       
        $key = $this->config_cityflag.'_growth_exp_way_alias_package_iDCert'.$groupId;
        $idCertExp = $this->mc->get($key);
	if($idCertExp === false){
		$idCertExp = $this->growthExpWayPackage->findScoreByWayAliasAndPackageId('iDCert',$groupId);
		$this->mc->set($key,$idCertExp,6000);
	}
        return $idCertExp;
    }
    
    //经纪人名片认证可以领到的房豆
    private function bcard_cert_credit($groupId){
        $key = $this->config_cityflag.'_growth_credit_way_alias_package_bCardCert'.$groupId;
	$bCardCertCredit = $this->mc->get($key);
	if($bCardCertCredit === false){
	    $bCardCertCredit = $this->growthCreditWayPackage->getScoreByWayAliasAndPackageId('bCardCert',$groupId);
	    $this->mc->set($key,$bCardCertCredit,6000);
	}
        return $bCardCertCredit;
    }
    
    //经纪人名片认证可以领到的成长值
    private function bcard_cert_exp($groupId){
        $key = $this->config_cityflag.'_growth_exp_way_alias_package_bCardCert'.$groupId;
	$bCardCertExp = $this->mc->get($key);
	if($bCardCertExp === false){
            $bCardCertExp = $this->growthExpWayPackage->findScoreByWayAliasAndPackageId('bCardCert',$groupId);
	    $this->mc->set($key,$bCardCertExp,6000);
	}
        return $bCardCertExp;
    }
    
    //经纪人职业认证可以领导的房豆
    private function occup_cert_credit($groupId){
        $key = $this->config_cityflag.'_growth_credit_way_alias_package_brokerCert'.$groupId;
	$brokerCertCredit = $this->mc->get($key);
        if($brokerCertCredit === false){
            $brokerCertCredit = $this->growthCreditWayPackage->getScoreByWayAliasAndPackageId('brokerCert',$groupId);
	    $this->mc->set($key,$brokerCertCredit,6000);
	}
        return $brokerCertCredit;
    }
    
    //经纪人职业认证可以领导的成长值
    private function occup_cert_exp($groupId){
        $key = $this->config_cityflag.'_growth_exp_way_alias_package_brokerCert'.$groupId;
	$brokerCertExp = $this->mc->get($key);
        if($brokerCertExp === false){
	    $brokerCertExp = $this->growthExpWayPackage->findScoreByWayAliasAndPackageId('brokerCert',$groupId);
	    $this->mc->set($key,$brokerCertExp,6000);
	}
        return $brokerCertExp;        
    }
    
    //md5加密
    private function encrypt_pwd($password, $key = ''){
        return md5($key.$password);
    }



    //明示牌认证上传
    public function expressCardsUpload(){
        $this->pic_model->set_filename("expressCardfile");
        $this->pic_model->set_image_width(640);
        $this->pic_model->set_image_height(480);
        $this->pic_model->set_resize_width(340);
        $this->pic_model->set_resize_height(220);
        $fileurl = $this->pic_model->common_upload();
        if($fileurl)
        {
            //$bigpicurl = str_replace("/thumb", "", $fileurl);
            $bigpicurl = pic_thumbTobig($fileurl);
            $imghtml = '<div style="width:320px;text-align:center;"><a href="'.$bigpicurl.'" target="_blank"><img style="height: 219px;" src="'.$fileurl.'" /></a></div>';
            echo "<script>window.parent.document.getElementById('expressShowPic').innerHTML='".$imghtml."';window.parent.document.getElementById('expresscardpic').value='".$bigpicurl."';window.parent.changeShowPic('expressShowPic');</script>";
        }
        else
        {
            echo "<script>window.parent.document.getElementById('jsAuthenticationProfession').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','pic_upload_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
        }

    }


    public function expressCardSave(){
        $expressCardNum = trim($this->input->post('expressCardNum',TRUE));
        $expresscardpic = trim($this->input->post('expresscardpic',TRUE));
        $session_info = $this->broker_model->get_user_session();


        if(!$expresscardpic || !$expressCardNum)
        {
            echo "<script>window.parent.document.getElementById('jsBusinessCard').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','expresscard_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
            exit;
        }

        //先处理待审核的
        $this->broker_model->check_certificate($session_info['uid'],'p_5',0,2,'本人重新提交');
        //添加记录
        $id = $this->broker_model->add_certificate($session_info['uid'],'p_5',$expresscardpic,$expressCardNum);

        if($id > 0)
        {
            $this->del_broker_cache($session_info['uid']);

            echo "<script>window.parent.showCallbackMsg('jsDialogT_msg','expresscard_set_success');window.parent.openWin('jsDialogT');setTimeout(function(){window.parent.location.href='/ucenter_information/index/';}, 1500);</script>";
        }
        else
        {
            echo "<script>window.parent.document.getElementById('jsBusinessCard').style.display = 'none';window.parent.showCallbackMsg('jsDialogE_msg','expresscard_set_fail');window.parent.openWin('jsDialogE');setTimeout(function(){window.parent.location.reload();},1500);</script>";
        }
    }

    /**
     * 修改密码页面
     * @author Livfer
     */
    public function edit_password()
    {
        $data = array();
        $data['page_title'] = '租售宝-个人中心-基本资料';
        $data['css'] = load_css('zsb/css/v1.0/style1.css,zsb/css/v1.0/jquery.Jcrop.css'); //需要加载的css
        $data['js'] = load_js('zsb/js/v1.0/jquery.validate.min.js,zsb/js/v1.0/messages_zh.js.js,zsb/js/v1.0/jquery.Jcrop.min.js,zsb/js/v1.0/js2.js');   //需要加载的css
        $this->view('ucenter', 'ucenter/edit_password',$data);
    }

}