<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class XianzhiController extends CommonController {
		// 电话查看列表
		public function all(){
			if (I('is_ajax')) {
				$condition = "e.gongsiid=".session('gongsiid');
				$x = _rbac_lists_where(251,0);
				if ($x && $x != "all" && $x != "me") {
					$condition .= " and e.bumen in ({$x})";
				} elseif ($x == "me") {
					$condition .= " and e.id=".session('uid');
				} elseif ($x == false) {
					$condition .= " and e.id=0";
				}
				$bumen = I('bumen');
				$sousuo = I('sousuo');
				$shijian = I('shijian');
				if ($bumen) {
					$string = get_bm_sz($bumen,2);
					$condition .= " and e.bumen in ($string)";
				}
				if ($shijian) {
					$time_s = explode(' - ',$shijian);
					$time_s1 = strtotime($time_s[0]);
					$time_s2 = strtotime($time_s[1])+86400;
					$condition .= " and a.shijian>=".$time_s1." and a.shijian<".$time_s2;
				}
				if ($sousuo) {
					$condition .= " and (e.ygmingcheng like '%$sousuo%' or e.pinyinjs like '%$sousuo%' or e.dianhua like '%$sousuo%' or a.zy_bianhao like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$dqpx = "a.".$field." ".$order;
				} else {
					$dqpx = "a.shijian desc";
				}
				$count = M('xianzhi')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id')->where($condition)->count();
				$Page = I('p');
				$data = M('xianzhi')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id')->field('a.*,e.ygmingcheng,e.dianhua,e.bumen')->where($condition)->order($dqpx)->page($Page,$limit)->select();
				foreach ($data as $key => $value) {
					$data[$key]['shijian'] = date('Y-m-d H:i:s',$value['shijian']);
					$data[$key]['bmming'] = zym($value['bumen'],6);
					$fy = M('fangyuan')->where(array('id'=>$value['fyid']))->field('bianhao,zhuangtai,weihurenid')->find();
					if ($fy) {
						$is_rbacxq = _rbac_btn_show(46,$fy['zhuangtai'],$fy['weihurenid']);
						$zyxqlj = U('fangyuan/neirong',array('bianhao'=>$fy['bianhao']));
						$data[$key]['rbacxq'] = $is_rbacxq;
						$data[$key]['zyxqlj'] = $zyxqlj;
					}
					$data[$key]['fybh'] = $fy['bianhao'] ? $fy['bianhao'] : "——";
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count,
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$select_categorys = bumen_option( $bumen, 251);
				$this->assign("select_categorys", $select_categorys);
				$this->display();
			}
		}
	}