<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class XinfangController extends CommonController {
		//户型列表
		public function huxing(){
			$is_rbac = _rbac_node_show(846);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$ckhx=I('ckhx');
			if ($ckhx == 1) {
				$condition = "gongsiid=".session('gongsiid');
				$sousuo=I('sousuo');
				if ($sousuo) {
					$condition.=" and ((e.pinyinjs like '%$sousuo%') or (e.ygmingcheng like '%$sousuo%') or (e.dianhua like '%$sousuo%') or (a.hxbianhao like '%$sousuo%') or (a.hxbiaoti like '%$sousuo%') or (f.xiaoqum like '%$sousuo%'))";
				}
				$bumen = I("get.bumen",0,'intval');
				$result = M('bumen')->order(array("sort" => "ASC"))->select();
				if ($bumen) {
					$arr_string = _rbac_bumen_array($result,$bumen);
					$arr_string[] = $bumen;
					$string = implode(',',$arr_string);
					$condition .= " and e.bumen in ($string)";
				}
				$count=M('huxing')->query("select count(*) from __HUXING__ a left join (select id as e_id,ygmingcheng,pinyinjs,bumen,dianhua from __YONGHU__) e on a.adduid=e.e_id left join (select id as f_id,xiaoqum from __XIAOQU__) f on a.xqid=f.f_id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],20);
				$show = $Page->show();
				$list="select a.*,b.cxming,c.zxming,e.ygmingcheng,e.bumen,f.xiaoqum from __HUXING__ a left join (select id as e_id,ygmingcheng,pinyinjs,bumen,dianhua from __YONGHU__) e on a.adduid=e.e_id 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 left join (select id as f_id,xiaoqum from __XIAOQU__) f on a.xqid=f.f_id where {$condition} order by addtime DESC limit ".$Page->firstRow.','.$Page->listRows;
				$bumen = I("get.bumen",0,'intval');
				$select_categorys = bumen_option( $bumen, 237);
				$this->assign("select_categorys", $select_categorys);
			} elseif ($ckhx == 2) {
				$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.hxbianhao,a.shi,a.ting,a.wei,a.chu,a.yangtai,a.jzmianji,a.symianji,a.remark,a.adduid,a.addtime,b.cxming,c.zxming,e.tjren 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 left join (select id as e_id,ygmingcheng as tjren from __YONGHU__) e on a.adduid=e.e_id ";
				$this->assign('xqid',$xqid);
			}
			$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 ckfwtx(){
			$map .= " where gongsiid=".session('gongsiid');
			$x = _rbac_lists_where(882,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('fjtixing')->query("select count(*) from __FJTIXING__ as a join (select id as e_id,ygmingcheng from __YONGHU__ {$map}) e on a.txuid=e.e_id where fjid=".I('fjid'));
			$Page=new \Think\Page($count['0']['count(*)'],20);
			$show=$Page->show();
			$list="select * from __FJTIXING__ as a join (select id as txr,ygmingcheng as txren from __YONGHU__ {$map}) e on a.txuid=e.txr left join (select id as tjr,ygmingcheng as tjren from __YONGHU__ ) as c on a.adduid=c.tjr where fjid=".I('fjid')." order by a.time DESC limit ".$Page->firstRow.','.$Page->listRows;
			$tixing=M('fjtixing')->query($list);
			$this->assign('firstRow',$Page->firstRow);
			$this->assign('tixing',$tixing);
			$this->assign('count',$count);
			$this->assign('page',$show);
			$this->display();
		}
		//添加房间提醒
		public function tixing(){
			$is_rbac = _rbac_node_show(881);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$fjxinxi=M('fjxinxi')->where(array('id'=>I('fjid')))->find();
				$data['xqid']=$fjxinxi['xqid'];
				$data['zdid']=$fjxinxi['zdid'];
				$data['dyid']=$fjxinxi['dyid'];
				$data['lcid']=$fjxinxi['lcid'];
				$data['fjid']=$fjxinxi['id'];
				$data['txuid']=I('txuid');
				$data['txneirong']=I('txneirong');
				$data['txshijian']=strtotime(I('txshijian'));
				$data['time']=time();
				$data['adduid']=session('uid');
				$data['gongsiid']=session('gongsiid');
				$isok=M('fjtixing')->add($data);
				if ($isok){
					$this->success('添加成功');
				}else{
					$this->error('添加失败');
				}
			} else {
				$this->ygmingcheng=M('Yonghu')->where(array('gongsiid'=>session('gongsiid')))->select();
				$this->display();
			}
		}
		// 小区列表
		public function xiaoqu(){
			$is_rbac = _rbac_node_show(891);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$sousuo=I('sousuo');
			if ($sousuo) {
				$condition.=" where (xiaoqum like '%$sousuo%')";
			}
			$count=M('xiaoqu')->query("select count(*) from __XIAOQU__ {$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 (select id as e_id,ygmingcheng,bumen from __YONGHU__) e on a.adduid=e.e_id left join (select id as b_id,xzqming from __XINGZHENGQU__ ) b on a.ssxzq=b.b_id left join (select id as c_id,pianqum from __PIANQU__ ) c on a.sspianqu=c.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');
			$this->jcpz=M('jcpz')->where(array('gongsiid'=>session('gongsiid')))->field('dtmiyao,dtzuobiao')->find();
			$xiaoqu=M('xiaoqu')->where(array('id'=>$id))->find();
			$this->pianqu=M('pianqu')->where(array('id'=>$xiaoqu['sspianqu']))->getField('pianqum');
			$this->xingzhengqu=M('xingzhengqu')->where(array('id'=>$xiaoqu['ssxzq']))->getField('xzqming');
			$this->xiaoqu=$xiaoqu;
			$this->zdshu=M('zdxinxi')->where(array('gongsiid'=>session('gongsiid'),'xqid'=>$id))->count();
			$this->fjshu=M('fjxinxi')->where(array('gongsiid'=>session('gongsiid'),'xqid'=>$id))->count();
			$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->display();
		}
		//楼盘字典
		public function loupanzd(){
			$is_rbac = _rbac_node_show(893);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$id=I('id');
			$this->xiaoquid=$id;
			$this->zdxinxi=M('zdxinxi')->where(array('xqid'=>$id))->order('xsshunxu asc')->select();
			$this->adduid=M('xiaoqu')->where(array('id'=>$id))->getField('adduid');
			$this->zdshu=M('zdxinxi')->where(array('gongsiid'=>session('gongsiid'),'xqid'=>$id))->count();
			$this->xianzhuang=M('peizhi')->where(array('pzming'=>'xianzhuang','zhuangtai'=>1))->order('xsshunxu asc')->select();
			$this->fjbackground=M('peizhi')->where(array('pzming'=>'fjbackground','zhuangtai'=>1))->order('xsshunxu asc')->select();
			$this->display();
		}
	}