<?php

    /***************************************************************\
    |                                                               |
    |   房哨（专业的房产运营ERP）                                     |
    |                                                               |
    |   © 2019 http://fs.ytsofts.cn/ All rights reserved.           |
    |                                                               |
    |   房哨由淮南市银泰软件科技有限公司提供技术支持                    |
    |                                                               |
    |   QQ:984784483                                                |
    |                                                               |
    \***************************************************************/

    namespace Erpadmin\Controller;
    use Think\Controller;
    class PublicController extends ErpadminbaseController {

        //模糊查询市
        public function get_region_txt(){
            $txt = I('txt');
            if (!$txt) {
                $txt = I('keywords');
            }
            $where['_string'] = ' level = 2 and ( (name like "%'.$txt.'%") OR (sign like "%'.$txt.'%"))';
            $list = M('region')->where($where)->field('id,name,sign')->limit(10)->select();
            $data = array('status'=>1,'data'=>$list);
            $this->ajaxReturn($data);
        }

        //模糊查询市
        public function get_regions_txt(){
            $data = I('data');
            $where['jjrxt_xingzhengqu.pid'] = array('in',$data);
            $list = M('xingzhengqu')->join('jjrxt_region on jjrxt_xingzhengqu.pid=jjrxt_region.id')->where($where)->field('jjrxt_xingzhengqu.id,jjrxt_xingzhengqu.xzqming,jjrxt_region.name as regionname,jjrxt_xingzhengqu.pid')->select();
            $data = array('status'=>1,'data'=>$list);
            $this->ajaxReturn($data);
        }

        //异步获取单元楼层房间关联信息
        public function gldylcfj(){
            $fjxzid=I('fjxzid');
            $zdxinxi=M("zdxinxi")->where(array('id'=>I('zdid')))->find();
            $fwleixing=get_peizhi('fwleixing',$zdxinxi['fwleixing'],3);
            $jiegou=get_peizhi('jiegou',$zdxinxi['jiegou'],3);
            $zhuangxiu=get_peizhi('zhuangxiu',$zdxinxi['zhuangxiu'],3);
            $yongtu=get_peizhi('yongtu',$zdxinxi['yongtu'],3);
            $chanquan=get_peizhi('chanquan',$zdxinxi['chanquan'],3);
            $fjbackground=get_peizhi('fjbackground',0,1);
            if ($fjxzid) {
                $fjshu=M('fjxinxi')->where(array('zdid'=>I('zdid'),'xianzhuang'=>$fjxzid))->count();
            } else {
                $fjshu=M('fjxinxi')->where(array('zdid'=>I('zdid')))->count();
            }
            $dyxinxi=M('dyxinxi')->where(array('zdid'=>I('zdid')))->order('xsshunxu asc')->select();
            $ubumen = M('yonghu')->where(array('id'=>$zdxinxi['zerenrid']))->getField('bumen');
            $dyid=array();
            $qxpdez = 1;
            $qxpddx = 1;
            $qxpdpl = 1;
            $qxpdal = 1;
            $qxpded = 1;
            $qxpddd = 1;
            $qxpdpf = 1;
            $qxpdaf = 1;
            $qxpdel = 1;
            $qxpddl = 1;
            $qxpdef = 1;
            $qxpddf = 1;
            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('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) {
                        $fangjian = M('fjxinxi')->where(array('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('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,'yongtu'=>$yongtu,'chanquan'=>$chanquan,'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('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=get_peizhi('lcleixing',$lcxinxi['lcleixing'],3);
            $fjshu=M('fjxinxi')->where(array('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');
            $ubumen = M('yonghu')->where(array('id'=>$zdid))->getField('bumen');
            $is_rbac = 1;
            $qxpdzs = 1;
            $qxpdzz = 1;
            $qxpdag = 1;
            $qxpdat = 1;
            $qxpdgj = 1;
            $qxpdtx = 1;
            $qxpdct = 1;
            $qxpdst = 1;
            $xiaoqu=$fjxinxi['xqid'];
            $fanghao=$fjxinxi['fjmwdw'];
            $danyuan=M('dyxinxi')->where(array('id'=>$fjxinxi['dyid']))->getField('dymwdw');
            $zuodong=M('zdxinxi')->where(array('id'=>$fjxinxi['zdid']))->getField('zdmwdw');
            $condition['gongsiid']=session('gongsiid');
            $condition['zhuangtai']=array('neq',get_options('fkyzt_config','fychengjiao_zhuangtai'));
            $condition['isdel']=2;
            $condition['xiaoqu']=$xiaoqu;
            $condition['zuodong']=$zuodong;
            $condition['danyuan']=$danyuan;
            $condition['fanghao']=$fanghao;
            if ($qxpdzs == 1) {
                $condition['leixing']=1;
                $cffy=M('fangyuan')->where($condition)->find();
                if($cffy){
                    $qxpdzs = 0;
                }
            }
            if ($qxpdzz == 1) {
                $condition['leixing']=2;
                $cffy=M('fangyuan')->where($condition)->find();
                if($cffy){
                    $qxpdzz = 0;
                }
            }
            $image1=M('fjphoto')->where(array('fjid'=>$fjid,'fengmian'=>1))->getField('image');
            $image2=M("fjphoto")->where(array('fjid'=>$fjid))->order('create_time desc')->getField('image');
            if ($image1) {
                $image=$image1;
            } else {
                $image=$image2;
            }
            $sccjrq=date('Y-m-d',$fjxinxi['sccjrq']);
            $yezhuzy=get_peizhi('yezhuzy',$fjxinxi['yezhuzy'],3);
            $xianzhuang=get_peizhi('xianzhuang',$fjxinxi['xianzhuang'],3);
            $fwleixing=get_peizhi('fwleixing',$fjxinxi['fwleixing'],3);
            $chanquan=get_peizhi('chanquan',$fjxinxi['chanquan'],3);
            $yongtu=get_peizhi('yongtu',$fjxinxi['yongtu'],3);
            $chaoxiang=get_peizhi('chaoxiang',$fjxinxi['chaoxiang'],3);
            $zhuangxiu=get_peizhi('zhuangxiu',$fjxinxi['zhuangxiu'],3);
            $data=array('status'=>0,'qxpdzs'=>$qxpdzs,'qxpdzz'=>$qxpdzz,'qxpdag'=>$qxpdag,'qxpdat'=>$qxpdat,'qxpdgj'=>$qxpdgj,'qxpdtx'=>$qxpdtx,'qxpdct'=>$qxpdct,'qxpdst'=>$qxpdst,'fjxinxi'=>$fjxinxi,'image'=>$image,'sccjrq'=>$sccjrq,'yezhuzy'=>$yezhuzy,'xianzhuang'=>$xianzhuang,'fwleixing'=>$fwleixing,'chanquan'=>$chanquan,'yongtu'=>$yongtu,'chaoxiang'=>$chaoxiang,'zhuangxiu'=>$zhuangxiu);
            header("Content-type: application/json");
            exit(json_encode($data));
        }

    }