<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class FyxgjiluController extends CommonController {
		// 房源修改记录列表
		public function all(){
			if (I('is_ajax') && I('zy_type')) {
				$startUnix = strtotime(I('datetime1'));
				$endUnix = strtotime(I('datetime2'))+86399;
				$p = I('pageSize');
				$sn = I('sortName');
				$so = I('sortOrder');
				$zy_type = I('zy_type');
				if ($zy_type==1) {
					$sousuo=" where zy_type=1";
				}elseif ($zy_type==2) {
					$sousuo=" where zy_type=2";
				}
				if (I('datetime1') and I('datetime2')) {
					$sousuo.=" and addtime >= '".$startUnix."' and addtime<'".$endUnix."'";
				}elseif (I('datetime1')) {
					$sousuo.=" and addtime >= '".$startUnix."'";
				}elseif (I('datetime2')) {
					$sousuo.=" and addtime<'".$endUnix."'";
				}
				if (I('searchText')) {
					$sousuo1.= " where (e.pinyinjs like '%" .I('searchText'). "%') or (e.ygmingcheng like '%" .I('searchText'). "%') or (a.zy_bianhao like '%" .I('searchText'). "%')";
				}
				$Model = new \Think\Model();
				/*权限控制开始*/
				$map = "gongsiid=".session('gongsiid');
				$x = _rbac_lists_where(252,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";
				}
				/*权限控制结束*/
				$sqlcount = "select count(a.id) FROM (select * FROM jjrxt_rizhi ".$sousuo.") as a join (select id as e_id,ygmingcheng,pinyinjs from __YONGHU__ where {$map}) e on a.uid=e.e_id  ".$sousuo1;
				$countb=$Model->query($sqlcount);
				$count=$countb[0]['count(a.id)'];
				$Page = new \Think\Page($count,$p); //实例化分页类 传入总记录数和每页显示的记录数(15)
				$show = $Page->show();  //分页显示输出    
				$sql="select a.*,e.ygmingcheng,e.bumen FROM (select * FROM jjrxt_rizhi ".$sousuo.") as a join (select id as e_id,ygmingcheng,pinyinjs,bumen from __YONGHU__ where {$map}) e on a.uid=e.e_id ".$sousuo1." order by a.id DESC limit  ".$Page->firstRow.','.$Page->listRows;
				$arr=$Model->query($sql);
				foreach ($arr as $key => $value) {
					$arr[$key]['addtime1']=date('Y-m-d H:i:s',$value['addtime']);
					$arr[$key]['bmming']=bumen($value['bumen']);
					if ($value['zy_type'] == 2) {
						$kyxq=0;
						$kys=M('fzky')->where(array('kyid'=>$value['zy_id']))->field('weihurenid')->select();
						foreach ($kys as $key1 => $value1) {
							$is_rbac1 = _rbac_btn_show(75,0,$value1['weihurenid']);
							if ($is_rbac1) {
								$kyxq=1;
								$kywhr=$value1['weihurenid'];
							}
						}
						if ($kyxq != 1) {
							$whrid=M('keyuan')->where(array('xqbianhao'=>$value['zy_bianhao']))->getField('weihurenid');
							$is_rbac2 = _rbac_btn_show(75,0,$whrid);
							if ($is_rbac2) {
								$kyxq=1;
							}
						}
						if ($kyxq == 1) {
							$arr[$key]['kyxqqx'] = 1;
							$arr[$key]['kywhr'] = $kywhr;
						}
					}
				}
				$data=array('data'=>$arr,'total'=>$count);
				header("Content-type: application/json");
				exit(json_encode($data));
			}else{
				$this->zy_type=I('zy_type');
				$this->display();
			}
		}
	}