<?php

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

namespace Admin\Controller;
use Think\Controller;
class AjaxController extends CommonController {
    public function xlpurl(){
        $id=I('ysid');
        $count=M('xlpurl')->query("select count(*) from __XLPURL__ ");
        $Page=new \Think\Page($count['0']['count(*)'],20);
        $show  = $Page->show();
        $list="select a.*,b.ygmingcheng from __XLPURL__ a left join (select id as b_id,ygmingcheng from __YONGHU__) b on a.adduid = b.b_id order by addtime DESC limit ".$Page->firstRow.','.$Page->listRows;
        $xlpurl=M('xlpurl')->query($list);
        $this->assign('firstRow',$Page->firstRow);
        $this->assign('xlpurl',$xlpurl);
        $this->assign('count',$count);
        $this->assign('page',$show);
        $this->display();
    }

    public function glphotos(){
        $gltplx=I('gltplx');
        if ($gltplx == 2) {
            $this->htid=I('htid');
        } elseif ($gltplx == 3) {
            $this->sjid=I('sjid');
        } elseif ($gltplx == 5) {
            $this->kyhf=I('kyhf');
        } elseif ($gltplx == 6) {
            $this->hxid=I('hxid');
        }
        $this->gltplx=$gltplx;
        $this->display();
    }

    public function tixing(){
        $condition = "gongsiid=".session('gongsiid');
        $sousuo=I('sousuo');
        if ($sousuo == 0) {//搜索
            $condition.=" and txuid=".session('uid')." and txshijian<".time()." and isyidu=0";
        } elseif ($sousuo == 1) {
            $condition.=" and txuid=".session('uid')." and txshijian<".time()." and isyidu=1";
        } elseif ($sousuo == 2) {
            $condition.=" and txuid=".session('uid')." and isyidu=0";
        } elseif ($sousuo == 3) {
            $condition.=" and txuid=".session('uid')." and isyidu=1";
        } elseif ($sousuo == 4) {
            $condition.=" and txuid=".session('uid');
        }
        if (I('shijian1') and I('shijian2')){
            if (I('shijian1') > I('shijian2')){
                $this->error('开始日大于结束日!');
            }
            $condition.=" and txshijian>".strtotime(I('shijian1'))." and txshijian<".strtotime(I('shijian2'));
        } elseif (I('shijian1')) {
            $condition.=" and txshijian>".strtotime(I('shijian1'));
        } elseif (I('shijian2')) {
            $condition.=" and txshijian<".strtotime(I('shijian2'));
        }
        $txlx=I('txlx');
        if ($txlx == 1) {
            $txb1=M('kytixing');
            $txb2='__KYTIXING__';
        } elseif ($txlx == 2) {
            $txb1=M('fjtixing');
            $txb2='__FJTIXING__';
            $fjtx1=',c.xiaoqum,d.zdming,e.dyming,f.lcming,g.fanghao';
            $fjtx2=' left join (select id as c_id,xiaoqum from __XIAOQU__) c on a.xqid=c.c_id left join (select id as d_id,zdming from __ZDXINXI__) d on a.zdid=d.d_id left join (select id as e_id,dyming from __DYXINXI__) e on a.dyid=e.e_id left join (select id as f_id,lcming from __LCXINXI__) f on a.lcid=f.f_id left join (select id as g_id,fanghao from __FJXINXI__) g on a.fjid = g.g_id ';
        }
        $count=$txb1->query("select count(*) from ".$txb2." where {$condition}");
        $Page=new \Think\Page($count['0']['count(*)'],20);
        $show  = $Page->show();
        $list="select a.*,b.ygmingcheng,b.dianhua".$fjtx1." from ".$txb2." a left join (select id as b_id,ygmingcheng,dianhua from __YONGHU__) b on a.adduid = b.b_id".$fjtx2." where {$condition} order by txshijian DESC limit ".$Page->firstRow.','.$Page->listRows;
        $tixing=$txb1->query($list);
        $this->assign('firstRow',$Page->firstRow);
        $this->assign('tixing',$tixing);
        $this->assign('count',$count);
        $this->assign('page',$show);
        $this->display();
    }

    public function tixingxq(){
        $id=I('id');
        $txlx=I('txlx');
        if ($txlx == 1) {
            $txb1=M('kytixing');
        } elseif ($txlx == 2) {
            $txb1=M('fjtixing');
        }
        $tixing=$txb1->where(array('id'=>$id))->find();
        if ($txlx == 2) {
            $this->xiaoqum=M('xiaoqu')->where(array('id'=>$tixing['xqid']))->getField('xiaoqum');
            $this->zdming=M('zdxinxi')->where(array('id'=>$tixing['zdid']))->getField('zdming');
            $this->dyming=M('dyxinxi')->where(array('id'=>$tixing['dyid']))->getField('dyming');
            $this->lcming=M('lcxinxi')->where(array('id'=>$tixing['lcid']))->getField('lcming');
            $this->fanghao=M('fjxinxi')->where(array('id'=>$tixing['lcid']))->getField('fanghao');
        }
        if ($tixing['txshijian'] < time()) {
            $isok=$txb1->where(array('id'=>$id))->setField('isyidu',1);
        }
        $this->txren=M('yonghu')->where(array('id'=>$tixing['txuid']))->getField('ygmingcheng');
        $this->tjren=M('yonghu')->where(array('id'=>$tixing['adduid']))->getField('ygmingcheng');
        $this->tixing=$tixing;
        $this->display();
    }

    public function get_yuangong(){
        $listObj = M('yonghu');
        $where['bumen'] = I('bmid');
        $where['gongsiid'] = session('gongsiid');
        $list = $listObj->where($where)->select();
        $data=array('status'=>0,'city'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_feiyongxm(){
        $id = I('id');
        if ($id == 1) {
            $arr = M('Peizhi')->where(array('pzming'=>'zhongjiexm','zhuangtai'=>1))->order('xsshunxu asc')->select();
            $data=array('status'=>1,'list'=>$arr);
            header("Content-type: application/json");
            exit(json_encode($data));       
        } else {
            $arr = M('Peizhi')->where(array('pzming'=>'jinrongxm','zhuangtai'=>1))->order('xsshunxu asc')->select(); 
            $data=array('status'=>1,'list'=>$arr);
            header("Content-type: application/json");
            exit(json_encode($data));  
        }
    }

    public function get_pinyin(){
        $txt=I('txt');
        $py = new \Lib\Pinyin\Pinyin;
        $s = $py->qupinyin($txt ,true);
        $q = $py->qupinyin($txt);
        $h = $s.' '.$q.' '.$txt;
        $data=array('status'=>1,'pyjs'=>$h);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_bumen(){
        $select_categorys = bumen_option( 0, I('jiedian'));
        $data=array('status'=>1,'sousuo'=>$select_categorys);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_bumen_yonghu(){
        $bmid=I('bmid');
        $User = M("yonghu"); // 实例化User对象
        $map['id'] = array('gt',2);
        $map['status'] = 1;
        $map['bumen'] = $bmid;
        $list=$User->where($map)->order('pinyinjs asc')->select(); 
        $data=array('status'=>1,'sousuo'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_yonghu(){
        $txt=I('txt');
        $User = M("yonghu"); // 实例化User对象
        $map['status'] = 1;
        $map['lock1'] = 0;
        $map['_string']='(pinyinjs like "%'.$txt.'%") OR (ygmingcheng like "%'.$txt.'%") OR (dianhua like "%'.$txt.'%")';
        $list=$User->where($map)->limit(10)->order('pinyinjs asc')->select(); 
        $data=array('status'=>1,'district'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_rsyonghu(){
        $txt=I('txt');
        $listObj = M('yonghu');
        $where['status'] = 1;
        $where['gongsiid'] = session('gongsiid');
        $where['_string']='(pinyinjs like "%'.$txt.'%") OR (ygmingcheng like "%'.$txt.'%") OR (dianhua like "%'.$txt.'%")';
        $list = $listObj->where($where)->limit(10)->order('pinyinjs asc')->select();
        $data=array('status'=>1,'district'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    // 房源打印模板管理图片上传（异步）
    public function upload(){
        if(!empty($_FILES)){
            $upload=new \Think\Upload();
            $upload->maxSize=3145728; //文件上传的大小限制
            $upload->exts=array('jpg','gif','png','jpeg'); //上传文件后缀的样式
            $upload->rootPath='./';   //上传文件根目录
            $upload->savePath='Upload/'.session('gongsiid').'/dayinmoban/'; //上传文件的子目录
            $upload->autoSub = false;
            $upload->saveName=date("Ymdhis",time()).rand(1,9);//上传文件的名称
            $info=$upload->uploadOne($_FILES['imageload']); //上传单文件
            if(!$info){
                $data['status']=0;
                $data['content']="上传失败";
                $this->ajaxReturn($data);
            }else{
                $data['status']=1;
                $data['src']=__ROOT__.'/'.$info['savepath'].$info['savename'];
                $data['upfilename']=$info['savename'];
                $data['content']="上传成功";
                $this->ajaxReturn($data);
            }
        }
    }

    //模糊查询小区
    public function get_xiaoqu_txt(){
        $txt=I('txt');
        $listObj = M('xiaoqu');
        $where['_string']='(xiaoqum like "%'.$txt.'%") OR (pinyinjs like "%'.$txt.'%")';
        $where['gongsiid'] = session('gongsiid');
        $list = $listObj->where($where)->limit(10)->select();
        $data=array('status'=>1,'lists'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //模糊查询小区
    public function get_xiaoqu_bdxs(){
        $xzqid=M('xingzhengqu')->where(array('gongsiid'=>session('gongsiid')))->order('id asc')->getField('id');
        $pqid=M('pianqu')->where(array('gongsiid'=>session('gongsiid'),'ssxzq'=>$xzqid))->order('id asc')->getField('id');
        $txt=I('txt');
        $sspq=I('sspq');
        $listObj = M('xiaoqu');
        $where['_string']='(xiaoqum like "%'.$txt.'%") OR (pinyinjs like "%'.$txt.'%")';
        $where['gongsiid'] = session('gongsiid');
        if ($sspq) {
            $where['sspianqu'] = $sspq;
        } else {
            $where['sspianqu'] = $pqid;
        }
        $list = $listObj->where($where)->limit(10)->select();
        $data=array('status'=>1,'lists'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }
    //联动异步获取片区
    public function get_pianqu_ld(){
        $listObj = M('pianqu');
        $where['ssxzq'] = I('quyuxzq');
        $where['gongsiid'] = session('gongsiid');
        $list = $listObj->where($where)->select();
        $data=array('status'=>1,'lists'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    // 添加坐标
    public function addzb(){
        $zuobiao = I('zuobiao');
        if ($zuobiao) {
            $zb = $zuobiao;
            $this->isedit = 1;
        }else{
            $zb = $this->jcpz['dtzuobiao'];
        }
        $this->zb = $zb;
        $this->display();
    }

    public function get_cjkybianhao(){
        $txt=I('txt');
        $listObj = M('keyuan');
        $where['_string']='(xqbianhao like "%'.$txt.'%")';
        $where['gongsiid'] = session('gongsiid');
        $where['isdel'] = 2;
        $list = $listObj->where($where)->limit(10)->select();
        $data=array('status'=>1,'district'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_ydkhbianhao(){
        $map="gongsiid=".session('gongsiid');
        $x = _rbac_lists_where(887,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="gongsiid=".session('gongsiid');
        $condition.=" and isdel=2";
        $txt=I('txt');
        $condition.=" and zhuangtai = 1";
        if ($txt) {
            $condition.=" and ((khxingming like '%$txt%') or (dianhua like '%$txt%') or (xqbianhao like '%$txt%'))";
        }
        $list="select c.xqbianhao from (select * from (select id,xqbianhao,weihurenid from __KEYUAN__ where {$condition}) a join (select id as b_id from __YONGHU__ where {$map}) b on a.weihurenid=b.b_id) c order by c.id desc limit 10";
        $keyuan=M('keyuan')->query($list);
        $data=array('status'=>1,'district'=>$keyuan);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_ydyhm(){
        $map = "gongsiid=".session('gongsiid');
        $map .= " and status=1";
        $map .= " and lock1=0";
        $txt=I('txt');
        $x = _rbac_lists_where(888,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";
        }
        if ($txt) {
            $map.=" and (dianhua like '%$txt%' or pinyinjs like '%$txt%' or ygmingcheng like '%$txt%' or ygbianhao like '%$txt%')";
        }
        $Yonghu=D('UserRelation')->where($map)->limit(10)->field('ygmingcheng')->order('pinyinjs asc')->select();
        $data=array('status'=>1,'district'=>$Yonghu);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_xsyhm(){
        $txt=I('txt');
        $xslx=I('xslx');
        $role=I('role');
        $map = "gongsiid=".session('gongsiid');
        $map .= " and lock1=0";
        $map .= " and status=1";
        if ($txt) {
            $map.=" and (dianhua like '%$txt%' or pinyinjs like '%$txt%' or ygmingcheng like '%$txt%' or ygbianhao like '%$txt%')";
        }
        if ($xslx == 1) {
            $map .= " and leixing=2";
            $list="select a.ygmingcheng from (select * from __YONGHU__ where {$map}) a join (select uid from __XQBDXS__ group by uid) as b on a.id=b.uid order by a.pinyinjs asc limit 10 ";
        } else if ($xslx == 2) {
            if ($role == 1) {
                $map .= " and leixing=2";
            } else if ($role == 2) {
                $map .= " and leixing=3";
            } else {
                $map .= " and (leixing=2 or leixing=3)";
            }
            $list="select ygmingcheng from __YONGHU__ where {$map} order by pinyinjs asc limit 10 ";
        }
        $Yonghu=M('yonghu')->query($list);
        $data=array('status'=>1,'district'=>$Yonghu);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    // 异步获取行政区新数据
    public function get_xzqxsj_ziyuan(){
        $listObj = M('xingzhengqu');
        $list = $listObj->order('id desc')->find();
        $data=array('pics'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    // 异步获取片区新数据
    public function get_pianqxsj_ziyuan(){
        $listObj = M('pianqu');
        $list = $listObj->order('id desc')->find();
        $data=array('pics'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    // 异步获取小区新数据
    public function get_xiaoqxsj_ziyuan(){
        $listObj = M('xiaoqu');
        $list = $listObj->order('id desc')->find();
        $data=array('pics'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_pzxsj(){
        $listObj = M('peizhi');
        $list = $listObj->order('id desc')->find();
        $data=array('pics'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_jsxsj(){
        $listObj = M('role');
        $list = $listObj->order('id desc')->find();
        $data=array('pics'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    public function get_bmxsj(){
        $listObj = M('bumen');
        $list = $listObj->order('id desc')->find();
        $data=array('pics'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //关联
    public function guanlian(){
        $qxpdep = _rbac_btn_show(425,0) == true? '1': '0';
        $qxpddp = _rbac_btn_show(427,0) == true? '1': '0';
        $id=I('id');
        $where['gongsiid']=session('gongsiid');
        $where['id']=$id;
        $pzming=M('peizhi')->where(array('id'=>I('id')))->getField('pzming');
        $leixing=M('peizhi')->where(array('pzming'=>$pzming,'zhuangtai'=>'1'))->order('xsshunxu asc')->select();
        $data=array('status'=>0,'leixing'=>$leixing,'qxpdep'=>$qxpdep,'qxpddp'=>$qxpddp);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    /**
     * [get_xq_img 异步返回图片列表]
     * @return [json] [图片相关的数组]
     */
    public function get_xq_img(){
        $listObj = M('xqphoto');
        $where['p.xqid'] = I('xq_id');
        $list = $listObj->alias('p')->join(' jjrxt_yonghu as y on p.uid=y.id ')->field('p.id,p.leixing,p.leixing as lxming,p.fengmian,p.gongsiid,p.image,FROM_UNIXTIME(p.create_time,"%Y-%m-%d") AS create_time,p.xqid,y.ygmingcheng')->where($where)->order('p.id desc')->select();
        if ($list) {
            $pzming='xqtplx';
        }
        foreach ($list as &$value) {
            $temp = get_peizhi($pzming,$value['leixing']);
            $value['lxming'] = $value['leixing']?$temp:'未设置图片类型';
            $value['fm'] = _rbac_btn_show(485,0,$value['uid']) == true? '1': '0';
            $value['del']  = _rbac_btn_show(134,0,$value['uid']) == true? '1': '0';
            $value['plxz']  = _rbac_btn_show(487,0,$value['uid']) == true? '1': '0';
        }
        //返回查询结果到异步json
        $data=array('pics'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //异步获取单元楼层房间关联信息
    public function gldylcfj(){
        $fjxzid=I('fjxzid');
        $zdxinxi=M("zdxinxi")->where(array('id'=>I('zdid')))->find();
        $fwleixing=M('peizhi')->where(array('pzming'=>'fwleixing','zhuangtai'=>1,'lxid'=>$zdxinxi['fwleixing']))->getField('lxming');
        $jiegou=M('peizhi')->where(array('pzming'=>'jiegou','zhuangtai'=>1,'lxid'=>$zdxinxi['jiegou']))->getField('lxming');
        $zhuangxiu=M('peizhi')->where(array('pzming'=>'zhuangxiu','zhuangtai'=>1,'lxid'=>$zdxinxi['zhuangxiu']))->getField('lxming');
        $fjbackground=M('peizhi')->where(array('pzming'=>'fjbackground','zhuangtai'=>1))->order('xsshunxu asc')->select();
        if ($fjxzid) {
            $fjshu=M('fjxinxi')->where(array('gongsiid'=>session('gongsiid'),'zdid'=>I('zdid'),'xianzhuang'=>$fjxzid))->count();
        } else {
            $fjshu=M('fjxinxi')->where(array('gongsiid'=>session('gongsiid'),'zdid'=>I('zdid')))->count();
        }
        $dyxinxi=M('dyxinxi')->where(array('gongsiid'=>session('gongsiid'),'zdid'=>I('zdid')))->order('xsshunxu asc')->select();
        $dyid=array();
        $qxpdez = _rbac_btn_show(507,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpddx = _rbac_btn_show(586,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpdpl = _rbac_btn_show(505,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpdal = _rbac_btn_show(512,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpded = _rbac_btn_show(510,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpddd = _rbac_btn_show(511,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpdpf = _rbac_btn_show(505,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpdaf = _rbac_btn_show(515,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpdel = _rbac_btn_show(513,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpddl = _rbac_btn_show(514,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpdef = _rbac_btn_show(516,0,$zdxinxi['zerenrid']) == true? '1': '0';
        $qxpddf = _rbac_btn_show(517,0,$zdxinxi['zerenrid']) == true? '1': '0';
        foreach($dyxinxi as $k=>$v){
            $dyid[$k]['id']=$v['id'];
            $dyid[$k]['zdid']=$v['zdid'];
            $dyid[$k]['xqid']=$v['xqid'];
            $dyid[$k]['dyming']=$v['dyming'];
            $dyid[$k]['louceng']=M('lcxinxi')->where(array('gongsiid'=>session('gongsiid'),'dyid'=>$v['id']))->order('xsshunxu desc')->select();
            foreach($dyid[$k]['louceng'] as $key=>$x){
                $dyid[$k]['louceng'][$key]['id']=$x['id'];
                $dyid[$k]['louceng'][$key]['zdid']=$x['zdid'];
                $dyid[$k]['louceng'][$key]['xqid']=$x['xqid'];
                $dyid[$k]['louceng'][$key]['fanghao']=$x['fanghao'];
                $dyid[$k]['louceng'][$key]['xianzhuang']=$x['xianzhuang'];
                if ($fjxzid) {
                    $dyid[$k]['louceng'][$key]['fanghao']=M('fjxinxi')->where(array('gongsiid'=>session('gongsiid'),'lcid'=>$x['id'],'xianzhuang'=>$fjxzid))->order('xsshunxu asc')->select();
                    // $fangjian = M('fjxinxi')->where(array('gongsiid'=>session('gongsiid'),'lcid'=>$x['id']))->order('xsshunxu asc')->select();
                    // foreach ($fangjian as $kf => $vf) {
                    //     if ($vf['xianzhuang'] != $fjxzid) {
                    //         $fangjian[$kf]['xianzhuang'] = 0;
                    //     }
                    // }
                    // $dyid[$k]['louceng'][$key]['fanghao'] = $fangjian;
                } else {
                    $dyid[$k]['louceng'][$key]['fanghao']=M('fjxinxi')->where(array('gongsiid'=>session('gongsiid'),'lcid'=>$x['id']))->order('xsshunxu asc')->select();
                }
            }
        }
        $data=array('status'=>0,'qxpdez'=>$qxpdez,'qxpddx'=>$qxpddx,'qxpdpl'=>$qxpdpl,'qxpdal'=>$qxpdal,'qxpded'=>$qxpded,'qxpddd'=>$qxpddd,'qxpdpf'=>$qxpdpf,'qxpdaf'=>$qxpdaf,'qxpdel'=>$qxpdel,'qxpddl'=>$qxpddl,'qxpdef'=>$qxpdef,'qxpddf'=>$qxpddf,'fjshu'=>$fjshu,'dyxinxi'=>$dyid,'zdxinxi'=>$zdxinxi,'fwleixing'=>$fwleixing,'jiegou'=>$jiegou,'zhuangxiu'=>$zhuangxiu,'fjbackground'=>$fjbackground);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //异步获取单元信息
    public function gldanyuan(){
        $dyxinxi=M("dyxinxi")->where(array('id'=>I('dyid')))->find();
        $lcshu=M('lcxinxi')->where(array('gongsiid'=>session('gongsiid'),'dyid'=>I('dyid')))->count();
        $data=array('status'=>0,'lcshu'=>$lcshu,'dyxinxi'=>$dyxinxi);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //异步获取楼层信息
    public function gllouceng(){
        $lcxinxi=M("lcxinxi")->where(array('id'=>I('lcid')))->find();
        $lcleixing=M('peizhi')->where(array('pzming'=>'lcleixing','zhuangtai'=>1,'lxid'=>$lcxinxi['lcleixing']))->getField('lxming');
        $fjshu=M('fjxinxi')->where(array('gongsiid'=>session('gongsiid'),'lcid'=>I('lcid')))->count();
        $data=array('status'=>0,'fjshu'=>$fjshu,'lcxinxi'=>$lcxinxi,'lcleixing'=>$lcleixing);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //异步获取房间信息
    public function glfangjian(){
        $fjid=I('fjid');
        $fjxinxi=M("fjxinxi")->where(array('id'=>$fjid))->find();
        $zdid=M("zdxinxi")->where(array('id'=>$fjxinxi['zdid']))->getField('zerenrid');
        $qxpdct = _rbac_btn_show(526,0,$zdid) == true? '1': '0';
        $qxpdst = _rbac_btn_show(527,0,$zdid) == true? '1': '0';
        $qxpdqj = _rbac_node_show(864) == true? '1': '0';
        $qxpdat = _rbac_node_show(881) == true? '1': '0';
        $qxpdtx = _rbac_node_show(882) == true? '1': '0';
        $qxpdsy = _rbac_node_show(883) == true? '1': '0';
        $qxpdsc = _rbac_node_show(885) == true? '1': '0';
        $fjyds=M("fjyd")->where(array('fjid'=>$fjxinxi['id']))->count();
        $fjcjs=M("chengjiao")->where(array('fybianhao'=>$fjxinxi['bianhao']))->count();
        if ($fjxinxi['xianzhuang'] == 4) {
            $cjuid=M("chengjiao")->where(array('fybianhao'=>$fjxinxi['bianhao']))->getField('cjuid');
            $qxpdcj = _rbac_btn_show(202,0,$cjuid) == true? '1': '0';
            $qxpdcr = _rbac_btn_show(886,0,$cjuid) == true? '1': '0';
        } else {
            $qxpdcx = _rbac_node_show(198) == true? '1': '0';
        }
        $fjyd=M("fjyd")->where(array('fjid'=>$fjxinxi['id'],'type'=>3))->field('id,uid')->find();
        if ($fjyd) {
            $qxpdey = _rbac_btn_show(880,0,$fjyd['uid']) == true? '1': '0';
        } elseif ($fjxinxi['xianzhuang'] == 1) {
            $qxpdyd = _rbac_node_show(879) == true? '1': '0';
        } elseif ($fjxinxi['xianzhuang'] == 2) {
            $qxpdyr = _rbac_btn_show(884,0,$fjyd['uid']) == true? '1': '0';
        }
        if ($qxpdcj == 1) {
            $cjid=M("chengjiao")->where(array('fybianhao'=>$fjxinxi['bianhao']))->getField('id');
            $cjbh=M("chengjiao")->where(array('fybianhao'=>$fjxinxi['bianhao']))->getField('cjbianhao');
            $fwcj = 1;
        } elseif ($qxpdcx == 1) {
            $fwcj = 2;
        }
        if ($qxpdyd == 1) {
            $fwyd = 1;
        } elseif ($qxpdey == 1) {
            $fwyd = 2;
        } elseif ($qxpdyr == 1) {
            $fwyd = 3;
        }
        $imagefm=M('fjphoto')->where(array('fjid'=>$fjid,'fengmian'=>1))->getField('image');
        $image=M("fjphoto")->where(array('fjid'=>$fjid))->order('create_time desc')->getField('image');
        $cxid=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('chaoxiang');
        $zxid=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('zhuangxiu');
        $shi=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('shi');
        $ting=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('ting');
        $wei=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('wei');
        $chu=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('chu');
        $yangtai=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('yangtai');
        $jzmianji=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('jzmianji');
        $symianji=M('huxing')->where(array('id'=>$fjxinxi['hxid']))->getField('symianji');
        if ($shi) {
            $hxshi=$shi."室";
        }
        if ($ting) {
            $hxting=$ting."厅";
        }
        if ($wei) {
            $hxwei=$wei."卫";
        }
        if ($chu) {
            $hxchu=$chu."厨";
        }
        if ($yangtai) {
            $hxyangtai=$yangtai."阳台";
        }
        $huxing=$hxshi.$hxting.$hxwei.$hxchu.$hxyangtai;
        $xianzhuang=M('peizhi')->where(array('pzming'=>'xianzhuang','zhuangtai'=>1,'lxid'=>$fjxinxi['xianzhuang']))->getField('lxming');
        $chaoxiang=M('peizhi')->where(array('pzming'=>'chaoxiang','zhuangtai'=>1,'lxid'=>$cxid))->getField('lxming');
        $zhuangxiu=M('peizhi')->where(array('pzming'=>'zhuangxiu','zhuangtai'=>1,'lxid'=>$zxid))->getField('lxming');
        $data=array('status'=>0,'qxpdzs'=>$qxpdzs,'qxpdzz'=>$qxpdzz,'qxpdat'=>$qxpdat,'qxpdtx'=>$qxpdtx,'qxpdct'=>$qxpdct,'qxpdst'=>$qxpdst,'qxpdqj'=>$qxpdqj,'qxpdsy'=>$qxpdsy,'qxpdsc'=>$qxpdsc,'qxpdcr'=>$qxpdcr,'fjyds'=>$fjyds,'fjcjs'=>$fjcjs,'cjid'=>$cjid,'cjbh'=>$cjbh,'fwcj'=>$fwcj,'fwyd'=>$fwyd,'ydid'=>$fjyd['id'],'fjxinxi'=>$fjxinxi,'imagefm'=>$imagefm,'image'=>$image,'huxing'=>$huxing,'jzmianji'=>$jzmianji,'symianji'=>$symianji,'xianzhuang'=>$xianzhuang,'chaoxiang'=>$chaoxiang,'zhuangxiu'=>$zhuangxiu);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //选择部门查询当前部门下的用户
    public function select_yuangong(){
        $id = I('id');
        $isjl = I('isjl');
        if($isjl == 1){
            $user = M('yonghu')->where(array('lock1'=>0,'status'=>1,'leixing'=>1,'bumen'=>$id))->field('id,ygmingcheng')->order('pinyinjs asc')->select();
        }else{
            $user = M('yonghu')->where(array('lock1'=>0,'status'=>1,'bumen'=>$id))->field('id,ygmingcheng')->order('pinyinjs asc')->select();
        }
        if($user){
            $this->ajaxReturn($user);
        }else{
            $this->ajaxReturn(array('status'=>0,'info'=>'当前部门下没有用户'));
        }
    }

    //选择部门查询当前部门下的部门
    public function select_bumen(){
        $id = I('id');
        $bumen = M('bumen')->where(array('level'=>3,'parentid'=>$id))->field('id,bmming')->select();
        if($bumen){
            $this->ajaxReturn($bumen);
        }else{
            $this->ajaxReturn(array('status'=>0,'info'=>'当前部门下没有部门'));
        }
    }

    public function get_fwbianhao_txt(){
        $txt=I('txt');
        $listObj = M('fjxinxi');
        $where['_string']='(bianhao like "%'.$txt.'%")';
        $where['gongsiid'] = session('gongsiid');
        $list = $listObj->where($where)->field('id,bianhao')->limit(10)->select();
        $data=array('status'=>1,'lists'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //搜索户型编号
    public function get_hxbianhao(){
        $txt=I('txt');
        $huxing = M("huxing");
        $map['xqid'] = I('xqid');
        $map['gongsiid'] = session('gongsiid');
        $map['_string'] = '(hxbiaoti like "%'.$txt.'%") or (hxbianhao like "%'.$txt.'%")';
        $list=$huxing->where($map)->field('id,hxbianhao')->limit(10)->select();
        $data=array('status'=>1,'district'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    // 户型选择
    public function huxingxz(){
        $xqid=I('xqid');
        $condition="gongsiid=".session('gongsiid');
        $condition.=" and xqid=$xqid";
        $sousuo=I('sousuo');
        if ($sousuo) {
            $condition.=" and ((hxbiaoti like '%$sousuo%') or (hxbianhao like '%$sousuo%'))";
        }
        $count=M('huxing')->query("select count(*) from __HUXING__ where {$condition}");
        $Page=new \Think\Page($count['0']['count(*)'],30);
        $show=$Page->show();
        $list="select a.id,a.hxbiaoti,a.fwdanjia,a.fwzongjia,a.hxbianhao,a.shi,a.ting,a.wei,a.chu,a.yangtai,a.jzmianji,a.symianji,a.remark,b.cxming,c.zxming from (select * from __HUXING__ where {$condition} order by addtime desc limit ".$Page->firstRow.','.$Page->listRows.") a left join (select lxid as b_id,lxming as cxming from __PEIZHI__ where pzming = 'chaoxiang' ) b on a.chaoxiang=b.b_id left join (select lxid as c_id,lxming as zxming from __PEIZHI__ where pzming = 'zhuangxiu' ) c on a.zhuangxiu=c.c_id ";
        $huxing=M('huxing')->query($list);
        $this->assign('firstRow',$Page->firstRow);
        $this->assign('huxing',$huxing);
        $this->assign('count',$count);
        $this->assign('page',$show);
        $this->display();
    }

    //查看客户回访图片
    public function ckkhhftp(){
        $kyhf=I('kyhf');
        $map="gongsiid=".session('gongsiid');
        $x = _rbac_lists_where(852,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="gongsiid=".session('gongsiid');
        $condition.=" and data_id=$kyhf";
        $condition.=" and data_table='kygenjin'";
        $list="select * from (select * from __PHOTOS__ where {$condition}) a join (select id as yhid,ygmingcheng from __YONGHU__ where {$map}) b on a.adduid=b.yhid order by a.addtime DESC ";
        $photo=M('photos')->query($list);
        if ($photo) {
            $pzming='hftplx';
        }
        foreach ($photo as &$value) {
            if ($value['data_type']) {
                $temp = get_peizhi($pzming,$value['data_type']);
            }
            $value['data_type'] = $temp?$temp:'未设置图片类型';
        }
        $this->assign('photo',$photo);
        $this->display();
    }

    public function get_fwbianhao(){
        $txt=I('txt');
        $listObj = M('fjxinxi');
        $where['_string']='(bianhao like "%'.$txt.'%")';
        $where['gongsiid'] = session('gongsiid');
        $where['hxid'] = I('hxid');
        $list = $listObj->where($where)->field('id,bianhao')->limit(10)->select();
        $data=array('status'=>1,'lists'=>$list);
        header("Content-type: application/json");
        exit(json_encode($data));
    }

    //房屋列表
    public function fangwu(){
        $hxid=I('hxid');
        $condition = "gongsiid=".session('gongsiid');
        $condition.=" and hxid=$hxid";
        $sousuo=I('sousuo');
        if ($sousuo) {
            $condition.=" and ((fanghao like '%$sousuo%') or (bianhao like '%$sousuo%'))";
        }
        $zuodong=I('zuodong');
        if ($zuodong) {
            $condition.=" and zdid=$zuodong";
        }
        $danyuan=I('danyuan');
        if ($danyuan) {
            $condition.=" and dyid=$danyuan";
        }
        $louceng=I('louceng');
        if ($louceng) {
            $condition.=" and lcid=$louceng";
        }
        $count=M('fjxinxi')->query("select count(*) from __FJXINXI__ where {$condition}");
        $Page = new \Think\Page($count['0']['count(*)'],20);
        $show = $Page->show();
        $list="select a.*,b.zdming,c.dyming,d.lcming from (select * from __FJXINXI__ where {$condition}) a left join (select id as b_id,zdming,xsshunxu as zdxs from __ZDXINXI__) b on a.zdid=b.b_id left join (select id as c_id,dyming,xsshunxu as dyxs from __DYXINXI__) c on a.dyid=c.c_id left join (select id as d_id,lcming,xsshunxu as lcxs from __LCXINXI__) d on a.lcid=d.d_id order by b.zdxs asc,c.dyxs asc,d.lcxs asc,a.xsshunxu asc limit ".$Page->firstRow.','.$Page->listRows;
        $fangwu=M('fjxinxi')->query($list);
        $this->assign('firstRow',$Page->firstRow);
        $this->assign('fangwu',$fangwu);
        $this->assign('count',$count);
        $this->assign('page',$show);
        $bumen = I("get.bumen",0,'intval');
        $select_categorys = bumen_option( $bumen, 237);
        $this->assign("select_categorys", $select_categorys);
        $this->display();
    }

    public function fjphoto() {
        $fjid=I('fjid');
        $zdid=M('fjxinxi')->where(array('id'=>$fjid))->getField('zdid');
        $adduid=M('zdxinxi')->where(array('id'=>$zdid))->getField('zerenrid');
        $list="select * from (select * from __FJPHOTO__ where fjid=$fjid ) as a left join (select id as yhid,ygmingcheng from __YONGHU__ ) as b on a.uid=b.yhid order by a.create_time DESC ";
        $photo=M('fjphoto')->query($list);
        if ($photo) {
            $pzming='zztplx';
        }
        foreach ($photo as &$value) {
            if ($value['leixing']) {
                $temp = get_peizhi($pzming,$value['leixing']);
            }
            $value['lxming'] = $temp?$temp:'未设置图片类型';
        }
        $this->assign('photo',$photo);
        $this->zerenrid=$adduid;
        $this->display();
    }

    //查看户型图片
    public function ckhxtp(){
        $hxid=I('hxid');
        $condition="gongsiid=".session('gongsiid');
        $condition.=" and data_id=$hxid";
        $condition.=" and data_table='huxing'";
        $list="select * from (select * from __PHOTOS__ where {$condition}) a join (select id as yhid,ygmingcheng from __YONGHU__) b on a.adduid=b.yhid order by a.addtime DESC ";
        $photo=M('photos')->query($list);
        if ($photo) {
            $pzming='hxtplx';
        }
        foreach ($photo as &$value) {
            if ($value['data_type']) {
                $temp = get_peizhi($pzming,$value['data_type']);
            }
            $value['data_type'] = $temp?$temp:'未设置图片类型';
        }
        $this->assign('photo',$photo);
        $this->display();
    }
}