<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class ShangjiController extends CommonController {

		//写字楼
		public function fyxiezilou(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$mmzl = I('mmzl');
				$leixing = I('leixing');
				$xzldengji = I('xzldengji');
				$zhuangxiu = I('zhuangxiu');
				$myfy = I('myfy');
				$mysc = I('mysc');
				$jrll = I('jrll');
				$tupian = I('tupian');
				$shipin = I('shipin');
				$xinshang = I('xinshang');
				$heyan = I('heyan');
				$jishou = I('jishou');
				$waiwangtb = I('waiwangtb');
				$yaoshi = I('yaoshi');
				$jiage1 = I('jiage1');
				$jiage2 = I('jiage2');
				$mianji1 = I('mianji1');
				$mianji2 = I('mianji2');
				$lurusj1 = strtotime(I('shijian1'));
				$lurusj2 = strtotime(I('shijian2'));
				$louceng1 = I('louceng1');
				$louceng2 = I('louceng2');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(863);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				if ($mmzl) {
					$condition .= " and a.mmzl=".$mmzl;
				}
				$fygpzt = get_options('chengjiao_options','fygongpan_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$fygpzt." and a.shtype=1";
				if ($myfy) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($mysc) {
					$sc = M('shoucang')->where(array('user_id'=>session('uid')))->select();
					if ($sc) {
						foreach ($sc as $key => $value) {
							$cs_arr[] = $value['fyid'];
						}
						$in_sc = implode(',', $cs_arr);
					} else {
						$in_sc = 0;
					}
					$condition .= " and a.id in ($in_sc)";
				}
				if ($jrll) {
					$today = "fyxzl".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in (".$history.")";
				}
				if ($leixing) {
					$condition .= " and a.leixing=".$leixing;
				}
				if ($xzldengji) {
					$condition .= " and a.xzldengji=".$xzldengji;
				}
				if ($zhuangxiu) {
					$condition .= " and a.zhuangxiu=".$zhuangxiu;
				}
				if ($tupian) {
					$condition .= " and a.tupian=1";
				}
				if ($shipin) {
					$condition .= " and a.shipin_url <> ''";
				}
				if ($xinshang) {
					$xshang = time()-(86400*3);
					$condition .= " and a.lurusj>".$xshang;
				}
				if ($heyan) {
					$condition .= " and a.heyan=1";
				}
				if ($jishou) {
					$condition .= " and a.jishou=1";
				}
				if ($waiwangtb) {
					$condition .= " and s.waiwangtb=1";
				}
				if ($yaoshi) {
					$condition .= " and (s.shouyaobm<>'' or a.shouyaoren<>'')";
				}
				if ($mmzl == 1) {
					if ($jiage1 && $jiage2) {
						$condition .= " and a.shoujia>=".$jiage1." and a.shoujia<=".$jiage2;
					} elseif ($jiage1) {
						$condition .= " and a.shoujia>=".$jiage1;
					} elseif ($jiage2) {
						$condition .= " and a.shoujia<=".$jiage2;
					}
				} elseif ($mmzl == 2) {
					if ($jiage1 && $jiage2) {
						$condition .= " and a.zujia>=".$jiage1." and a.zujia<=".$jiage2;
					} elseif ($jiage1) {
						$condition .= " and a.zujia>=".$jiage1;
					} elseif ($jiage2) {
						$condition .= " and a.zujia<=".$jiage2;
					}
				}
				if ($mianji1 && $mianji2) {
					$condition .= " and a.jzmianji>=".$mianji1." and a.jzmianji<=".$mianji2;
				} elseif ($mianji1) {
					$condition .= " and a.jzmianji>=".$mianji1;
				} elseif ($mianji2) {
					$condition .= " and a.jzmianji<=".$mianji2;
				}
				if ($lurusj1 && $lurusj2) {
					$lurusj3 = $lurusj2+86399;
					$condition .= " and a.lurusj>=".$lurusj1." and a.lurusj<=".$lurusj3;
				} elseif ($lurusj1) {
					$condition .= " and a.lurusj>=".$lurusj1;
				} elseif ($lurusj2) {
					$lurusj3 = $lurusj2+86399;
					$condition .= " and a.lurusj<=".$lurusj3;
				}
				if ($louceng1 && $louceng2) {
					$condition .= " and a.louceng>=".$louceng1." and a.louceng<=".$louceng2;
				} elseif ($louceng1) {
					$condition .= " and a.louceng>=".$louceng1;
				} elseif ($louceng2) {
					$condition .= " and a.louceng<=".$louceng2;
				}
				if ($sousuo) {
					$condition .= " and (a.fybiaoti like '%$sousuo%' or a.yezhu like '%$sousuo%' or a.weihuren like '%$sousuo%' or a.yezhudianhua like '%$sousuo%' or a.yezhudianhua2 like '%$sousuo%' or a.yezhudianhua3 like '%$sousuo%' or a.bianhao like '%$sousuo%' or a.xiaoqum like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$fypx .= "order by a.".$field." ".$order;
				} else {
					$fypx .= "order by a.id DESC";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __FYXIEZILOU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.*,e.ygmingcheng from __FYXIEZILOU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$fypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					$isshikan[$key] = M('shikan')->where(array('fybh'=>$es['bianhao'],'fylx'=>13))->find();
					$dqshu[$key] = M('xianzhi')->where(array('fyid'=>$value['id'],'fylx'=>13))->count();
					if ($isshikan[$key]) {
						$data[$key]['isshikan'] = 1;
					}
					if ($value['shoujia'] > 0) {
						$fyjg = floatval($value['shoujia'])."万";
					} else if ($value['zujia']) {
						$fyjg = floatval($value['zujia']).get_peizhi('zujialx',$value['zujialx'],3);
					}
					$data[$key]['dqshu'] = $dqshu[$key];
					$data[$key]['img'] = get_s_img($value['bianhao']);
					$data[$key]['xqm'] = zym($value['xiaoqu'],3);
					$data[$key]['jzmianji'] = floatval($value['jzmianji'])."m²";
					$data[$key]['fyjg'] = $fyjg;
					$data[$key]['danjia'] = $value['danjia'] ? floatval($value['danjia'])."元/m²" : "——";
					$data[$key]['fylc'] = $value['louceng']."/".$value['zlouceng'];
					$data[$key]['xzllx'] = get_peizhi('xzlleixing',$value['leixing'],3);
					$data[$key]['xzldj'] = get_peizhi('xzldengji',$value['xzldengji'],3);
					$data[$key]['xzlzx'] = get_peizhi('xzlzhuangxiu',$value['zhuangxiu'],3);
					$data[$key]['fyzt'] = get_peizhi('zhuangtai',$value['zhuangtai'],3);
					$data[$key]['fydj'] = $value['fydengji'] ? get_peizhi('fydengji',$value['fydengji'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$is_rbacxq = _rbac_btn_show(46,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
					$photo[$key] = M('photo')->where(array('fybh'=>$value['bianhao'],'image'=>array('neq',$data[$key]['img'])))->field('image')->select();
					$data[$key]['photo'] = $photo[$key];
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->zhuangxiu = get_peizhi('xzlzhuangxiu',0,1);
				$this->xzldengji = get_peizhi('xzldengji',0,1);
				$this->leixing = get_peizhi('xzlleixing',0,1);
				$this->display();// 输出模板
			}
		}

		//商铺
		public function fyshangpu(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$mmzl = I('mmzl');
				$yetai = I('yetai');
				$hangye = I('hangye');
				$leixing = I('leixing');
				$zhuangxiu = I('zhuangxiu');
				$myfy = I('myfy');
				$mysc = I('mysc');
				$jrll = I('jrll');
				$tupian = I('tupian');
				$shipin = I('shipin');
				$xinshang = I('xinshang');
				$heyan = I('heyan');
				$jishou = I('jishou');
				$waiwangtb = I('waiwangtb');
				$yaoshi = I('yaoshi');
				$jiage1 = I('jiage1');
				$jiage2 = I('jiage2');
				$mianji1 = I('mianji1');
				$mianji2 = I('mianji2');
				$lurusj1 = strtotime(I('shijian1'));
				$lurusj2 = strtotime(I('shijian2'));
				$louceng1 = I('louceng1');
				$louceng2 = I('louceng2');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(863);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				if ($mmzl) {
					$condition .= " and a.mmzl=".$mmzl;
				}
				$fygpzt = get_options('chengjiao_options','fygongpan_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$fygpzt." and a.shtype=1";
				if ($myfy) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($mysc) {
					$sc = M('shoucang')->where(array('user_id'=>session('uid')))->select();
					if ($sc) {
						foreach ($sc as $key => $value) {
							$cs_arr[] = $value['fyid'];
						}
						$in_sc = implode(',', $cs_arr);
					} else {
						$in_sc = 0;
					}
					$condition .= " and a.id in ($in_sc)";
				}
				if ($jrll) {
					$today = "fysp".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in (".$history.")";
				}
				if ($yetai) {
					$condition .= " and a.yetai=".$yetai;
				}
				if ($hangye) {
					$condition .= " and a.hangye=".$hangye;
				}
				if ($leixing) {
					$condition .= " and a.leixing=".$leixing;
				}
				if ($zhuangxiu) {
					$condition .= " and a.zhuangxiu=".$zhuangxiu;
				}
				if ($tupian) {
					$condition .= " and a.tupian=1";
				}
				if ($shipin) {
					$condition .= " and a.shipin_url <> ''";
				}
				if ($xinshang) {
					$xshang = time()-(86400*3);
					$condition .= " and a.lurusj>".$xshang;
				}
				if ($heyan) {
					$condition .= " and a.heyan=1";
				}
				if ($jishou) {
					$condition .= " and a.jishou=1";
				}
				if ($waiwangtb) {
					$condition .= " and s.waiwangtb=1";
				}
				if ($yaoshi) {
					$condition .= " and (s.shouyaobm<>'' or a.shouyaoren<>'')";
				}
				if ($mmzl == 1) {
					if ($jiage1 && $jiage2) {
						$condition .= " and a.shoujia>=".$jiage1." and a.shoujia<=".$jiage2;
					} elseif ($jiage1) {
						$condition .= " and a.shoujia>=".$jiage1;
					} elseif ($jiage2) {
						$condition .= " and a.shoujia<=".$jiage2;
					}
				} elseif ($mmzl == 2) {
					if ($jiage1 && $jiage2) {
						$condition .= " and a.zujia>=".$jiage1." and a.zujia<=".$jiage2;
					} elseif ($jiage1) {
						$condition .= " and a.zujia>=".$jiage1;
					} elseif ($jiage2) {
						$condition .= " and a.zujia<=".$jiage2;
					}
				}
				if ($mianji1 && $mianji2) {
					$condition .= " and a.jzmianji>=".$mianji1." and a.jzmianji<=".$mianji2;
				} elseif ($mianji1) {
					$condition .= " and a.jzmianji>=".$mianji1;
				} elseif ($mianji2) {
					$condition .= " and a.jzmianji<=".$mianji2;
				}
				if ($lurusj1 && $lurusj2) {
					$lurusj3 = $lurusj2+86399;
					$condition .= " and a.lurusj>=".$lurusj1." and a.lurusj<=".$lurusj3;
				} elseif ($lurusj1) {
					$condition .= " and a.lurusj>=".$lurusj1;
				} elseif ($lurusj2) {
					$lurusj3 = $lurusj2+86399;
					$condition .= " and a.lurusj<=".$lurusj3;
				}
				if ($louceng1 && $louceng2) {
					$condition .= " and a.louceng>=".$louceng1." and a.louceng<=".$louceng2;
				} elseif ($louceng1) {
					$condition .= " and a.louceng>=".$louceng1;
				} elseif ($louceng2) {
					$condition .= " and a.louceng<=".$louceng2;
				}
				if ($sousuo) {
					$condition .= " and (a.fybiaoti like '%$sousuo%' or a.yezhu like '%$sousuo%' or a.weihuren like '%$sousuo%' or a.yezhudianhua like '%$sousuo%' or a.yezhudianhua2 like '%$sousuo%' or a.yezhudianhua3 like '%$sousuo%' or a.bianhao like '%$sousuo%' or a.xiaoqum like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$fypx .= "order by a.".$field." ".$order;
				} else {
					$fypx .= "order by a.id DESC";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __FYSHANGPU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.*,e.ygmingcheng from __FYSHANGPU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$fypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					$isshikan[$key] = M('shikan')->where(array('fybh'=>$es['bianhao'],'fylx'=>14))->find();
					$dqshu[$key] = M('xianzhi')->where(array('fyid'=>$value['id'],'fylx'=>14))->count();
					if ($isshikan[$key]) {
						$data[$key]['isshikan'] = 1;
					}
					if ($value['shoujia'] > 0) {
						$fyjg = floatval($value['shoujia'])."万";
					} else if ($value['zujia']) {
						$fyjg = floatval($value['zujia']).get_peizhi('zujialx',$value['zujialx'],3);
					}
					$data[$key]['dqshu'] = $dqshu[$key];
					$data[$key]['img'] = get_s_img($value['bianhao']);
					$data[$key]['xqm'] = zym($value['xiaoqu'],3);
					$data[$key]['jzmianji'] = floatval($value['jzmianji'])."m²";
					$data[$key]['fyjg'] = $fyjg;
					$data[$key]['danjia'] = $value['danjia'] ? floatval($value['danjia'])."元/m²" : "——";
					$data[$key]['fylc'] = $value['louceng']."/".$value['zlouceng'];
					$data[$key]['splx'] = get_peizhi('spleixing',$value['leixing'],3);
					$data[$key]['spyt'] = get_peizhi('spyetai',$value['yetai'],3);
					$data[$key]['sphy'] = get_peizhi('sphangye',$value['hangye'],3);
					$data[$key]['syl'] = get_peizhi('sptese',$value['shiyonglv'],3);
					$data[$key]['fyzt'] = get_peizhi('zhuangtai',$value['zhuangtai'],3);
					$data[$key]['fyzx'] = get_peizhi('zhuangxiu',$value['zhuangxiu'],3);
					$data[$key]['fydj'] = $value['fydengji'] ? get_peizhi('fydengji',$value['fydengji'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$is_rbacxq = _rbac_btn_show(46,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
					$photo[$key] = M('photo')->where(array('fybh'=>$value['bianhao'],'image'=>array('neq',$data[$key]['img'])))->field('image')->select();
					$data[$key]['photo'] = $photo[$key];
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->zhuangxiu = get_peizhi('zhuangxiu',0,1);
				$this->leixing = get_peizhi('spleixing',0,1);
				$this->hangye = get_peizhi('sphangye',0,1);
				$this->yetai = get_peizhi('spyetai',0,1);
				$this->display();// 输出模板
			}
		}

		//住宅
		public function fyzhuzhai(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$mmzl = I('mmzl');
				$zhuangxiu = I('zhuangxiu');
				$chaoxiang = I('chaoxiang');
				$yongtu = I('yongtu');
				$myfy = I('myfy');
				$mysc = I('mysc');
				$jrll = I('jrll');
				$tupian = I('tupian');
				$shipin = I('shipin');
				$xinshang = I('xinshang');
				$heyan = I('heyan');
				$jishou = I('jishou');
				$xuequ = I('xuequ');
				$wushui = I('wushui');
				$xinzheng = I('xinzheng');
				$youdaikuan = I('youdaikuan');
				$waiwangtb = I('waiwangtb');
				$yaoshi = I('yaoshi');
				$jiage1 = I('jiage1');
				$jiage2 = I('jiage2');
				$mianji1 = I('mianji1');
				$mianji2 = I('mianji2');
				$lurusj1 = strtotime(I('shijian1'));
				$lurusj2 = strtotime(I('shijian2'));
				$huxing1 = I('huxing1');
				$huxing2 = I('huxing2');
				$louceng1 = I('louceng1');
				$louceng2 = I('louceng2');
				$condition = "gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(863);
				if (!$is_rbacfck) {
					$condition .= " and fpck=2";
				}
				if ($mmzl) {
					$condition .= " and mmzl=".$mmzl;
				}
				$fygpzt = get_options('chengjiao_options','fygongpan_zhuangtai');
				$condition .= " and isdel=2 and zhuangtai=".$fygpzt." and shtype=1";
				if ($myfy) {
					$condition .= " and weihurenid=".session('uid');
				}
				if ($mysc) {
					$sc = M('shoucang')->where(array('user_id'=>session('uid')))->select();
					if ($sc) {
						foreach ($sc as $key => $value) {
							$cs_arr[] = $value['fyid'];
						}
						$in_sc = implode(',', $cs_arr);
					} else {
						$in_sc = 0;
					}
					$condition .= " and id in ($in_sc)";
				}
				if ($jrll) {
					$today = "fyzz".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and id in (".$history.")";
				}
				if ($zhuangxiu) {
					$condition .= " and zhuangxiu=".$zhuangxiu;
				}
				if ($chaoxiang) {
					$condition .= " and chaoxiang=".$chaoxiang;
				}
				if ($yongtu) {
					$condition .= " and yongtu=".$yongtu;
				}
				if ($tupian) {
					$condition .= " and tupian=1";
				}
				if ($shipin) {
					$condition .= " and shipin_url <> ''";
				}
				if ($xinshang) {
					$xshang = time()-(86400*3);
					$condition .= " and lurusj>".$xshang;
				}
				if ($heyan) {
					$condition .= " and heyan=1";
				}
				if ($jishou) {
					$condition .= " and jishou=1";
				}
				if ($xuequ) {
					$condition .= " and xuequ=1";
				}
				if ($wushui) {
					$condition .= " and wushui=1";
				}
				if ($xinzheng) {
					$condition .= " and xinzheng=1";
				}
				if ($youdaikuan) {
					$condition .= " and youdaikuan=1";
				}
				if ($waiwangtb) {
					$condition .= " and waiwangtb=1";
				}
				if ($yaoshi) {
					$condition .= " and (shouyaobm<>'' or shouyaoren<>'')";
				}
				if ($mmzl == 1) {
					if ($jiage1 && $jiage2) {
						$condition .= " and shoujia>=".$jiage1." and shoujia<=".$jiage2;
					} elseif ($jiage1) {
						$condition .= " and shoujia>=".$jiage1;
					} elseif ($jiage2) {
						$condition .= " and shoujia<=".$jiage2;
					}
				} elseif ($mmzl == 2) {
					if ($jiage1 && $jiage2) {
						$condition .= " and zujia>=".$jiage1." and zujia<=".$jiage2;
					} elseif ($jiage1) {
						$condition .= " and zujia>=".$jiage1;
					} elseif ($jiage2) {
						$condition .= " and zujia<=".$jiage2;
					}
				}
				if ($mianji1 && $mianji2) {
					$condition .= " and mianji>=".$mianji1." and mianji<=".$mianji2;
				} elseif ($mianji1) {
					$condition .= " and mianji>=".$mianji1;
				} elseif ($mianji2) {
					$condition .= " and mianji<=".$mianji2;
				}
				if ($lurusj1 && $lurusj2) {
					$lurusj3 = $lurusj2+86399;
					$condition .= " and lurusj>=".$lurusj1." and lurusj<=".$lurusj3;
				} elseif ($lurusj1) {
					$condition .= " and lurusj>=".$lurusj1;
				} elseif ($lurusj2) {
					$lurusj3 = $lurusj2+86399;
					$condition .= " and lurusj<=".$lurusj3;
				}
				if ($huxing1 && $huxing2) {
					$condition .= " and shi>=".$huxing1." and shi<=".$huxing2;
				} elseif ($huxing1) {
					$condition .= " and shi>=".$huxing1;
				} elseif ($huxing2) {
					$condition .= " and shi<=".$huxing2;
				}
				if ($louceng1 && $louceng2) {
					$condition .= " and louceng>=".$louceng1." and louceng<=".$louceng2;
				} elseif ($louceng1) {
					$condition .= " and louceng>=".$louceng1;
				} elseif ($louceng2) {
					$condition .= " and louceng<=".$louceng2;
				}
				if ($sousuo) {
					$condition .= " and (fybiaoti like '%$sousuo%' or yezhu like '%$sousuo%' or weihuren like '%$sousuo%' or yezhudianhua like '%$sousuo%' or yezhudianhua2 like '%$sousuo%' or yezhudianhua3 like '%$sousuo%' or bianhao like '%$sousuo%' or xiaoqum like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$fypx .= "order by ".$field." ".$order;
				} else {
					$fypx .= "order by id DESC";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from (select * from __FANGYUAN__ where {$condition}) a join (select id as e_id from __YONGHU__) e on a.weihurenid=e.e_id");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select * from (select * from __FANGYUAN__ where {$condition}) a join (select id as e_id from __YONGHU__) e on a.weihurenid=e.e_id ".$fypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					$isshikan[$key] = M('shikan')->where(array('fybh'=>$es['bianhao'],'fylx'=>1))->find();
					$dqshu[$key] = M('xianzhi')->where(array('fyid'=>$value['id'],'fylx'=>1))->count();
					$jznd[$key] = M('xiaoqu')->where(array('id'=>$value['xiaoqu']))->getField('jianzaond');
					if ($isshikan[$key]) {
						$data[$key]['isshikan'] = 1;
					}
					if ($value['shoujia'] > 0) {
						$fyjg = floatval($value['shoujia'])."万";
					} else if ($value['zujia']) {
						$fyjg = floatval($value['zujia']).get_peizhi('zujialx',$value['zujialx'],3);
					}
					$fyhx = "";
					if ($value['shi']) {
						$fyhx .= $value['shi']."室";
					}
					if ($value['ting']) {
						$fyhx .= $value['ting']."厅";
					}
					if ($value['wei']) {
						$fyhx .= $value['wei']."卫";
					}
					if ($value['chu']) {
						$fyhx .= $value['chu']."厨";
					}
					if ($value['yangtai']) {
						$fyhx .= $value['yangtai']."阳台";
					}
					$data[$key]['dqshu'] = $dqshu[$key];
					$data[$key]['jznd'] = $jznd[$key]."年";
					$data[$key]['img'] = get_s_img($value['bianhao']);
					$data[$key]['xqm'] = zym($value['xiaoqu'],3);
					$data[$key]['mianji'] = floatval($value['mianji'])."m²";
					$data[$key]['fyjg'] = $fyjg;
					$data[$key]['danjia'] = $value['danjia'] ? floatval($value['danjia'])."元/m²" : "——";
					$data[$key]['fyhx'] = $fyhx ? $fyhx : "——";
					$data[$key]['fylc'] = $value['louceng']."/".$value['zlouceng'];
					$data[$key]['fyyt'] = get_peizhi('yongtu',$value['yongtu'],3);
					$data[$key]['fycx'] = get_peizhi('chaoxiang',$value['chaoxiang'],3);
					$data[$key]['fyzt'] = get_peizhi('zhuangtai',$value['zhuangtai'],3);
					$data[$key]['fyzx'] = get_peizhi('zhuangxiu',$value['zhuangxiu'],3);
					$data[$key]['fydj'] = $value['fydengji'] ? get_peizhi('fydengji',$value['fydengji'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$is_rbacxq = _rbac_btn_show(46,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
					$photo[$key] = M('photo')->where(array('fybh'=>$value['bianhao'],'image'=>array('neq',$data[$key]['img'])))->field('image')->select();
					$data[$key]['photo'] = $photo[$key];
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->chaoxiang = get_peizhi('chaoxiang',0,1);
				$this->zhuangxiu = get_peizhi('zhuangxiu',0,1);
				$this->yongtu = get_peizhi('yongtu',0,1);
				$this->display();// 输出模板
			}
		}

		//写字楼客源
		public function kyxiezilou(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$mmzl = I('mmzl');
				$xzlleixing = I('xzlleixing');
				$jiage = I('jiage');
				$mianji = I('mianji');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$daikan = I('daikan');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				if ($mmzl) {
					$condition .= " and a.mmzl=".$mmzl;
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($xzlleixing) {
					$condition .= " and a.xqleixing=".$xzlleixing;
				}
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kyxzl".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($daikan) {
					$condition .= " and a.daikan=1";
				}
				if ($jiage) {
					$condition .= " and a.xqjiage1<=".$jiage." and a.xqjiage2>=".$jiage;
				}
				if ($mianji) {
					$condition .= " and a.xqmianji1<=".$mianji." and a.xqmianji2>=".$mianji;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.xqquyu like '%$sousuo%' or a.xqxiaoqu like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KYXIEZILOU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KYXIEZILOU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					switch ($value['mmzl']) {
						case '1':
							$jgdw = "万";
							break;
						case '2':
							$jgdw = "元";
							break;
						default:
							$jgdw = "";
							break;
					}
					if ($value['xqmianji1'] && $value['xqmianji2']) {
						$xqmj = $value['xqmianji1']."m²~".$value['xqmianji2']."m²";
					} else if ($value['xqmianji1']) {
						$xqmj = $value['xqmianji1']."m²以上";
					} else if ($value['xqmianji2']) {
						$xqmj = $value['xqmianji2']."m²以下";
					} else {
						$xqmj = "";
					}
					if ($value['xqjiage1'] && $value['xqjiage2']) {
						$xqjg = $value['xqjiage1'].$jgdw."~".$value['xqjiage2'].$jgdw;
					} elseif ($value['xqjiage1']) {
						$xqjg = $value['xqjiage1'].$jgdw."以上";
					} elseif ($value['xqjiage2']) {
						$xqjg = $value['xqjiage2'].$jgdw."以下";
					} else {
						$xqjg = "";
					}
					$data[$key]['xqmj'] = $xqmj ? $xqmj : "——";
					$data[$key]['xqjg'] = $xqjg ? $xqjg : "——";
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->xzlleixing = get_peizhi('xzlleixing',0,1);
				$this->display();
			}
		}

		//商铺客源
		public function kyshangpu(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$mmzl = I('mmzl');
				$spleixing = I('spleixing');
				$spyetai = I('spyetai');
				$sphangye = I('sphangye');
				$jiage = I('jiage');
				$mianji = I('mianji');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$daikan = I('daikan');
				$fenge = I('fenge');
				$zuyue = I('zuyue');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				if ($mmzl) {
					$condition .= " and a.mmzl=".$mmzl;
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($spleixing) {
					$condition .= " and a.spleixing=".$spleixing;
				}
				if ($spyetai) {
					$condition .= " and a.spyetai=".$spyetai;
				}
				if ($sphangye) {
					$condition .= " and a.sphangye=".$sphangye;
				}
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kysp".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($daikan) {
					$condition .= " and a.daikan=1";
				}
				if ($fenge) {
					$condition .= " and a.fenge=1";
				}
				if ($zuyue) {
					$condition .= " and a.zuyue=1";
				}
				if ($jiage) {
					$condition .= " and a.xqjiage1<=".$jiage." and a.xqjiage2>=".$jiage;
				}
				if ($mianji) {
					$condition .= " and a.xqmianji1<=".$mianji." and a.xqmianji2>=".$mianji;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.xqquyu like '%$sousuo%' or a.xqxiaoqu like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KYSHANGPU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KYSHANGPU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					switch ($value['mmzl']) {
						case '1':
							$jgdw = "万";
							break;
						case '2':
							$jgdw = "元";
							break;
						default:
							$jgdw = "";
							break;
					}
					if ($value['xqmianji1'] && $value['xqmianji2']) {
						$xqmj = $value['xqmianji1']."m²~".$value['xqmianji2']."m²";
					} else if ($value['xqmianji1']) {
						$xqmj = $value['xqmianji1']."m²以上";
					} else if ($value['xqmianji2']) {
						$xqmj = $value['xqmianji2']."m²以下";
					} else {
						$xqmj = "";
					}
					if ($value['xqjiage1'] && $value['xqjiage2']) {
						$xqjg = $value['xqjiage1'].$jgdw."~".$value['xqjiage2'].$jgdw;
					} elseif ($value['xqjiage1']) {
						$xqjg = $value['xqjiage1'].$jgdw."以上";
					} elseif ($value['xqjiage2']) {
						$xqjg = $value['xqjiage2'].$jgdw."以下";
					} else {
						$xqjg = "";
					}
					$data[$key]['xqmj'] = $xqmj ? $xqmj : "——";
					$data[$key]['xqjg'] = $xqjg ? $xqjg : "——";
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->spyetai = get_peizhi('spyetai',0,1);
				$this->sphangye = get_peizhi('sphangye',0,1);
				$this->spleixing = get_peizhi('spleixing',0,1);
				$this->display();
			}
		}

		//住宅客源
		public function kyzhuzhai(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$mmzl = I('mmzl');
				$jiage = I('jiage');
				$mianji = I('mianji');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$daikan = I('daikan');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				if ($mmzl) {
					$condition .= " and a.mmzl=".$mmzl;
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kyzz".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($daikan) {
					$condition .= " and a.daikan=1";
				}
				if ($jiage) {
					$condition .= " and a.xqjiage1<=".$jiage." and a.xqjiage2>=".$jiage;
				}
				if ($mianji) {
					$condition .= " and a.xqmianji1<=".$mianji." and a.xqmianji2>=".$mianji;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.xqquyu like '%$sousuo%' or a.xqxiaoqu like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KEYUAN__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KEYUAN__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					switch ($value['mmzl']) {
						case '1':
							$jgdw = "万";
							break;
						case '2':
							$jgdw = "元";
							break;
						default:
							$jgdw = "";
							break;
					}
					if ($value['xqmianji1'] && $value['xqmianji2']) {
						$xqmj = $value['xqmianji1']."m²~".$value['xqmianji2']."m²";
					} else if ($value['xqmianji1']) {
						$xqmj = $value['xqmianji1']."m²以上";
					} else if ($value['xqmianji2']) {
						$xqmj = $value['xqmianji2']."m²以下";
					} else {
						$xqmj = "";
					}
					if ($value['xqjiage1'] && $value['xqjiage2']) {
						$xqjg = $value['xqjiage1'].$jgdw."~".$value['xqjiage2'].$jgdw;
					} else if ($value['xqjiage1']) {
						$xqjg = $value['xqjiage1'].$jgdw."以上";
					} else if ($value['xqjiage2']) {
						$xqjg = $value['xqjiage2'].$jgdw."以下";
					} else {
						$xqjg = "";
					}
					if ($value['xqhuxing1'] && $value['xqhuxing2']) {
						$xqhx = $value['xqhuxing1']."室~".$value['xqhuxing2']."室";
					} else if ($value['xqhuxing1']) {
						$xqhx = $value['xqhuxing1']."室以上";
					} else if ($value['xqhuxing2']) {
						$xqhx = $value['xqhuxing2']."室以下";
					} else {
						$xqhx = "";
					}
					$data[$key]['xqmj'] = $xqmj ? $xqmj : "——";
					$data[$key]['xqjg'] = $xqjg ? $xqjg : "——";
					$data[$key]['xqhx'] = $xqhx ? $xqhx : "——";
					$data[$key]['xqlx'] = get_peizhi('fwleixing',$value['xqleixing'],3);
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}

		//新房客源
		public function kyxinfang(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$xfwylx = I('xfwylx');
				$jiage = I('jiage');
				$mianji = I('mianji');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$daikan = I('daikan');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($xfwylx) {
					$condition .= " and a.xqleixing=".$xfwylx;
				}
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kyxf".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($daikan) {
					$condition .= " and a.daikan=1";
				}
				if ($jiage) {
					$condition .= " and a.xqjiage1<=".$jiage." and a.xqjiage2>=".$jiage;
				}
				if ($mianji) {
					$condition .= " and a.xqmianji1<=".$mianji." and a.xqmianji2>=".$mianji;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.xqquyu like '%$sousuo%' or a.xqxinfang like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KYXINFANG__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KYXINFANG__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					if ($value['xqjiage1'] && $value['xqjiage2']) {
						$xqjg = $value['xqjiage1']."万~".$value['xqjiage2']."万";
					} elseif ($value['xqjiage1']) {
						$xqjg = $value['xqjiage1']."万以上";
					} elseif ($value['xqjiage2']) {
						$xqjg = $value['xqjiage2']."万以下";
					} else {
						$xqjg = "";
					}
					if ($value['xqmianji1'] && $value['xqmianji2']) {
						$xqmj = $value['xqmianji1']."m²~".$value['xqmianji2']."m²";
					} elseif ($value['xqmianji1']) {
						$xqmj = $value['xqmianji1']."m²以上";
					} elseif ($value['xqmianji2']) {
						$xqmj = $value['xqmianji2']."m²以下";
					} else {
						$xqmj = "";
					}
					if ($value['xqhuxing1'] && $value['xqhuxing2']) {
						$xqhx = $value['xqhuxing1']."m²~".$value['xqhuxing2']."m²";
					} elseif ($value['xqhuxing1']) {
						$xqhx = $value['xqhuxing1']."m²以上";
					} elseif ($value['xqhuxing2']) {
						$xqhx = $value['xqhuxing2']."m²以下";
					} else {
						$xqhx = "";
					}
					$data[$key]['xqjg'] = $xqjg ? $xqjg : "——";
					$data[$key]['xqmj'] = $xqmj ? $xqmj : "——";
					$data[$key]['xqhx'] = $xqhx ? $xqhx : "——";
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->xfwylx = get_peizhi('xfwylx',0,1);
				$this->display();
			}
		}

		//金融客源
		public function kyjinrong(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$jiage = I('jiage');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kyjr".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($jiage) {
					$condition .= " and a.xqjiage1<=".$jiage." and a.xqjiage2>=".$jiage;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KYJINRONG__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KYJINRONG__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					$data[$key]['zijinxq'] = $value['zijinxq'] ? $value['zijinxq']."万" : "——";
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['dkfs'] = $value['daikuanfs'] ? get_peizhi('daikuanfs',$value['daikuanfs'],3) : "——";
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['xuyaosj'] = $value['xuyaosj'] ? date('Y-m-d',$value['xuyaosj']) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}

		//装修客源
		public function kyzhuangxiu(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$jiage = I('jiage');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kyzx".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($jiage1 && $jiage2) {
					$condition .= " and yusuan>=".$jiage1." and yusuan<=".$jiage2;
				} elseif ($jiage1) {
					$condition .= " and yusuan>=".$jiage1;
				} elseif ($jiage2) {
					$condition .= " and yusuan<=".$jiage2;
				}
				if ($mianji1 && $mianji2) {
					$condition .= " and mianji>=".$mianji1." and mianji<=".$mianji2;
				} elseif ($mianji1) {
					$condition .= " and mianji>=".$mianji1;
				} elseif ($mianji2) {
					$condition .= " and mianji<=".$mianji2;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KYZHUANGXIU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KYZHUANGXIU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					$data[$key]['yusuan'] = $value['yusuan']."元";
					$data[$key]['mianji'] = $value['mianji']."m²";
					$data[$key]['dizhi'] = zym($value['chengshi'],1)."-".zym($value['quyu'],2)."-".zym($value['xiaoqu'],3);
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}

		//工商客源
		public function kygongshang(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$jiage = I('jiage');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kygs".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($jiage1 && $jiage2) {
					$condition .= " and zczijin>=".$jiage1." and zczijin<=".$jiage2;
				} elseif ($jiage1) {
					$condition .= " and zczijin>=".$jiage1;
				} elseif ($jiage2) {
					$condition .= " and zczijin<=".$jiage2;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KYGONGSHANG__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KYGONGSHANG__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					$data[$key]['zczijin'] = $value['zczijin']."万";
					$data[$key]['gsrenshu'] = $value['gsrenshu']."人";
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}

		//会计客源
		public function kykuaiji(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$jiage = I('jiage');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kykj".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($jiage) {
					$condition .= " and a.xqjiage1<=".$jiage." and a.xqjiage2>=".$jiage;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KYKUAIJI__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KYKUAIJI__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					if ($value['xqjiage1'] && $value['xqjiage2']) {
						$xqjg = $value['xqjiage1']."万~".$value['xqjiage2']."万";
					} elseif ($value['xqjiage1']) {
						$xqjg = $value['xqjiage1']."万以上";
					} elseif ($value['xqjiage2']) {
						$xqjg = $value['xqjiage2']."万以下";
					} else {
						$xqjg = "";
					}
					$data[$key]['xqjg'] = $xqjg ? $xqjg : "——";
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['xqrenshu'] = $value['xqrenshu']."人";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}

		//家具客源
		public function kyjiaju(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$jiage = I('jiage');
				$jrll = I('jrll');
				$jiqie = I('jiqie');
				$myky = I('myky');
				$condition = "a.gongsiid=".session('gongsiid');
				$is_rbacfck = _rbac_node_show(865);
				if (!$is_rbacfck) {
					$condition .= " and a.fpck=2";
				}
				$kygkzt = get_options('chengjiao_options','kygongke_zhuangtai');
				$condition .= " and a.isdel=2 and a.zhuangtai=".$kygkzt." and a.shtype=1";
				if ($myky) {
					$condition .= " and a.weihurenid=".session('uid');
				}
				if ($jrll) {
					$today = "kyjj".date("m-d");
					if (!cookie($today)) {
						$history = 0;
					} else {
						$history = cookie($today);
					}
					$condition .= " and a.id in ($history)";
				}
				if ($jiqie) {
					$condition .= " and a.jiqie=1";
				}
				if ($jiage) {
					$condition .= " and a.xqjiage1<=".$jiage." and a.xqjiage2>=".$jiage;
				}
				if ($sousuo) {
					$condition .= " and (a.xqbianhao like '%$sousuo%' or a.khxingming like '%$sousuo%' or a.dianhua like '%$sousuo%' or a.weihuren like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$kypx = "order by a.".$field." ".$order;
				} else {
					$kypx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __KYJIAJU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.* from __KYJIAJU__ a join __YONGHU__ e on a.weihurenid=e.id where {$condition} ".$kypx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					if ($value['xqjiage1'] && $value['xqjiage2']) {
						$xqjg = $value['xqjiage1']."元~".$value['xqjiage2']."元";
					} elseif ($value['xqjiage1']) {
						$xqjg = $value['xqjiage1']."元以上";
					} elseif ($value['xqjiage2']) {
						$xqjg = $value['xqjiage2']."元以下";
					} else {
						$xqjg = "";
					}
					$data[$key]['xqjg'] = $xqjg ? $xqjg : "——";
					$data[$key]['khly'] = get_peizhi('laiyuan',$value['khlaiyuan'],3);
					$data[$key]['kyzt'] = get_peizhi('khzhuangtai',$value['zhuangtai'],3);
					$data[$key]['khxm'] = $value['khxingming'].get_peizhi('yezhulx',$value['kehulx'],3);
					$data[$key]['gtjd'] = $value['gtjieduan'] ? get_peizhi('gtjieduan',$value['gtjieduan'],3) : "——";
					$data[$key]['lurusj'] = $value['lurusj'] ? date('Y-m-d H:i:s',$value['lurusj']) : "——";
					$data[$key]['whr'] = zym($value['weihurenid'],5);
					$data[$key]['whrdh'] = zym($value['weihurenid'],14);
					$is_rbacxq = _rbac_btn_show(75,$value['zhuangtai'],$value['weihurenid']);
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}

	}