<?php

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

    namespace Admin\Controller;
    use Think\Controller;
    class FangyuanController extends CommonController {
        //二手房源列表
        public function Esfy(){
            if (I('get.isget')) {
                $leixing=I('leixing');
                $sousuo=I('sousuo');
                $myfy=I('myfy');
                $mysc=I('mysc');
                $jrll=I('jrll');
                $tupian=I('tupian');
                $xinshang=I('xinshang');
                $wushui=I('wushui');
                $jishou=I('jishou');
                $xuequ=I('xuequ');
                $xinzheng=I('xinzheng');
                $youdaikuan=I('youdaikuan');
                $zhuangtai=I('zhuangtai');
                $zhuangxiu=I('zhuangxiu');
                $chaoxiang=I('chaoxiang');
                $yongtu=I('yongtu');
                $waiwangtb=I('waiwangtb');
                $yaoshi=I('yaoshi');
                $isdel=I('isdel');
                $jiage1=I('jiage1');
                $jiage2=I('jiage2');
                $mianji1=I('mianji1');
                $mianji2=I('mianji2');
                $lurusj1=strtotime(I('shijian1'));
                $lurusj2=strtotime(I('shijian2'));
                $huxing1=I('huxing1');
                $huxing2=I('huxing2');
                $louceng1=I('louceng1');
                $louceng2=I('louceng2');
                $fengpan=I('fengpan');
                $dshenhe=I('dshenhe');
                $condition="gongsiid=".session('gongsiid');
                $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
                $options_arr = json_decode($chengjiao_options['option_value'],true);
                if($isdel){
                    $condition.=" and isdel=1";
                } else {
                    $condition.=" and isdel=2";
                }
                $is_rbacfck = _rbac_node_show(863);
                if (!$is_rbacfck) {
                    $condition.=" and fpck=2";
                }
                if($leixing){//类型
                    $condition.=" and leixing=$leixing";
                }
                if ($sousuo) {//搜索
                    $condition.=" and (fybiaoti like '%$sousuo%' or yezhu like '%$sousuo%' or weihuren like '%$sousuo%' or yezhudianhua like '%$sousuo%' or yezhudianhua2 like '%$sousuo%' or yezhudianhua3 like '%$sousuo%' or bianhao like '%$sousuo%' or xiaoqum like '%$sousuo%')";
                }
                if ($fengpan) {//封盘
                    $condition.=" and zhuangtai in (".$options_arr['fyfengpan_zhuangtai'].")";
                }else{
                    $condition.=" and zhuangtai not in (".$options_arr['fyfengpan_zhuangtai'].")";
                }
                if ($dshenhe) {//待审核
                    $condition.=" and zhuangtai=0";
                }else{
                    $condition.=" and zhuangtai>0";
                }
                if ($zhuangtai) {//状态
                    $condition.=" and zhuangtai=$zhuangtai";
                }
                if ($myfy) {//我的房源
                    $user_id=session('uid');
                    $condition.=" and weihurenid=$user_id";
                }
                if ($mysc) {//我的收藏
                    $sc = M('shoucang')->where(array('user_id'=>session('uid')))->select();
                    if ($sc) {
                        foreach ($sc as $key => $value) {
                            $cs_arr[] = $value['fyid'];
                        }
                        $in_sc = implode(',', $cs_arr);
                    } else {
                        $in_sc = 0;
                    }
                    $condition.=" and id in ($in_sc)";
                }
                if ($jrll) {//今日浏览
                    $today="sj".date("m-d");
                    if (!cookie($today)) {
                        $history=0;
                    }else{
                        $history = cookie($today);
                    }
                    $condition.=" and id in ($history)";
                }
                if ($xinshang) {
                    $xshang=time()-(86400*3);
                    $condition.=" and lurusj>$xshang";
                }
                if ($tupian) {//图片
                    $condition.=" and tupian=$tupian";
                }
                if ($wushui) {//无税
                    $condition.=" and wushui=$wushui";
                }
                if ($jishou) {//急售
                    $condition.=" and jishou=$jishou";
                }
                if ($xuequ) {//学区
                    $condition.=" and xuequ=$xuequ";
                }
                if ($xinzheng) {//新证
                    $condition.=" and xinzheng=$xinzheng";
                }
                if ($youdaikuan) {//有贷款
                    $condition.=" and youdaikuan=$youdaikuan";
                }
                if ($zhuangxiu) {//装修
                    $condition.=" and zhuangxiu=$zhuangxiu";
                }
                if ($chaoxiang) {//朝向
                    $condition.=" and chaoxiang=$chaoxiang";
                }
                if ($yongtu) {//用途
                    $condition.=" and yongtu=$yongtu";
                }
                if ($waiwangtb) {//外网同步
                    $condition.=" and waiwangtb=$waiwangtb";
                }
                if ($yaoshi) {//是否有钥匙
                    $condition.=" and (shouyaobm<>'' or shouyaoren<>'')";
                }
                if ($leixing==1) {
                    if ($jiage1!="" && $jiage2!="") {//售价区间
                        $condition.=" and shoujia>=$jiage1 and shoujia<=$jiage2";
                    }else if ($jiage1) {
                        $condition.=" and shoujia>=$jiage1";
                    }else if ($jiage2) {
                        $condition.=" and shoujia<=$jiage2";
                    }
                } elseif ($leixing==2) {
                    if ($jiage1!="" && $jiage2!="") {//租价区间
                        $condition.=" and zujia>=$jiage1 and zujia<=$jiage2";
                    }else if ($jiage1) {
                        $condition.=" and zujia>=$jiage1";
                    }else if ($jiage2) {
                        $condition.=" and zujia<=$jiage2";
                    }
                }
                if ($mianji1!="" && $mianji2!="") {//建筑面积区间
                    $condition.=" and mianji>=$mianji1 and mianji<=$mianji2";
                }else if ($mianji1) {
                    $condition.=" and mianji>=$mianji1";
                }else if ($mianji2) {
                    $condition.=" and mianji<=$mianji2";
                }
                if ($lurusj1!="" && $lurusj2!="") {//录入时间区间
                    $lurusj3=$lurusj2+86399;
                    $condition.=" and lurusj>=$lurusj1 and lurusj<=$lurusj3";
                }else if ($lurusj1) {
                    $condition.=" and lurusj>=$lurusj1";
                }else if ($lurusj2) {
                    $lurusj3=$lurusj2+86399;
                    $condition.=" and lurusj<=$lurusj3";
                }
                if ($huxing1!="" && $huxing2!="") {//户型区间
                    $condition.=" and shi>=$huxing1 and shi<=$huxing2";
                }else if ($huxing1) {
                    $condition.=" and shi>=$huxing1";
                }else if ($huxing2) {
                    $condition.=" and shi<=$huxing2";
                }
                if ($louceng1!="" && $louceng2!="") {//楼层区间
                    $condition.=" and louceng>=$louceng1 and louceng<=$louceng2";
                }else if ($louceng1) {
                    $condition.=" and louceng>=$louceng1";
                }else if ($louceng2) {
                    $condition.=" and louceng<=$louceng2";
                }
                /*权限控制开始*/
                $map = "gongsiid=".session('gongsiid');
                $x = _rbac_lists_where(41,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";
                }
                /*权限控制结束*/
                $count=M('fangyuan')->query("select count(*) 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 ");
                $Page  = new \Think\Page($count['0']['count(*)'],20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
                $show  = $Page->show();// 分页显示输出
                $paixu="id DESC";
                if (I('paixu')==1) {
                    $paixu="bianhao DESC";
                }elseif (I('paixu')==2) {
                    $paixu="shoujia DESC";
                }elseif (I('paixu')==3) {
                    $paixu="shoujia ASC";
                }elseif (I('paixu')==4) {
                    $paixu="mianji DESC";
                }elseif (I('paixu')==5) {
                    $paixu="mianji ASC";
                }elseif (I('paixu')==6) {
                    $paixu="danjia DESC";
                }elseif (I('paixu')==7) {
                    $paixu="danjia ASC";
                }elseif (I('paixu')==8) {
                    $paixu="zhgjsj DESC";
                }
                $list="select a.*,b.*,d.* from (select c.*,e.ygmingcheng from __FANGYUAN__ c join (select id as e_id,ygmingcheng from __YONGHU__ where {$map}) e on c.weihurenid=e.e_id where {$condition} order by ".$paixu." limit ".$Page->firstRow.','.$Page->listRows.") a left outer join (select fyid,count(*) dqshu from __XIANZHI__ group by fyid) b on a.id=b.fyid left join (select id as xqid,jianzaond  from __XIAOQU__) d on a.xiaoqu=d.xqid ";
                $Model = new \Think\Model;
                $fangyuan=$Model->query($list);
                foreach ($fangyuan as $key => $value) {
                    $fangyuan[$key]['img'] = get_s_img($value['bianhao']);
                    $photo[$key]=M('photo')->where(array('fybh'=>$value['bianhao'],'image'=>array('neq',$fangyuan[$key]['img'])))->field('image')->select();
                    $fangyuan[$key]['photo'] = $photo[$key];
                }
                $this->assign('fangyuan',$fangyuan);// 赋值数据集
                $this->assign('count',$count);// 赋值分页输出
                $this->assign('page',$show);
                $this->zujialx=M('Peizhi')->where(array('pzming'=>'zujialx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->leixing=M('Peizhi')->where(array('pzming'=>'leixing','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->yongtu=M('Peizhi')->where(array('pzming'=>'yongtu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->zhuangtai=M('Peizhi')->where(array('pzming'=>'zhuangtai','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->chaoxiang=M('Peizhi')->where(array('pzming'=>'chaoxiang','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->zhuangxiu=M('Peizhi')->where(array('pzming'=>'zhuangxiu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->fydengji=M('Peizhi')->where(array('pzming'=>'fydengji','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display('fy_lists');
            } else {
                $this->zhuangtai=M('Peizhi')->where(array('pzming'=>'zhuangtai','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->chaoxiang=M('Peizhi')->where(array('pzming'=>'chaoxiang','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->zhuangxiu=M('Peizhi')->where(array('pzming'=>'zhuangxiu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->yongtu=M('Peizhi')->where(array('pzming'=>'yongtu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display();// 输出模板
            }
        }
        //添加二手房源
        public function addEsfy(){
            $is_rbac = _rbac_btn_show(42,0);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                if (session('gongsiid')=="") {
                    $this->error('请重新登录');
                }
                $fjid=I('fjid');
                if($fjid){
                    $fangjian=M('fjxinxi')->where(array('id'=>$fjid))->find();
                    $xiaoqum=M('xiaoqu')->where(array('id'=>$fangjian['xqid']))->getField('xiaoqum');
                    $zdmwdw=M('zdxinxi')->where(array('id'=>$fangjian['zdid']))->getField('zdmwdw');
                    $dymwdw=M('dyxinxi')->where(array('id'=>$fangjian['dyid']))->getField('dymwdw');
                    $lcmwdw=M('lcxinxi')->where(array('id'=>$fangjian['lcid']))->getField('lcmwdw');
                    $lcshu=M('lcxinxi')->where(array('dyid'=>$fangjian['dyid']))->count();
                }
                if (!_rbac_btn_show(563,0) && !$fangjian) {
                    $this->error('异常错误!');
                }
                if($fangjian['xqid']){
                    $xiaoqu=$fangjian['xqid'];
                }elseif(I('xiaoqu')){
                    $xiaoqu=I('xiaoqu');
                    $xiaoqum=M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('xiaoqum');
                }else{
                    $this->error('请选择小区');
                }
                $xingzhengqu=M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('ssxzq');
                $pianqu=M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('sspianqu');
                $xq=M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('ssxuexiao');
                if($xq){
                    $xuequ=1;
                }else{
                    $xuequ=0;
                }
                if($zdmwdw){
                    $zuodong=$zdmwdw;
                }elseif(I('zuodong')){
                    $zuodong=I('zuodong');
                }else{
                    $this->error('请输入座栋');
                }
                if($dymwdw){
                    $danyuan=$dymwdw;
                }elseif(I('danyuan')){
                    $danyuan=I('danyuan');
                }else{
                    $this->error('请输入单元');
                }
                if($lcmwdw){
                    $louceng=$lcmwdw;
                }elseif(I('louceng')){
                    $louceng=I('louceng');
                }else{
                    $this->error('请输入楼层');
                }
                if($lcshu){
                    $zlouceng=$lcshu;
                }elseif(I('zlouceng')){
                    $zlouceng=I('zlouceng');
                }else{
                    $this->error('请输入总楼层');
                }
                if($fangjian['fjmwdw']){
                    $fanghao=$fangjian['fjmwdw'];
                }elseif(I('fanghao')){
                    $fanghao=I('fanghao');
                }else{
                    $this->error('请输入房号');
                }
                if($fangjian['shi']){
                    $shi=$fangjian['shi'];
                }elseif(I('shi')){
                    $shi=I('shi');
                }else{
                    $this->error('请输入卧室数');
                }
                if($fangjian['ting']){
                    $ting=$fangjian['ting'];
                }elseif(I('ting')){
                    $ting=I('ting');
                }else{
                    $this->error('请输入客厅数');
                }
                if($fangjian['wei']){
                    $wei=$fangjian['wei'];
                }elseif(I('wei')){
                    $wei=I('wei');
                }
                if($fangjian['chu']){
                    $chu=$fangjian['chu'];
                }elseif(I('chu')){
                    $chu=I('chu');
                }
                if($fangjian['yangtai']){
                    $yangtai=$fangjian['yangtai'];
                }elseif(I('yangtai')){
                    $yangtai=I('yangtai');
                }
                if($fangjian['yongtu']){
                    $yongtu=$fangjian['yongtu'];
                }elseif(I('yongtu')){
                    $yongtu=I('yongtu');
                }else{
                    $this->error('请选择用途');
                }
                if($fangjian['jzmianji']){
                    $mianji=$fangjian['jzmianji'];
                }elseif(I('mianji')){
                    $mianji=I('mianji');
                }else{
                    $this->error('请输入建筑面积');
                }
                if($fangjian['symianji']){
                    $symianji=$fangjian['symianji'];
                }elseif(I('symianji')){
                    $symianji=I('symianji');
                }
                if($fangjian['yezhu']){
                    $yezhu=$fangjian['yezhuxm'];
                }elseif(I('yezhu')){
                    $yezhu=I('yezhu');
                }else{
                    $this->error('请输入业主姓名');
                }
                if($fangjian['yezhuxb']){
                    $yezhulx=$fangjian['yezhuxb'];
                }elseif(I('yezhulx')){
                    $yezhulx=I('yezhulx');
                }else{
                    $this->error('请选择业主类型');
                }
                if($fangjian['yezhudianhua']){
                    $yezhudianhua=$fangjian['yezhusj'];
                }elseif(I('yezhudianhua')){
                    $yezhudianhua=I('yezhudianhua');
                }else{
                    $this->error('请输入业主电话');
                }
                if($fangjian['zhuangxiu']){
                    $zhuangxiu=$fangjian['zhuangxiu'];
                }elseif(I('zhuangxiu')){
                    $zhuangxiu=I('zhuangxiu');
                }else{
                    $this->error('请选择装修');
                }
                if($fangjian['chaoxiang']){
                    $chaoxiang=$fangjian['chaoxiang'];
                }elseif(I('chaoxiang')){
                    $chaoxiang=I('chaoxiang');
                }else{
                    $this->error('请选择朝向');
                }
                if($fangjian['xianzhuang']){
                    $xianzhuang=$fangjian['xianzhuang'];
                }elseif(I('xianzhuang')){
                    $xianzhuang=I('xianzhuang');
                }else{
                    $this->error('请选择现状');
                }
                if($fangjian['fwleixing']){
                    $fwleixing=$fangjian['fwleixing'];
                }elseif(I('fwleixing')){
                    $fwleixing=I('fwleixing');
                }else{
                    $this->error('请选择房屋类型');
                }
                if($fangjian['cqxingzhi']){
                    $cqxingzhi=$fangjian['chanquan'];
                }elseif(I('cqxingzhi')){
                    $cqxingzhi=I('cqxingzhi');
                }
                $cqnianxian=I('cqnianxian');
                $ti=I('ti');
                $hu=I('hu');
                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(!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,3})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{4})(\.[0][0]{0,1})?$/",$mianji) || !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})?$/",$symianji)){
                    $this->error('面积请输入＞0且≤一万的数字（限两位小数）！');
                }
                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}$|^0\d{2,3}-?\d{7,8}$/",$yezhudianhua)){
                    $this->error('业主电话请输入正确的手机号码或电话号码！');
                }
                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的整数！');
                }
                if (I('leixing')==1) {
                    $chushoudj=I('chushoudj');
                    $shoujia=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})?$/",$chushoudj)){
                        $this->error('出售底价请输入＞0且≤十亿的数字（限六位小数）！');
                    }
                    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})?$/",$shoujia)){
                        $this->error('售价请输入＞0且≤十亿的数字（限六位小数）！');
                    }
                }elseif (I('leixing')==2) {
                    $chuzudj=I('chuzudj');
                    $zujia=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})?$/",$chuzudj)){
                        $this->error('出租底价请输入＞0且≤十万的数字（限两位小数）！');
                    }
                    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})?$/",$zujia)){
                        $this->error('租价请输入＞0且≤十万的数字（限两位小数）！');
                    }
                }
                $beizhu=preg_replace ( "/\s(?=\s)/","\\1", I('beizhu') );
                if(!preg_match("/^$|^[\s\S]{0,300}$/",$beizhu)){
                    $this->error('备注只能输入300个字符！');
                }
                $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['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;
                }
                $zhan_bumen = M('xingzhengqu')->where(array('id'=>$xingzhengqu))->getField('bumen');
                $data['zhan_bumen'] = $zhan_bumen;
                $data['xiaoqu']=$xiaoqu;
                $data['xiaoqum']=$xiaoqum;
                $data['xuequ']=$xuequ;
                $data['pianqu']=$pianqu;
                $data['xingzhengqu']=$xingzhengqu;
                $data['zuodong']=$zuodong;
                $data['danyuan']=$danyuan;
                $data['louceng']=$louceng;
                $data['zlouceng']=$zlouceng;
                $data['fanghao']=$fanghao;
                $data['shi']=$shi;
                $data['ting']=$ting;
                $data['wei']=$wei;
                $data['chu']=$chu;
                $data['yangtai']=$yangtai;
                $data['symianji']=$symianji;
                $data['mianji']=$mianji;
                $data['yezhudianhua']=$yezhudianhua;
                $data['yongtu']=$yongtu;
                $data['yezhu']=$yezhu;
                $data['yezhulx']=$yezhulx;
                $data['zhuangxiu']=$zhuangxiu;
                $data['chaoxiang']=$chaoxiang;
                $data['xianzhuang']=$xianzhuang;
                $data['fwleixing']=$fwleixing;
                $data['cqxingzhi']=$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']=$cqnianxian;
                $data['fyshuifei']=I('fyshuifei');
                $data['kanfangfs']=I('kanfangfs');
                $data['laiyuan']=I('laiyuan');
                $data['yaoshidian']=I('yaoshidian');
                $data['weihuren']=session('ygmingcheng');
                $data['weihurenid']=session('uid');
                $data['lururenid']=session('uid');
                $data['fybiaoti']=I('fybiaoti');
                $data['ti']=$ti;
                $data['hu']=$hu;
                $data['niandai']=I('niandai');
                $data['chuzudj']=I('chuzudj');
                $data['fwleixing']=I('fwleixing');
                $data['beizhu']=$beizhu;
                $data['chanquanzheng']=I('chanquanzheng');
                $data['tudizheng']=I('tudizheng');
                $data['budongchanzheng']=I('budongchanzheng');
                if (I('shouyaobm')) {
                    $data['shouyaobm']=I('shouyaobm');
                    $data['shouyaoren']=session('uid');
                }
                $data['czriqi']=strtotime(I('czriqi'));
                $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['lurusj']=time();
                $data['zhgjsj']=time();
                $data['xiugaisj']=time();
                $data['zhuangtai']=I('zhuangtai');//状态
                $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->zhuangtai=M('Peizhi')->where(array('pzming'=>'zhuangtai','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 (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();
                if(I('fjid')){
                    $fangjian=M('fjxinxi')->where(array('id'=>I('fjid')))->find();
                    $this->fangjian=$fangjian;
                    $this->xiaoqum=M('xiaoqu')->where(array('id'=>$fangjian['xqid']))->getField('xiaoqum');
                    $this->zdmwdw=M('zdxinxi')->where(array('id'=>$fangjian['zdid']))->getField('zdmwdw');
                    $this->dymwdw=M('dyxinxi')->where(array('id'=>$fangjian['dyid']))->getField('dymwdw');
                    $this->lcmwdw=M('lcxinxi')->where(array('id'=>$fangjian['lcid']))->getField('lcmwdw');
                    $this->lcshu=M('lcxinxi')->where(array('dyid'=>$fangjian['dyid']))->count();
                }
                $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_rbacfck = _rbac_node_show(863);
            if (!$is_rbacfck && ($fangyuan['fpck'] != 2)) {
                $this->redirect('Index/error');
            }
            $is_rbac = _rbac_btn_show(46,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $is_rbacfdh = _rbac_node_show(859);
            if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
                $this->is_rbacfdh=1;
            }
            $is_rbacfdz = _rbac_node_show(860);
            if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
                $this->is_rbacfdz=1;
            }
            $is_rbacfdj = _rbac_node_show(861);
            if ($is_rbacfdj || ($fangyuan['fpdj'] == 2)) {
                $this->is_rbacfdj=1;
            }
            $is_rbacfdq = _rbac_node_show(862);
            if ($is_rbacfdq || ($fangyuan['fpdq'] == 2)) {
                $this->is_rbacfdq=1;
            }
            $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->zhuangtai=M('Peizhi')->where(array('pzming'=>'zhuangtai','lxid'=>$fangyuan['zhuangtai']))->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->xianzhuang=M('Peizhi')->where(array('pzming'=>'xianzhuang','lxid'=>$fangyuan['xianzhuang']))->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();
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            $this->options_arr=$options_arr;
            $this->isshoucang=M('shoucang')->where('fyid='.$fangyuan['id'].' and user_id='.session("uid"))->find();
            $peitao1=$fangyuan['peitao'];
            if ($peitao1) {
                $condition="pzming = 'peitao'";
                $condition.=" and lxid in ($peitao1)";
                $this->peitao=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
            }
            //房源上图人
            $bianhao=$fangyuan['bianhao'];
            $uid=M('photo')->where(array('gongsiid'=>session('gongsiid'),'fybh'=>$bianhao))->group('fybh')->getField('uid');
            $shangturen=M('yonghu')->where(array('id'=>$uid))->find();
            $this->assign('shangturen',$shangturen);
            //存钥部门
            $shouyaobmid=$fangyuan['shouyaobm'];
            $this->shouyaobm=M('bumen')->where(array('id'=>$shouyaobmid))->find();
            //收钥人
            $shouyaorenid=$fangyuan['shouyaoren'];
            $this->shouyaoren=M('yonghu')->where(array('id'=>$shouyaorenid))->find();
            //录入人
            $weihurenid=$fangyuan['weihurenid'];
            $this->weihuren=M('yonghu')->where(array('id'=>$weihurenid))->field('ygmingcheng,dianhua')->find();
            $this->fengpanren=M('yonghu')->where(array('id'=>$fangyuan['fengpanrenid']))->field('ygmingcheng,dianhua')->find();
            $weibanuid=M('weiban')->where(array('fybianhao'=>$fangyuan['bianhao']))->getField('uid');
            $this->weibanren=M('yonghu')->where(array('id'=>$weibanuid))->field('ygmingcheng,dianhua')->find();
            $shikanuid=M('shikan')->where(array('fybh'=>$fangyuan['bianhao']))->getField('uid');
            $this->shikanren=M('yonghu')->where(array('id'=>$shikanuid))->field('ygmingcheng,dianhua')->find();
            $Model = new \Think\Model;
            $this->fygenjin = $Model->table(array('jjrxt_fygenjin'=>'a','jjrxt_yonghu'=>'b','jjrxt_bumen'=>'c'))->field('a.neirong,a.shijian,c.bmming,b.ygmingcheng,a.genjinfs,a.zhuangtai,a.id,a.gjvoice')->where('a.uid=b.id and b.bumen=c.id and fyid='.$fangyuan['id'])->order('a.shijian desc')->select();
            $this->diaoqujl = $Model->table(array('jjrxt_xianzhi'=>'a','jjrxt_yonghu'=>'b','jjrxt_bumen'=>'c'))->field('a.shijian,c.bmming,b.ygmingcheng')->where('a.uid=b.id and b.bumen=c.id and fyid='.$fangyuan['id'])->order('a.shijian desc')->select();
            $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->xuexiao=M('xuequ')->where(array('id'=>$this->xiaoqu['ssxuexiao']))->getField('xuexiaom');
            $qitiannei = time()-604800;
            $this->daikanshu=M('kydaikan')->where('gongsiid ='.session('gongsiid').' and (fybh = "'.$fangyuan['bianhao'].'") and dkshijian >'.$qitiannei)->count();
            $dianhua=M('yonghu')->where(array('id'=>$fangyuan['weihurenid']))->getField('dianhua');
            $today="sj".date("m-d");
               if (!cookie($today)) {
                cookie($today,$fangyuan['id'],3600*24);
            }else{
                $value = cookie($today);
                $val=$value.','.$fangyuan['id'];
                cookie($today,$val,3600*24);
            }
            //钥匙列表
            $yoashi_sql="select a.*,b.ygmingcheng as ys_uid,c.ygmingcheng as adduid FROM  (select * from __YAOSHI__ where fybianhao='{$bianhao}' ) as a inner join (select * from __YONGHU__ ) as b on a.ys_uid=b.id left join __YONGHU__ as c on a.adduid=c.id  order by id DESC ";
            $this->yaoshi = $Model->query($yoashi_sql);
            $this->yaoshishu=M('yaoshi')->where(array('fybianhao'=>$bianhao))->count();
            //委办列表
            $weiban_sql="select a.*,b.ygmingcheng as uid,c.ygmingcheng as adduid FROM  (select * from __WEIBAN__ where fybianhao='{$bianhao}' ) as a inner join (select * from __YONGHU__ ) as b on a.uid=b.id left join __YONGHU__ as c on a.adduid=c.id  order by id DESC ";
            $this->weiban = $Model->query($weiban_sql);
            $this->display();
        }
        /**
            * [fy_pic_setfengmian 异步房源图片为封面]
            * @return [json] [description]
        */
        public function fy_pic_setfengmian(){
            $id=I('fy_pic_id');
            //根据图片id查找房源图片的房源编号fybh
            $fybh = M('Photo')->where(array('id'=>$id))->getField('fybh');
            $fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
            $uid = M('photo')->where(array('id'=>$id))->getField('uid');
            $is_rbac = _rbac_btn_show(481,$fyzhuangtai,$uid);
            if (!$is_rbac) {
                $this->error('异常错误！');
            }
            M('Photo')->where(array('fybh'=>$fybh,'fengmian'=>1))->setField(array('fengmian'=>0));
            $r = M('Photo')->where(array('id'=>$id))->setField(array('fengmian'=>1));
            if ($r) {
                $fyxgsj=M('fangyuan')->where(array('bianhao'=>$fybh))->setField('xiugaisj',time());
                $this->success('设置成功');
            }else{
                $this->error('设置失败');
            }
        }
        /**
            * [fy_pic_del 异步删除图片]
            * @return [json] [description]
        */
        public function fy_pic_del(){
            $id=I('fy_pic_id');
            //根据图片id查看当前是否还有当前房源的图片
            $fybh = M('Photo')->where(array('id'=>$id))->getField('fybh');
            $fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
            $uid = M('photo')->where(array('id'=>$id))->getField('uid');
            $is_rbac = _rbac_btn_show(50,$fyzhuangtai,$uid);
            if (!$is_rbac) {
                $this->error('异常错误！');
            }
            $piccount = M('Photo')->where(array('fybh'=>$fybh))->count();
            $dp=M('Photo');
            //删除当前图片
            if($id){
                $plist = $dp->where(array('id'=>$id))->find();
                if ($plist){
                    unlink('./Upload/'.$plist['gongsiid'].'/'.$plist['fybh'].'/'.$plist['image']);
                    unlink('./Upload/'.$plist['gongsiid'].'/'.$plist['fybh'].'/t_'.$plist['image']);
                    $dp->where(array('id'=>$id))->delete();
                    $data_rizhi['zy_type']=1;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=13;
                    $fyid=M('fangyuan')->where(array('bianhao'=>$fybh))->getField('id');
                    $data_rizhi['zy_id']=$fyid;
                    $data_rizhi['zy_bianhao']=$fybh;
                    $neirong="删除图片";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $data=array('pics'=>$plist);
                    //删除最后一个房源图片后给fangyun表的tupian字段置 0
                    if ($piccount==1) {
                        M('Fangyuan')->where(array('bianhao'=>$fybh))->setField('tupian',0);
                    }
                    $fyxgsj=M('fangyuan')->where(array('bianhao'=>$fybh))->setField('xiugaisj',time());
                    $this->success('删除成功');
                }else{
                    $this->error('删除失败');
                }
            }
        }
        //批量删除房源图片
        public function fy_pic_dels(){
            $is_rbac = _rbac_node_show(482,0);
            if (!$is_rbac) {
                $this->error('异常错误！');
            }
            $ids=I('fy_pic_ids');
            $fybh = M('Photo')->where(array('id'=>$ids[0]))->getField('fybh');
            $fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
            foreach ($ids as $key => $value) {
                $uid = M('photo')->where(array('id'=>$value))->getField('uid');
                $is_rbac = _rbac_btn_show(482,$fyzhuangtai,$uid);
                if (!$is_rbac) {
                    $this->error("您选择了权限范围之外的图片！");
                }
            }
            if(is_array($ids)){   
                $where = 'id in('.implode(',',$ids).')';
                $dp=M('Photo');
                //删除房源图片文件
                foreach ($ids as $value) {
                    $plist = $dp->where(array('id'=>$value))->find();
                    unlink('./Upload/'.$plist['gongsiid'].'/'.$plist['fybh'].'/'.$plist['image']);
                    unlink('./Upload/'.$plist['gongsiid'].'/'.$plist['fybh'].'/t_'.$plist['image']);
                }
                //删除图片记录
                $dp->where($where)->delete();
                //写入删除日志
                $data_rizhi['zy_type']=1;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=13;
                $fyid=M('fangyuan')->where(array('bianhao'=>$fybh))->getField('id');
                $data_rizhi['zy_id']=$fyid;
                $data_rizhi['zy_bianhao']=$fybh;
                $neirong="删除房源图片 ".count($ids)." 张";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                //删除最后一个房源图片后给fangyun表的tupian字段置 0
                $nopic = M('Photo')->where(array('fybh'=>$fybh))->count();
                if ($nopic<=0) {
                    M('Fangyuan')->where(array('bianhao'=>$fybh))->setField('tupian',0);
                }
                $fyxgsj=M('fangyuan')->where(array('bianhao'=>$fybh))->setField('xiugaisj',time());
                $this->success('删除成功');
            }else{
                $this->error('删除失败'); 
            }
        }
        //批量下载房源图片
        public function fy_pic_downloads(){
            $is_rbac = _rbac_node_show(483,0);
            if (!$is_rbac) {
                $this->error('异常错误！');
            }
            $ids=I('fy_pic_ids');
            $fybh = M('Photo')->where(array('id'=>$ids[0]))->getField('fybh');
            $fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
            foreach ($ids as $key => $value) {
                $uid = M('photo')->where(array('id'=>$value))->getField('uid');
                $is_rbac = _rbac_btn_show(483,$fyzhuangtai,$uid);
                if (!$is_rbac) {
                    $this->error("您选择了权限范围之外的图片！");
                }
            }
            $where = 'id in('.implode(',',$ids).')';
            $dp=M('Photo');
            $plist = $dp->where($where)->field('id,gongsiid,fybh,image')->select();
            $zip = new \ZipArchive;
            if ($plist) {
                //压缩文件名(临时文件)
                $filename = './Upload/'.$plist[0]['gongsiid'].'/'.$plist[0]['fybh'].'/'.md5($plist[0]['fybh']).'.zip';
                $downname = I("server.HTTP_HOST").'/Upload/'.$plist[0]['gongsiid'].'/'.$plist[0]['fybh'].'/'.md5($plist[0]['fybh']).'.zip';
            }
            //新建zip压缩包
            $zip->open($filename,\ZipArchive::OVERWRITE | \ZipArchive::CREATE);
            //把图片一张一张加进去压缩
            foreach ($plist as $value) {
                $zip->addFile('./Upload/'.$value['gongsiid'].'/'.$value['fybh'].'/'.$value['image']);
                $zip->renameName('./Upload/'.$value['gongsiid'].'/'.$value['fybh'].'/'.$value['image'],$value['image']);
            }
            //打包zip
            $zip->close();
            //可以直接重定向下载
            //header('Location:'.$downname);
            $this->success($downname);
        }
        //设置图片类型
        public function settupianleixing(){
            $is_rbac = _rbac_node_show(484,0);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $ids=explode(",",I('fy_pic_ids'));
                $fybh = M('Photo')->where(array('id'=>$ids[0]))->getField('fybh');
                $fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
                foreach ($ids as $key => $value) {
                    $uid = M('photo')->where(array('id'=>$value))->getField('uid');
                    $is_rbac = _rbac_btn_show(484,$fyzhuangtai,$uid);
                    if (!$is_rbac) {
                        $this->error("您选择了权限范围之外的图片！");
                    }
                }
                $ids1=I('fy_pic_ids');
                $tpleixing = I('tpleixing');
                if ($tpleixing=="") {
                    $this->error("请选择图片类型");
                }
                $where = 'id in('.$ids1.')';
                $dp=M('Photo');
                $plist = $dp->where($where)->setField(array('leixing' => $tpleixing ));               
                if ($plist) {
                    $fyxgsj=M('fangyuan')->where(array('bianhao'=>$fybh))->setField('xiugaisj',time());
                    $this->success("设置成功");
                }else{
                    $this->error("设置失败");
                }
            } else {
                $this->yongtu = M('Peizhi')->where(array('pzming'=>'yongtu',lxid=>I('fy_yongtu'),'zhuangtai'=>1))->order('xsshunxu asc')->find();
                $pzming='';
                switch (I('fy_yongtu')) {
                    case 1:
                        $pzming='zztplx';   //住宅
                        break;
                    case 2:
                        $pzming='bstplx';   //别墅
                        break;
                    case 3:
                        $pzming='sptplx';   //商铺
                        break;    
                    case 4:
                        $pzming='cktplx';   //仓库
                        break;
                    case 5:
                        $pzming='chftplx';   //厂房
                        break;
                    case 6:
                        $pzming='tdtplx';   //土地
                        break;
                    case 7:
                        $pzming='chktplx';   //车库
                        break;
                    case 8:
                        $pzming='xzltplx';   //写字楼
                        break;
                    default:
                        $pzming='zztplx';
                        break;
                }
                $this->tpleixing = M('Peizhi')->where(array('pzming'=>$pzming,'zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display();// 输出模板
            }
        }
    }