<?php

    /***************************************************************\
    |                                                               |
    |   开单大师 - 专业的房产ERP管理                                  |
    |                                                               |
    |   © 2019 http://www.kaidandashi.com All rights reserved.      |
    |                                                               |
    |   开单大师由淮南市银泰软件科技有限公司提供技术                    |
    |                                                               |
    |   QQ:984784483                                                |
    |                                                               |
    \***************************************************************/

    namespace Admin\Controller;
    use Think\Controller;
    class FyneirongController extends CommonController {
        //收藏房源
        public function shoucang(){
            $is_rbac = _rbac_btn_show(388,0);
            if (!$is_rbac) {
                $this->error("异常错误！");
            }
            $id=I('id');
            $data['user_id']=session("uid");
            $data['fyid']=$id;
            if (M('shoucang')->add($data)) {
                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }
        //取消收藏
        public function noshoucang(){
            $is_rbac = _rbac_btn_show(389,0);
            if (!$is_rbac) {
                $this->error("异常错误！");
            }
            $id=I('id');
            $data['user_id']=session("uid");
            $data['fyid']=$id;
            if (M('shoucang')->where('fyid='.$id.' and user_id='.session("uid"))->delete()) {
                $this->success('取消成功');
            }else{
                $this->error('取消失败');
            }
        }
        //封盘
        public function fengpan(){
            $fangyuan=M('fangyuan')->where(array('id'=>I('fyid')))->find();
            $is_rbac = _rbac_btn_show(830,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $fkplx=I('fkplx');
                if ((($fangyuan['fpdh'] == 1) && ($fkplx == 1)) || (($fangyuan['fpdz'] == 1) && ($fkplx == 2)) || (($fangyuan['fpdj'] == 1) && ($fkplx == 3)) || (($fangyuan['fpdq'] == 1) && ($fkplx == 4)) || (($fangyuan['fpck'] == 1) && ($fkplx == 5))) {
                    $this->error('异常错误！');
                }
                $qs=date("Y-m-d",time()+86399);
                $js=date("Y-m-d",time()+604799);
                $endunix=strtotime(I('endunix'));
                if ((strtotime($qs) > $endunix) || (strtotime($js) < $endunix)) {
                    $this->error('结束时间异常！');
                }
                $data['zylx']=1;
                $data['czlx']=1;
                $data['type']=3;
                $data['uid']=I('uid');
                $data['fkplx']=$fkplx;
                $data['yuanyin']=I('yuanyin');
                $data['zyid']=$fangyuan['id'];
                $data['zybh']=$fangyuan['bianhao'];
                $data['addtime']=time();
                $data['adduid']=session("uid");
                $data['gongsiid']=session("gongsiid");
                $data['endunix']=$endunix;
                $isok=M('fpkp')->add($data);
                if ($isok){
                    $data_fangyuan['fengpanrenid']=I('uid');
                    if ($fkplx == 1) {
                        $data_fangyuan['fpdh']=1;
                    }
                    if ($fkplx == 2) {
                        $data_fangyuan['fpdz']=1;
                    }
                    if ($fkplx == 3) {
                        $data_fangyuan['fpdj']=1;
                    }
                    if ($fkplx == 4) {
                        $data_fangyuan['fpdq']=1;
                    }
                    if ($fkplx == 5) {
                        $data_fangyuan['fpck']=1;
                    }
                    M('fangyuan')->where(array('id'=>$fangyuan['id']))->save($data_fangyuan);
                    $data_rizhi['zy_type']=1;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=14;
                    $data_rizhi['zy_id']=$fangyuan['id'];
                    $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                    $neirong="封盘";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('已提交申请');
                }else{
                    $this->error('申请失败');
                }
            }else{
                if ($fangyuan['fpdh'] == 2) {
                    $this->fdh=1;
                }
                if ($fangyuan['fpdz'] == 2) {
                    $this->fdz=1;
                }
                if ($fangyuan['fpdj'] == 2) {
                    $this->fdj=1;
                }
                if ($fangyuan['fpdq'] == 2) {
                    $this->fdq=1;
                }
                if ($fangyuan['fpck'] == 2) {
                    $this->fck=1;
                }
                $this->fyid=I('fyid');
                $this->display();
            }
        }
        //开盘
        public function kaipan(){
            $fangyuan=M('fangyuan')->where(array('id'=>I('fyid')))->find();
            $is_rbac = _rbac_btn_show(831,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $fkplx=I('fkplx');
                if ((($fangyuan['fpdh'] == 2) && ($fkplx == 1)) || (($fangyuan['fpdz'] == 2) && ($fkplx == 2)) || (($fangyuan['fpdj'] == 2) && ($fkplx == 3)) || (($fangyuan['fpdq'] == 2) && ($fkplx == 4)) || (($fangyuan['fpck'] == 2) && ($fkplx == 5))) {
                    $this->error('异常错误！');
                }
                $data['zylx']=1;
                $data['czlx']=2;
                $data['type']=3;
                $data['uid']=I('uid');
                $data['fkplx']=$fkplx;
                $data['yuanyin']=I('yuanyin');
                $data['zyid']=$fangyuan['id'];
                $data['zybh']=$fangyuan['bianhao'];
                $data['addtime']=time();
                $data['adduid']=session("uid");
                $data['gongsiid']=session("gongsiid");
                $isok=M('fpkp')->add($data);
                if ($isok){
                    $data_rizhi['zy_type']=1;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=15;
                    $data_rizhi['zy_id']=$fangyuan['id'];
                    $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                    $neirong="开盘";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('已提交申请');
                }else{
                    $this->error('申请失败');
                }
            }else{
                if ($fangyuan['fpdh'] == 1) {
                    $this->kdh=1;
                }
                if ($fangyuan['fpdz'] == 1) {
                    $this->kdz=1;
                }
                if ($fangyuan['fpdj'] == 1) {
                    $this->kdj=1;
                }
                if ($fangyuan['fpdq'] == 1) {
                    $this->kdq=1;
                }
                if ($fangyuan['fpck'] == 1) {
                    $this->kck=1;
                }
                $this->fyid=I('fyid');
                $this->display();
            }
        }
        //封盘审核列表
        public function fpsh(){
            $map .= " where gongsiid=".session('gongsiid');
            $x = _rbac_lists_where(844,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";
            }
            $condition = " where gongsiid=".session('gongsiid');
            $condition.=" and zylx=1 and czlx=1";
            $type=I('type');
            if ($type) {
                $condition.=" and type=".$type;
                $this->type=$type;
            } else {
                $condition.="";
                $this->type=0;
            }
            $fkplx=I('fkplx');
            if ($fkplx) {
                $condition.=" and fkplx=".$fkplx;
                $this->fkplx=$fkplx;
            } else {
                $condition.="";
                $this->fkplx=0;
            }
            $shijian1=I('shijian1');
            $shijian2=I('shijian2');
            if ($shijian1) {
                $this->shijian1=$shijian1;
                $shijian3=strtotime($shijian1);
            }
            if ($shijian2) {
                $this->shijian2=$shijian2;
                $shijian4=strtotime($shijian2)+86400;
            }
            if ($shijian3 and $shijian4){
                if ($shijian1 > $shijian2){
                    $condition.=" and addtime>".$shijian4." and addtime<".$shijian3;
                    $this->shijian1=$shijian2;
                    $this->shijian2=$shijian1;
                } else {
                    $condition.=" and addtime>".$shijian3." and addtime<".$shijian4;
                }
            } elseif ($shijian3) {
                $condition.=" and addtime>".$shijian3;
            } elseif ($shijian4) {
                $condition.=" and addtime<".$shijian4;
            }
            $count=M('fpkp')->query("select count(*) from (select * from __FPKP__ {$condition}) a join (select id as b_id from __YONGHU__ {$map}) b on a.uid = b.b_id");
            $Page=new \Think\Page($count['0']['count(*)'],20);
            $show  = $Page->show();
            $list="select d.*,c.tjren,c.tjdh from (select a.*,b.fpren,b.fpdh,b.fpbm from (select * from __FPKP__ {$condition}) a join (select id as b_id,ygmingcheng as fpren,dianhua as fpdh,bumen as fpbm from __YONGHU__ {$map}) b on a.uid = b.b_id order by a.addtime DESC limit ".$Page->firstRow.','.$Page->listRows.") d left join (select id as c_id,ygmingcheng as tjren,dianhua as tjdh from __YONGHU__) c on d.adduid = c.c_id ";
            $fengpan=M('fpkp')->query($list);
            $this->assign('firstRow',$Page->firstRow);
            $this->assign('fengpan',$fengpan);
            $this->assign('count',$count);
            $this->assign('page',$show);
            $this->display();
        }
        //封盘审核
        public function fpshenhe(){
            $id=I('id');
            $fpkp=M('fpkp')->where(array('id'=>$id,'zylx'=>1,'czlx'=>1))->field('uid,zyid,type,fkplx')->find();
            $fyzt=M('fangyuan')->where(array('id'=>$fpkp['zyid']))->getField('zhuangtai');
            $is_rbac = _rbac_btn_show(845,$fyzt,$fpkp['uid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $type=I('type');
                if ($fpkp['type'] != 3){
                    $this->error('已审核！');
                }
                if ($type==""){
                    $this->error('请选择审核意见！');
                }
                if ($type!=1 && $type!=2){
                    $this->error('审核意见异常！');
                }
                $data['type']=$type;
                $data['remark']=I('remark');
                $data['shshijian']=time();
                $data['shuid']=session('uid');
                $isok=M('fpkp')->where(array('id'=>$id,'zylx'=>1,'czlx'=>1))->save($data);
                if ($isok){
                    if ($type==2) {
                        $data_fangyuan['fengpanrenid']="";
                        if ($fpkp['fkplx'] == 1) {
                            $data_fangyuan['fpdh']=2;
                        }
                        if ($fpkp['fkplx'] == 2) {
                            $data_fangyuan['fpdz']=2;
                        }
                        if ($fpkp['fkplx'] == 3) {
                            $data_fangyuan['fpdj']=2;
                        }
                        if ($fpkp['fkplx'] == 4) {
                            $data_fangyuan['fpdq']=2;
                        }
                        if ($fpkp['fkplx'] == 5) {
                            $data_fangyuan['fpck']=2;
                        }
                        M('fangyuan')->where(array('id'=>$fpkp['zyid']))->save($data_fangyuan);
                    }
                    $this->success('审核成功');
                }else{
                    $this->error('审核失败');
                }
            }else{
                $this->display();
            }
        }
        //封盘日志
        public function fprizhi(){
            $rzlx=I('rzlx');
            if ($rzlx == 1) {
                $map .= " where gongsiid=".session('gongsiid');
                $x = _rbac_lists_where(846,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";
                }
                $condition = " where gongsiid=".session('gongsiid');
                $condition.=" and zylx=1 and czlx=1";
                $type=I('type');
                if ($type) {
                    $condition.=" and type=".$type;
                    $this->type=$type;
                } else {
                    $condition.="";
                    $this->type=0;
                }
                $fkplx=I('fkplx');
                if ($fkplx) {
                    $condition.=" and fkplx=".$fkplx;
                    $this->fkplx=$fkplx;
                } else {
                    $condition.="";
                    $this->fkplx=0;
                }
                $shijian1=I('shijian1');
                $shijian2=I('shijian2');
                if ($shijian1) {
                    $this->shijian1=$shijian1;
                    $shijian3=strtotime($shijian1);
                }
                if ($shijian2) {
                    $this->shijian2=$shijian2;
                    $shijian4=strtotime($shijian2)+86400;
                }
                if ($shijian3 and $shijian4){
                    if ($shijian1 > $shijian2){
                        $condition.=" and addtime>".$shijian4." and addtime<".$shijian3;
                        $this->shijian1=$shijian2;
                        $this->shijian2=$shijian1;
                    } else {
                        $condition.=" and addtime>".$shijian3." and addtime<".$shijian4;
                    }
                } elseif ($shijian3) {
                    $condition.=" and addtime>".$shijian3;
                } elseif ($shijian4) {
                    $condition.=" and addtime<".$shijian4;
                }
                $count=M('fpkp')->query("select count(*) from (select * from __FPKP__ {$condition}) a join (select id as b_id from __YONGHU__ {$map}) b on a.uid = b.b_id");
                $Page=new \Think\Page($count['0']['count(*)'],20);
                $show  = $Page->show();
                $list="select e.*,c.tjren,c.tjdh,d.shren,d.shdh from (select a.*,b.fpren,b.fpdh,b.fpbm from (select * from __FPKP__ {$condition}) a join (select id as b_id,ygmingcheng as fpren,dianhua as fpdh,bumen as fpbm from __YONGHU__ {$map}) b on a.uid = b.b_id order by a.addtime DESC limit ".$Page->firstRow.','.$Page->listRows.") e left join (select id as c_id,ygmingcheng as tjren,dianhua as tjdh from __YONGHU__) c on e.adduid = c.c_id left join (select id as d_id,ygmingcheng as shren,dianhua as shdh from __YONGHU__) d on e.shuid = d.d_id ";
                $fengpan=M('fpkp')->query($list);
                $this->assign('firstRow',$Page->firstRow);
                $this->assign('fengpan',$fengpan);
                $this->assign('count',$count);
                $this->assign('page',$show);
            } elseif ($rzlx == 2) {
                $fyfp=M('fpkp')->where(array('id'=>I('id'),'zylx'=>1,'czlx'=>1))->field('shuid,shshijian,remark,type')->find();
                $this->shren=M('Yonghu')->where(array('id'=>$fyfp['shuid']))->getField('ygmingcheng');
                $this->shdh=M('Yonghu')->where(array('id'=>$fyfp['shuid']))->getField('dianhua');
                $this->fyfp=$fyfp;
            }
            $this->rzlx=$rzlx;
            $this->display();
        }
        //开盘审核列表
        public function kpsh(){
            $map .= " where gongsiid=".session('gongsiid');
            $x = _rbac_lists_where(847,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";
            }
            $condition = " where gongsiid=".session('gongsiid');
            $condition.=" and zylx=1 and czlx=2";
            $type=I('type');
            if ($type) {
                $condition.=" and type=".$type;
                $this->type=$type;
            } else {
                $condition.="";
                $this->type=0;
            }
            $fkplx=I('fkplx');
            if ($fkplx) {
                $condition.=" and fkplx=".$fkplx;
                $this->fkplx=$fkplx;
            } else {
                $condition.="";
                $this->fkplx=0;
            }
            $shijian1=I('shijian1');
            $shijian2=I('shijian2');
            if ($shijian1) {
                $this->shijian1=$shijian1;
                $shijian3=strtotime($shijian1);
            }
            if ($shijian2) {
                $this->shijian2=$shijian2;
                $shijian4=strtotime($shijian2)+86400;
            }
            if ($shijian3 and $shijian4){
                if ($shijian1 > $shijian2){
                    $condition.=" and addtime>".$shijian4." and addtime<".$shijian3;
                    $this->shijian1=$shijian2;
                    $this->shijian2=$shijian1;
                } else {
                    $condition.=" and addtime>".$shijian3." and addtime<".$shijian4;
                }
            } elseif ($shijian3) {
                $condition.=" and addtime>".$shijian3;
            } elseif ($shijian4) {
                $condition.=" and addtime<".$shijian4;
            }
            $count=M('fpkp')->query("select count(*) from (select * from __FPKP__ {$condition}) a join (select id as b_id from __YONGHU__ {$map}) b on a.uid = b.b_id");
            $Page=new \Think\Page($count['0']['count(*)'],20);
            $show  = $Page->show();
            $list="select d.*,c.tjren,c.tjdh from (select a.*,b.kpren,b.kpdh,b.kpbm from (select * from __FPKP__ {$condition}) a join (select id as b_id,ygmingcheng as kpren,dianhua as kpdh,bumen as kpbm from __YONGHU__ {$map}) b on a.uid = b.b_id order by a.addtime DESC limit ".$Page->firstRow.','.$Page->listRows.") d left join (select id as c_id,ygmingcheng as tjren,dianhua as tjdh from __YONGHU__) c on d.adduid = c.c_id ";
            $kaipan=M('fpkp')->query($list);
            $this->assign('firstRow',$Page->firstRow);
            $this->assign('kaipan',$kaipan);
            $this->assign('count',$count);
            $this->assign('page',$show);
            $this->display();
        }
        //开盘审核
        public function kpshenhe(){
            $id=I('id');
            $fpkp=M('fpkp')->where(array('id'=>$id,'zylx'=>1,'czlx'=>2))->field('uid,zyid,type,fkplx')->find();
            $fyzt=M('fangyuan')->where(array('id'=>$fpkp['zyid']))->getField('zhuangtai');
            $is_rbac = _rbac_btn_show(848,$fyzt,$fpkp['uid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $type=I('type');
                if ($fpkp['type'] != 3){
                    $this->error('已审核！');
                }
                if ($type==""){
                    $this->error('请选择审核意见！');
                }
                if ($type!=1 && $type!=2){
                    $this->error('审核意见异常！');
                }
                $data['type']=$type;
                $data['remark']=I('remark');
                $data['shshijian']=time();
                $data['shuid']=session('uid');
                $isok=M('fpkp')->where(array('id'=>$id,'zylx'=>1,'czlx'=>2))->save($data);
                if ($isok){
                    if ($type==1) {
                        $data_fangyuan['fengpanrenid']="";
                        if ($fpkp['fkplx'] == 1) {
                            $data_fangyuan['fpdh']=2;
                        }
                        if ($fpkp['fkplx'] == 2) {
                            $data_fangyuan['fpdz']=2;
                        }
                        if ($fpkp['fkplx'] == 3) {
                            $data_fangyuan['fpdj']=2;
                        }
                        if ($fpkp['fkplx'] == 4) {
                            $data_fangyuan['fpdq']=2;
                        }
                        if ($fpkp['fkplx'] == 5) {
                            $data_fangyuan['fpck']=2;
                        }
                        M('fangyuan')->where(array('id'=>$fpkp['zyid']))->save($data_fangyuan);
                    }
                    $this->success('审核成功');
                }else{
                    $this->error('审核失败');
                }
            }else{
                $this->display();
            }
        }
        //开盘日志
        public function kprizhi(){
            $rzlx=I('rzlx');
            if ($rzlx == 1) {
                $map .= " where gongsiid=".session('gongsiid');
                $x = _rbac_lists_where(849,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";
                }
                $condition = " where gongsiid=".session('gongsiid');
                $condition.=" and zylx=1 and czlx=2";
                $type=I('type');
                if ($type) {
                    $condition.=" and type=".$type;
                    $this->type=$type;
                } else {
                    $condition.="";
                    $this->type=0;
                }
                $fkplx=I('fkplx');
                if ($fkplx) {
                    $condition.=" and fkplx=".$fkplx;
                    $this->fkplx=$fkplx;
                } else {
                    $condition.="";
                    $this->fkplx=0;
                }
                $shijian1=I('shijian1');
                $shijian2=I('shijian2');
                if ($shijian1) {
                    $this->shijian1=$shijian1;
                    $shijian3=strtotime($shijian1);
                }
                if ($shijian2) {
                    $this->shijian2=$shijian2;
                    $shijian4=strtotime($shijian2)+86400;
                }
                if ($shijian3 and $shijian4){
                    if ($shijian1 > $shijian2){
                        $condition.=" and addtime>".$shijian4." and addtime<".$shijian3;
                        $this->shijian1=$shijian2;
                        $this->shijian2=$shijian1;
                    } else {
                        $condition.=" and addtime>".$shijian3." and addtime<".$shijian4;
                    }
                } elseif ($shijian3) {
                    $condition.=" and addtime>".$shijian3;
                } elseif ($shijian4) {
                    $condition.=" and addtime<".$shijian4;
                }
                $count=M('fpkp')->query("select count(*) from (select * from __FPKP__ {$condition}) a join (select id as b_id from __YONGHU__ {$map}) b on a.uid = b.b_id");
                $Page=new \Think\Page($count['0']['count(*)'],20);
                $show  = $Page->show();
                $list="select e.*,c.tjren,c.tjdh,d.shren,d.shdh from (select a.*,b.kpren,b.kpdh,b.kpbm from (select * from __FPKP__ {$condition}) a join (select id as b_id,ygmingcheng as kpren,dianhua as kpdh,bumen as kpbm from __YONGHU__ {$map}) b on a.uid = b.b_id order by a.addtime DESC limit ".$Page->firstRow.','.$Page->listRows.") e left join (select id as c_id,ygmingcheng as tjren,dianhua as tjdh from __YONGHU__) c on e.adduid = c.c_id left join (select id as d_id,ygmingcheng as shren,dianhua as shdh from __YONGHU__) d on e.shuid = d.d_id ";
                $kaipan=M('fpkp')->query($list);
                $this->assign('firstRow',$Page->firstRow);
                $this->assign('kaipan',$kaipan);
                $this->assign('count',$count);
                $this->assign('page',$show);
            } elseif ($rzlx == 2) {
                $fykp=M('fpkp')->where(array('id'=>I('id'),'zylx'=>1,'czlx'=>2))->field('shuid,shshijian,remark,type')->find();
                $this->shren=M('Yonghu')->where(array('id'=>$fykp['shuid']))->getField('ygmingcheng');
                $this->shdh=M('Yonghu')->where(array('id'=>$fykp['shuid']))->getField('dianhua');
                $this->fykp=$fykp;
            }
            $this->rzlx=$rzlx;
            $this->display();
        }
        //更新房源
        public function xiugai(){
            $id=I('id');
            $fy1=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(56,$fy1['zhuangtai'],$fy1['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $is_rbacfdj = _rbac_node_show(861);
            if ($is_rbacfdj || ($fy1['fpdj'] == 2)) {
                $is_rbacfdj=1;
                $this->is_rbacfdj=1;
            }
            if (IS_POST) {
                $data['yongtu']=I('yongtu');//用途
                if ($is_rbacfdj == 1) {
                    if(I('chushoudj')){
                        if(!preg_match("/^([1-9][0-9]{0,4})(\.[0-9]{1,6})?$|^([0]\.[1-9][0-9]{0,5})$|^([0]\.[0][0-9]{0,4}[1-9]{1})$|^([0]\.[0]{2}[0-9]{0,3}[1-9]{1})$|^([0]\.[0]{3}[0-9]{0,2}[1-9]{1})$|^([0]\.[0]{4}[0-9]{0,1}[1-9]{1})$|^([0]\.[0]{5}[1-9]{1})$|^(1[0]{5})(\.[0][0]{0,5})?$/",I('chushoudj'))){
                            $this->error('出售底价请输入＞0且≤十亿的数字（限六位小数）！');
                        }
                        $data['chushoudj']=I('chushoudj');
                    }
                    if(I('chuzudj')){
                        if(!preg_match("/^([1-9][0-9]{0,4})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{5})(\.[0][0]{0,1})?$/",I('chuzudj'))){
                            $this->error('出租底价请输入＞0且≤十万的数字（限两位小数）！');
                        }
                        $data['chuzudj']=I('chuzudj');
                    }
                }
                if(I('shoujia')){
                    if(!preg_match("/^([1-9][0-9]{0,4})(\.[0-9]{1,6})?$|^([0]\.[1-9][0-9]{0,5})$|^([0]\.[0][0-9]{0,4}[1-9]{1})$|^([0]\.[0]{2}[0-9]{0,3}[1-9]{1})$|^([0]\.[0]{3}[0-9]{0,2}[1-9]{1})$|^([0]\.[0]{4}[0-9]{0,1}[1-9]{1})$|^([0]\.[0]{5}[1-9]{1})$|^(1[0]{5})(\.[0][0]{0,5})?$/",I('shoujia'))){
                        $this->error('售价请输入＞0且≤十亿的数字（限六位小数）！');
                    }
                    $data['shoujia']=I('shoujia');
                }
                if (I('zujia')) {
                    if(!preg_match("/^([1-9][0-9]{0,4})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{5})(\.[0][0]{0,1})?$/",I('zujia'))){
                        $this->error('租价请输入＞0且≤十万的数字（限两位小数）！');
                    }
                    $data['zujia']=I('zujia');
                    $data['zujialx']=I('zujialx');
                }
                if(I('mianji')){
                    if(!preg_match("/^([1-9][0-9]{0,3})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{4})(\.[0][0]{0,1})?$/",I('mianji'))){
                        $this->error('建筑面积请输入＞0且≤一万的数字（限两位小数）！');
                    }
                    $data['mianji']=I('mianji');
                }
                if(I('symianji')){
                    if(!preg_match("/^([1-9][0-9]{0,3})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{4})(\.[0][0]{0,1})?$/",I('symianji'))){
                        $this->error('使用面积请输入＞0且≤一万的数字（限两位小数）！');
                    }
                    $data['symianji']=I('symianji');
                }
                $louceng=I('louceng');
                $zlouceng=I('zlouceng');
                $shi=I('shi');
                $ting=I('ting');
                $wei=I('wei');
                $chu=I('chu');
                $yangtai=I('yangtai');
                $ti=I('ti');
                $hu=I('hu');
                $cqnianxian=I('cqnianxian');
                if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$louceng)){
                    $this->error('楼层首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
                }
                if(!preg_match("/^([1-9]{1})$|^([1-9][0-9]{1})$|^(1[0-9]{2})$|^(2[0]{2})$/",$zlouceng)){
                    $this->error('总楼层请输入＞0≤200的整数！');
                }
                if(!preg_match("/^([1-9]{1})$|^(1[0]{1})$/",$shi) || !preg_match("/^([1-9]{1})$|^(1[0]{1})$/",$ting) || !preg_match("/^$|^([1-9]{1})$|^(1[0]{1})$/",$wei) || !preg_match("/^$|^([1-9]{1})$|^(1[0]{1})$/",$chu) || !preg_match("/^$|^([1-9]{1})$|^(1[0]{1})$/",$yangtai)){
                    $this->error('户型请输入＞0≤10的整数！');
                }
                if(!preg_match("/^$|^([1-9][0-9]{0,1})$|^(1[0]{2})$/",$ti) || !preg_match("/^$|^([1-9][0-9]{0,1})$|^(1[0]{2})$/",$hu)){
                    $this->error('梯户请输入＞0≤100的整数！');
                }
                if(!preg_match("/^$|^([1-9][0-9]{0,2})$|^(1[0]{3})$/",$cqnianxian)){
                    $this->error('产权年限请输入＞0≤1000的整数！');
                }
                $beizhu=preg_replace ( "/\s(?=\s)/","\\1", I('beizhu') );
                if(!preg_match("/^$|^[\s\S]{0,300}$/",$beizhu)){
                    $this->error('备注只能输入300个字符！');
                }
                if(I('mianji')!="" and I('shoujia')!=""){
                    $num1=I('shoujia')*10000;
                    $num2=I('mianji');
                    $num=$num1/$num2;
                    $danjia=number_format($num,2,".", "");
                    $data['danjia']=$danjia;
                }
                if (I('chaoxiang')) {
                    $data['chaoxiang']=I('chaoxiang');
                }
                $data['zhuangxiu']=I('zhuangxiu');
                $pt1=array_keys(I('peitao')); 
                $pt2=implode(',',$pt1);
                $data['peitao']=$pt2;
                if (I('xianzhuang')) {
                    $data['xianzhuang']=I('xianzhuang');
                }
                if (I('fwleixing')) {
                    $data['fwleixing']=I('fwleixing');
                }
                if (I('jiegou')) {
                    $data['jiegou']=I('jiegou');
                }
                $data['cqxingzhi']=I('cqxingzhi');
                $data['cqnianxian']=$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']=$shi;
                $data['ting']=$ting;
                $data['wei']=$wei;
                $data['chu']=$chu;
                $data['yangtai']=$yangtai;
                $data['louceng']=$louceng;
                $data['zlouceng']=$zlouceng;
                $data['ti']=$ti;
                $data['hu']=$hu;
                $data['niandai']=I('niandai');
                $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('waiwangtb')){
                    $waiwangtb=1;
                }else{
                    $waiwangtb=0;
                }
                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['waiwangtb']=$waiwangtb;
                $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['xianzhuang']!=I('xianzhuang') && ($fy1['xianzhuang']==true || I('xianzhuang')==true)) {
                    $xiugai.=get_xiugai($fy1['xianzhuang'],I('xianzhuang'),'xianzhuang');
                }
                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['xianzhuang']!=I('xianzhuang') && ($fy1['xianzhuang']==true || I('xianzhuang')==true)) {
                    $xiugai.=get_xiugai($fy1['xianzhuang'],I('xianzhuang'),'xianzhuang');
                }
                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 ($is_rbacfdj == 1) {
                    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['waiwangtb']!=$waiwangtb && ($fy1['waiwangtb']==true || $waiwangtb==true)) {
                    $wai=$fy1['waiwangtb']?"是":"否";
                    $wai1=$waiwangtb?"是":"否";
                    $xiugai.="外网同步:[".$wai."]=>[".$wai1."];";
                }
                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->xianzhuang=M('Peizhi')->where(array('pzming'=>'xianzhuang','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 ($fy1['leixing'] == 1) {
                    $fukuan="fukuan";
                } elseif ($fy1['leixing'] == 2) {
                    $fukuan="zlfukuan";
                }
                $this->fukuan=M('Peizhi')->where(array('pzming'=>$fukuan,'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);
                /*p($peitao2);
                die;*/
                $this->fangyuan=M('fangyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->find();
                $this->display();
            }
        }
        //变更状态
        public function bgfyzt(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(695,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            if (IS_POST) {
                if ($fangyuan['zhuangtai'] == $options_arr['fychengjiao_zhuangtai']){
                    $this->error('房源已成交');
                }
                $data['zhuangtai']=I('zhuangtai');
                $data['xiugaisj']=time();
                $yzt=M('peizhi')->where(array('pzming'=>'zhuangtai','lxid'=>$fangyuan['zhuangtai']))->getField('lxming');
                $xzt=M('peizhi')->where(array('pzming'=>'zhuangtai','lxid'=>I('zhuangtai')))->getField('lxming');
                $isok=M("fangyuan")->where(array('id'=>I('id')))->save($data);
                if ($isok){
                    $data_rizhi['zy_type']=1;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=24;
                    $data_rizhi['zy_id']=I('id');
                    $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                    $neirong="变更状态:[".$yzt."]=>[".$xzt."]";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('变更成功');
                }else{
                    $this->error('变更失败');
                }
            }else{
                $this->fyzt=$fangyuan['zhuangtai'];
                $this->zhuangtai=M('Peizhi')->where(array('pzming'=>'zhuangtai','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display();
            }
        }
        //调取
    	public function diaoqu() {
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(58,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->error('您没有权限!');
            }
            $is_rbacfdq = _rbac_node_show(862);
            if (!$is_rbacfdq && ($fangyuan['fpdq'] != 2)) {
                $this->error('您没有权限!');
            }
            $is_rbacfdh = _rbac_node_show(859);
            $is_rbacfdz = _rbac_node_show(860);
            if (!$is_rbacfdh && !$is_rbacfdz && ($fangyuan['fpdh'] == 1) && ($fangyuan['fpdz'] == 1)) {
                $this->error('您没有权限!');
            }
            $guohu_options=M('options')->where(array('option_name'=>'diaoqu_options'))->find();
            $diaoqu_arr = json_decode($guohu_options['option_value'],true);
            if ($diaoqu_arr['sz_ytpe'] == 1 && session('username') != C('RBAC_SUPERADMIN')) {
                switch ($diaoqu_arr['sz_ytpe1']['type']) {
                    case '1':
                        $startUnix = strtotime(date('Y-m-d',time()));
                        break;
                    case '2':
                        $startUnix = strtotime(date('Y-m-d', strtotime('this week')));
                        break;
                    case '3':
                        $startUnix = strtotime(date('Y-m', time()) . '-01 00:00:00');
                        break;
                    case '4':
                        $season = ceil((date('n'))/3);
                        $startUnix = mktime(0, 0, 0,$season*3-3+1,1,date('Y'));
                        break;
                    case '5':
                        $startUnix = strtotime(date('Y', time()) . '-01-01 00:00:00');
                        break;
                    default:
                        $startUnix = strtotime(date('Y-m-d',time()));
                        break;
                }
                $find = M('xianzhi')->where(array('fyid'=>$id,'uid'=>session('uid'),'shijian'=>array('gt',$startUnix)))->find();
                $map = 'uid='.session('uid');
                $map .= ' and  shijian>="'.$startUnix.'"';
                $sql = "select count(*) from (select * from __XIANZHI__ where $map group by fyid) as a";
                $Model = new \Think\Model;
                $count=$Model->query($sql);
                if ($count[0]['count(*)'] >= $diaoqu_arr['sz_ytpe1']['count']) {
                    $this->error('调取次数已用完!');
                }
                $sycishu = $diaoqu_arr['sz_ytpe1']['count'] - $count[0]['count(*)'] - 1;
            }elseif ($diaoqu_arr['sz_ytpe'] == 2 && session('username') != C('RBAC_SUPERADMIN')) {
                $role_id=M('role_user')->where(array('user_id'=>session('uid')))->getField('role_id');
                switch ($diaoqu_arr['sz_ytpe2'][$role_id]['type']) {
                    case '1':
                        $startUnix = strtotime(date('Y-m-d',time()));
                        break;
                    case '2':
                        $startUnix = strtotime(date('Y-m-d', strtotime('this week')));
                        break;
                    case '3':
                        $startUnix = strtotime(date('Y-m', time()) . '-01 00:00:00');
                        break;
                    case '4':
                        $season = ceil((date('n'))/3);
                        $startUnix = mktime(0, 0, 0,$season*3-3+1,1,date('Y'));
                        break;
                    case '5':
                        $startUnix = $startUnix = strtotime(date('Y', time()) . '-01-01 00:00:00');
                        break;
                    default:
                        $startUnix = strtotime(date('Y-m-d',time()));
                        break;
                }
                $find = M('xianzhi')->where(array('fyid'=>$id,'uid'=>session('uid'),'shijian'=>array('gt',$startUnix)))->find();
                $map = 'uid='.session('uid');
                $map .= ' and  shijian>="'.$startUnix.'"';
                $sql = "select count(*) from (select * from __XIANZHI__ where $map group by fyid) as a";
                $Model = new \Think\Model;
                $count=$Model->query($sql);
                if ($count[0]['count(*)'] >= $diaoqu_arr['sz_ytpe2'][$role_id]['count']) {
                    $this->error('调取次数已用完!');
                }
                $sycishu = $diaoqu_arr['sz_ytpe2'][$role_id]['count'] - $count[0]['count(*)'] - 1;
            }
            $data['fyid']=$id;
            $data['uid']=session('uid');
            $data['time']=date("Y-m");
            $data['shijian']=time();
            M('xianzhi')->add($data);
            if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
                $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;
            }
            if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
                $diaoqu['zuodong']=$fangyuan['zuodong'];
                $diaoqu['danyuan']=$fangyuan['danyuan'];
                $diaoqu['fanghao']=$fangyuan['fanghao'];
            }
            if ($sycishu) {
                $info="剩余调取数为".$sycishu."次";
            }
            $data1=array('status'=>1,'diaoqu1'=>$diaoqu,'info'=>$info);
            header("Content-type: application/json");
            exit(json_encode($data1));
        }
        //写跟进
        public function genjin(){
            $fangyuan=M('fangyuan')->where(array('id'=>I('fyid')))->find();
            $is_rbac = _rbac_btn_show(61,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $gjid = I('gjid');
            $gongsiid = session('gongsiid');
            //音频操作ajax（上传，删除）
            switch (I('gt')) {
                case '1':
                    //语音上传
                    $upload = new \Think\Upload();
                    $upload->maxSize = 2097152;
                    $upload->exts = ''; //array('mp3','ogg');
                    $upload->rootPath = './Upload/';
                    $upload->savePath = './Genjin/'.$gongsiid.'/'.$fangyuan['bianhao'].'/';
                    $upload->autoSub = false;
                    $uplaod->replace = true;    //存在同名文件是否是覆盖，默认为false
                    $upload->saveName = $gjid;
                    //开始上传音频文件
                    $info = $upload->upload();
                    if (!$info) {
                        $this->error($upload->getError());
                    }else{
                        M('fygenjin')->where(array('id'=>$gjid))->setField(array('gjvoice'=>1));
                        $this->success($info);
                    }
                    break;
                case '2':
                    $isok = unlink('./Upload/Genjin/'.$gongsiid.'/'.$fangyuan['bianhao'].'/'.$gjid.'.mp3');
                    if ($isok) {
                        M('fygenjin')->where(array('id'=>$gjid))->setField(array('gjvoice'=>null)); 
                    }
                    $this->success('删除语音成功！');
                    break;
                default:
                    break;
            }
            if (IS_POST) {
                $data['gongsiid']=session("gongsiid");
                $data['fybh']=I('fybh');
                $data['fyid']=I('fyid');
                $data['uid']=session("uid");
                $data['genjinfs']=I('genjinfs');
                $data['neirong']=I('neirong');
                $data['shijian']=strtotime(I('gjshijian'));
                $data['time']=time();
                $isok = M('fygenjin')->add($data);
                if ($isok) {
                    $data_rizhi['zy_type']=1;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=5;
                    $data_rizhi['zy_id']=$data['fyid'];
                    $data_rizhi['zy_bianhao']=$data['fybh'];
                    $data_rizhi['neirong']=$data['neirong'];
                    M('rizhi')->add($data_rizhi);
                    $data_genjin['zhgjsj']=time();
                    $data_genjin['xiugaisj']=time();
                    $this->success('添加成功');
                }else{
                    $this->error('添加失败');
                }
            }else{
                $this->genjinfs=M('Peizhi')->where(array('pzming'=>'genjinfs','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display();
            }
        }
        //设置全景地址处理
        public function quanjingHandle(){
        	$id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(76,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
        	$data['vr_url']=I('text');
            $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']=6;
                $data_rizhi['zy_id']=$id;
                $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                $neirong="全景设置:[".$fangyuan['vr_url']."]=>[".$data['vr_url']."]";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('添加成功');
            }else{
                $this->error('添加失败');
            }
        }
        //修改门牌号
        public function xgzuodong(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(150,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $is_rbacfdh = _rbac_node_show(859);
            $is_rbacfdz = _rbac_node_show(860);
            if (!$is_rbacfdh && !$is_rbacfdz && ($fangyuan['fpdh'] == 1) && ($fangyuan['fpdz'] == 1)) {
                $this->redirect('Index/error');
            }
            if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
                $this->is_rbacfdh=1;
            }
            if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
                $this->is_rbacfdz=1;
            }
            if (IS_POST) {
                if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
                    $dianhua1=I('dianhua1');
                    $dianhua2=I('dianhua2');
                    $dianhua3=I('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}$/",$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 (($dianhua1==true && $dianhua2==true && $dianhua1==$dianhua2) || ($dianhua1==true && $dianhua3==true && $dianhua1==$dianhua3) || ($dianhua1==true && $dianhua2==true && $dianhua2==$dianhua3)) {
                        $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');
                }
                if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
                    $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('房号首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
                    }
                    $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
                    $options_arr = json_decode($chengjiao_options['option_value'],true);
                    $condition['gongsiid']=session('gongsiid');
                    $condition['zhuangtai']=array('neq',$options_arr['fychengjiao_zhuangtai']);
                    $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('房源已存在');
                    }
                }
                if (($is_rbacfdh || ($fangyuan['fpdh'] == 2)) && ($is_rbacfdz || ($fangyuan['fpdz'] == 2))) {
                    $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;
                } else if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
                    $xiugaiqian='业主：'.$fangyuan['yezhu'].$yezhulxq.'。电话：'.$fangyuan['yezhudianhua'].'（'.$yezhugxq.'）；'.$fangyuan['yezhudianhua2'].'（'.$yezhugx2q.'）；'.$fangyuan['yezhudianhua3'].'（'.$yezhugx3q.'）。';
                    $xiugaihou='业主：'.I('yezhu').$yezhulxh.'。电话：'.$dianhua1.'（'.$yezhugxh.'）；'.$dianhua2.'（'.$yezhugx2h.'）；'.$dianhua3.'（'.$yezhugx3h.'）。';
                } else if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
                    $xiugaiqian='座栋：'.$fangyuan['zuodong'].'。单元：'.$fangyuan['danyuan'].'。房号：'.$fangyuan['fanghao'];
                    $xiugaihou='座栋：'.$zuodong.'。单元：'.$danyuan.'。房号：'.$fanghao;
                }
                $map['xiugaiqian']=$xiugaiqian;
                $map['xiugaihou']=$xiugaihou;
                $map['time']=time();
                $map['fybianhao']=$fangyuan['bianhao'];
                $map['uid']=session('uid');
                M('fyxiugai')->add($map);
                if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
                    $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;
                }
                if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
                    $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{
                $this->fangyuan=$fangyuan;
                if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
                    $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 delEsfy(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(380,$fangyuan['zhuangtai'],$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(766,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            $condition['gongsiid']=session('gongsiid');
            $condition['zhuangtai']=array('neq',$options_arr['fychengjiao_zhuangtai']);
            $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(767,$fangyuan['zhuangtai'],$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 sipanHandle(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(379,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            if ($fangyuan['zhuangtai'] == $options_arr['fychengjiao_zhuangtai']){
                $this->error('房源已成交');
            }
            $data['gspan']=1;
			$data['zhuangtai']=$options_arr['fysipan_zhuangtai'];
			$data['weihurenid']=session('uid');
			$data['weihuren']=session('ygmingcheng');
            $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']=3;
                $data_rizhi['zy_id']=$id;
                $data_rizhi['zy_bianhao']=$fangyuan['bianhao'];
                $neirong="转为私盘";
                $data_rizhi['neirong']=$neirong;
                $rizhi=M('rizhi')->add($data_rizhi);
                $this->success('修改成功');
            }else{
                $this->error('修改失败');
            }
        }
        public function gongpanHandle(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(380,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            if ($fangyuan['zhuangtai'] == $options_arr['fychengjiao_zhuangtai']){
                $this->error('房源已成交');
            }
			$data['gspan']=2;
			$data['zhuangtai']=$options_arr['fygongpan_zhuangtai'];
            $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']=4;
				$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 bgwhr(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(381,$fangyuan['zhuangtai'],$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');
                $this->display();
            }
        }
        //编辑视频
        public function editshipin(){
            $id=I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->field('zhuangtai,weihurenid')->find();
            $is_rbac = _rbac_btn_show(498,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                if (preg_match_all('/src=&quot;(.*?)&quot;/', I('shipin_url'), $matches)) {
                    $s1 = $matches[1][0];
                    $shipin_url='<iframe src="'.$s1.'" frameborder="0" allowfullscreen="true" width="100%" height="100%"></iframe>';
                }elseif (preg_match_all('/src=\'(.*?)\'/', I('shipin_url'), $matches)) {
                    $s1 = $matches[1][0];
                    $shipin_url='<iframe src="'.$s1.'" frameborder="0" allowfullscreen="true" width="100%" height="100%"></iframe>';
                }else{
                    $this->error('修改失败!');
                }
                $isok=M('fangyuan')->where(array('id'=>$id))->setField('shipin_url',$shipin_url);
                if ($isok) {
                    $fyxgsj=M('fangyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
                    $this->success('修改成功!');
                }else{
                    $this->error('修改失败!');
                }
            }else{
                $this->shipin_url=M('fangyuan')->where(array('id'=>$id))->getField('shipin_url');
                $this->display();
            }
        }
        //实勘
        public function shikan(){
            $id = I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->field('zhuangtai,weihurenid')->find();
            $is_rbac = _rbac_btn_show(565,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $bianhao = M('fangyuan')->where(array('id'=>$id))->getField('bianhao');
            $isshikan = M('shikan')->where(array('fybh'=>$bianhao))->find();
            if ($isshikan) {
                $this->error('已有人实勘!');
            }
            $data['uid']=session('uid');
            $data['addtime']=time();
            $data['fybh']=$bianhao;
            $isok = M('shikan')->fetchSql($fetchSql)->add($data);
            if ($isok) {
                $fyxgsj=M('fangyuan')->where(array('id'=>$id))->fetchSql($fetchSql)->setField('xiugaisj',time());
                $this->success('实勘成功!');
            }else{
                $this->error('实勘失败!');
            }
        }
        //委办
        public function weiban(){
            $fangyuan=M('fangyuan')->where(array('bianhao'=>I('fybianhao')))->field('zhuangtai,weihurenid')->find();
            $is_rbac = _rbac_btn_show(564,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $isshikan = M('weiban')->where(array('fybianhao' => I('fybianhao'),'status'=>1))->find();
                if ($isshikan) {
                    $this->error('已有人委办!');
                }
                $file_arr = I('file_path');
                if (!$file_arr) {
                    $this->error('请上传图片！');
                }else{
                    if (count($arr) > 6) {
                        $this->error('最多上传6张！');
                    }
                }
                $wb_uid = M('yonghu')->where(array('ygmingcheng'=>I('wb_user')))->getField('id');
                if (!$wb_uid) {
                    $this->error('查找不到该用户！');
                }
                $data['fybianhao'] = I('fybianhao');
                $data['wbtime'] = strtotime(I('wbtime'));
                $time_s = explode(' - ',I('shijian'));
                $data['uid'] = $wb_uid;
                $data['xieyibh'] = I('xieyibh');
                $data['jiage'] = I('jiage');
                $data['baozhengjin'] = I('baozhengjin');
                $data['startunix'] = strtotime($time_s[0]);
                $data['endunix'] = strtotime($time_s[1]);
                $data['beizhu'] = I('beizhu');
                $data['addtime'] = time();
                $data['adduid'] = session('uid');
                $data['status'] = 1;
                $isok = M('weiban')->add($data);
                if ($isok) {
                    foreach ($file_arr as $value) {
                        $file_img_arr[] = array(
                            'data_id' => $isok,
                            'img_path' => $value,
                            'addtime' => time(),
                            'adduid' => session('uid'),
                            'gongsiid' => session('gongsiid'),
                            'data_table' => 'weiban'
                        );
                    }
                    M('photos')->addAll($file_img_arr);
                    $fyxgsj=M('fangyuan')->where(array('bianhao'=>I('fybianhao')))->fetchSql($fetchSql)->setField('xiugaisj',time());
                    $this->success('保存成功!');
                } else {
                    $this->error('保存失败!');
                }
            } else {
                $this->display();
            }
        }
        //添加钥匙
        public function yaoshi(){
            $fangyuan = M('fangyuan')->where(array('bianhao' => I('fybianhao')))->field('zhuangtai,weihurenid')->find();
            $is_rbac = _rbac_btn_show(750, $fangyuan['zhuangtai'], $fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $file_arr = I('file_path');
                if (!$file_arr) {
                    $this->error('请上传图片！');
                }else{
                    if (count($arr) > 6) {
                        $this->error('最多上传6张！');
                    }
                }
                $data['fybianhao'] = I('fybianhao');
                $data['ys_time'] = strtotime(I('ys_time'));
                $ys_uid = I('ys_user');
                if (!$ys_uid) {
                    $this->error('查找不到该用户！');
                }
                $data['ys_uid'] = $ys_uid;
                $data['ys_bumen'] = I('ys_bumen');
                $data['ys_bianhao'] = I('ys_bianhao');
                $data['ys_weizhihao'] = I('ys_weizhihao');
                if (I('ys_menjin')) {
                    $data['ys_menjin'] = 1;
                }
                $data['beizhu'] = I('beizhu');
                $data['addtime'] = time();
                $data['adduid'] = session('uid');
                $data['status'] = 1;
                $isok = M('yaoshi')->add($data);
                if ($isok) {
                    $data_fangyuan['xiugaisj'] = time();
                    $data_fangyuan['shouyaoren'] = $ys_uid;
                    $data_fangyuan['shouyaobm'] = $data['ys_bumen'];
                    $fytjys=M('fangyuan')->where(array('bianhao'=>$data['fybianhao']))->fetchSql($fetchSql)->save($data_fangyuan);
                    foreach ($file_arr as $value) {
                        $file_img_arr[] = array(
                            'data_id' => $isok,
                            'img_path' => $value,
                            'addtime' => time(),
                            'adduid' => session('uid'),
                            'gongsiid' => session('gongsiid'),
                            'data_table' => 'yaoshi'
                        );
                    }
                    M('photos')->addAll($file_img_arr);
                    $this->success('保存成功!');
                } else {
                    $this->error('保存失败!');
                }
            } else {
                $parentid = I("get.parentid",0,'intval');
                $select_categorys = bumen_option( $parentid, 739);
                $this->assign("select_categorys", $select_categorys);
                $this->display();
            }
        }
        //移动钥匙
        public function ydyaoshi(){
            $fybianhao = I('fybianhao');
            $fangyuan = M('fangyuan')->where(array('bianhao' => $fybianhao))->field('zhuangtai,weihurenid')->find();
            $is_rbac = _rbac_btn_show(753, $fangyuan['zhuangtai'], $fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $q_uid = I('q_user');
                if (!$q_uid) {
                    $this->error('查找不到该用户！');
                }
                $data['q_time'] = strtotime(I('q_time'));
                $data['q_uid'] = $q_uid;
                $data['q_bumen'] = I('q_bumen');
                $data['ys_id'] = I('ys_id');
                $data['q_type'] = I('q_type');
                $data['beizhu'] = I('beizhu');
                $data['addtime'] = time();
                $data['adduid'] = session('uid');
                $isok = M('yaoshi_log')->add($data);
                if ($isok) {
                    M('fangyuan')->where(array('bianhao'=>I('fybianhao')))->setField('xiugaisj',time());
                    $this->success('操作成功！');
                }else{
                    $this->error('操作失败！');
                }
            }else{
                $this->yaoshi = M('yaoshi')->where(array('fybianhao'=>$fybianhao,'status'=>1))->select();
                $parentid = I("get.parentid",0,'intval');
                $select_categorys = bumen_option( $parentid, 739);
                $this->assign("select_categorys", $select_categorys);
                $this->display();
            }
        }
        //上传附件
        public function fujianimg(){
            $files = $_FILES['file'];
            // 上传
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './Upload/fujian/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            // 上传文件  
            $info   =   $upload->upload();
            //p($info);die;
            $file_name = '/Upload/fujian/'.$info['file']['savepath'].$info['file']['savename'];
            //p($info);die;
            $data_re = array(
                'path'=>$file_name,
                'y_name'=>$info['file']['name']
            );
            if (!$info) {
                $this->error($upload->getError());
            }else{
                $data = array(
                    'info' => '上传成功！',
                    'data' => $data_re,
                    'status' => 1
                );
                $this->ajaxReturn($data);
            }
        }
        //认证房源
        public function renzheng(){
            $id = I('id');
            $fangyuan=M('fangyuan')->where(array('id'=>$id))->field('zhuangtai,weihurenid')->find();
            $is_rbac = _rbac_btn_show(618,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $bianhao = M('fangyuan')->where(array('id'=>$id))->getField('bianhao');
            $data['renzhengren'] = session('uid');
            $data['renzhengtime'] = time();
            $data['xiugaisj']=time();
            $isok = M('fangyuan')->where(array('id'=>$id))->fetchSql($fetchSql)->save($data);
            if ($isok) {
                $this->success('认证成功!');
            }else{
                $this->error('认证失败!');
            }
        }
    }
?>