<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class FygenjinController extends CommonController {
		// 房源跟进列表
		public function all(){
			$map = "gongsiid=".session('gongsiid');
			$x = _rbac_lists_where(253,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";
			}
			$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.fybh 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)";
			}
			$shijian1=I('shijian1');
			$shijian2=I('shijian2');
			if ($shijian1) {
				$this->shijian1=$shijian1;
				$shijian3=strtotime($shijian1);
			}
			if ($shijian2) {
				$this->shijian2=$shijian2;
				$shijian4=strtotime($shijian2)+86400;
			}
			if ($shijian3 and $shijian4){
				if ($shijian3 > $shijian4){
					$condition.=" and shijian>".$shijian4." and shijian<".$shijian3;
					$this->shijian1=$shijian2;
					$this->shijian2=$shijian1;
				} else {
					$condition.=" and shijian>".$shijian3." and shijian<".$shijian4;
				}
			} elseif ($shijian3) {
				$condition.=" and shijian>".$shijian3;
			} elseif ($shijian4) {
				$condition.=" and shijian<".$shijian4;
			}
			$count=M('Fygenjin')->query("select count(*) from __FYGENJIN__ a join (select id as e_id,ygmingcheng,pinyinjs,bumen,dianhua from __YONGHU__ where {$map}) e on a.uid=e.e_id where {$condition}");
			$Page = new \Think\Page($count['0']['count(*)'],20);
			$show = $Page->show();
			$list="select * from __FYGENJIN__ a join (select id as e_id,ygmingcheng,pinyinjs,bumen,dianhua from __YONGHU__ where {$map}) e on a.uid=e.e_id where {$condition} order by id DESC limit ".$Page->firstRow.','.$Page->listRows;
			$fygenjinList=M()->query($list);
			$this->assign('fygenjinList', $fygenjinList);
			$this->assign('count',$count);
			$this->assign('page',$show);
			$select_categorys = bumen_option( $bumen, 253);
			$this->assign("select_categorys", $select_categorys);
			$this->display();
		}
	}