<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class FyxgjiluController extends CommonController {
		// 房源修改记录列表
		public function all(){
			if (I('is_ajax')) {
				$startUnix = strtotime(I('datetime1'));
				$endUnix = strtotime(I('datetime2'))+86399;
				$p = I('pageSize');
				$sn = I('sortName');
				$so = I('sortOrder');
				$sousuo=" where e.gongsiid=".session('gongsiid')." and a.zy_type=2";
				if (I('datetime1') and I('datetime2')) {
					$sousuo.=" and a.addtime >= '".$startUnix."' and a.addtime<'".$endUnix."'";
				}elseif (I('datetime1')) {
					$sousuo.=" and a.addtime >= '".$startUnix."'";
				}elseif (I('datetime2')) {
					$sousuo.=" and a.addtime<'".$endUnix."'";
				}
				if (I('searchText')) {
					$sousuo.= " and (e.pinyinjs like '%" .I('searchText'). "%') or (e.ygmingcheng like '%" .I('searchText'). "%') or (a.zy_bianhao like '%" .I('searchText'). "%')";
				}
				$Model = new \Think\Model();
				/*权限控制开始*/
				$x = _rbac_lists_where(252,0);
				if ($x && $x != "all" && $x != "me") {
					$sousuo .= " and e.bumen in ({$x})";
				}elseif ($x == "me") {
					$sousuo .= " and e.id=".session('uid');
				}elseif ($x == false) {
					$sousuo .= " and e.id=0";
				}
				/*权限控制结束*/
				$sqlcount = "select count(a.id) from __RIZHI__ a join __YONGHU__ e on a.uid=e.id {$sousuo} ";
				$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 __RIZHI__ a join __YONGHU__ e on a.uid=e.id {$sousuo} 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']);
					$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->display();
			}
		}
	}