<?php

	/***************************************************************\
	|																|
	| 开单大师（专业的房产ERP管理系统）								|
	|																|
	| © 2018 http://www.kaidandashi.com All rights reserved.		|
	|																|
	| 本系统由淮南市银泰科技软件有限公司提供技术支持				|
	|																|
	| QQ号：1264399051												|
	|																|
	\***************************************************************/

    namespace Admin\Controller;
    use Think\Controller;
    class FangyuanController extends CommonController {
        //二手房源列表
        public function Esfy(){
            if (I('is_ajax')) {
                $startUnix = strtotime(I('datetime1'));
                $endUnix = strtotime(I('datetime2'))+86399; 
                $p = I('pageSize');
                $sn = I('sortName');
                $so = I('sortOrder');
                $condition="gongsiid=".session('gongsiid');
                $condition.=" and isdel=2";
                $searchText=I('searchText');
                if (I('datetime1') and I('datetime2')) {
                    $condition.=" and lurusj >= '".$startUnix."' and lurusj<'".$endUnix."'";
                }elseif (I('datetime1')) {
                    $condition.=" and lurusj >= '".$startUnix."'";
                }elseif (I('datetime2')) {
                    $condition.=" and lurusj<'".$endUnix."'";
                }
                if ($searchText) {
                    $condition.=" and (fybiaoti like '%$searchText%' or yezhu like '%$searchText%' or weihuren like '%$searchText%' or yezhudianhua like '$searchText' or yezhudianhua2 like '$searchText' or yezhudianhua3 like '$searchText' or bianhao like '%$searchText%' or xiaoqum like '%$searchText%')";
                }
                $map = "gongsiid=".session('gongsiid');
                $x = _rbac_lists_where(903,0);
                if ($x && $x != "all" && $x != "me") {
                    $map .= " and bumen in ({$x})";
                }elseif ($x == "me") {
                    $map .= " and id=".session('uid');
                }elseif ($x == false) {
                    $map .= " and id=0";
                }
                $Model = new \Think\Model();
                $sqlcount = "select count(a.id) from (select * from __FANGYUAN__ where {$condition}) a join (select id as e_id,ygmingcheng from __YONGHU__ where {$map}) e on a.weihurenid=e.e_id ";
                $countb=$Model->query($sqlcount);
                $count=$countb[0]['count(a.id)'];
                $Page = new \Think\Page($count,$p); //实例化分页类 传入总记录数和每页显示的记录数(15)
                $show = $Page->show(); //分页显示输出
                $sql="select c.*,d.jianzaond from (select * from (select * from __FANGYUAN__ where {$condition}) a join (select id as e_id,ygmingcheng from __YONGHU__ where {$map}) e on a.weihurenid=e.e_id order by a.id DESC limit ".$Page->firstRow.','.$Page->listRows.") c left join (select id as xqid,jianzaond from __XIAOQU__ ) d on c.xiaoqu=d.xqid ";
                $arr=$Model->query($sql);
                foreach ($arr as $key => $value) {
                    if ($value['shi']) {
                        $hx1=$value['shi']."室";
                    }
                    if ($value['ting']) {
                        $hx2=$value['ting']."厅";
                    }
                    if ($value['wei']) {
                        $hx3=$value['wei']."卫";
                    }
                    if ($value['chu']) {
                        $hx4=$value['chu']."厨";
                    }
                    if ($value['yangtai']) {
                        $hx5=$value['yangtai']."阳台";
                    }
                    if ($value['shoujia'] > 0) {
                        $jiage=$value['shoujia']."万元";
                    } else if ($value['zujia'] > 0) {
                        $zjlx=M('peizhi')->where(array('pzming'=>'zujialx','lxid'=>$value['zujialx']))->getField('lxming');
                        $jiage=$value['zujia'].$zjlx;
                    }
                    $fycx=M('peizhi')->where(array('pzming'=>'chaoxiang','lxid'=>$value['chaoxiang']))->getField('lxming');
                    $fydj=M('peizhi')->where(array('pzming'=>'fydengji','lxid'=>$value['fydengji']))->getField('lxming');
                    $fyyt=M('peizhi')->where(array('pzming'=>'yongtu','lxid'=>$value['yongtu']))->getField('lxming');
                    $fyzx=M('peizhi')->where(array('pzming'=>'zhuangxiu','lxid'=>$value['zhuangxiu']))->getField('lxming');
                    $fylc=$value['louceng'].'/'.$value['zlouceng'];
                    $huxing=$hx1.$hx2.$hx3.$hx4.$hx5;
                    $arr[$key]['fylc']=$fylc;
                    $arr[$key]['fycx']=$fycx;
                    $arr[$key]['fydj']=$fydj;
                    $arr[$key]['fyyt']=$fyyt;
                    $arr[$key]['fyzx']=$fyzx;
                    $arr[$key]['jiage']=$jiage;
                    $arr[$key]['huxing']=$huxing;
                    $arr[$key]['lurusj']=date('Y-m-d H:i',$value['lurusj']);
                    $arr[$key]['qxpdxq']=_rbac_btn_show(46,0,$value['weihurenid']) == true? '1': '0';
                }
                $data=array('data'=>$arr,'total'=>$count);
                header("Content-type: application/json");
                exit(json_encode($data));
            }else{
                $this->display();
            }
        }
        //添加二手房源
        public function addEsfy(){
            $is_rbac = _rbac_btn_show(904,0);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                if (session('gongsiid')=="") {
                    $this->error('请重新登录');
                }
                $xiaoqu=I('xiaoqu');
                $xingzhengqu=M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('ssxzq');
                $pianqu=M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('sspianqu');
                $zuodong=I('zuodong');
                $danyuan=I('danyuan');
                $fanghao=I('fanghao');
                if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$zuodong)){
                    $this->error('座栋首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
                }
                if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$danyuan)){
                    $this->error('单元首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
                }
                if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$fanghao)){
                    $this->error('房号首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
                }
                $condition['gongsiid']=session('gongsiid');
                $condition['isdel']=2;
                $condition['xiaoqu']=$xiaoqu;
                $condition['zuodong']=$zuodong;
                $condition['danyuan']=$danyuan;
                $condition['fanghao']=$fanghao;
                $condition['leixing']=I('leixing');
                $cffy=M('fangyuan')->where($condition)->find();
                if($cffy){
                    $this->error('房源已存在');
                }
                $bh=M('bianhao')->where(array('id'=>1))->setInc('bianhao');
                $bh1=M('bianhao')->where(array('id'=>1))->getField('bianhao');
                $bm = M('yonghu')->where('id='.session("uid"))->getField('bumen');
                $data['bumen']=$bm;
                $data['gongsiid']=session('gongsiid');
                if (I('leixing')==1) {
                    $data['bianhao']="M-".$bh1;
                }elseif (I('leixing')==2) {
                    $data['bianhao']="Z-".$bh1;
                }
                $data['leixing']=I('leixing');
                if(I('shoujia')){
                    $data['shoujia']=I('shoujia');
                }
                if(I('chushoudj')){
                    $data['chushoudj']=I('chushoudj');
                }
                if(I('mianji')!="" and I('shoujia')!=""){
                    $num1=I('shoujia')*10000;
                    $num2=I('mianji');
                    $num=$num1/$num2;
                    $danjia=number_format($num,2,".", "");
                    $data['danjia']=$danjia;
                }
                $data['xiaoqu']=$xiaoqu;
                $data['xiaoqum']=I('xiaoqum');
                $data['pianqu']=$pianqu;
                $data['xingzhengqu']=$xingzhengqu;
                $data['zuodong']=$zuodong;
                $data['danyuan']=$danyuan;
                $data['fanghao']=$fanghao;
                $data['louceng']=I('louceng');
                $data['zlouceng']=I('zlouceng');
                $data['shi']=I('shi');
                $data['ting']=I('ting');
                $data['wei']=I('wei');
                $data['chu']=I('chu');
                $data['yangtai']=I('yangtai');
                $data['yongtu']=I('yongtu');
                $data['mianji']=I('mianji');
                $data['symianji']=I('symianji');
                $data['yezhu']=I('yezhu');
                $data['yezhulx']=I('yezhulx');
                $data['yezhudianhua']=I('yezhudianhua');
                $data['zhuangxiu']=I('zhuangxiu');
                $data['chaoxiang']=I('chaoxiang');
                $data['fwleixing']=I('fwleixing');
                $data['cqxingzhi']=I('cqxingzhi');
                $data['fydengji']=I('fydengji');
                $data['zujia']=I('zujia');
                $data['yezhugx']=I('yezhugx');
                $data['zujialx']=I('zujialx');
                $pt1=array_keys(I('peitao')); 
                $pt2=implode(',',$pt1);
                $data['peitao']=$pt2;
                $data['jiegou']=I('jiegou');
                $data['cqnianxian']=I('cqnianxian');
                $data['fyshuifei']=I('fyshuifei');
                $data['kanfangfs']=I('kanfangfs');
                $data['laiyuan']=I('laiyuan');
                $data['fukuan']=I('fukuan');
                $data['yaoshidian']=I('yaoshidian');
                $data['weihuren']=session('ygmingcheng');
                $data['weihurenid']=session('uid');
                $data['lururenid']=session('uid');
                $data['fybiaoti']=I('fybiaoti');
                $data['ti']=I('ti');
                $data['hu']=I('hu');
                $data['niandai']=I('niandai');
                $data['chuzudj']=I('chuzudj');
                $data['menweizhi']=I('menweizhi');
                $data['cheku']=I('cheku');
                $data['fwleixing']=I('fwleixing');
                $data['hezuotandan']=I('hezuotandan');
                $beizhu=preg_replace ( "/\s(?=\s)/","\\1", I('beizhu') );
                $data['beizhu']=$beizhu;
                $data['chanquanzheng']=I('chanquanzheng');
                $data['tudizheng']=I('tudizheng');
                $data['budongchanzheng']=I('budongchanzheng');
                $data['czriqi']=strtotime(I('czriqi'));
                $data['fukuanfs']=I('fukuanfs');
                if(I('wushui')){
                    $wushui=1;
                    $geshui=0;
                    $zengshui=0;
                }else{
                    $wushui=0;
                    if(I('geshui')){
                        $geshui=1;
                    }else{
                        $geshui=0;
                    }
                    if(I('zengshui')){
                        $zengshui=1;
                    }else{
                        $zengshui=0;
                    }
                }
                if(I('man5')){
                    $man5=1;
                }else{
                    $man5=0;
                }
                if(I('man2')){
                    $man2=1;
                }else{
                    $man2=0;
                }
                if(I('weiyi')){
                    $weiyi=1;
                }else{
                    $weiyi=0;
                }
                if(I('jishou')){
                    $jishou=1;
                }else{
                    $jishou=0;
                }
                if(I('quankuan')){
                    $quankuan=1;
                }else{
                    $quankuan=0;
                }
                if(I('youdaikuan')){
                    $youdaikuan=1;
                }else{
                    $youdaikuan=0;
                }
                if(I('xinzheng')){
                    $xinzheng=1;
                }else{
                    $xinzheng=0;
                }
                $data['wushui']=$wushui;
                $data['geshui']=$geshui;
                $data['zengshui']=$zengshui;
                $data['jishou']=$jishou;
                $data['quankuan']=$quankuan;
                $data['weiyi']=$weiyi;
                $data['man5']=$man5;
                $data['man2']=$man2;
                $data['youdaikuan']=$youdaikuan;
                $data['xinzheng']=$xinzheng;
                $data['lurusj']=time();
                $data['zhgjsj']=time();
                $data['xiugaisj']=time();
                $isok=M('Fangyuan')->add($data);
                if ($isok) {
                    $data_rizhi['zy_type']=1;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=1;
                    $data_rizhi['zy_id']=$isok;
                    $data_rizhi['zy_bianhao']=$data['bianhao'];
                    if ($data['leixing']==1) {
                        $neirong="新增出售房源";
                    }elseif ($data['leixing']==2) {
                        $neirong="新增出租房源";
                    }
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('添加成功');
                }else{
                    $this->error('添加失败');
                }
            }else{
                $select_categorys = bumen_option( 0, 0);
                $this->assign("select_categorys", $select_categorys);
                //配置值输出
                $this->yongtu=M('Peizhi')->where(array('pzming'=>'yongtu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->leixing=M('Peizhi')->where(array('pzming'=>'leixing','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->chaoxiang=M('Peizhi')->where(array('pzming'=>'chaoxiang','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->fwleixing=M('Peizhi')->where(array('pzming'=>'fwleixing','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->jiegou=M('Peizhi')->where(array('pzming'=>'jiegou','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->chanquan=M('Peizhi')->where(array('pzming'=>'chanquan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->kanfangfs=M('Peizhi')->where(array('pzming'=>'kanfangfs','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->laiyuan=M('Peizhi')->where(array('pzming'=>'laiyuan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                if (I('jylx')==1) {
                    $fuk = "fukuan";
                }elseif (I('jylx')==2) {
                    $fuk = "zlfukuan";
                    $this->zujialx=M('Peizhi')->where(array('pzming'=>'zujialx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                }
                $this->fukuan=M('Peizhi')->where(array('pzming'=>$fuk,'zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->yezhulx=M('Peizhi')->where(array('pzming'=>'yezhulx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->yezhugx=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->zhuangxiu=M('Peizhi')->where(array('pzming'=>'zhuangxiu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->peitao=M('Peizhi')->where(array('pzming'=>'peitao','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->iszheng=M('Peizhi')->where(array('pzming'=>'iszheng','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->fydengji=M('Peizhi')->where(array('pzming'=>'fydengji','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display();
            }
        }
        //内容页
        public function neirong(){
            $id=I('id');
            $fybh = I('bianhao');
            if ($id) {
                $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            } elseif($fybh) {
                $fangyuan=M('fangyuan')->where(array('bianhao'=>$fybh))->find();
            }
            if (!$fangyuan) {
                $this->error('异常错误!');
            }
            $is_rbac = _rbac_btn_show(905,0,$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $this->fangyuan=$fangyuan;
            $this->fydengji=M('Peizhi')->where(array('pzming'=>'fydengji','lxid'=>$fangyuan['fydengji']))->getField('lxming');
            $this->chanquanzheng=M('Peizhi')->where(array('pzming'=>'iszheng','lxid'=>$fangyuan['chanquanzheng']))->getField('lxming');
            $this->budongchanzheng=M('Peizhi')->where(array('pzming'=>'iszheng','lxid'=>$fangyuan['budongchanzheng']))->getField('lxming');
            $this->tudizheng=M('Peizhi')->where(array('pzming'=>'iszheng','lxid'=>$fangyuan['tudizheng']))->getField('lxming');
            $this->leixing=M('Peizhi')->where(array('pzming'=>'leixing','lxid'=>$fangyuan['leixing']))->getField('lxming');
            $this->yongtu=M('Peizhi')->where(array('pzming'=>'yongtu','lxid'=>$fangyuan['yongtu']))->getField('lxming');
            $this->zujialx=M('Peizhi')->where(array('pzming'=>'zujialx','lxid'=>$fangyuan['zujialx']))->getField('lxming');
            $this->chaoxiang=M('Peizhi')->where(array('pzming'=>'chaoxiang','lxid'=>$fangyuan['chaoxiang']))->getField('lxming');
            $this->zhuangxiu=M('Peizhi')->where(array('pzming'=>'zhuangxiu','lxid'=>$fangyuan['zhuangxiu']))->getField('lxming');
            $this->fwleixing=M('Peizhi')->where(array('pzming'=>'fwleixing','lxid'=>$fangyuan['fwleixing']))->getField('lxming');
            $this->jiegou=M('Peizhi')->where(array('pzming'=>'jiegou','lxid'=>$fangyuan['jiegou']))->getField('lxming');
            $this->cqxingzhi=M('Peizhi')->where(array('pzming'=>'chanquan','lxid'=>$fangyuan['cqxingzhi']))->getField('lxming');
            $this->laiyuan=M('Peizhi')->where(array('pzming'=>'laiyuan','lxid'=>$fangyuan['laiyuan']))->getField('lxming');
            $this->kanfangfs=M('Peizhi')->where(array('pzming'=>'kanfangfs','lxid'=>$fangyuan['kanfangfs']))->getField('lxming');
            $this->genjinfs=M('Peizhi')->where(array('pzming'=>'genjinfs'))->select();
            $this->jcpz=M('jcpz')->where(array('gongsiid'=>session('gongsiid')))->field('dtmiyao,dtzuobiao')->find();
            $peitao1=$fangyuan['peitao'];
            if ($peitao1) {
                $condition="pzming = 'peitao'";
                $condition.=" and lxid in ($peitao1)";
                $this->peitao=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
            }
            //录入人
            $this->lururen=M('yonghu')->where(array('id'=>$fangyuan['lururenid']))->field('ygmingcheng,dianhua')->find();
            $this->weihuren=M('yonghu')->where(array('id'=>$fangyuan['weihurenid']))->field('ygmingcheng,dianhua')->find();
            $Model = new \Think\Model;
            $this->volist = $Model->table(array('jjrxt_rizhi'=>'a','jjrxt_yonghu'=>'b'))->field('a.*,b.ygmingcheng')->where('a.uid=b.id and zy_type=1 and zy_id='.$fangyuan['id'])->order('a.id desc')->select();
            $this->xiaoqu=M('xiaoqu')->where(array('id'=>$fangyuan['xiaoqu']))->find();
            $this->display();
        }
        //更新房源
        public function xiugai(){
            $id=I('id');
            $fy1=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(906,0,$fy1['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $data['yongtu']=I('yongtu');//用途
                if(I('mianji')){
                    $data['mianji']=I('mianji');
                }
                if(I('shoujia')){
                    $data['shoujia']=I('shoujia');
                }
                if(I('symianji')){
                    $data['symianji']=I('symianji');
                }
                if(I('chushoudj')){
                    $data['chushoudj']=I('chushoudj');
                }
                if(I('mianji')!="" and I('shoujia')!=""){
                    $num1=I('shoujia')*10000;
                    $num2=I('mianji');
                    $num=$num1/$num2;
                    $danjia=number_format($num,2,".", "");
                    $data['danjia']=$danjia;
                }
                $data['zujia']=I('zujia');
                if (I('zujialx')) {
                    $data['zujialx']=I('zujialx');
                }
                if (I('chaoxiang')) {
                    $data['chaoxiang']=I('chaoxiang');
                }
                $data['zhuangxiu']=I('zhuangxiu');
                $pt1=array_keys(I('peitao')); 
                $pt2=implode(',',$pt1);
                $data['peitao']=$pt2;
                if (I('fwleixing')) {
                    $data['fwleixing']=I('fwleixing');
                }
                if (I('jiegou')) {
                    $data['jiegou']=I('jiegou');
                }
                $data['cqxingzhi']=I('cqxingzhi');
                $data['cqnianxian']=I('cqnianxian');
                if (I('kanfangfs')) {
                    $data['kanfangfs']=I('kanfangfs');
                }
                if (I('laiyuan')) {
                    $data['laiyuan']=I('laiyuan');
                }
                $data['fydengji']=I('fydengji');
                $data['fybiaoti']=I('fybiaoti');
                $data['shi']=I('shi');
                $data['ting']=I('ting');
                $data['wei']=I('wei');
                $data['chu']=I('chu');
                $data['yangtai']=I('yangtai');
                $data['louceng']=I('louceng');
                $data['zlouceng']=I('zlouceng');
                $data['ti']=I('ti');
                $data['hu']=I('hu');
                $data['niandai']=I('niandai');
                $data['chuzudj']=I('chuzudj');
                $beizhu=preg_replace ( "/\s(?=\s)/","\\1", I('beizhu') );
                $data['beizhu']=$beizhu;
                $data['czriqi']=strtotime(I('czriqi'));
                $data['chanquanzheng']=I('chanquanzheng');
                $data['tudizheng']=I('tudizheng');
                $data['budongchanzheng']=I('budongchanzheng');
                if (I('fukuanfs')) {
                    $data['fukuanfs']=I('fukuanfs');
                }
                if(I('wushui')){
                    $wushui=1;
                    $geshui=0;
                    $zengshui=0;
                }else{
                    $wushui=0;
                    if(I('geshui')){
                        $geshui=1;
                    }else{
                        $geshui=0;
                    }
                    if(I('zengshui')){
                        $zengshui=1;
                    }else{
                        $zengshui=0;
                    }
                }
                if(I('man5')){
                    $man5=1;
                }else{
                    $man5=0;
                }
                if(I('man2')){
                    $man2=1;
                }else{
                    $man2=0;
                }
                if(I('weiyi')){
                    $weiyi=1;
                }else{
                    $weiyi=0;
                }
                if(I('jishou')){
                    $jishou=1;
                }else{
                    $jishou=0;
                }
                if(I('quankuan')){
                    $quankuan=1;
                }else{
                    $quankuan=0;
                }
                if(I('youdaikuan')){
                    $youdaikuan=1;
                }else{
                    $youdaikuan=0;
                }
                if(I('xinzheng')){
                    $xinzheng=1;
                }else{
                    $xinzheng=0;
                }
                $data['wushui']=$wushui;
                $data['geshui']=$geshui;
                $data['zengshui']=$zengshui;
                $data['jishou']=$jishou;
                $data['quankuan']=$quankuan;
                $data['weiyi']=$weiyi;
                $data['man5']=$man5;
                $data['man2']=$man2;
                $data['youdaikuan']=$youdaikuan;
                $data['xinzheng']=$xinzheng;
                $data['xiugaisj']=time();
                if (I('yongtu')!=$fy1['yongtu'] && ($fy1['yongtu']==true || I('yongtu')==true)) {
                    $xiugai.=get_xiugai($fy1['yongtu'],I('yongtu'),'yongtu');
                }
                if ($fy1['mianji']!=I('mianji') && ($fy1['mianji']==true || I('mianji')==true)) {
                    $xiugai.="面积:[".$fy1['mianji']."]=>[".I('mianji')."];";
                }
                if ($fy1['shoujia']!=I('shoujia') && ($fy1['shoujia']==true || I('shoujia')==true)) {
                    $xiugai.="售价:[".$fy1['shoujia']."]=>[".I('shoujia')."];";
                }
                if ($fy1['zujia']!=I('zujia') && ($fy1['zujia']==true || I('zujia')==true)) {
                    $xiugai.="租价:[".$fy1['zujia']."]=>[".I('zujia')."];";
                }
                if ($fy1['zujialx']!=I('zujialx') && ($fy1['zujialx']==true || I('zujialx')==true)) {
                    $xiugai.=get_xiugai($fy1['zujialx'],I('zujialx'),'zujialx');
                }
                if ($fy1['chaoxiang']!=I('chaoxiang') && ($fy1['chaoxiang']==true || I('chaoxiang')==true)) {
                    $xiugai.=get_xiugai($fy1['chaoxiang'],I('chaoxiang'),'chaoxiang');
                }
                if ($fy1['zhuangxiu']!=I('zhuangxiu') && ($fy1['zhuangxiu']==true || I('zhuangxiu')==true)) {
                    $xiugai.=get_xiugai($fy1['zhuangxiu'],I('zhuangxiu'),'zhuangxiu');
                }
                if ($fy1['peitao']!=$pt2) {
                    if ($fy1['peitao']) {
                        $condition1="pzming = 'peitao'";
                        $condition1.=" and lxid in (".$fy1['peitao'].")";
                        $peitao1=M('peizhi')->query("select * from __PEIZHI__ where {$condition1}");
                        $goods1 = array();
                        foreach ($peitao1 AS $key => $val) {
                            $goods1[$key]['lxming'] = $val['lxming'];
                            $box1.= ",".$val['lxming'];
                        }
                    }
                    if ($pt2) {
                        $condition2="pzming = 'peitao'";
                        $condition2.=" and lxid in (".$pt2.")";
                        $peitao2=M('peizhi')->query("select * from __PEIZHI__ where {$condition2}");
                        $goods2 = array();
                        foreach ($peitao2 AS $key => $val) {
                            $goods2[$key]['lxming'] = $val['lxming'];
                            $box2.= $val['lxming'].",";
                        }
                    }
                    $xiugai.="配套:[".$box1."]=>[".$box2."];";
                }
                if ($fy1['fwleixing']!=I('fwleixing') && ($fy1['fwleixing']==true || I('fwleixing')==true)) {
                    $xiugai.=get_xiugai($fy1['fwleixing'],I('fwleixing'),'fwleixing');
                }
                if ($fy1['jiegou']!=I('jiegou') && ($fy1['jiegou']==true || I('jiegou')==true)) {
                    $xiugai.=get_xiugai($fy1['jiegou'],I('jiegou'),'jiegou');
                }
                if ($fy1['cqnianxian']!=I('cqnianxian') && ($fy1['cqnianxian']==true || I('cqnianxian')==true)) {
                    $xiugai.="产权年限:[".$fy1['cqnianxian']."]=>[".I('cqnianxian')."];";
                }
                if ($fy1['cqxingzhi']!=I('cqxingzhi') && ($fy1['cqxingzhi']==true || I('cqxingzhi')==true)) {
                    $xiugai.=get_xiugai($fy1['cqxingzhi'],I('cqxingzhi'),'chanquan');
                }
                if ($fy1['kanfangfs']!=I('kanfangfs') && ($fy1['kanfangfs']==true || I('kanfangfs')==true)) {
                    $xiugai.=get_xiugai($fy1['kanfangfs'],I('kanfangfs'),'kanfangfs');
                }
                if ($fy1['laiyuan']!=I('laiyuan') && ($fy1['laiyuan']==true || I('laiyuan')==true)) {
                    $xiugai.=get_xiugai($fy1['laiyuan'],I('laiyuan'),'laiyuan');
                }
                if ($fy1['fukuanfs']!=I('fukuanfs') && ($fy1['fukuanfs']==true || I('fukuanfs')==true)) {
                    if ($data['leixing']==1) {
                        $fuk="fukuan";
                    }elseif ($data['leixing']==2) {
                        $fuk="zlfukuan";
                    }
                    $xiugai.=get_xiugai($fy1['fukuanfs'],I('fukuanfs'),$fuk);
                }
                if ($fy1['fybiaoti']!=I('fybiaoti') && ($fy1['fybiaoti']==true || I('fybiaoti')==true)) {
                    $xiugai.="房源标题:[".$fy1['fybiaoti']."]=>[".I('fybiaoti')."];";
                }
                if ($fy1['shi']!=I('shi') && ($fy1['shi']==true || I('shi')==true)) {
                    $xiugai.="室:[".$fy1['shi']."]=>[".I('shi')."];";
                }
                if ($fy1['ting']!=I('ting') && ($fy1['ting']==true || I('ting')==true)) {
                    $xiugai.="厅:[".$fy1['ting']."]=>[".I('ting')."];";
                }
                if ($fy1['wei']!=I('wei') && ($fy1['wei']==true || I('wei')==true)) {
                    $xiugai.="卫:[".$fy1['wei']."]=>[".I('wei')."];";
                }
                if ($fy1['chu']!=I('chu') && ($fy1['chu']==true || I('chu')==true)) {
                    $xiugai.="厨:[".$fy1['chu']."]=>[".I('chu')."];";
                }
                if ($fy1['yangtai']!=I('yangtai') && ($fy1['yangtai']==true || I('yangtai')==true)) {
                    $xiugai.="阳台:[".$fy1['yangtai']."]=>[".I('yangtai')."];";
                }
                if ($fy1['symianji']!=I('symianji') && ($fy1['symianji']==true || I('symianji')==true)) {
                    $xiugai.="使用面积:[".$fy1['symianji']."]=>[".I('symianji')."];";
                }
                if ($fy1['louceng']!=I('louceng') && ($fy1['louceng']==true || I('louceng')==true)) {
                    $xiugai.="楼层:[".$fy1['louceng']."]=>[".I('louceng')."];";
                }
                if ($fy1['zlouceng']!=I('zlouceng') && ($fy1['zlouceng']==true || I('zlouceng')==true)) {
                    $xiugai.="总楼层:[".$fy1['zlouceng']."]=>[".I('zlouceng')."];";
                }
                if ($fy1['ti']!=I('ti') && ($fy1['ti']==true || I('ti')==true)) {
                    $xiugai.="梯:[".$fy1['ti']."]=>[".I('ti')."];";
                }
                if ($fy1['hu']!=I('hu') && ($fy1['hu']==true || I('hu')==true)) {
                    $xiugai.="户:[".$fy1['hu']."]=>[".I('hu')."];";
                }
                if ($fy1['niandai']!=I('niandai') && ($fy1['niandai']==true || I('niandai')==true)) {
                    $xiugai.="年代:[".$fy1['niandai']."]=>[".I('niandai')."];";
                }
                if ($fy1['chushoudj']!=I('chushoudj') && ($fy1['chushoudj']==true || I('chushoudj')==true)) {
                    $xiugai.="出售底价:[".$fy1['chushoudj']."]=>[".I('chushoudj')."];";
                }
                if ($fy1['chuzudj']!=I('chuzudj') && ($fy1['chuzudj']==true || I('chuzudj')==true)) {
                    $xiugai.="出租底价:[".$fy1['chuzudj']."]=>[".I('chuzudj')."];";
                }
                if ($fy1['beizhu']!=trim(I('beizhu')) && ($fy1['beizhu']==true || trim(I('beizhu'))==true)) {
                    $xiugai.="备注:[".$fy1['beizhu']."]=>[".trim(I('beizhu'))."];";
                }
                if ($fy1['czriqi']!=strtotime(I('czriqi')) && ($fy1['czriqi']==true || I('czriqi')==true)) {
                    $xiugai.="产证日期:[".date('Y-m-d',$fy1['czriqi'])."]=>[".I('czriqi')."];";
                }
                if (($fy1['wushui']!=$wushui && ($fy1['wushui']==true || $wushui==true)) || ($fy1['geshui']!=$geshui && ($fy1['geshui']==true || $geshui==true)) || ($fy1['zengshui']!=$zengshui && ($fy1['zengshui']==true || $zengshui==true))) {
                    $wai=$fy1['wushui']?"无税":"";
                    $wai1=$wushui?"无税":"";
                    $wai2=$fy1['geshui']?"个税;":"";
                    $wai3=$geshui?"个税;":"";
                    $wai4=$fy1['zengshui']?"增值税;":"";
                    $wai5=$zengshui?"增值税;":"";
                    $xiugai.="税收:[".$wai.$wai2.$wai4."]=>[".$wai1.$wai3.$wai5."];";
                }
                if ($fy1['jishou']!=$jishou && ($fy1['jishou']==true || $jishou==true)) {
                    $jis=$fy1['jishou']?"是":"否";
                    $jis1=$jishou?"是":"否";
                    $xiugai.="急售:[".$jis."]=>[".$jis1."];";
                }
                if ($fy1['quankuan']!=$quankuan && ($fy1['quankuan']==true || $quankuan==true)) {
                    $quan=$fy1['quankuan']?"是":"否";
                    $quan1=$quankuan?"是":"否";
                    $xiugai.="全款:[".$quan."]=>[".$quan1."];";
                }
                if ($fy1['weiyi']!=$weiyi && ($fy1['weiyi']==true || $weiyi==true)) {
                    $wei1=$fy1['weiyi']?"是":"否";
                    $wei2=$weiyi?"是":"否";
                    $xiugai.="唯一:[".$wei1."]=>[".$wei2."];";
                }
                if ($fy1['man2']!=$man2 && ($fy1['man2']==true || $man2==true)) {
                    $man21=$fy1['man2']?"是":"否";
                    $man22=$man2?"是":"否";
                    $xiugai.="满2:[".$man21."]=>[".$man22."];";
                }
                if ($fy1['xuequ']!=$xuequ && ($fy1['xuequ']==true || $xuequ==true)) {
                    $xue1=$fy1['xuequ']?"是":"否";
                    $xue2=$xuequ?"是":"否";
                    $xiugai.="学区:[".$xue1."]=>[".$xue2."];";
                }
                if ($fy1['youdaikuan']!=$youdaikuan && ($fy1['youdaikuan']==true || $youdaikuan==true)) {
                    $youdaik1=$fy1['youdaikuan']?"是":"否";
                    $youdaik2=$youdaikuan?"是":"否";
                    $xiugai.="有贷款:[".$youdaik1."]=>[".$youdaik2."];";
                }
                if ($fy1['xinzheng']!=$xinzheng && ($fy1['xinzheng']==true || $xinzheng==true)) {
                    $xin1=$fy1['xinzheng']?"是":"否";
                    $xin2=$xinzheng?"是":"否";
                    $xiugai.="新证:[".$xin1."]=>[".$xin2."];";
                }
                $data_rizhi=array(
                    'zy_type'=>1,
                    'uid'=>session('uid'),
                    'addtime'=>time(),
                    'cz_type'=>2,
                    'zy_bianhao'=>$fy1['bianhao'],
                    'zy_id'=>$fy1['id'],
                    'neirong'=>$xiugai,
                );
                $isok=M('fangyuan')->where(array('id'=>I('id')))->save($data);
                if($isok){
                    M('rizhi')->add($data_rizhi);
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败');
                }
                
            }else{
                $this->bumen=M('bumen')->where(array('gongsiid'=>session('gongsiid')))->select();
                $this->xiaoqum=M('xiaoqu')->where(array('gongsiid'=>session('gongsiid')))->select();
                $this->yongtu=M('Peizhi')->where(array('pzming'=>'yongtu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->leixing=M('Peizhi')->where(array('pzming'=>'leixing','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->zujialx=M('Peizhi')->where(array('pzming'=>'zujialx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->chaoxiang=M('Peizhi')->where(array('pzming'=>'chaoxiang','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->fwleixing=M('Peizhi')->where(array('pzming'=>'fwleixing','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->jiegou=M('Peizhi')->where(array('pzming'=>'jiegou','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->chanquan=M('Peizhi')->where(array('pzming'=>'chanquan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->kanfangfs=M('Peizhi')->where(array('pzming'=>'kanfangfs','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->laiyuan=M('Peizhi')->where(array('pzming'=>'laiyuan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->fukuan=M('Peizhi')->where(array('pzming'=>'fukuan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->zlfukuan=M('Peizhi')->where(array('pzming'=>'zlfukuan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->zhuangxiu=M('Peizhi')->where(array('pzming'=>'zhuangxiu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->iszheng=M('Peizhi')->where(array('pzming'=>'iszheng','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->fydengji=M('Peizhi')->where(array('pzming'=>'fydengji','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->peitao=M('Peizhi')->where(array('pzming'=>'peitao','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $peitao1=M('fangyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('peitao');
                $this->peitao2= explode(",",$peitao1);
                $this->fangyuan=M('fangyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->find();
                $this->display();
            }
        }
        //修改门牌号
        public function xgzuodong(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(907,0,$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $dianhua1=I('dianhua1');
                $dianhua2=I('dianhua2');
                $dianhua3=I('dianhua3');
                $zuodong=I('zuodong');
                $danyuan=I('danyuan');
                $fanghao=I('fanghao');
                if(!preg_match("/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[8-9])\d{8}$/",$dianhua1) && !preg_match("/^0\d{2,3}-?\d{7,8}$/",$dianhua1)){
                    $this->error('请输出正确的手机号码或电话号码！');
                }
                if ($dianhua2) {
                    if(!preg_match("/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[8-9])\d{8}$/",$dianhua2) && !preg_match("/^0\d{2,3}-?\d{7,8}$/",$dianhua2)){
                        $this->error('请输出正确的手机号码或电话号码！');
                    }
                }
                if ($dianhua3) {
                    if(!preg_match("/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[8-9])\d{8}$/",$dianhua3) && !preg_match("/^0\d{2,3}-?\d{7,8}$/",$dianhua3)){
                        $this->error('请输出正确的手机号码或电话号码！');
                    }
                }
                if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$zuodong)){
                    $this->error('座栋首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
                }
                if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$danyuan)){
                    $this->error('单元首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
                }
                if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$fanghao)){
                    $this->error('房号首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
                }
                if (($dianhua1==true && $dianhua2==true && $dianhua1==$dianhua2) || ($dianhua1==true && $dianhua3==true && $dianhua1==$dianhua3) || ($dianhua1==true && $dianhua2==true && $dianhua2==$dianhua3)) {
                    $this->error('手机号码或电话号码重复！');
                }
                $condition['gongsiid']=session('gongsiid');
                $condition['id']=array('neq',$id);
                $condition['isdel']=2;
                $condition['xiaoqu']=$fangyuan['xiaoqu'];
                $condition['zuodong']=$zuodong;
                $condition['danyuan']=$danyuan;
                $condition['fanghao']=$fanghao;
                $condition['leixing']=$fangyuan['leixing'];
                $cffy=M('fangyuan')->where($condition)->find();
                if($cffy){
                    $this->error('房源已存在');
                }
                $yezhulxq=M('Peizhi')->where(array('pzming'=>'yezhulx','zhuangtai'=>1,'lxid'=>$fangyuan['yezhulx']))->order('xsshunxu asc')->getField('lxming');
                $yezhulxh=M('Peizhi')->where(array('pzming'=>'yezhulx','zhuangtai'=>1,'lxid'=>I('yezhulx')))->order('xsshunxu asc')->getField('lxming');
                $yezhugxq=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>$fangyuan['yezhugx']))->order('xsshunxu asc')->getField('lxming');
                $yezhugxh=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>I('yezhugx1')))->order('xsshunxu asc')->getField('lxming');
                $yezhugx2q=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>$fangyuan['yezhugx2']))->order('xsshunxu asc')->getField('lxming');
                $yezhugx2h=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>I('yezhugx2')))->order('xsshunxu asc')->getField('lxming');
                $yezhugx3q=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>$fangyuan['yezhugx3']))->order('xsshunxu asc')->getField('lxming');
                $yezhugx3h=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>I('yezhugx3')))->order('xsshunxu asc')->getField('lxming');
                $xiugaiqian='业主：'.$fangyuan['yezhu'].$yezhulxq.'。电话：'.$fangyuan['yezhudianhua'].'（'.$yezhugxq.'）；'.$fangyuan['yezhudianhua2'].'（'.$yezhugx2q.'）；'.$fangyuan['yezhudianhua3'].'（'.$yezhugx3q.'）。座栋：'.$fangyuan['zuodong'].'。单元：'.$fangyuan['danyuan'].'。房号：'.$fangyuan['fanghao'];
                $xiugaihou='业主：'.I('yezhu').$yezhulxh.'。电话：'.$dianhua1.'（'.$yezhugxh.'）；'.$dianhua2.'（'.$yezhugx2h.'）；'.$dianhua3.'（'.$yezhugx3h.'）。座栋：'.$zuodong.'。单元：'.$danyuan.'。房号：'.$fanghao;
                $map['xiugaiqian']=$xiugaiqian;
                $map['xiugaihou']=$xiugaihou;
                $map['time']=time();
                $map['fybianhao']=$fangyuan['bianhao'];
                $map['uid']=session('uid');
                M('fyxiugai')->add($map);
                $data['yezhu']=I('yezhu');
                $data['yezhulx']=I('yezhulx');
                $data['yezhugx']=I('yezhugx1');
                $data['yezhugx2']=I('yezhugx2');
                $data['yezhugx3']=I('yezhugx3');
                $data['yezhudianhua']=$dianhua1;
                $data['yezhudianhua2']=$dianhua2;
                $data['yezhudianhua3']=$dianhua3;
                $data['zuodong']=$zuodong;
                $data['danyuan']=$danyuan;
                $data['fanghao']=$fanghao;
                $data['xiugaisj']=time();
                $isok=M('fangyuan')->where(array('id'=>$id))->save($data);
                if ($isok) {
                    $data_rizhi['zy_type']=1;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=7;
                    $data_rizhi['zy_id']=$id;
                    $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                    $neirong="核心修改";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败');
                }
            }else{
                $id=I('id');
                $this->fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
                $this->yezhulx=M('Peizhi')->where(array('pzming'=>'yezhulx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->yezhugx=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display();
            }
        }
        //变更维护人
        public function bgwhr(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(908,0,$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $data['weihurenid']=I('weihurenid');
                $xweihu=M('Yonghu')->where(array('id'=>I('weihurenid')))->getField('ygmingcheng');
                $fangyuan1=M('fangyuan')->where(array('id'=>$id))->find();
                $data['weihuren']=$xweihu;
                $data['xiugaisj']=time();
                $fangyuan=M("fangyuan")->where(array('id'=>$id))->save($data);
                if ($fangyuan){
                    $fyxgsj=M('fangyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
                    $data_rizhi['zy_type']=1;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=9;
                    $data_rizhi['zy_id']=I('id');
                    $data_rizhi['zy_bianhao']=$fangyuan1['bianhao'];
                    $neirong="变更维护人:[".$fangyuan1['weihuren']."]=>[".$xweihu."]";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败');
                }
            }else{
                $this->weihuren=M('fangyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('weihuren');
                $map = "gongsiid=".session('gongsiid');
                $x = _rbac_lists_where(17,0);
                if ($x && $x != "all" && $x != "me") {
                    $map .= " and bumen in ({$x})";
                }elseif ($x == "me") {
                    $map .= " and id=".session('uid');
                }elseif ($x == false) {
                    $map .= " and id=0";
                }
                $this->ygmingcheng=M('Yonghu')->where($map)->select();
                $this->display();
            }
        }
        //删除房源
        public function delEsfy(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(909,0,$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $isok=M('fangyuan')->where(array('id'=>$id))->setField('isdel',1);
            if ($isok) {
                $fyxgsj=M('fangyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
                $data_rizhi['zy_type']=1;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=8;
                $data_rizhi['zy_id']=$id;
                $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                $neirong="删除";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }
        //恢复房源
        public function huifufy(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(910,0,$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $condition['gongsiid']=session('gongsiid');
            $condition['id']=array('neq',$id);
            $condition['isdel']=2;
            $condition['xiaoqu']=$fangyuan['xiaoqu'];
            $condition['leixing']=$fangyuan['leixing'];
            $condition['zuodong']=$fangyuan['zuodong'];
            $condition['danyuan']=$fangyuan['danyuan'];
            $condition['fanghao']=$fangyuan['fanghao'];
            $cffy=M('fangyuan')->where($condition)->find();
            if($cffy){
                $this->error('房源已存在，无法还原！');
            }
            if($fangyuan['isdel'] == 2){
                $this->error('房源已还原！');
            }
            $isok=M('fangyuan')->where(array('id'=>$id))->setField('isdel',2);
            if ($isok) {
                $fyxgsj=M('fangyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
                $data_rizhi['zy_type']=1;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=8;
                $data_rizhi['zy_id']=$id;
                $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                $neirong="还原删除房源";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('还原成功');
            }else{
                $this->error('还原失败');
            }
        }
        //永久删除房源
        public function yjdelfy(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(911,0,$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $isok=M('fangyuan')->where(array('id'=>$id))->delete();
            if ($isok) {
                $data_rizhi['zy_type']=1;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=8;
                $data_rizhi['zy_id']=$id;
                $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                $neirong="永久删除";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }
        //调取
        public function diaoqu() {
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(912,0,$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $yezhulx=M('Peizhi')->where(array('pzming'=>'yezhulx','zhuangtai'=>1,'lxid'=>$fangyuan['yezhulx']))->order('xsshunxu asc')->getField('lxming');
            $yezhugx=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>$fangyuan['yezhugx']))->order('xsshunxu asc')->getField('lxming');
            $yezhugx2=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>$fangyuan['yezhugx2']))->order('xsshunxu asc')->getField('lxming');
            $yezhugx3=M('Peizhi')->where(array('pzming'=>'yezhugx','zhuangtai'=>1,'lxid'=>$fangyuan['yezhugx3']))->order('xsshunxu asc')->getField('lxming');
            if ($yezhugx) {
                $yzguanxi = "（".$yezhugx."）";
            } else {
                $yzguanxi = "";
            }
            if ($yezhugx2) {
                $yzguanxi2 = "（".$yezhugx2."）";
            } else {
                $yzguanxi2 = "";
            }
            if ($yezhugx3) {
                $yzguanxi3 = "（".$yezhugx3."）";
            } else {
                $yzguanxi3 = "";
            }
            $diaoqu['yezhu']=$fangyuan['yezhu'].$yezhulx;
            $diaoqu['yezhudianhua']=$fangyuan['yezhudianhua'].$yzguanxi;
            $diaoqu['yezhudianhua2']=$fangyuan['yezhudianhua2'].$yzguanxi2;
            $diaoqu['yezhudianhua3']=$fangyuan['yezhudianhua3'].$yzguanxi3;
            $diaoqu['zuodong']=$fangyuan['zuodong'];
            $diaoqu['danyuan']=$fangyuan['danyuan'];
            $diaoqu['fanghao']=$fangyuan['fanghao'];
            $diaoqu['chushoudj']=$fangyuan['chushoudj'];
            $diaoqu['chuzudj']=$fangyuan['chuzudj'];
            if ($sycishu) {
                $info="剩余调取数为".$sycishu."次";
            }
            $data1=array('status'=>1,'diaoqu1'=>$diaoqu,'info'=>$info);
            header("Content-type: application/json");
            exit(json_encode($data1));
        }
    }