<?php

	/***************************************************************************\
	|																			|
	| 房佳（专业的新房分销ERP管理系统）											|
	|																			|
	| Copyright (c) 2008-2019 http://fj.ytsofts.cn/ All rights reserved.	|
	|																			|
	| 本系统由淮南市银泰软件科技有限公司提供技术支持							|
	|																			|
	| QQ号：984784483															|
	|																			|
	\***************************************************************************/

	namespace Admin\Controller;
	use Think\Controller;
	class XinfangController extends CommonController {
		// 小区列表
		public function xiaoqu(){
			$is_rbac = _rbac_node_show(891);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$condition = " where a.id > 0";
			$is_rbac1 = _rbac_node_show(932);
			if (!$is_rbac1) {
				$condition .= " and a.status=1";
			}
			$sousuo = I('sousuo');
			if ($sousuo) {//搜索
				$condition .= " and (a.xiaoqum like '%$sousuo%')";
			}
			$user = M('yonghu')->where(array('id'=>session('uid')))->field('bumen,leixing')->find();
			if ($user['leixing'] == 1) {
				$qybm = M('bumen')->where(array('id'=>$user['bumen']))->field('id,level')->find();
				if ($qybm['level'] == 2) {
					$condition .= " and a.bumen=".$qybm['id'];
				}
			}
			if ($user['leixing'] == 2) {
				$xqidsz = M('xqbdxs')->where(array('uid'=>session('uid')))->field('xqid')->select();
				$xqids = array();
				foreach ($xqidsz as $key => $value) {
					$xqids[] = $value['xqid'];
				}
				$xqids[] = M('xiaoqu')->where(array('bdbumen'=>$user['bumen']))->getField('id');
				$xqids = implode(',',$xqids);
				if ($xqids) {
					$condition .= " and a.id in (".$xqids.")";
				}
			}
			if ($user['leixing'] == 3) {
				$xqidsz = M('xqbdxs')->where(array('uid'=>session('uid')))->field('xqid')->select();
				$xqids = array();
				foreach ($xqidsz as $key => $value) {
					$xqids[] = $value['xqid'];
				}
				$xqids = implode(',',$xqids);
				if ($xqids) {
					$condition .= " and a.id in (".$xqids.")";
				}
			}
			$count=M('xiaoqu')->query("select count(*) from __XIAOQU__ a {$condition}");
			$Page=new \Think\Page($count['0']['count(*)'],30);
			$show=$Page->show();
			$list="select a.*,b.xzqming,c.pianqum,e.ygmingcheng,e.bumen from __XIAOQU__ a left join __YONGHU__ e on a.adduid=e.id left join __XINGZHENGQU__ b on a.ssxzq=b.id left join __PIANQU__ c on a.sspianqu=c.id {$condition} order by id DESC limit ".$Page->firstRow.','.$Page->listRows;
			$xiaoqu=M('xiaoqu')->query($list);
			$this->assign('firstRow',$Page->firstRow);
			$this->assign('xiaoqu',$xiaoqu);
			$this->assign('count',$count);
			$this->assign('page',$show);
			$this->display();
		}
		// 小区详情
		public function xiaoqurr(){
			$is_rbac = _rbac_node_show(892);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$id=I('id');
			$xiaoqu=M('xiaoqu')->where(array('id'=>$id))->find();
			$is_rbac1 = _rbac_node_show(932);
			if (!$is_rbac1 && $xiaoqu['status'] != 1) {
				$xiaoqu="";
			} else {
				$this->pianqu=M('pianqu')->where(array('id'=>$xiaoqu['sspianqu']))->getField('pianqum');
				$this->xingzhengqu=M('xingzhengqu')->where(array('id'=>$xiaoqu['ssxzq']))->getField('xzqming');
				$this->zdshu=0;
				$this->fjshu=0;
				$this->wuyelx=M('peizhi')->where(array('pzming'=>'wuyelx','lxid'=>$xiaoqu['wuyelx']))->getField('lxming');
				$this->wuyezz=M('peizhi')->where(array('pzming'=>'wuyezz','lxid'=>$xiaoqu['wuyezz']))->getField('lxming');
				$this->xmjibie=M('peizhi')->where(array('pzming'=>'xmjibie','lxid'=>$xiaoqu['xmjibie']))->getField('lxming');
				$this->gongqifs=M('peizhi')->where(array('pzming'=>'gongqifs','lxid'=>$xiaoqu['gongqifs']))->getField('lxming');
				$this->kangzhen=M('peizhi')->where(array('pzming'=>'kangzhen','lxid'=>$xiaoqu['kangzhen']))->getField('lxming');
				$this->ceweizldw=M('peizhi')->where(array('pzming'=>'ceweizldw','lxid'=>$xiaoqu['ceweizldw']))->getField('lxming');
				$this->gongdianlx=M('peizhi')->where(array('pzming'=>'gongdianlx','lxid'=>$xiaoqu['gongdianlx']))->getField('lxming');
				$this->gongshuilx=M('peizhi')->where(array('pzming'=>'gongshuilx','lxid'=>$xiaoqu['gongshuilx']))->getField('lxming');
				$this->spjzleixing=M('peizhi')->where(array('pzming'=>'spjzleixing','lxid'=>$xiaoqu['spjzleixing']))->getField('lxming');
				$jiegou1=M('xiaoqu')->where(array('id'=>$id))->getField('jiegou');
				if ($jiegou1) {
					$condition="pzming = 'jiegou'";
					$condition.=" and lxid in ($jiegou1)";
					$this->jiegou=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$yongtu1=M('xiaoqu')->where(array('id'=>$id))->getField('yongtu');
				if ($yongtu1) {
					$condition="pzming = 'yongtu'";
					$condition.=" and lxid in ($yongtu1)";
					$this->yongtu=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$dianshi1=M('xiaoqu')->where(array('id'=>$id))->getField('dianshi');
				if ($dianshi1) {
					$condition="pzming = 'dianshi'";
					$condition.=" and lxid in ($dianshi1)";
					$this->dianshi=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$tongxun1=M('xiaoqu')->where(array('id'=>$id))->getField('tongxun');
				if ($tongxun1) {
					$condition="pzming = 'tongxun'";
					$condition.=" and lxid in ($tongxun1)";
					$this->tongxun=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$chanquan1=M('xiaoqu')->where(array('id'=>$id))->getField('chanquan');
				if ($chanquan1) {
					$condition="pzming = 'chanquan'";
					$condition.=" and lxid in ($chanquan1)";
					$this->chanquan=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$sqanquan1=M('xiaoqu')->where(array('id'=>$id))->getField('sqanquan');
				if ($sqanquan1) {
					$condition="pzming = 'sqanquan'";
					$condition.=" and lxid in ($sqanquan1)";
					$this->sqanquan=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$cainuanfs1=M('xiaoqu')->where(array('id'=>$id))->getField('cainuanfs');
				if ($cainuanfs1) {
					$condition="pzming = 'cainuanfs'";
					$condition.=" and lxid in ($cainuanfs1)";
					$this->cainuanfs=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$fwleixing1=M('xiaoqu')->where(array('id'=>$id))->getField('fwleixing');
				if ($fwleixing1) {
					$condition="pzming = 'fwleixing'";
					$condition.=" and lxid in ($fwleixing1)";
					$this->fwleixing=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$wldibanlx1=M('xiaoqu')->where(array('id'=>$id))->getField('wldibanlx');
				if ($wldibanlx1) {
					$condition="pzming = 'wldibanlx'";
					$condition.=" and lxid in ($wldibanlx1)";
					$this->wldibanlx=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
				$gongshuifs1=M('xiaoqu')->where(array('id'=>$id))->getField('gongshuifs');
				if ($gongshuifs1) {
					$condition="pzming = 'gongshuifs'";
					$condition.=" and lxid in ($gongshuifs1)";
					$this->gongshuifs=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
				}
			}
			$this->jcpz=M('jcpz')->where(array('gongsiid'=>session('gongsiid')))->field('dtmiyao,dtzuobiao')->find();
			$this->xiaoqu=$xiaoqu;
			$this->display();
		}
	}