<?php

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

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

		//收藏房源
		public function shoucang(){
			$is_rbac = _rbac_btn_show(388,0);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			$id = I('id');
			$fybh = M('fangyuan')->where(array('id'=>$id))->getField('bianhao');
			$data['user_id'] = session("uid");
			$data['fyid'] = $fybh;
			$data['fyid'] = $id;
			$data['fylx'] = 1;
			$data['addtime'] = time();
			$isok = M('shoucang')->add($data);
			if ($isok) {
				$mmzl = M('fangyuan')->where(array('id'=>$id))->getField('mmzl');
				if ($mmzl == 1) {
					$zyzs = "住宅（出售）";
				} elseif ($mmzl == 2) {
					$zyzs = "住宅（出租）";
				}
				data_rizhi(1,4,$id,$fybh,"收藏房源",U('fangyuan/neirong',array('id'=>$id)),$zyzs);
				$this->success('添加成功');
			} else {
				$this->error('添加失败');
			}
		}

		//取消收藏
		public function noshoucang(){
			$is_rbac = _rbac_btn_show(389,0);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			$id = I('id');
			$fybh = M('fangyuan')->where(array('id'=>$id))->getField('bianhao');
			$isok = M('shoucang')->where(array('fyid'=>$id,'user_id'=>session("uid"),'fylx'=>1))->delete();
			if ($isok) {
				$mmzl = M('fangyuan')->where(array('id'=>$id))->getField('mmzl');
				if ($mmzl == 1) {
					$zyzs = "住宅（出售）";
				} elseif ($mmzl == 2) {
					$zyzs = "住宅（出租）";
				}
				data_rizhi(1,4,$id,$fybh,"取消收藏房源",U('fangyuan/neirong',array('id'=>$id)),$zyzs);
				$this->success('取消成功');
			} else {
				$this->error('取消失败');
			}
		}

		//封盘
		public function fengpan(){
			$fangyuan = M('fangyuan')->where(array('id'=>I('fyid')))->find();
			$is_rbac = _rbac_btn_show(830,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			} else {
				if ($fangyuan['fpdh'] == 2) {
					$this->fdh = 1;
				}
				if ($fangyuan['fpdz'] == 2) {
					$this->fdz = 1;
				}
				if ($fangyuan['fpdj'] == 2) {
					$this->fdj = 1;
				}
				if ($fangyuan['fpdq'] == 2) {
					$this->fdq = 1;
				}
				if ($fangyuan['fpck'] == 2) {
					$this->fck = 1;
				}
				$this->fyid = I('fyid');
				$this->display();
			}
		}

		//开盘
		public function kaipan(){
			$fangyuan = M('fangyuan')->where(array('id'=>I('fyid')))->find();
			$is_rbac = _rbac_btn_show(831,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			} else {
				if ($fangyuan['fpdh'] == 1) {
					$this->kdh = 1;
				}
				if ($fangyuan['fpdz'] == 1) {
					$this->kdz = 1;
				}
				if ($fangyuan['fpdj'] == 1) {
					$this->kdj = 1;
				}
				if ($fangyuan['fpdq'] == 1) {
					$this->kdq = 1;
				}
				if ($fangyuan['fpck'] == 1) {
					$this->kck = 1;
				}
				$this->fyid = I('fyid');
				$this->display();
			}
		}

		//封盘审核列表
		public function fpsh(){
			if (I('is_ajax')) {
				$condition = " where b.gongsiid=".session('gongsiid');
				$x = _rbac_lists_where(844,0);
				if ($x && $x != "all" && $x != "me") {
					$condition .= " and b.bumen in ({$x})";
				} elseif ($x == "me") {
					$condition .= " and b.id=".session('uid');
				} elseif ($x == false) {
					$condition .= " and b.id=0";
				}
				$type = I('type');
				$fylx = I('fylx');
				$fkplx = I('fkplx');
				$condition .= " and a.czlx=1";
				$fylxs = "1,13,14";
				$fylxs1 = explode(",",$fylxs);
				if (in_array($fylx,$fylxs1)) {
					$condition .= " and a.zylx = ".$fylx;
				} else {
					$condition .= " and a.zylx in (".$fylxs.")";
				}
				if ($type) {
					$condition .= " and a.type=".$type;
				}
				if ($fkplx) {
					$condition .= " and a.fkplx=".$fkplx;
				}
				$shijian1 = I('shijian1');
				$shijian2 = I('shijian2');
				if ($shijian1) {
					$shijian3 = strtotime($shijian1);
				}
				if ($shijian2) {
					$shijian4 = strtotime($shijian2)+86400;
				}
				if ($shijian3 and $shijian4) {
					if ($shijian3 > $shijian4) {
						$shijian3 = strtotime($shijian2);
						$shijian4 = strtotime($shijian1)+86400;
					}
					$condition .= " and a.addtime>".$shijian3." and a.addtime<".$shijian4;
				} elseif ($shijian3) {
					$condition .= " and a.addtime>".$shijian3;
				} elseif ($shijian4) {
					$condition .= " and a.addtime<".$shijian4;
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$gjpx = "order by a.".$field." ".$order;
				} else {
					$gjpx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __FPKP__ a join __YONGHU__ b on a.uid = b.id {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.*,b.ygmingcheng as fpren,b.dianhua as fpdh,b.bumen as fpbm from __FPKP__ a join __YONGHU__ b on a.uid = b.id {$condition} ".$fppx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					switch ($value['zylx']) {
						case '1':
							$fyb = M('fangyuan');
							$fylxm = "住宅";
							$fyxqlj = U('fangyuan/neirong',array('id'=>$value['zyid']));
							break;
						case '13':
							$fyb = M('fyxiezilou');
							$fylxm = "写字楼";
							$fyxqlj = U('fyxiezilou/neirong',array('id'=>$value['zyid']));
							break;
						case '14':
							$fyb = M('fyshangpu');
							$fylxm = "商铺";
							$fyxqlj = U('fyshangpu/neirong',array('id'=>$value['zyid']));
							break;
					}
					if ($fyb) {
						$fyxq = $fyb->where(array('id'=>$value['zyid']))->field('mmzl,zhuangtai,weihurenid')->find();
					}
					switch ($fyxq['mmzl']) {
						case '1':
							$mmzl = "（出售）";
							break;
						case '2':
							$mmzl = "（出租）";
							break;
						default:
							$mmzl = "";
							break;
					}
					$fylxm = $fylxm.$mmzl;
					if ($fyxq) {
						$is_rbacxq = _rbac_btn_show(75,$fyxq['zhuangtai'],$fyxq['weihurenid']);
					} else {
						$is_rbacxq = "";
					}
					switch ($value['type']) {
						case '1':
							$type = "已通过";
							break;
						case '2':
							$type = "已驳回";
							break;
						case '3':
							$type = "审核中";
							break;
						default:
							$type = "";
							break;
					}
					switch ($value['fkplx']) {
						case '1':
							$fkplx = "封电话";
							break;
						case '2':
							$fkplx = "封地址";
							break;
						case '3':
							$fkplx = "封底价";
							break;
						case '4':
							$fkplx = "封调取";
							break;
						case '5':
							$fkplx = "封查看";
							break;
						default:
							$fkplx = "";
							break;
					}
					if ($value['type'] == 3) {
						$is_rbacsh = _rbac_btn_show(845,$fyxq['zhuangtai'],$value['uid']);
						$data[$key]['rbacsh'] = $is_rbacsh ? 1 : 0;
					} else {
						$is_rbacrz = _rbac_btn_show(846,0,$value['uid']);
						$data[$key]['rbacrz'] = $is_rbacrz ? 1 : 0;
					}
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
					$data[$key]['fyxqlj'] = $fyxqlj;
					$data[$key]['fylxm'] = $fylxm;
					$data[$key]['fkplx'] = $fkplx;
					$data[$key]['type'] = $type;
					$data[$key]['fprxx'] = $value['fpren']."/".zym($value['fpbm'],6)."（".$value['fpdh']."）";
					$data[$key]['sqren'] = zym($value['adduid'],5)."（".zym($value['adduid'],14)."）";
					$data[$key]['endunix'] = $value['endunix'] ? date('Y-m-d',$value['endunix']) : "";
					$data[$key]['addtime'] = $value['addtime'] ? date('Y-m-d H:i:s',$value['addtime']) : "";
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}

		//封盘审核
		public function fpshenhe(){
			$id = I('id');
			$fpkp = M('fpkp')->where(array('id'=>$id,'czlx'=>1))->field('uid,zyid,zylx,type,fkplx')->find();
			$fyzt = M('fangyuan')->where(array('id'=>$fpkp['zyid']))->getField('zhuangtai');
			$is_rbac = _rbac_btn_show(845,$fyzt,$fpkp['uid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			} else {
				$this->display();
			}
		}

		//封盘日志
		public function fprizhi(){
			$rzlx = I('rzlx');
			if ($rzlx == 1) {
				if (I('is_ajax')) {
					$condition = " where b.gongsiid=".session('gongsiid');
					$x = _rbac_lists_where(846,0);
					if ($x && $x != "all" && $x != "me") {
						$condition .= " and b.bumen in ({$x})";
					} elseif ($x == "me") {
						$condition .= " and b.id=".session('uid');
					} elseif ($x == false) {
						$condition .= " and b.id=0";
					}
					$fylx = I('fylx');
					$type = I('type');
					$fkplx = I('fkplx');
					$condition .= " and czlx=1";
					$fylxs = "1,13,14";
					$fylxs1 = explode(",",$fylxs);
					if (in_array($fylx,$fylxs1)) {
						$condition .= " and a.zylx = ".$fylx;
					} else {
						$condition .= " and a.zylx in (".$fylxs.")";
					}
					if ($type) {
						$condition .= " and type=".$type;
					}
					if ($fkplx) {
						$condition .= " and fkplx=".$fkplx;
					}
					$shijian1 = I('shijian1');
					$shijian2 = I('shijian2');
					if ($shijian1) {
						$shijian3 = strtotime($shijian1);
					}
					if ($shijian2) {
						$shijian4 = strtotime($shijian2)+86400;
					}
					if ($shijian3 and $shijian4) {
						if ($shijian3 > $shijian4) {
							$shijian3 = strtotime($shijian2);
							$shijian4 = strtotime($shijian1)+86400;
						}
						$condition .= " and a.addtime>".$shijian3." and a.addtime<".$shijian4;
					} elseif ($shijian3) {
						$condition .= " and a.addtime>".$shijian3;
					} elseif ($shijian4) {
						$condition .= " and a.addtime<".$shijian4;
					}
					$field = I('field'); //排序字段名
					$order = I('order'); //排序方式
					$limit = I('limit',30,'int'); //每页条数
					$limit = $limit > 150 ? 150 : $limit;
					if ($field && $order) {
						$gjpx = "order by a.".$field." ".$order;
					} else {
						$gjpx = "order by a.id desc";
					}
					$Model = new \Think\Model();
					$count = $Model->query("select count(*) from __FPKP__ a join __YONGHU__ b on a.uid = b.id {$condition}");
					$Page = new \Think\Page($count['0']['count(*)'],$limit);
					$list = "select a.*,b.ygmingcheng as fpren,b.dianhua as fpdh,b.bumen as fpbm from __FPKP__ a join __YONGHU__ b on a.uid = b.id {$condition} ".$fppx." limit ".$Page->firstRow.','.$Page->listRows;
					$data = $Model->query($list);
					foreach ($data as $key => $value) {
						switch ($value['zylx']) {
							case '1':
								$fyb = M('fangyuan');
								$fylxm = "住宅";
								$fyxqlj = U('fangyuan/neirong',array('id'=>$value['zyid']));
								break;
							case '13':
								$fyb = M('fyxiezilou');
								$fylxm = "写字楼";
								$fyxqlj = U('fyxiezilou/neirong',array('id'=>$value['zyid']));
								break;
							case '14':
								$fyb = M('fyshangpu');
								$fylxm = "商铺";
								$fyxqlj = U('fyshangpu/neirong',array('id'=>$value['zyid']));
								break;
						}
						if ($fyb) {
							$fyxq = $fyb->where(array('id'=>$value['zyid']))->field('mmzl,zhuangtai,weihurenid')->find();
						}
						switch ($fyxq['mmzl']) {
							case '1':
								$mmzl = "（出售）";
								break;
							case '2':
								$mmzl = "（出租）";
								break;
							default:
								$mmzl = "";
								break;
						}
						$fylxm = $fylxm.$mmzl;
						if ($fyxq) {
							$is_rbacxq = _rbac_btn_show(46,$fyxq['zhuangtai'],$fyxq['weihurenid']);
						} else {
							$is_rbacxq = "";
						}
						switch ($value['type']) {
							case '1':
								$type = "已通过";
								break;
							case '2':
								$type = "已驳回";
								break;
							case '3':
								$type = "审核中";
								break;
							default:
								$type = "";
								break;
						}
						switch ($value['fkplx']) {
							case '1':
								$fkplx = "封电话";
								break;
							case '2':
								$fkplx = "封地址";
								break;
							case '3':
								$fkplx = "封底价";
								break;
							case '4':
								$fkplx = "封调取";
								break;
							case '5':
								$fkplx = "封查看";
								break;
							default:
								$fkplx = "";
								break;
						}
						$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
						$data[$key]['fyxqlj'] = $fyxqlj;
						$data[$key]['fylxm'] = $fylxm;
						$data[$key]['fkplx'] = $fkplx;
						$data[$key]['type'] = $type;
						$data[$key]['fprxx'] = $value['fpren']."/".zym($value['fpbm'],6)."（".$value['fpdh']."）";
						$data[$key]['sqren'] = zym($value['adduid'],5)."（".zym($value['adduid'],14)."）";
						$data[$key]['shren'] = $value['shuid'] ? zym($value['shuid'],5)."（".zym($value['shuid'],14)."）" : "——";
						$data[$key]['endunix'] = $value['endunix'] ? date('Y-m-d',$value['endunix']) : "";
						$data[$key]['addtime'] = $value['addtime'] ? date('Y-m-d H:i:s',$value['addtime']) : "";
						$data[$key]['shshijian'] = $value['shshijian'] ? date('Y-m-d H:i:s',$value['shshijian']) : "——";
						$data[$key]['remark'] = $value['remark'] ? $value['remark'] : "——";
					}
					$return_data = array(
						'code'=>0,
						'count'=>$count['0']['count(*)'],
						'data'=>$data
					);
					$this->ajaxReturn($return_data);
				} else {
					$this->display();
				}
			} elseif ($rzlx == 2) {
				$fyfp=M('fpkp')->where(array('id'=>I('id'),'czlx'=>1))->field('shuid,shshijian,remark,type')->find();
				$this->fyfp=$fyfp;
			}
			$this->rzlx=$rzlx;
			$this->display();
		}

		//开盘审核列表
		public function kpsh(){
			if (I('is_ajax')) {
				$condition = " where b.gongsiid=".session('gongsiid');
				$x = _rbac_lists_where(847,0);
				if ($x && $x != "all" && $x != "me") {
					$condition .= " and b.bumen in ({$x})";
				} elseif ($x == "me") {
					$condition .= " and b.id=".session('uid');
				} elseif ($x == false) {
					$condition .= " and b.id=0";
				}
				$type = I('type');
				$fylx = I('fylx');
				$fkplx = I('fkplx');
				$condition .= " and a.czlx=2";
				$fylxs = "1,13,14";
				$fylxs1 = explode(",",$fylxs);
				if (in_array($fylx,$fylxs1)) {
					$condition .= " and a.zylx = ".$fylx;
				} else {
					$condition .= " and a.zylx in (".$fylxs.")";
				}
				if ($type) {
					$condition .= " and a.type=".$type;
				}
				if ($fkplx) {
					$condition .= " and a.fkplx=".$fkplx;
				}
				$shijian1 = I('shijian1');
				$shijian2 = I('shijian2');
				if ($shijian1) {
					$shijian3 = strtotime($shijian1);
				}
				if ($shijian2) {
					$shijian4 = strtotime($shijian2)+86400;
				}
				if ($shijian3 and $shijian4) {
					if ($shijian3 > $shijian4) {
						$shijian3 = strtotime($shijian2);
						$shijian4 = strtotime($shijian1)+86400;
					}
					$condition .= " and a.addtime>".$shijian3." and a.addtime<".$shijian4;
				} elseif ($shijian3) {
					$condition .= " and a.addtime>".$shijian3;
				} elseif ($shijian4) {
					$condition .= " and a.addtime<".$shijian4;
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$gjpx = "order by a.".$field." ".$order;
				} else {
					$gjpx = "order by a.id desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __FPKP__ a join __YONGHU__ b on a.uid = b.id {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.*,b.ygmingcheng as kpren,b.dianhua as kpdh,b.bumen as kpbm from __FPKP__ a join __YONGHU__ b on a.uid = b.id {$condition} ".$fppx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					switch ($value['zylx']) {
						case '1':
							$fyb = M('fangyuan');
							$fylxm = "住宅";
							$fyxqlj = U('fangyuan/neirong',array('id'=>$value['zyid']));
							break;
						case '13':
							$fyb = M('fyxiezilou');
							$fylxm = "写字楼";
							$fyxqlj = U('fyxiezilou/neirong',array('id'=>$value['zyid']));
							break;
						case '14':
							$fyb = M('fyshangpu');
							$fylxm = "商铺";
							$fyxqlj = U('fyshangpu/neirong',array('id'=>$value['zyid']));
							break;
					}
					if ($fyb) {
						$fyxq = $fyb->where(array('id'=>$value['zyid']))->field('mmzl,zhuangtai,weihurenid')->find();
					}
					switch ($fyxq['mmzl']) {
						case '1':
							$mmzl = "（出售）";
							break;
						case '2':
							$mmzl = "（出租）";
							break;
						default:
							$mmzl = "";
							break;
					}
					$fylxm = $fylxm.$mmzl;
					if ($fyxq) {
						$is_rbacxq = _rbac_btn_show(75,$fyxq['zhuangtai'],$fyxq['weihurenid']);
					} else {
						$is_rbacxq = "";
					}
					switch ($value['type']) {
						case '1':
							$type = "已通过";
							break;
						case '2':
							$type = "已驳回";
							break;
						case '3':
							$type = "审核中";
							break;
						default:
							$type = "";
							break;
					}
					switch ($value['fkplx']) {
						case '1':
							$fkplx = "开电话";
							break;
						case '2':
							$fkplx = "开地址";
							break;
						case '3':
							$fkplx = "开底价";
							break;
						case '4':
							$fkplx = "开调取";
							break;
						case '5':
							$fkplx = "开查看";
							break;
						default:
							$fkplx = "";
							break;
					}
					if ($value['type'] == 3) {
						$is_rbacsh = _rbac_btn_show(848,$fyxq['zhuangtai'],$value['uid']);
						$data[$key]['rbacsh'] = $is_rbacsh ? 1 : 0;
					} else {
						$is_rbacrz = _rbac_btn_show(849,0,$value['uid']);
						$data[$key]['rbacrz'] = $is_rbacrz ? 1 : 0;
					}
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
					$data[$key]['fyxqlj'] = $fyxqlj;
					$data[$key]['fylxm'] = $fylxm;
					$data[$key]['fkplx'] = $fkplx;
					$data[$key]['type'] = $type;
					$data[$key]['kprxx'] = $value['kpren']."/".zym($value['kpbm'],6)."（".$value['kpdh']."）";
					$data[$key]['sqren'] = zym($value['adduid'],5)."（".zym($value['adduid'],14)."）";
					$data[$key]['addtime'] = $value['addtime'] ? date('Y-m-d H:i:s',$value['addtime']) : "";
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count['0']['count(*)'],
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->display();
			}
		}

		//开盘审核
		public function kpshenhe(){
			$id = I('id');
			$fpkp = M('fpkp')->where(array('id'=>$id,'czlx'=>2))->field('uid,zyid,zylx,type,fkplx')->find();
			$fyzt = M('fangyuan')->where(array('id'=>$fpkp['zyid']))->getField('zhuangtai');
			$is_rbac = _rbac_btn_show(848,$fyzt,$fpkp['uid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			} else {
				$this->display();
			}
		}

		//开盘日志
		public function kprizhi(){
			$rzlx = I('rzlx');
			if ($rzlx == 1) {
				if (I('is_ajax')) {
					$condition = " where b.gongsiid=".session('gongsiid');
					$x = _rbac_lists_where(849,0);
					if ($x && $x != "all" && $x != "me") {
						$condition .= " and b.bumen in ({$x})";
					} elseif ($x == "me") {
						$condition .= " and b.id=".session('uid');
					} elseif ($x == false) {
						$condition .= " and b.id=0";
					}
					$fylx = I('fylx');
					$type = I('type');
					$fkplx = I('fkplx');
					$condition .= " and czlx=2";
					$fylxs = "1,13,14";
					$fylxs1 = explode(",",$fylxs);
					if (in_array($fylx,$fylxs1)) {
						$condition .= " and a.zylx = ".$fylx;
					} else {
						$condition .= " and a.zylx in (".$fylxs.")";
					}
					if ($type) {
						$condition .= " and type=".$type;
					}
					if ($fkplx) {
						$condition .= " and fkplx=".$fkplx;
					}
					$shijian1 = I('shijian1');
					$shijian2 = I('shijian2');
					if ($shijian1) {
						$shijian3 = strtotime($shijian1);
					}
					if ($shijian2) {
						$shijian4 = strtotime($shijian2)+86400;
					}
					if ($shijian3 and $shijian4) {
						if ($shijian3 > $shijian4) {
							$shijian3 = strtotime($shijian2);
							$shijian4 = strtotime($shijian1)+86400;
						}
						$condition .= " and a.addtime>".$shijian3." and a.addtime<".$shijian4;
					} elseif ($shijian3) {
						$condition .= " and a.addtime>".$shijian3;
					} elseif ($shijian4) {
						$condition .= " and a.addtime<".$shijian4;
					}
					$field = I('field'); //排序字段名
					$order = I('order'); //排序方式
					$limit = I('limit',30,'int'); //每页条数
					$limit = $limit > 150 ? 150 : $limit;
					if ($field && $order) {
						$gjpx = "order by a.".$field." ".$order;
					} else {
						$gjpx = "order by a.id desc";
					}
					$Model = new \Think\Model();
					$count = $Model->query("select count(*) from __FPKP__ a join __YONGHU__ b on a.uid = b.id {$condition}");
					$Page = new \Think\Page($count['0']['count(*)'],$limit);
					$list = "select a.*,b.ygmingcheng as kpren,b.dianhua as kpdh,b.bumen as kpbm from __FPKP__ a join __YONGHU__ b on a.uid = b.id {$condition} ".$fppx." limit ".$Page->firstRow.','.$Page->listRows;
					$data = $Model->query($list);
					foreach ($data as $key => $value) {
						switch ($value['zylx']) {
							case '1':
								$fyb = M('fangyuan');
								$fylxm = "住宅";
								$fyxqlj = U('fangyuan/neirong',array('id'=>$value['zyid']));
								break;
							case '13':
								$fyb = M('fyxiezilou');
								$fylxm = "写字楼";
								$fyxqlj = U('fyxiezilou/neirong',array('id'=>$value['zyid']));
								break;
							case '14':
								$fyb = M('fyshangpu');
								$fylxm = "商铺";
								$fyxqlj = U('fyshangpu/neirong',array('id'=>$value['zyid']));
								break;
						}
						if ($fyb) {
							$fyxq = $fyb->where(array('id'=>$value['zyid']))->field('mmzl,zhuangtai,weihurenid')->find();
						}
						switch ($fyxq['mmzl']) {
							case '1':
								$mmzl = "（出售）";
								break;
							case '2':
								$mmzl = "（出租）";
								break;
							default:
								$mmzl = "";
								break;
						}
						$fylxm = $fylxm.$mmzl;
						if ($fyxq) {
							$is_rbacxq = _rbac_btn_show(75,$fyxq['zhuangtai'],$fyxq['weihurenid']);
						} else {
							$is_rbacxq = "";
						}
						switch ($value['type']) {
							case '1':
								$type = "已通过";
								break;
							case '2':
								$type = "已驳回";
								break;
							case '3':
								$type = "审核中";
								break;
							default:
								$type = "";
								break;
						}
						switch ($value['fkplx']) {
							case '1':
								$fkplx = "开电话";
								break;
							case '2':
								$fkplx = "开地址";
								break;
							case '3':
								$fkplx = "开底价";
								break;
							case '4':
								$fkplx = "开调取";
								break;
							case '5':
								$fkplx = "开查看";
								break;
							default:
								$fkplx = "";
								break;
						}
						$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
						$data[$key]['fyxqlj'] = $fyxqlj;
						$data[$key]['fylxm'] = $fylxm;
						$data[$key]['fkplx'] = $fkplx;
						$data[$key]['type'] = $type;
						$data[$key]['kprxx'] = $value['kpren']."/".zym($value['kpbm'],6)."（".$value['kpdh']."）";
						$data[$key]['sqren'] = zym($value['adduid'],5)."（".zym($value['adduid'],14)."）";
						$data[$key]['shren'] = $value['shuid'] ? zym($value['shuid'],5)."（".zym($value['shuid'],14)."）" : "——";
						$data[$key]['addtime'] = $value['addtime'] ? date('Y-m-d H:i:s',$value['addtime']) : "";
						$data[$key]['shshijian'] = $value['shshijian'] ? date('Y-m-d H:i:s',$value['shshijian']) : "——";
						$data[$key]['remark'] = $value['remark'] ? $value['remark'] : "——";
					}
					$return_data = array(
						'code'=>0,
						'count'=>$count['0']['count(*)'],
						'data'=>$data
					);
					$this->ajaxReturn($return_data);
				} else {
					$this->display();
				}
			} elseif ($rzlx == 2) {
				$fykp=M('fpkp')->where(array('id'=>I('id'),'czlx'=>2))->field('shuid,shshijian,remark,type')->find();
				$this->fykp=$fykp;
			}
			$this->rzlx=$rzlx;
			$this->display();
		}

		//更新房源
		public function xiugai(){
			$id=I('id');
			$fy1=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(56,$fy1['zhuangtai'],$fy1['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fy1['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fy1['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			$is_rbacfdj = _rbac_node_show(861);
			if ($is_rbacfdj || ($fy1['fpdj'] == 2)) {
				$is_rbacfdj=1;
				$this->is_rbacfdj=1;
			}
			if (IS_POST) {
				$data['yongtu']=I('yongtu');//用途
				if ($is_rbacfdj == 1) {
					if(I('chushoudj')){
						if(!preg_match("/^([1-9][0-9]{0,4})(\.[0-9]{1,6})?$|^([0]\.[1-9][0-9]{0,5})$|^([0]\.[0][0-9]{0,4}[1-9]{1})$|^([0]\.[0]{2}[0-9]{0,3}[1-9]{1})$|^([0]\.[0]{3}[0-9]{0,2}[1-9]{1})$|^([0]\.[0]{4}[0-9]{0,1}[1-9]{1})$|^([0]\.[0]{5}[1-9]{1})$|^(1[0]{5})(\.[0][0]{0,5})?$/",I('chushoudj'))){
							$this->error('出售底价请输入＞0且≤十亿的数字（限六位小数）！');
						}
						$data['chushoudj']=I('chushoudj');
					}
					if(I('chuzudj')){
						if(!preg_match("/^([1-9][0-9]{0,4})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{5})(\.[0][0]{0,1})?$/",I('chuzudj'))){
							$this->error('出租底价请输入＞0且≤十万的数字（限两位小数）！');
						}
						$data['chuzudj']=I('chuzudj');
					}
				}
				if(I('shoujia')){
					if(!preg_match("/^([1-9][0-9]{0,4})(\.[0-9]{1,6})?$|^([0]\.[1-9][0-9]{0,5})$|^([0]\.[0][0-9]{0,4}[1-9]{1})$|^([0]\.[0]{2}[0-9]{0,3}[1-9]{1})$|^([0]\.[0]{3}[0-9]{0,2}[1-9]{1})$|^([0]\.[0]{4}[0-9]{0,1}[1-9]{1})$|^([0]\.[0]{5}[1-9]{1})$|^(1[0]{5})(\.[0][0]{0,5})?$/",I('shoujia'))){
						$this->error('售价请输入＞0且≤十亿的数字（限六位小数）！');
					}
					$data['shoujia']=I('shoujia');
				}
				if (I('zujia')) {
					if(!preg_match("/^([1-9][0-9]{0,4})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{5})(\.[0][0]{0,1})?$/",I('zujia'))){
						$this->error('租价请输入＞0且≤十万的数字（限两位小数）！');
					}
					$data['zujia']=I('zujia');
					$data['zujialx']=I('zujialx');
				}
				if(I('mianji')){
					if(!preg_match("/^([1-9][0-9]{0,3})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{4})(\.[0][0]{0,1})?$/",I('mianji'))){
						$this->error('建筑面积请输入＞0且≤一万的数字（限两位小数）！');
					}
					$data['mianji']=I('mianji');
				}
				if(I('symianji')){
					if(!preg_match("/^([1-9][0-9]{0,3})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{4})(\.[0][0]{0,1})?$/",I('symianji'))){
						$this->error('使用面积请输入＞0且≤一万的数字（限两位小数）！');
					}
					$data['symianji']=I('symianji');
				}
				$louceng=I('louceng');
				$zlouceng=I('zlouceng');
				$shi=I('shi');
				$ting=I('ting');
				$wei=I('wei');
				$chu=I('chu');
				$yangtai=I('yangtai');
				$ti=I('ti');
				$hu=I('hu');
				$cqnianxian=I('cqnianxian');
				if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$louceng)){
					$this->error('楼层首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
				}
				if(!preg_match("/^([1-9]{1})$|^([1-9][0-9]{1})$|^(1[0-9]{2})$|^(2[0]{2})$/",$zlouceng)){
					$this->error('总楼层请输入＞0≤200的整数！');
				}
				if(!preg_match("/^([1-9]{1})$|^(1[0]{1})$/",$shi) || !preg_match("/^([1-9]{1})$|^(1[0]{1})$/",$ting) || !preg_match("/^$|^([1-9]{1})$|^(1[0]{1})$/",$wei) || !preg_match("/^$|^([1-9]{1})$|^(1[0]{1})$/",$chu) || !preg_match("/^$|^([1-9]{1})$|^(1[0]{1})$/",$yangtai)){
					$this->error('户型请输入＞0≤10的整数！');
				}
				if(!preg_match("/^$|^([1-9][0-9]{0,1})$|^(1[0]{2})$/",$ti) || !preg_match("/^$|^([1-9][0-9]{0,1})$|^(1[0]{2})$/",$hu)){
					$this->error('梯户请输入＞0≤100的整数！');
				}
				if(!preg_match("/^$|^([1-9][0-9]{0,2})$|^(1[0]{3})$/",$cqnianxian)){
					$this->error('产权年限请输入＞0≤1000的整数！');
				}
				$beizhu=preg_replace ( "/\s(?=\s)/","\\1", I('beizhu') );
				if(!preg_match("/^$|^[\s\S]{0,300}$/",$beizhu)){
					$this->error('备注只能输入300个字符！');
				}
				if(I('mianji')!="" and I('shoujia')!=""){
					$num1=I('shoujia')*10000;
					$num2=I('mianji');
					$num=$num1/$num2;
					$danjia=number_format($num,2,".", "");
					$data['danjia']=$danjia;
				}
				if (I('chaoxiang')) {
					$data['chaoxiang']=I('chaoxiang');
				}
				$data['zhuangxiu']=I('zhuangxiu');
				$pt1=array_keys(I('peitao')); 
				$pt2=implode(',',$pt1);
				$data['peitao']=$pt2;
				if (I('xianzhuang')) {
					$data['xianzhuang']=I('xianzhuang');
				}
				if (I('leixing')) {
					$data['leixing']=I('leixing');
				}
				if (I('jiegou')) {
					$data['jiegou']=I('jiegou');
				}
				$data['cqxingzhi']=I('cqxingzhi');
				$data['cqnianxian']=$cqnianxian;
				if (I('kanfangfs')) {
					$data['kanfangfs']=I('kanfangfs');
				}
				if (I('laiyuan')) {
					$data['laiyuan']=I('laiyuan');
				}
				$data['fydengji']=I('fydengji');
				$data['fybiaoti']=I('fybiaoti');
				$data['shi']=$shi;
				$data['ting']=$ting;
				$data['wei']=$wei;
				$data['chu']=$chu;
				$data['yangtai']=$yangtai;
				$data['louceng']=$louceng;
				$data['zlouceng']=$zlouceng;
				$data['ti']=$ti;
				$data['hu']=$hu;
				$data['niandai']=I('niandai');
				$data['beizhu']=$beizhu;
				$data['czriqi']=strtotime(I('czriqi'));
				$data['chanquanzheng']=I('chanquanzheng');
				$data['tudizheng']=I('tudizheng');
				$data['budongchanzheng']=I('budongchanzheng');
				if (I('fukuanfs')) {
					$data['fukuanfs']=I('fukuanfs');
				}
				$is_rbactb = _rbac_node_show(1052);
				if ($is_rbactb) {
					if (I('waiwangtb')) {
						$waiwangtb = 1;
					} else {
						$waiwangtb = 0;
					}
				}
				if(I('wushui')){
					$wushui=1;
					$geshui=0;
					$zengshui=0;
				} else {
					$wushui=0;
					if(I('geshui')){
						$geshui=1;
					} else {
						$geshui=0;
					}
					if(I('zengshui')){
						$zengshui=1;
					} else {
						$zengshui=0;
					}
				}
				if(I('man5')){
					$man5=1;
				} else {
					$man5=0;
				}
				if(I('man2')){
					$man2=1;
				} else {
					$man2=0;
				}
				if(I('weiyi')){
					$weiyi=1;
				} else {
					$weiyi=0;
				}
				if(I('heyan')){
					$heyan=1;
				} else {
					$heyan=0;
				}
				if(I('jishou')){
					$jishou=1;
				} else {
					$jishou=0;
				}
				if(I('quankuan')){
					$quankuan=1;
				} else {
					$quankuan=0;
				}
				if(I('youdaikuan')){
					$youdaikuan=1;
				} else {
					$youdaikuan=0;
				}
				if(I('xinzheng')){
					$xinzheng=1;
				} else {
					$xinzheng=0;
				}
				$data['waiwangtb']=$waiwangtb;
				$data['wushui']=$wushui;
				$data['geshui']=$geshui;
				$data['zengshui']=$zengshui;
				$data['heyan']=$heyan;
				$data['jishou']=$jishou;
				$data['quankuan']=$quankuan;
				$data['weiyi']=$weiyi;
				$data['man5']=$man5;
				$data['man2']=$man2;
				$data['youdaikuan']=$youdaikuan;
				$data['xinzheng']=$xinzheng;
				$data['xiugaisj']=time();
				$xiugai = "";
				if (I('yongtu') != $fy1['yongtu'] && ($fy1['yongtu'] || I('yongtu'))) {
					$xiugai.=get_xiugai($fy1['yongtu'],I('yongtu'),'yongtu');
				}
				if ($fy1['mianji'] != I('mianji') && ($fy1['mianji'] || I('mianji'))) {
					$xiugai.="面积：[".$fy1['mianji']."]=>[".I('mianji')."]；";
				}
				if ($fy1['shoujia'] != I('shoujia') && ($fy1['shoujia'] || I('shoujia'))) {
					$xiugai.="售价：[".$fy1['shoujia']."]=>[".I('shoujia')."]；";
				}
				if ($fy1['zujia'] != I('zujia') && ($fy1['zujia'] || I('zujia'))) {
					$xiugai.="租价：[".$fy1['zujia']."]=>[".I('zujia')."]；";
				}
				if ($fy1['zujialx'] != I('zujialx') && ($fy1['zujialx'] || I('zujialx'))) {
					$xiugai.=get_xiugai($fy1['zujialx'],I('zujialx'),'zujialx');
				}
				if ($fy1['chaoxiang'] != I('chaoxiang') && ($fy1['chaoxiang'] || I('chaoxiang'))) {
					$xiugai.=get_xiugai($fy1['chaoxiang'],I('chaoxiang'),'chaoxiang');
				}
				if ($fy1['zhuangxiu'] != I('zhuangxiu') && ($fy1['zhuangxiu'] || I('zhuangxiu'))) {
					$xiugai.=get_xiugai($fy1['zhuangxiu'],I('zhuangxiu'),'zhuangxiu');
				}
				$Model = new \Think\Model();
				if ($fy1['peitao'] != $pt2) {
					if ($fy1['peitao']) {
						$condition1="pzming = 'peitao' and lxid in (".$fy1['peitao'].")";
						$peitao1=$Model->query("select * from __PEIZHI__ where {$condition1} order by xsshunxu asc");
						$goods1 = array();
						foreach ($peitao1 AS $key => $val) {
							$goods1[$key]['lxming'] = $val['lxming'];
							$box1.= ",".$val['lxming'];
						}
					}
					if ($pt2) {
						$condition2="pzming = 'peitao' and lxid in (".$pt2.")";
						$peitao2=$Model->query("select * from __PEIZHI__ where {$condition2} order by xsshunxu asc");
						$goods2 = array();
						foreach ($peitao2 AS $key => $val) {
							$goods2[$key]['lxming'] = $val['lxming'];
							$box2.= $val['lxming'].",";
						}
					}
					$xiugai.="配套：[".$box1."]=>[".$box2."]；";
				}
				if ($fy1['xianzhuang'] != I('xianzhuang') && ($fy1['xianzhuang'] || I('xianzhuang'))) {
					$xiugai.=get_xiugai($fy1['xianzhuang'],I('xianzhuang'),'xianzhuang');
				}
				if ($fy1['leixing'] != I('leixing') && ($fy1['leixing'] || I('leixing'))) {
					$xiugai.=get_xiugai($fy1['leixing'],I('leixing'),'fwleixing');
				}
				if ($fy1['jiegou'] != I('jiegou') && ($fy1['jiegou'] || I('jiegou'))) {
					$xiugai.=get_xiugai($fy1['jiegou'],I('jiegou'),'jiegou');
				}
				if ($fy1['xianzhuang'] != I('xianzhuang') && ($fy1['xianzhuang'] || I('xianzhuang'))) {
					$xiugai.=get_xiugai($fy1['xianzhuang'],I('xianzhuang'),'xianzhuang');
				}
				if ($fy1['cqnianxian'] != I('cqnianxian') && ($fy1['cqnianxian'] || I('cqnianxian'))) {
					$xiugai.="产权年限：[".$fy1['cqnianxian']."]=>[".I('cqnianxian')."]；";
				}
				if ($fy1['cqxingzhi'] != I('cqxingzhi') && ($fy1['cqxingzhi'] || I('cqxingzhi'))) {
					$xiugai.=get_xiugai($fy1['cqxingzhi'],I('cqxingzhi'),'chanquan');
				}
				if ($fy1['kanfangfs'] != I('kanfangfs') && ($fy1['kanfangfs'] || I('kanfangfs'))) {
					$xiugai.=get_xiugai($fy1['kanfangfs'],I('kanfangfs'),'kanfangfs');
				}
				if ($fy1['laiyuan'] != I('laiyuan') && ($fy1['laiyuan'] || I('laiyuan'))) {
					$xiugai.=get_xiugai($fy1['laiyuan'],I('laiyuan'),'laiyuan');
				}
				if ($fy1['fukuanfs'] != I('fukuanfs') && ($fy1['fukuanfs'] || I('fukuanfs'))) {
					if ($data['mmzl']==1) {
						$fuk="fukuan";
					} elseif ($data['mmzl']==2) {
						$fuk="zlfukuan";
					}
					$xiugai.=get_xiugai($fy1['fukuanfs'],I('fukuanfs'),$fuk);
				}
				if ($fy1['fybiaoti'] != I('fybiaoti') && ($fy1['fybiaoti'] || I('fybiaoti'))) {
					$xiugai.="房源标题：[".$fy1['fybiaoti']."]=>[".I('fybiaoti')."]；";
				}
				if ($fy1['shi'] != I('shi') && ($fy1['shi'] || I('shi'))) {
					$xiugai.="室：[".$fy1['shi']."]=>[".I('shi')."]；";
				}
				if ($fy1['ting'] != I('ting') && ($fy1['ting'] || I('ting'))) {
					$xiugai.="厅：[".$fy1['ting']."]=>[".I('ting')."]；";
				}
				if ($fy1['wei'] != I('wei') && ($fy1['wei'] || I('wei'))) {
					$xiugai.="卫：[".$fy1['wei']."]=>[".I('wei')."]；";
				}
				if ($fy1['chu'] != I('chu') && ($fy1['chu'] || I('chu'))) {
					$xiugai.="厨：[".$fy1['chu']."]=>[".I('chu')."]；";
				}
				if ($fy1['yangtai'] != I('yangtai') && ($fy1['yangtai'] || I('yangtai'))) {
					$xiugai.="阳台：[".$fy1['yangtai']."]=>[".I('yangtai')."]；";
				}
				if ($fy1['symianji'] != I('symianji') && ($fy1['symianji'] || I('symianji'))) {
					$xiugai.="使用面积：[".$fy1['symianji']."]=>[".I('symianji')."]；";
				}
				if ($fy1['louceng'] != I('louceng') && ($fy1['louceng'] || I('louceng'))) {
					$xiugai.="楼层：[".$fy1['louceng']."]=>[".I('louceng')."]；";
				}
				if ($fy1['zlouceng'] != I('zlouceng') && ($fy1['zlouceng'] || I('zlouceng'))) {
					$xiugai.="总楼层：[".$fy1['zlouceng']."]=>[".I('zlouceng')."]；";
				}
				if ($fy1['ti'] != I('ti') && ($fy1['ti'] || I('ti'))) {
					$xiugai.="梯：[".$fy1['ti']."]=>[".I('ti')."]；";
				}
				if ($fy1['hu'] != I('hu') && ($fy1['hu'] || I('hu'))) {
					$xiugai.="户：[".$fy1['hu']."]=>[".I('hu')."]；";
				}
				if ($fy1['niandai'] != I('niandai') && ($fy1['niandai'] || I('niandai'))) {
					$xiugai.="年代：[".$fy1['niandai']."]=>[".I('niandai')."]；";
				}
				if ($is_rbacfdj == 1) {
					if ($fy1['chushoudj'] != I('chushoudj') && ($fy1['chushoudj'] || I('chushoudj'))) {
						$xiugai.="出售底价：[".$fy1['chushoudj']."]=>[".I('chushoudj')."]；";
					}
					if ($fy1['chuzudj'] != I('chuzudj') && ($fy1['chuzudj'] || I('chuzudj'))) {
						$xiugai.="出租底价：[".$fy1['chuzudj']."]=>[".I('chuzudj')."]；";
					}
				}
				if ($fy1['beizhu'] != trim(I('beizhu')) && ($fy1['beizhu'] || trim(I('beizhu')))) {
					$xiugai.="备注：[".$fy1['beizhu']."]=>[".trim(I('beizhu'))."]；";
				}
				if ($fy1['czriqi'] != strtotime(I('czriqi')) && ($fy1['czriqi'] || I('czriqi'))) {
					$xiugai.="产证日期：[".date('Y-m-d',$fy1['czriqi'])."]=>[".I('czriqi')."]；";
				}
				if ($fy1['waiwangtb'] != $waiwangtb && ($fy1['waiwangtb'] || $waiwangtb)) {
					$wai=$fy1['waiwangtb']?"是":"否";
					$wai1=$waiwangtb?"是":"否";
					$xiugai.="外网同步：[".$wai."]=>[".$wai1."]；";
				}
				if (($fy1['wushui'] != $wushui && ($fy1['wushui'] || $wushui)) || ($fy1['geshui'] != $geshui && ($fy1['geshui'] || $geshui)) || ($fy1['zengshui'] != $zengshui && ($fy1['zengshui'] || $zengshui))) {
					$wai=$fy1['wushui']?"无税":"";
					$wai1=$wushui?"无税":"";
					$wai2=$fy1['geshui']?"个税;":"";
					$wai3=$geshui?"个税;":"";
					$wai4=$fy1['zengshui']?"增值税;":"";
					$wai5=$zengshui?"增值税;":"";
					$xiugai.="税收：[".$wai.$wai2.$wai4."]=>[".$wai1.$wai3.$wai5."]；";
				}
				if ($fy1['heyan'] != $heyan && ($fy1['heyan'] || $heyan)) {
					$jis=$fy1['heyan']?"是":"否";
					$jis1=$heyan?"是":"否";
					$xiugai.="核验：[".$jis."]=>[".$jis1."]；";
				}
				if ($fy1['jishou'] != $jishou && ($fy1['jishou'] || $jishou)) {
					$jis=$fy1['jishou']?"是":"否";
					$jis1=$jishou?"是":"否";
					$xiugai.="急售：[".$jis."]=>[".$jis1."]；";
				}
				if ($fy1['quankuan'] != $quankuan && ($fy1['quankuan'] || $quankuan)) {
					$quan=$fy1['quankuan']?"是":"否";
					$quan1=$quankuan?"是":"否";
					$xiugai.="全款：[".$quan."]=>[".$quan1."]；";
				}
				if ($fy1['weiyi'] != $weiyi && ($fy1['weiyi'] || $weiyi)) {
					$wei1=$fy1['weiyi']?"是":"否";
					$wei2=$weiyi?"是":"否";
					$xiugai.="唯一：[".$wei1."]=>[".$wei2."]；";
				}
				if ($fy1['man2'] != $man2 && ($fy1['man2'] || $man2)) {
					$man21=$fy1['man2']?"是":"否";
					$man22=$man2?"是":"否";
					$xiugai.="满2：[".$man21."]=>[".$man22."]；";
				}
				if ($fy1['xuequ'] != $xuequ && ($fy1['xuequ'] || $xuequ)) {
					$xue1=$fy1['xuequ']?"是":"否";
					$xue2=$xuequ?"是":"否";
					$xiugai.="学区：[".$xue1."]=>[".$xue2."]；";
				}
				if ($fy1['youdaikuan'] != $youdaikuan && ($fy1['youdaikuan'] || $youdaikuan)) {
					$youdaik1=$fy1['youdaikuan']?"是":"否";
					$youdaik2=$youdaikuan?"是":"否";
					$xiugai.="有贷款：[".$youdaik1."]=>[".$youdaik2."]；";
				}
				if ($fy1['xinzheng'] != $xinzheng && ($fy1['xinzheng'] || $xinzheng)) {
					$xin1=$fy1['xinzheng']?"是":"否";
					$xin2=$xinzheng?"是":"否";
					$xiugai.="新证：[".$xin1."]=>[".$xin2."]；";
				}
				$isok=M('fangyuan')->where(array('id'=>$id))->save($data);
				if($isok){
					if ($fy1['mmzl'] == 1) {
						$zyzs = "住宅（出售）";
					} elseif ($fy1['mmzl'] == 2) {
						$zyzs = "住宅（出租）";
					}
					data_rizhi(1,2,$id,$fy1['bianhao'],$xiugai,U('fangyuan/neirong',array('id'=>$id)),$zyzs);
					if ($fy1['shtype'] == 2) {
						M('fangyuan')->where(array('id'=>$id))->setField('shtype',3);
						$this->success('已更新，请等待审核！');
					} else {
						$this->success('更新成功');
					}
				} else {
					$this->error('更新失败！');
				}
			} else {
				$this->yongtu=get_peizhi('yongtu',0,1);
				$this->zujialx=get_peizhi('zujialx',0,1);
				$this->chaoxiang=get_peizhi('chaoxiang',0,1);
				$this->xianzhuang=get_peizhi('xianzhuang',0,1);
				$this->leixing=get_peizhi('fwleixing',0,1);
				$this->jiegou=get_peizhi('jiegou',0,1);
				$this->chanquan=get_peizhi('chanquan',0,1);
				$this->kanfangfs=get_peizhi('kanfangfs',0,1);
				$this->laiyuan=get_peizhi('laiyuan',0,1);
				if ($fy1['mmzl'] == 1) {
					$fukuan="fukuan";
				} elseif ($fy1['mmzl'] == 2) {
					$fukuan="zlfukuan";
				}
				$this->fukuan=get_peizhi($fukuan,0,1);
				$this->zhuangxiu=get_peizhi('zhuangxiu',0,1);
				$this->iszheng=get_peizhi('iszheng',0,1);
				$this->fydengji=get_peizhi('fydengji',0,1);
				$this->peitao=get_peizhi('peitao',0,1);
				$peitao1=M('fangyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('peitao');
				$this->peitao2= explode(",",$peitao1);
				$this->fangyuan=$fy1;
				$this->display();
			}
		}

		//变更状态
		public function bgfyzt(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(695,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			if (IS_POST) {
				if ($fangyuan['zhuangtai'] == get_options('chengjiao_options','fychengjiao_zhuangtai')){
					$this->error('房源已成交');
				}
				$data['zhuangtai']=I('zhuangtai');
				$data['xiugaisj']=time();
				$isok=M("fangyuan")->where(array('id'=>$id))->save($data);
				if ($isok){
					$xiugai = "变更".get_xiugai($fangyuan['zhuangtai'],I('zhuangtai'),'zhuangtai');
					if ($fangyuan['mmzl'] == 1) {
						$zyzs = "住宅（出售）";
					} elseif ($fangyuan['mmzl'] == 2) {
						$zyzs = "住宅（出租）";
					}
					data_rizhi(1,24,$id,$fangyuan['bianhao'],$xiugai,U('fangyuan/neirong',array('id'=>$id)),$zyzs);
					$this->success('变更成功');
				} else {
					$this->error('变更失败');
				}
			} else {
				$this->fyzt=$fangyuan['zhuangtai'];
				$this->zhuangtai=get_peizhi('zhuangtai',0,1);
				$this->display();
			}
		}

		//调取
		public function diaoqu() {
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(58,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error('您没有权限!');
			}
			$is_rbacfdq = _rbac_node_show(862);
			if (!$is_rbacfdq && ($fangyuan['fpdq'] != 2)) {
				$this->error('您没有权限!');
			}
			$is_rbacfdh = _rbac_node_show(859);
			$is_rbacfdz = _rbac_node_show(860);
			if (!$is_rbacfdh && !$is_rbacfdz && ($fangyuan['fpdh'] == 1) && ($fangyuan['fpdz'] == 1)) {
				$this->error('您没有权限!');
			}
			$Model = new \Think\Model;
			$diaoqu_arr = get_options('diaoqu_options',0);
			$username = zym(session('uid'),14);
			if ($diaoqu_arr['sz_ytpe'] == 1 && $username != C('RBAC_SUPERADMIN')) {
				switch ($diaoqu_arr['sz_ytpe1']['type']) {
					case '1':
						$startUnix = strtotime(date('Y-m-d',time()));
						break;
					case '2':
						$startUnix = strtotime(date('Y-m-d', strtotime('this week')));
						break;
					case '3':
						$startUnix = strtotime(date('Y-m', time()) . '-01 00:00:00');
						break;
					case '4':
						$season = ceil((date('n'))/3);
						$startUnix = mktime(0, 0, 0,$season*3-3+1,1,date('Y'));
						break;
					case '5':
						$startUnix = strtotime(date('Y', time()) . '-01-01 00:00:00');
						break;
					default:
						$startUnix = strtotime(date('Y-m-d',time()));
						break;
				}
				$find = M('xianzhi')->where(array('fyid'=>$id,'fylx'=>1,'uid'=>session('uid'),'shijian'=>array('gt',$startUnix)))->find();
				$map = ' fylx=1 and uid='.session('uid')." and shijian>=".$startUnix;
				$sql = "select count(*) from (select * from __XIANZHI__ where $map group by fyid) as a";
				$count=$Model->query($sql);
				if ($count[0]['count(*)'] >= $diaoqu_arr['sz_ytpe1']['count']) {
					$this->error('调取次数已用完!');
				}
				$sycishu = $diaoqu_arr['sz_ytpe1']['count'] - $count[0]['count(*)'] - 1;
			} elseif ($diaoqu_arr['sz_ytpe'] == 2 && $username != C('RBAC_SUPERADMIN')) {
				$role_id=M('role_user')->where(array('user_id'=>session('uid')))->getField('role_id');
				switch ($diaoqu_arr['sz_ytpe2'][$role_id]['type']) {
					case '1':
						$startUnix = strtotime(date('Y-m-d',time()));
						break;
					case '2':
						$startUnix = strtotime(date('Y-m-d', strtotime('this week')));
						break;
					case '3':
						$startUnix = strtotime(date('Y-m', time()) . '-01 00:00:00');
						break;
					case '4':
						$season = ceil((date('n'))/3);
						$startUnix = mktime(0, 0, 0,$season*3-3+1,1,date('Y'));
						break;
					case '5':
						$startUnix = $startUnix = strtotime(date('Y', time()) . '-01-01 00:00:00');
						break;
					default:
						$startUnix = strtotime(date('Y-m-d',time()));
						break;
				}
				$find = M('xianzhi')->where(array('fyid'=>$id,'fylx'=>1,'uid'=>session('uid'),'shijian'=>array('gt',$startUnix)))->find();
				$map = ' fylx=1 and uid='.session('uid')." and shijian>=".$startUnix;
				$sql = "select count(*) from (select * from __XIANZHI__ where $map group by fyid) as a";
				$count=$Model->query($sql);
				if ($count[0]['count(*)'] >= $diaoqu_arr['sz_ytpe2'][$role_id]['count']) {
					$this->error('调取次数已用完!');
				}
				$sycishu = $diaoqu_arr['sz_ytpe2'][$role_id]['count'] - $count[0]['count(*)'] - 1;
			}
			$data['fylx']=1;
			$data['fyid']=$id;
			$data['fybh']=$fangyuan['bianhao'];
			$data['uid']=session('uid');
			$data['time']=date("Y-m");
			$data['shijian']=time();
			M('xianzhi')->add($data);
			if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
				$yezhulx=get_peizhi('yezhulx',$fangyuan['yezhulx'],3);
				$yezhugx=get_peizhi('yezhugx',$fangyuan['yezhugx'],3);
				$yezhugx2=get_peizhi('yezhugx',$fangyuan['yezhugx2'],3);
				$yezhugx3=get_peizhi('yezhugx',$fangyuan['yezhugx3'],3);
				if ($yezhugx) {
					$yzguanxi = "（".$yezhugx."）";
				} else {
					$yzguanxi = "";
				}
				if ($yezhugx2) {
					$yzguanxi2 = "（".$yezhugx2."）";
				} else {
					$yzguanxi2 = "";
				}
				if ($yezhugx3) {
					$yzguanxi3 = "（".$yezhugx3."）";
				} else {
					$yzguanxi3 = "";
				}
				$diaoqu['yezhu']=$fangyuan['yezhu'].$yezhulx;
				$diaoqu['yezhudianhua']=$fangyuan['yezhudianhua'].$yzguanxi;
				$diaoqu['yezhudianhua2']=$fangyuan['yezhudianhua2'].$yzguanxi2;
				$diaoqu['yezhudianhua3']=$fangyuan['yezhudianhua3'].$yzguanxi3;
			}
			if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
				$diaoqu['zuodong']=$fangyuan['zuodong'];
				$diaoqu['danyuan']=$fangyuan['danyuan'];
				$diaoqu['fanghao']=$fangyuan['fanghao'];
			}
			if ($sycishu) {
				$info="剩余调取数为".$sycishu."次";
			}
			$data1=array('status'=>1,'diaoqu1'=>$diaoqu,'info'=>$info);
			header("Content-type: application/json");
			exit(json_encode($data1));
		}

		//写跟进
		public function genjin(){
			$fangyuan=M('fangyuan')->where(array('id'=>I('fyid')))->find();
			$is_rbac = _rbac_btn_show(61,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			$gjid = I('gjid');
			$gongsiid = session('gongsiid');
			if ($fangyuan['mmzl'] == 1) {
				$zyzs = "住宅（出售）";
			} elseif ($fangyuan['mmzl'] == 2) {
				$zyzs = "住宅（出租）";
			}
			//音频操作ajax（上传，删除）
			switch (I('gt')) {
				case '1':
					//语音上传
					$upload = new \Think\Upload();
					$upload->maxSize = 2097152;
					$upload->exts = ''; //array('mp3','ogg');
					$upload->rootPath = './Upload/';
					$upload->savePath = './Genjin/'.$gongsiid.'/fangyuan/'.$fangyuan['bianhao'].'/';
					$upload->autoSub = false;
					$uplaod->replace = true;	//存在同名文件是否是覆盖，默认为false
					$upload->saveName = 'gj'.$gjid;
					//开始上传音频文件
					$info = $upload->upload();
					p($info);die;
					if (!$info) {
						$this->error($upload->getError());
					} else {
						M('fygenjin')->where(array('id'=>$gjid))->setField(array('gjvoice'=>1));
						data_rizhi(1,5,$gjid,$fangyuan['bianhao'],"上传跟进语音",U('fangyuan/neirong',array('id'=>$fangyuan['id'])),$zyzs);
						$this->success($info);
					}
					break;
				case '2':
					$isok = unlink('./Upload/Genjin/'.$gongsiid.'/fangyuan/'.$fangyuan['bianhao'].'/gj'.$gjid.'.mp3');
					if ($isok) {
						M('fygenjin')->where(array('id'=>$gjid))->setField(array('gjvoice'=>null)); 
					}
					data_rizhi(1,5,$gjid,$fangyuan['bianhao'],"删除跟进语音",U('fangyuan/neirong',array('id'=>$fangyuan['id'])),$zyzs);
					$this->success('删除语音成功！');
					break;
				default:
					break;
			}
			if (IS_POST) {
				$data['gongsiid']=session("gongsiid");
				$data['fylx']=1;
				$data['fybh']=$fangyuan['bianhao'];
				$data['fyid']=I('fyid');
				$data['uid']=session("uid");
				$data['genjinfs']=I('genjinfs');
				$data['neirong']=I('neirong');
				$data['shijian']=strtotime(I('gjshijian'));
				$data['time']=time();
				$isok = M('fygenjin')->add($data);
				if ($isok) {
					$data_genjin['zhgjsj']=time();
					$data_genjin['xiugaisj']=time();
					if ($fangyuan['weihurenid'] == session("uid")) {
						$data_genjin['whrzhgenjin'] = time();
					}
					$data_genjin['qyzhgenjin'] = time();
					M('fangyuan')->where(array('id'=>I('fyid')))->save($data_genjin);
					$xiugai = "添加房源跟进：".$data['neirong'];
					data_rizhi(1,5,$isok,$data['fybh'],$xiugai,U('fangyuan/neirong',array('id'=>$data['fyid'])),$zyzs);
					$this->success('添加成功');
				} else {
					$this->error('添加失败');
				}
			} else {
				$this->genjinfs=get_peizhi('genjinfs',0,1);
				$this->display();
			}
		}

		//设置全景地址处理
		public function quanjingHandle(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(76,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			$data['vr_url']=I('text');
			$data['xiugaisj']=time();
			$isok=M('fangyuan')->where(array('id'=>$id))->save($data);
			if ($isok) {
				if ($fangyuan['mmzl'] == 1) {
					$zyzs = "住宅（出售）";
				} elseif ($fangyuan['mmzl'] == 2) {
					$zyzs = "住宅（出租）";
				}
				$xiugai = "全景设置：[".$fangyuan['vr_url']."]=>[".$data['vr_url']."]";
				data_rizhi(1,6,$id,$fangyuan['bianhao'],$xiugai,U('fangyuan/neirong',array('id'=>$id)),$zyzs);
				$this->success('添加成功');
			} else {
				$this->error('添加失败');
			}
		}

		//修改门牌号
		public function xgzuodong(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(150,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			$is_rbacfdh = _rbac_node_show(859);
			$is_rbacfdz = _rbac_node_show(860);
			if (!$is_rbacfdh && !$is_rbacfdz && ($fangyuan['fpdh'] == 1) && ($fangyuan['fpdz'] == 1)) {
				$this->redirect('Index/error');
			}
			if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
				$this->is_rbacfdh=1;
			}
			if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
				$this->is_rbacfdz=1;
			}
			if (IS_POST) {
				if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
					$dianhua1=I('dianhua1');
					$dianhua2=I('dianhua2');
					$dianhua3=I('dianhua3');
					if(!preg_match("/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[8-9])\d{8}$/",$dianhua1) && !preg_match("/^0\d{2,3}-?\d{7,8}$/",$dianhua1)){
						$this->error('请输出正确的手机号码或电话号码！');
					}
					if ($dianhua2) {
						if(!preg_match("/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[8-9])\d{8}$/",$dianhua2) && !preg_match("/^0\d{2,3}-?\d{7,8}$/",$dianhua2)){
							$this->error('请输出正确的手机号码或电话号码！');
						}
					}
					if ($dianhua3) {
						if(!preg_match("/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[8-9])\d{8}$/",$dianhua3) && !preg_match("/^0\d{2,3}-?\d{7,8}$/",$dianhua3)){
							$this->error('请输出正确的手机号码或电话号码！');
						}
					}
					if (($dianhua1 && $dianhua2 && $dianhua1==$dianhua2) || ($dianhua1 && $dianhua3 && $dianhua1==$dianhua3) || ($dianhua1 && $dianhua2 && $dianhua2==$dianhua3)) {
						$this->error('手机号码或电话号码重复！');
					}
					$yezhulxq=get_peizhi('yezhulx',$fangyuan['yezhulx'],3);
					$yezhulxh=get_peizhi('yezhulx',I('yezhulx'),3);
					$yezhugxq=get_peizhi('yezhugx',$fangyuan['yezhugx'],3);
					$yezhugxh=get_peizhi('yezhugx',I('yezhugx1'),3);
					$yezhugx2q=get_peizhi('yezhugx',$fangyuan['yezhugx2'],3);
					$yezhugx2h=get_peizhi('yezhugx',I('yezhugx2'),3);
					$yezhugx3q=get_peizhi('yezhugx',$fangyuan['yezhugx3'],3);
					$yezhugx3h=get_peizhi('yezhugx',I('yezhugx3'),3);
				}
				if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
					$zuodong=I('zuodong');
					$danyuan=I('danyuan');
					$fanghao=I('fanghao');
					if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$zuodong)){
						$this->error('座栋首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
					}
					if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$danyuan)){
						$this->error('单元首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
					}
					if(!preg_match("/^[a-zA-Z1-9][0-9]{0,6}$/",$fanghao)){
						$this->error('房号首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
					}
					$condition['gongsiid']=session('gongsiid');
					$condition['zhuangtai']=array('neq',get_options('chengjiao_options','fychengjiao_zhuangtai'));
					$condition['id']=array('neq',$id);
					$condition['isdel']=2;
					$condition['xiaoqu']=$fangyuan['xiaoqu'];
					$condition['zuodong']=$zuodong;
					$condition['danyuan']=$danyuan;
					$condition['fanghao']=$fanghao;
					$condition['mmzl']=$fangyuan['mmzl'];
					$cffy=M('fangyuan')->where($condition)->find();
					if($cffy){
						$this->error('房源已存在');
					}
				}
				$xiugai = "";
				if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
					if (($fangyuan['yezhu'] != I('yezhu') && ($fangyuan['yezhu'] || I('yezhu'))) || ($yezhulxq != $yezhulxh && ($yezhulxq || $yezhulxh))) {
						$xiugai .= "业主：[".$fangyuan['yezhu'].$yezhulxq."]=>[".I('yezhu').$yezhulxh."]；";
					}
					if (($fangyuan['yezhudianhua'] != $dianhua1 && ($fangyuan['yezhudianhua'] || $dianhua1)) || ($yezhugxq != $yezhugxh && ($yezhugxq || $yezhugxh))) {
						$xiugai .= "电话1：[".$fangyuan['yezhudianhua']."（".$yezhugxq."）]=>[".$dianhua1."（".$yezhugxh."）]；";
					}
					if (($fangyuan['yezhudianhua2'] != $dianhua1 && ($fangyuan['yezhudianhua2'] || $dianhua1)) || ($yezhugx2q != $yezhugx2h && ($yezhugx2q || $yezhugx2h))) {
						$xiugai .= "电话2：[".$fangyuan['yezhudianhua2']."（".$yezhugx2q."）]=>[".$dianhua1."（".$yezhugx2h."）]；";
					}
					if (($fangyuan['yezhudianhua3'] != $dianhua1 && ($fangyuan['yezhudianhua3'] || $dianhua1)) || ($yezhugx3q != $yezhugx3h && ($yezhugx3q || $yezhugx3h))) {
						$xiugai .= "电话3：[".$fangyuan['yezhudianhua3']."（".$yezhugx3q."）]=>[".$dianhua1."（".$yezhugx3h."）]；";
					}
				}
				if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
					if ($fangyuan['zuodong'] != $zuodong && ($fangyuan['zuodong'] || $zuodong)) {
						$xiugai .= "座栋：[".$fangyuan['zuodong']."]=>[".$zuodong."]；";
					}
					if ($fangyuan['danyuan'] != $danyuan && ($fangyuan['danyuan'] || $danyuan)) {
						$xiugai .= "单元：[".$fangyuan['danyuan']."]=>[".$danyuan."]；";
					}
					if ($fangyuan['fanghao'] != $fanghao && ($fangyuan['fanghao'] || $fanghao)) {
						$xiugai .= "房号：[".$fangyuan['fanghao']."]=>[".$fanghao."]；";
					}
				}
				if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
					$data['yezhu']=I('yezhu');
					$data['yezhulx']=I('yezhulx');
					$data['yezhugx']=I('yezhugx1');
					$data['yezhugx2']=I('yezhugx2');
					$data['yezhugx3']=I('yezhugx3');
					$data['yezhudianhua']=$dianhua1;
					$data['yezhudianhua2']=$dianhua2;
					$data['yezhudianhua3']=$dianhua3;
				}
				if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
					$data['zuodong']=$zuodong;
					$data['danyuan']=$danyuan;
					$data['fanghao']=$fanghao;
				}
				$data['xiugaisj']=time();
				$isok=M('fangyuan')->where(array('id'=>$id))->save($data);
				if ($isok) {
					if ($fangyuan['mmzl'] == 1) {
						$zyzs = "住宅（出售）";
					} elseif ($fangyuan['mmzl'] == 2) {
						$zyzs = "住宅（出租）";
					}
					data_rizhi(1,7,$id,$fangyuan['bianhao'],$xiugai,U('fangyuan/neirong',array('id'=>$id)),$zyzs);
					$this->success('修改成功');
				} else {
					$this->error('修改失败');
				}
			} else {
				$this->fangyuan=$fangyuan;
				if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
					$this->yezhulx=get_peizhi('yezhulx',0,1);
					$this->yezhugx=get_peizhi('yezhugx',0,1);
				}
				$this->display();
			}
		}

		//抓取房源
		public function sipanHandle(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(379,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			$options_arr = get_options('chengjiao_options',0);
			if ($fangyuan['zhuangtai'] == $options_arr['fychengjiao_zhuangtai']){
				$this->error('房源已成交');
			}
			$fywhrs=M('fkywhr')->where(array('zylx'=>1,'id'=>$id))->select();
			foreach ($fywhrs as $key => $value) {
				if ($value['whrid'] == session('uid')) {
					$this->error('您不能抓取此房源');
				}
			}
			$data['zhuangtai']=$options_arr['fysipan_zhuangtai'];
			$data['weihurenid']=session('uid');
			$data['weihuren']=session('ygmingcheng');
			$data['xiugaisj']=time();
			$isok=M('fangyuan')->where(array('id'=>$id))->save($data);
			if ($isok) {
				data_fkywhr(1,$id,session('uid'));
				if ($fangyuan['mmzl'] == 1) {
					$zyzs = "住宅（出售）";
				} elseif ($fangyuan['mmzl'] == 2) {
					$zyzs = "住宅（出租）";
				}
				$xiugai = session("ygmingcheng")."抓取房源".$fangyuan['bianhao']."为私盘";
				data_rizhi(1,3,$id,$fangyuan['bianhao'],$xiugai,U('fangyuan/neirong',array('id'=>$id)),$zyzs);
				$this->success('修改成功');
			} else {
				$this->error('修改失败');
			}
		}

		//变更维护人
		public function bgwhr(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(381,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			if (IS_POST) {
				$data['weihurenid']=I('weihurenid');
				$xweihu=M('Yonghu')->where(array('id'=>I('weihurenid')))->getField('ygmingcheng');
				$data['weihuren']=$xweihu;
				$data['xiugaisj']=time();
				$isok=M("fangyuan")->where(array('id'=>$id))->save($data);
				if ($isok){
					M('fangyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
					data_fkywhr(1,$id,session('uid'));
					if ($fangyuan['mmzl'] == 1) {
						$zyzs = "住宅（出售）";
					} elseif ($fangyuan['mmzl'] == 2) {
						$zyzs = "住宅（出租）";
					}
					$xiugai = "变更维护人：[".$fangyuan['weihuren']."]=>[".$xweihu."]";
					data_rizhi(1,9,$id,$fangyuan['bianhao'],$xiugai,U('fangyuan/neirong',array('id'=>$id)),$zyzs);
					$this->success('修改成功');
				} else {
					$this->error('修改失败');
				}
			} else {
				$this->weihuren=M('fangyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('weihuren');
				$this->display();
			}
		}

		//编辑视频
		public function editshipin(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->field('zhuangtai,weihurenid,bianhao,isdel,shtype')->find();
			$is_rbac = _rbac_btn_show(498,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			if (IS_POST) {
				if (preg_match_all('/src=&quot;(.*?)&quot;/', I('shipin_url'), $matches)) {
					$s1 = $matches[1][0];
					$shipin_url='<iframe src="'.$s1.'" frameborder="0" allowfullscreen="true" width="100%" height="100%"></iframe>';
				} elseif (preg_match_all('/src=\'(.*?)\'/', I('shipin_url'), $matches)) {
					$s1 = $matches[1][0];
					$shipin_url='<iframe src="'.$s1.'" frameborder="0" allowfullscreen="true" width="100%" height="100%"></iframe>';
				} else {
					$this->error('修改失败!');
				}
				$isok=M('fangyuan')->where(array('id'=>$id))->setField('shipin_url',$shipin_url);
				if ($isok) {
					M('fangyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
					if ($fangyuan['mmzl'] == 1) {
						$zyzs = "住宅（出售）";
					} elseif ($fangyuan['mmzl'] == 2) {
						$zyzs = "住宅（出租）";
					}
					data_rizhi(1,31,$id,$fangyuan['bianhao'],"设置视频地址：".$shipin_url,U('fangyuan/neirong',array('id'=>$id)),$zyzs);
					$this->success('修改成功!');
				} else {
					$this->error('修改失败!');
				}
			} else {
				$this->shipin_url=M('fangyuan')->where(array('id'=>$id))->getField('shipin_url');
				$this->display();
			}
		}

		//实勘
		public function shikan(){
			$id = I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->field('zhuangtai,weihurenid,bianhao,isdel,shtype,mmzl')->find();
			$is_rbac = _rbac_btn_show(565,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			$isshikan = M('shikan')->where(array('fybh'=>$fangyuan['bianhao'],'fylx'=>1,'status'=>1))->find();
			if ($isshikan) {
				$this->error('已有人实勘!');
			}
			$this->error('请联系客服（19965783436）获取正式版功能！');
		}

		//委办
		public function weiban(){
			$fybh = I('fybianhao');
			$fangyuan=M('fangyuan')->where(array('bianhao'=>$fybh))->field('zhuangtai,weihurenid,isdel,shtype,mmzl')->find();
			$is_rbac = _rbac_btn_show(564,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			} else {
				$this->display();
			}
		}

		//添加钥匙
		public function yaoshi(){
			$fybh = I('fybianhao');
			$fangyuan = M('fangyuan')->where(array('bianhao'=>$fybh))->field('zhuangtai,weihurenid,isdel,shtype,mmzl')->find();
			$is_rbac = _rbac_btn_show(750, $fangyuan['zhuangtai'], $fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			} else {
				$parentid = I("get.parentid",0,'intval');
				$select_categorys = bumen_option( $parentid, 739);
				$this->assign("select_categorys", $select_categorys);
				$this->display();
			}
		}

		//移动钥匙
		public function ydyaoshi(){
			$fybianhao = I('fybianhao');
			$fangyuan = M('fangyuan')->where(array('bianhao'=>$fybianhao))->field('zhuangtai,weihurenid,mmzl')->find();
			$is_rbac = _rbac_btn_show(753, $fangyuan['zhuangtai'], $fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			} else {
				$this->yaoshi = M('yaoshi')->where(array('fybianhao'=>$fybianhao,'fylx'=>1,'status'=>1))->select();
				$parentid = I("get.parentid",0,'intval');
				$select_categorys = bumen_option( $parentid, 739);
				$this->assign("select_categorys", $select_categorys);
				$this->display();
			}
		}

		//上传附件
		public function fujianimg(){
			$data = array(
				'info' => '请联系客服（19965783436）获取正式版功能！',
				'data' => '',
				'status' => 0
			);
			$this->ajaxReturn($data);
		}

		//认证房源
		public function renzheng(){
			$id = I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->field('zhuangtai,weihurenid,bianhao,isdel,shtype,mmzl')->find();
			$is_rbac = _rbac_btn_show(618,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			if ($fangyuan['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if ($fangyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($fangyuan['shtype'] == 2) {
				$this->error('房源已驳回！');
			}
			$this->error('请联系客服（19965783436）获取正式版功能！');
		}

		//删除房源
		public function delEsfy(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(416,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			$this->error('请联系客服（19965783436）获取正式版功能！');
		}

		//还原房源
		public function huifufy(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(766,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			$condition['gongsiid']=session('gongsiid');
			$condition['zhuangtai']=array('neq',get_options('chengjiao_options','fychengjiao_zhuangtai'));
			$condition['id']=array('neq',$id);
			$condition['isdel']=2;
			$condition['xiaoqu']=$fangyuan['xiaoqu'];
			$condition['mmzl']=$fangyuan['mmzl'];
			$condition['zuodong']=$fangyuan['zuodong'];
			$condition['danyuan']=$fangyuan['danyuan'];
			$condition['fanghao']=$fangyuan['fanghao'];
			$cffy=M('fangyuan')->where($condition)->find();
			if($cffy){
				$this->error('房源已存在，无法还原！');
			}
			if($fangyuan['isdel'] == 2){
				$this->error('房源已还原！');
			}
			$this->error('请联系客服（19965783436）获取正式版功能！');
		}

		//永久删除房源
		public function yjdelfy(){
			$id=I('id');
			$fangyuan=M('fangyuan')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(767,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			$this->error('请联系客服（19965783436）获取正式版功能！');
		}

		// 房源审核
		public function fyshenhe(){
			$id = I('id');
			$fy1 = M('fangyuan')->where(array('id'=>$id))->field('weihurenid,isdel,shtype,mmzl')->find();
			$is_rbac = _rbac_btn_show(954,0,$fy1['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($fy1['isdel'] == 1) {
				$this->error('房源已删除！');
			}
			if (IS_POST) {
				$shtype = I('shtype');
				if ($fy1['shtype'] == 1 || $fy1['shtype'] == 2){
					$this->error('已审核');
				}
				if ($shtype == ""){
					$this->error('请选择审核意见');
				}
				$isok = M('fangyuan')->where(array('id'=>$id))->setField('shtype',$shtype);
				if ($isok){
					if ($shtype == 1) {
						$xiugai = "通过了";
					}
					if ($shtype == 2) {
						$xiugai = "驳回了";
					}
					$fybh = M('fangyuan')->where(array('id'=>$id))->getField('bianhao');
					$xiugai .= $fybh."的添加。";
					if ($fy1['mmzl'] == 1) {
						$zyzs = "住宅（出售）";
					} elseif ($fy1['mmzl'] == 2) {
						$zyzs = "住宅（出租）";
					}
					data_rizhi(1,18,$id,$fybh,$xiugai,U('fangyuan/neirong',array('id'=>$id)),$zyzs);
					$this->success('审核成功！');
				} else {
					$this->error('审核失败！');
				}
			} else {
				$this->display();
			}
		}

	}