<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class XianzhiController extends CommonController {
		// 电话查看列表
		public function all(){
			$map .= " where gongsiid=".session('gongsiid');
			$x = _rbac_lists_where(251,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";
			}
			$sousuo=I('sousuo');
			if ($sousuo) {//搜索
				$condition.=" where ((e.ygmingcheng like '%$sousuo%') or (e.dianhua like '%$sousuo%') or (f.bianhao like '%$sousuo%'))";
			}
			if(I('bumen')){
				$map.=" and bumen=".I('bumen');
			}
			$count=M('Xianzhi')->query("select count(*) from __XIANZHI__ a join (select id as e_id,ygmingcheng,bumen from __YONGHU__ {$map}) e on a.uid=e.e_id");
			$Page=new \Think\Page($count['0']['count(*)'],30);
			$show=$Page->show();
			$list="select a.*,e.ygmingcheng,e.bumen,e.dianhua,f.bianhao,f.zhuangtai,f.weihurenid from __XIANZHI__ a join (select id as e_id,ygmingcheng,bumen,dianhua from __YONGHU__ {$map}) e on a.uid=e.e_id join (select id as f_id,bianhao,zhuangtai,weihurenid from __FANGYUAN__) f on a.fyid=f.f_id {$condition} order by shijian DESC limit ".$Page->firstRow.','.$Page->listRows;
			$xianzhiList=M('Xianzhi')->query($list);
			$this->assign('firstRow',$Page->firstRow);
			$this->assign('xianzhiList',$xianzhiList);
			$this->assign('count',$count);
			$this->assign('page',$show);
			$bumen = I("get.bumen",0,'intval');
			$select_categorys = bumen_option( $bumen, 251);
			$this->assign("select_categorys", $select_categorys);
			$this->display();
		}
	}