<?php

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

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

		//住宅列表
		public function Esfy(){
			if (I('is_ajax')) {
				$sousuo = I('sousuo');
				$mmzl = I('mmzl');
				$zhuangtai = I('zhuangtai');
				$zhuangxiu = I('zhuangxiu');
				$chaoxiang = I('chaoxiang');
				$yongtu = I('yongtu');
				$myfy = I('myfy');
				$mysc = I('mysc');
				$dshenhe = I('dshenhe');
				$bohui = I('bohui');
				$isdel = I('isdel');
				$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');
				$wuxiao = I('wuxiao');
				$jiage1 = I('jiage1');
				$jiage2 = I('jiage2');
				$mianji1 = I('mianji1');
				$mianji2 = I('mianji2');
				$shijian1 = I('shijian1');
				$shijian2 = 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 ($isdel) {
					$condition .= " and isdel=1";
				} else {
					$condition .= " and isdel=2";
				}
				if ($mmzl) {
					$condition .= " and mmzl=".$mmzl;
				}
				$fywxzt = get_options('chengjiao_options','fyfengpan_zhuangtai');
				if ($wuxiao) {
					$condition .= " and zhuangtai in (".$fywxzt.")";
				} else {
					$condition .= " and zhuangtai not in (".$fywxzt.")";
				}
				if ($zhuangtai) {
					$condition .= " and zhuangtai=".$zhuangtai;
				}
				if ($dshenhe) {
					$condition .= " and shtype=3";
				}
				if ($bohui) {
					$condition .= " and shtype=2";
				}
				if (!$dshenhe && !$bohui) {
					$condition .= " 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 ($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 lurusj>=".$shijian3." and lurusj<".$shijian4;
				} elseif ($shijian3) {
					$condition .= " and lurusj>=".$shijian3;
				} elseif ($shijian4) {
					$condition .= " and lurusj<".$shijian4;
				}
				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%')";
				}
				/*权限控制开始*/
				$map = "gongsiid=".session('gongsiid');
				$x = _rbac_lists_where(41,0);
				if ($x && $x != "all" && $x != "me") {
					$map .= " and bumen in ({$x})";
				} elseif ($x == "me") {
					$map .= " and id=".session('uid');
				} elseif ($x == false) {
					$map .= " and id=0";
				}
				/*权限控制结束*/
				$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__ where {$map}) 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__ where {$map}) 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']);
					if ($value['isdel'] == 1) {
						$is_rbachy = _rbac_btn_show(766,$value['zhuangtai'],$value['weihurenid']);
						$is_rbacsc = _rbac_btn_show(767,$value['zhuangtai'],$value['weihurenid']);
						$data[$key]['rbachy'] = $is_rbachy ? 1 : 0;
						$data[$key]['rbacsc'] = $is_rbacsc ? 1 : 0;
					} else if ($value['isdel'] == 2) {
						$is_rbacdy = _rbac_btn_show(214,$value['zhuangtai'],$value['weihurenid']);
						$data[$key]['rbacdy'] = $is_rbacdy ? 1 : 0;
					}
					if ($value['shtype'] == 3) {
						$is_rbacsh = _rbac_btn_show(766,$value['zhuangtai'],$value['weihurenid']);
						$data[$key]['rbacsh'] = $is_rbacsh ? 1 : 0;
					}
					$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->zhuangtai = get_peizhi('zhuangtai',0,1);
				$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 addEsfy(){
			$is_rbac = _rbac_node_show(42);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$khxqid = I('khxqid');
				if ($khxqid) {
					$xiaoqu = I('xiaoqu');
				} else {
					$fjid = I('fjid');
					if ($fjid) {
						if (I('ishb') == 1) {
							$fjxxb = M('fjhbxx');
						} else {
							$fjxxb = M('fjxinxi');
						}
						$fangjian = $fjxxb->where(array('id'=>$fjid))->find();
						$xiaoqum = zym($fangjian['xqid'],3);
						$zdmwdw = M('zdxinxi')->where(array('id'=>$fangjian['zdid']))->getField('zdmwdw');
						$dymwdw = M('dyxinxi')->where(array('id'=>$fangjian['dyid']))->getField('dymwdw');
						$lcmwdw = M('lcxinxi')->where(array('id'=>$fangjian['lcid']))->getField('lcmwdw');
						$lcshu = M('lcxinxi')->where(array('dyid'=>$fangjian['dyid']))->count();
					} else {
						$this->error('异常错误!');
					}
					if ($fangjian['xqid']) {
						$xiaoqu = $fangjian['xqid'];
					} else {
						$this->error('请选择楼盘');
					}
				}
				$xingzhengqu = M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('ssxzq');
				$pianqu = M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('sspianqu');
				$xq = M('xiaoqu')->where(array('id'=>$xiaoqu))->getField('ssxuexiao');
				if ($xq) {
					$xuequ = 1;
				} else {
					$xuequ = 0;
				}
				if ($zdmwdw) {
					$zuodong = $zdmwdw;
				} elseif (I('zuodong')) {
					$zuodong = I('zuodong');
				} else {
					$this->error('请输入座栋');
				}
				if ($dymwdw) {
					$danyuan = $dymwdw;
				} elseif (I('danyuan')) {
					$danyuan = I('danyuan');
				} else {
					$this->error('请输入单元');
				}
				if ($lcmwdw) {
					$louceng = $lcmwdw;
				} elseif (I('louceng')) {
					$louceng = I('louceng');
				} else {
					$this->error('请输入楼层');
				}
				if ($lcshu) {
					$zlouceng = $lcshu;
				} elseif (I('zlouceng')) {
					$zlouceng = I('zlouceng');
				} else {
					$this->error('请输入总楼层');
				}
				if ($fangjian['fjmwdw']) {
					$fanghao = $fangjian['fjmwdw'];
				} elseif (I('fanghao')) {
					$fanghao = I('fanghao');
				} else {
					$this->error('请输入房号');
				}
				$mmzl = I('mmzl');
				$condition['gongsiid'] = session('gongsiid');
				$condition['zhuangtai'] = array('neq',get_options('chengjiao_options','fychengjiao_zhuangtai'));
				$condition['isdel'] = 2;
				$condition['xiaoqu'] = $xiaoqu;
				$condition['zuodong'] = $zuodong;
				$condition['danyuan'] = $danyuan;
				$condition['fanghao'] = $fanghao;
				$condition['mmzl'] = $mmzl;
				$cffy = M('fangyuan')->where($condition)->find();
				if ($cffy) {
					$this->error('房源已存在');
				}
				if ($fangjian['shi']) {
					$shi = $fangjian['shi'];
				} elseif (I('shi')) {
					$shi = I('shi');
				} else {
					$this->error('请输入卧室数');
				}
				if ($fangjian['ting']) {
					$ting = $fangjian['ting'];
				} elseif (I('ting')) {
					$ting = I('ting');
				} else {
					$this->error('请输入客厅数');
				}
				if ($fangjian['wei']) {
					$wei = $fangjian['wei'];
				} elseif (I('wei')) {
					$wei = I('wei');
				}
				if ($fangjian['chu']) {
					$chu = $fangjian['chu'];
				} elseif (I('chu')) {
					$chu = I('chu');
				}
				if ($fangjian['yangtai']) {
					$yangtai = $fangjian['yangtai'];
				} elseif (I('yangtai')) {
					$yangtai = I('yangtai');
				}
				if ($fangjian['yongtu']) {
					$yongtu = $fangjian['yongtu'];
				} elseif (I('yongtu')) {
					$yongtu = I('yongtu');
				} else {
					$this->error('请选择用途');
				}
				if ($fangjian['jzmianji']) {
					$mianji = $fangjian['jzmianji'];
				} elseif (I('mianji')) {
					$mianji = I('mianji');
				} else {
					$this->error('请输入建筑面积');
				}
				if ($fangjian['symianji']) {
					$symianji = $fangjian['symianji'];
				} elseif (I('symianji')) {
					$symianji = I('symianji');
				}
				if ($fangjian['yezhu']) {
					$yezhu = $fangjian['yezhuxm'];
				} elseif (I('yezhu')) {
					$yezhu = I('yezhu');
				} else {
					$this->error('请输入业主姓名');
				}
				if ($fangjian['yezhuxb']) {
					$yezhulx = $fangjian['yezhuxb'];
				} elseif (I('yezhulx')) {
					$yezhulx = I('yezhulx');
				} else {
					$this->error('请选择业主类型');
				}
				if ($fangjian['yezhudianhua']) {
					$yezhudianhua = $fangjian['yezhusj'];
				} elseif (I('yezhudianhua')) {
					$yezhudianhua = I('yezhudianhua');
				} else {
					$this->error('请输入业主电话');
				}
				if ($fangjian['zhuangxiu']) {
					$zhuangxiu = $fangjian['zhuangxiu'];
				} elseif (I('zhuangxiu')) {
					$zhuangxiu = I('zhuangxiu');
				} else {
					$this->error('请选择装修');
				}
				if ($fangjian['chaoxiang']) {
					$chaoxiang = $fangjian['chaoxiang'];
				} elseif (I('chaoxiang')) {
					$chaoxiang = I('chaoxiang');
				} else {
					$this->error('请选择朝向');
				}
				if ($fangjian['xianzhuang']) {
					$xianzhuang = $fangjian['xianzhuang'];
				} elseif (I('xianzhuang')) {
					$xianzhuang = I('xianzhuang');
				} else {
					$this->error('请选择现状');
				}
				if ($fangjian['cqxingzhi']) {
					$cqxingzhi = $fangjian['chanquan'];
				} elseif (I('cqxingzhi')) {
					$cqxingzhi = I('cqxingzhi');
				}
				$cqnianxian = I('cqnianxian');
				$ti = I('ti');
				$hu = I('hu');
				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('房号首字符可以是非零整数或字母，除首字符外必须为非负整数（限六位整数）！');
				}
				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,3})(\.[0-9]{1,2})?$|^([0]\.[1-9][0-9]{0,1})$|^([0]\.[0][1-9]{1})$|^(1[0]{4})(\.[0][0]{0,1})?$/",$mianji) || !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})?$/",$symianji)) {
					$this->error('面积请输入＞0且≤一万的数字（限两位小数）！');
				}
				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}$|^0\d{2,3}-?\d{7,8}$/",$yezhudianhua)) {
					$this->error('业主电话请输入正确的手机号码或电话号码！');
				}
				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的整数！');
				}
				if ($mmzl == 1) {
					$chushoudj = I('chushoudj');
					$shoujia = 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})?$/",$chushoudj)) {
						$this->error('出售底价请输入＞0且≤十亿的数字（限六位小数）！');
					}
					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})?$/",$shoujia)) {
						$this->error('售价请输入＞0且≤十亿的数字（限六位小数）！');
					}
				} elseif ($mmzl == 2) {
					$chuzudj = I('chuzudj');
					$zujia = 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})?$/",$chuzudj)) {
						$this->error('出租底价请输入＞0且≤十万的数字（限两位小数）！');
					}
					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})?$/",$zujia)) {
						$this->error('租价请输入＞0且≤十万的数字（限两位小数）！');
					}
				}
				$beizhu = preg_replace ( "/\s(?=\s)/","\\1", I('beizhu') );
				if (!preg_match("/^$|^[\s\S]{0,300}$/",$beizhu)) {
					$this->error('备注只能输入300个字符！');
				}
				$bh = M('bianhao')->where(array('id'=>1))->setInc('bianhao');
				$bh1 = M('bianhao')->where(array('id'=>1))->getField('bianhao');
				$data['bumen'] = yhbm(session("uid"),1);
				$data['gongsiid'] = session('gongsiid');
				if ($mmzl == 1) {
					$zyzs = "住宅（出售）";
					$data['bianhao'] = "MF-".$bh1;
				} elseif ($mmzl == 2) {
					$zyzs = "住宅（出租）";
					$data['bianhao'] = "ZF-".$bh1;
				}
				$data['mmzl'] = $mmzl;
				if (I('shoujia')) {
					$data['shoujia'] = I('shoujia');
				}
				if (I('chushoudj')) {
					$data['chushoudj'] = I('chushoudj');
				}
				if (I('mianji') and I('shoujia')) {
					$num1 = I('shoujia')*10000;
					$num2 = I('mianji');
					$num = $num1/$num2;
					$danjia = number_format($num,2,".", "");
					$data['danjia'] = $danjia;
				}
				$zhan_bumen = M('xingzhengqu')->where(array('id'=>$xingzhengqu))->getField('bumen');
				$data['zhan_bumen'] = $zhan_bumen;
				if ($khxqid) {
					$zhuangtai = get_options('chengjiao_options','fygongpan_zhuangtai');
				} else {
					$zhuangtai = get_options('chengjiao_options','fysipan_zhuangtai');
				}
				$data['zhuangtai'] = $zhuangtai;
				$data['xiaoqu'] = $xiaoqu;
				$data['xiaoqum'] = $xiaoqum;
				$data['xuequ'] = $xuequ;
				$data['pianqu'] = $pianqu;
				$data['xingzhengqu'] = $xingzhengqu;
				$data['zuodong'] = $zuodong;
				$data['danyuan'] = $danyuan;
				$data['louceng'] = $louceng;
				$data['zlouceng'] = $zlouceng;
				$data['fanghao'] = $fanghao;
				$data['shi'] = $shi;
				$data['ting'] = $ting;
				$data['wei'] = $wei;
				$data['chu'] = $chu;
				$data['yangtai'] = $yangtai;
				$data['symianji'] = $symianji;
				$data['mianji'] = $mianji;
				$data['yezhudianhua'] = $yezhudianhua;
				$data['yongtu'] = $yongtu;
				$data['yezhu'] = $yezhu;
				$data['yezhulx'] = $yezhulx;
				$data['zhuangxiu'] = $zhuangxiu;
				$data['chaoxiang'] = $chaoxiang;
				$data['xianzhuang'] = $xianzhuang;
				$data['cqxingzhi'] = $cqxingzhi;
				$data['leixing'] = I('leixing');
				$data['fydengji'] = I('fydengji');
				$data['zujia'] = I('zujia');
				$data['yezhugx'] = I('yezhugx');
				$data['zujialx'] = I('zujialx');
				$pt1 = array_keys(I('peitao')); 
				$pt2 = implode(',',$pt1);
				$data['peitao'] = $pt2;
				$data['jiegou'] = I('jiegou');
				$data['cqnianxian'] = $cqnianxian;
				$data['kanfangfs'] = I('kanfangfs');
				$data['laiyuan'] = I('laiyuan');
				$data['weihuren'] = session('ygmingcheng');
				$data['weihurenid'] = session('uid');
				$data['lururenid'] = session('uid');
				$data['fybiaoti'] = I('fybiaoti');
				$data['ti'] = $ti;
				$data['hu'] = $hu;
				$data['niandai'] = I('niandai');
				$data['chuzudj'] = I('chuzudj');
				$data['beizhu'] = $beizhu;
				$data['chanquanzheng'] = I('chanquanzheng');
				$data['tudizheng'] = I('tudizheng');
				$data['budongchanzheng'] = I('budongchanzheng');
				$data['czriqi'] = strtotime(I('czriqi'));
				$data['fukuanfs'] = I('fukuanfs');
				$is_rbactb = _rbac_node_show(1052);
				if ($is_rbactb) {
					if (I('waiwangtb')) {
						$waiwangtb = 1;
					} else {
						$waiwangtb = 0;
					}
				} 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['lurusj'] = time();
				$data['zhgjsj'] = time();
				$data['xiugaisj'] = time();
				$data['whrzhgenjin'] = time();
				$data['qyzhgenjin'] = time();
				$isok = M('Fangyuan')->add($data);
				if ($isok) {
					if ($khxqid) {
						$xiugai = "客户需求转入商机中心（住宅）。";
						$data_khxq['zybh'] = $data['bianhao'];
						$data_khxq['zylj'] = U('fangyuan/neirong',array('id'=>$isok));
						$data_khxq['zrsjzx'] = "已被".zym(session('uid'),5)."转入商机中心（住宅）。";
						$data_khxq['wangzhipc'] = U('Home/ershoufang/content',array('fybh'=>$data['bianhao']));
						$data_khxq['wangzhiyd'] = U('Wap/fyzhuzhai/content',array('fybh'=>$data['bianhao']));
						M('fabufy')->where(array("id"=>$khxqid))->save($data_khxq);
						data_rizhi(5,1,$isok,$data['bianhao'],$xiugai,U('fangyuan/neirong',array('id'=>$isok)),"外网客户");
					} else {
						$xiugai = "添加了一条房源数据。";
						data_fkywhr(1,$isok,session('uid'));
					}
					data_rizhi(1,1,$isok,$data['bianhao'],$xiugai,U('fangyuan/neirong',array('id'=>$isok)),$zyzs);
					$this->success('已添加，请等待审核！');
				} else {
					$this->error('添加失败！');
				}
			} else {
				//配置值输出
				$this->yongtu = get_peizhi('yongtu',0,1);
				$this->zhuangtai = get_peizhi('zhuangtai',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 (I('mmzl') == 1) {
					$fuk = "fukuan";
				} elseif (I('mmzl') == 2) {
					$fuk = "zlfukuan";
					$this->zujialx = get_peizhi('zujialx',0,1);
				}
				$this->fukuan = get_peizhi($fuk,0,1);
				$this->yezhulx = get_peizhi('yezhulx',0,1);
				$this->yezhugx = get_peizhi('yezhugx',0,1);
				$this->zhuangxiu = get_peizhi('zhuangxiu',0,1);
				$this->peitao = get_peizhi('peitao',0,1);
				$this->iszheng = get_peizhi('iszheng',0,1);
				$this->fydengji = get_peizhi('fydengji',0,1);
				if (I('fjid')) {
					if (I('ishb') == 1) {
						$fjxxb = M('fjhbxx');
					} else {
						$fjxxb = M('fjxinxi');
					}
					$fangjian = $fjxxb->where(array('id'=>I('fjid')))->find();
					$this->fangjian = $fangjian;
					$this->xiaoqum = zym($fangjian['xqid'],3);
					$this->zdmwdw = M('zdxinxi')->where(array('id'=>$fangjian['zdid']))->getField('zdmwdw');
					$this->dymwdw = M('dyxinxi')->where(array('id'=>$fangjian['dyid']))->getField('dymwdw');
					$this->lcmwdw = M('lcxinxi')->where(array('id'=>$fangjian['lcid']))->getField('lcmwdw');
					$this->lcshu = M('lcxinxi')->where(array('dyid'=>$fangjian['dyid']))->count();
				}
				$this->display();
			}
		}

		//房源内容页
		public function neirong(){
			$id = I('id');
			$fybh = I('bianhao');
			if ($id) {
				$fangyuan = M('fangyuan')->where(array('id'=>$id))->find();
			} elseif ($fybh) {
				$fangyuan = M('fangyuan')->where(array('bianhao'=>$fybh))->find();
			}
			if (!$fangyuan) {
				$this->error('未找到房源！');
			}
			$is_rbacfck = _rbac_node_show(863);
			if (!$is_rbacfck && ($fangyuan['fpck'] != 2)) {
				$this->redirect('Index/error');
			}
			$is_rbac = _rbac_btn_show(46,$fangyuan['zhuangtai'],$fangyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$is_rbacfdh = _rbac_node_show(859);
			if ($is_rbacfdh || ($fangyuan['fpdh'] == 2)) {
				$this->is_rbacfdh=1;
			}
			$is_rbacfdz = _rbac_node_show(860);
			if ($is_rbacfdz || ($fangyuan['fpdz'] == 2)) {
				$this->is_rbacfdz=1;
			}
			$is_rbacfdj = _rbac_node_show(861);
			if ($is_rbacfdj || ($fangyuan['fpdj'] == 2)) {
				$this->is_rbacfdj=1;
			}
			$is_rbacfdq = _rbac_node_show(862);
			if ($is_rbacfdq || ($fangyuan['fpdq'] == 2)) {
				$this->is_rbacfdq=1;
			}
			$iskzq = 1;
			$fywxzt = get_options('chengjiao_options','fyfengpan_zhuangtai');
			if (!in_array($fangyuan['zhuangtai'],$fywxzt)) {
				$fywhrs = M('fkywhr')->where(array('zylx'=>1,'id'=>$fangyuan['id']))->select();
				foreach ($fywhrs as $key => $value) {
					if ($value['whrid'] == session('uid')) {
						$iskzq = 2;
					}
				}
			}
			$this->iskzq = $iskzq;
			$this->fangyuan = $fangyuan;
			if ($fangyuan['mmzl'] == 1) {
				$fuk = "fukuan";
			} elseif ($fangyuan['mmzl'] == 2) {
				$fuk = "zlfukuan";
				$this->zujialx = get_peizhi('zujialx',$fangyuan['zujialx'],3);
			}
			$this->fydengji = get_peizhi('fydengji',$fangyuan['fydengji'],3);
			$this->chanquanzheng = get_peizhi('iszheng',$fangyuan['chanquanzheng'],3);
			$this->budongchanzheng = get_peizhi('iszheng',$fangyuan['budongchanzheng'],3);
			$this->tudizheng = get_peizhi('iszheng',$fangyuan['tudizheng'],3);
			$this->yongtu = get_peizhi('yongtu',$fangyuan['yongtu'],3);
			$this->zhuangtai = get_peizhi('zhuangtai',$fangyuan['zhuangtai'],3);
			$this->chaoxiang = get_peizhi('chaoxiang',$fangyuan['chaoxiang'],3);
			$this->zhuangxiu = get_peizhi('zhuangxiu',$fangyuan['zhuangxiu'],3);
			$this->xianzhuang = get_peizhi('xianzhuang',$fangyuan['xianzhuang'],3);
			$this->leixing = get_peizhi('fwleixing',$fangyuan['leixing'],3);
			$this->jiegou = get_peizhi('jiegou',$fangyuan['jiegou'],3);
			$this->cqxingzhi = get_peizhi('chanquan',$fangyuan['cqxingzhi'],3);
			$this->laiyuan = get_peizhi('laiyuan',$fangyuan['laiyuan'],3);
			$this->kanfangfs = get_peizhi('kanfangfs',$fangyuan['kanfangfs'],3);
			$this->fukuanfs = get_peizhi($fuk,$fangyuan['fukuanfs'],3);
			$options_arr = get_options('chengjiao_options',0);
			$this->options_arr = $options_arr;
			$this->isshoucang = M('shoucang')->where(array('user_id'=>session('uid'),'fyid'=>$fangyuan['id'],'fylx'=>1))->find();
			$Model = new \Think\Model();
			if ($fangyuan['peitao']) {
				$condition = "pzming = 'peitao' and lxid in (".$fangyuan['peitao'].")";
				$peitao1 = $Model->query("select * from __PEIZHI__ where {$condition} order by xsshunxu asc");
				$peitao2 = array();
				foreach ($peitao1 as $key => $value) {
					$peitao2[$key] = $value['lxming'];
				}
				$this->peitao = implode('；',$peitao2);
			}
			$uid = M('photo')->where(array('gongsiid'=>session('gongsiid'),'fybh'=>$fangyuan['bianhao']))->group('fybh')->getField('uid');
			$this->shangturen = M('yonghu')->where(array('id'=>$uid))->field('ygmingcheng,bumen,dianhua')->find();
			$this->bmdianhua = M('bumen')->where(array('id'=>$fangyuan['shouyaobm']))->getField('bmdianhua');
			$this->shouyaoren = M('yonghu')->where(array('id'=>$fangyuan['shouyaoren']))->field('ygmingcheng,bumen,dianhua')->find();
			$this->lururen = M('yonghu')->where(array('id'=>$fangyuan['lururenid']))->field('ygmingcheng,bumen,dianhua')->find();
			$this->weihuren = M('yonghu')->where(array('id'=>$fangyuan['weihurenid']))->field('ygmingcheng,bumen,dianhua')->find();
			$this->fengpanren = M('yonghu')->where(array('id'=>$fangyuan['fengpanrenid']))->field('ygmingcheng,bumen,dianhua')->find();
			$weibanuid = M('weiban')->where(array('fybianhao'=>$fangyuan['bianhao']))->getField('uid');
			$this->weibanren = M('yonghu')->where(array('id'=>$weibanuid))->field('ygmingcheng,bumen,dianhua')->find();
			$shikanuid = M('shikan')->where(array('fybh'=>$fangyuan['bianhao']))->getField('uid');
			$this->shikanren = M('yonghu')->where(array('id'=>$shikanuid))->field('ygmingcheng,bumen,dianhua')->find();
			$this->fygenjin = M('fygenjin')->where(array('fyid'=>$fangyuan['id'],'fylx'=>1))->order('shijian desc')->select();
			$this->diaoqujl = M('xianzhi')->where(array('fyid'=>$fangyuan['id'],'fylx'=>1))->order('shijian desc')->select();
			$this->volist = M('rizhi')->where(array('zy_bianhao'=>$fangyuan['bianhao'],'zy_type'=>1))->order('id desc')->select();
			$this->xiaoqu = M('xiaoqu')->where(array('id'=>$fangyuan['xiaoqu']))->find();
			$this->xuexiao = zym($this->xiaoqu['ssxuexiao'],4);
			$qitiannei = time()-604800;
			$this->daikanshu = M('kydaikan')->where(array('kylx'=>2,'fybh'=>$fangyuan['bianhao'],'dkshijian'=>array('gt',$qitiannei)))->count();
			$today = "fyzz".date("m-d");
			if (!cookie($today)) {
				cookie($today,$fangyuan['id'],3600*24);
			} else {
				$value = cookie($today);
				$val = $value.','.$fangyuan['id'];
				cookie($today,$val,3600*24);
			}
			$this->yaoshi = M('yaoshi')->where(array('fylx'=>1,'fybianhao'=>$fangyuan['bianhao']))->order('addtime desc')->select();
			$this->weiban = M('weiban')->where(array('fylx'=>1,'fybianhao'=>$fangyuan['bianhao']))->order('addtime desc')->select();
			$this->display();
		}

		/**
			* [fy_pic_setfengmian 异步房源图片为封面]
			* @return [json] [description]
		*/

		//设置图片封面
		public function fy_pic_setfengmian(){
			$id = I('fy_pic_id');
			//根据图片id查找房源图片的房源编号fybh
			$fybh = M('Photo')->where(array('id'=>$id))->getField('fybh');
			$fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
			$uid = M('photo')->where(array('id'=>$id))->getField('uid');
			$is_rbac = _rbac_btn_show(481,$fyzhuangtai,$uid);
			if (!$is_rbac) {
				$this->error('异常错误！');
			}
			M('Photo')->where(array('fybh'=>$fybh,'fengmian'=>1))->setField(array('fengmian'=>0));
			$r = M('Photo')->where(array('id'=>$id))->setField(array('fengmian'=>1));
			if ($r) {
				M('fangyuan')->where(array('bianhao'=>$fybh))->setField('xiugaisj',time());
				$fyid = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('id');
				$mmzl = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('mmzl');
				if ($mmzl == 1) {
					$zyzs = "住宅（出售）";
				} elseif ($mmzl == 2) {
					$zyzs = "住宅（出租）";
				}
				data_rizhi(1,30,$id,$fybh,"设置图片封面",U('fangyuan/neirong',array('id'=>$fyid)),$zyzs);
				$this->success('设置成功');
			} else {
				$this->error('设置失败');
			}
		}

		/**
			* [fy_pic_del 异步删除图片]
			* @return [json] [description]
		*/

		//删除房源图片
		public function fy_pic_del(){
			$id = I('fy_pic_id');
			//根据图片id查看当前是否还有当前房源的图片
			$fybh = M('Photo')->where(array('id'=>$id))->getField('fybh');
			$fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
			$uid = M('photo')->where(array('id'=>$id))->getField('uid');
			$is_rbac = _rbac_btn_show(50,$fyzhuangtai,$uid);
			if (!$is_rbac) {
				$this->error('异常错误！');
			}
			$piccount = M('Photo')->where(array('fybh'=>$fybh))->count();
			$dp = M('Photo');
			//删除当前图片
			if ($id) {
				$plist = $dp->where(array('id'=>$id))->find();
				if ($plist) {
					unlink('./Upload/'.$plist['gongsiid'].'/'.$plist['fybh'].'/'.$plist['image']);
					unlink('./Upload/'.$plist['gongsiid'].'/'.$plist['fybh'].'/t_'.$plist['image']);
					$dp->where(array('id'=>$id))->delete();
					$fyid = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('id');
					$mmzl = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('mmzl');
					if ($mmzl == 1) {
						$zyzs = "住宅（出售）";
					} elseif ($mmzl == 2) {
						$zyzs = "住宅（出租）";
					}
					data_rizhi(1,13,$id,$fybh,"删除图片",U('fangyuan/neirong',array('id'=>$fyid)),$zyzs);
					$data = array('pics'=>$plist);
					//删除最后一个房源图片后给fangyun表的tupian字段置 0
					if ($piccount == 1) {
						M('Fangyuan')->where(array('bianhao'=>$fybh))->setField('tupian',0);
					}
					M('fangyuan')->where(array('bianhao'=>$fybh))->setField('xiugaisj',time());
					$this->success('删除成功');
				} else {
					$this->error('删除失败');
				}
			}
		}

		//批量删除房源图片
		public function fy_pic_dels(){
			$is_rbac = _rbac_node_show(482,0);
			if (!$is_rbac) {
				$this->error('异常错误！');
			}
			$ids = I('fy_pic_ids');
			$fybh = M('Photo')->where(array('id'=>$ids[0]))->getField('fybh');
			$fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
			foreach ($ids as $key => $value) {
				$uid = M('photo')->where(array('id'=>$value))->getField('uid');
				$is_rbac = _rbac_btn_show(482,$fyzhuangtai,$uid);
				if (!$is_rbac) {
					$this->error("您选择了权限范围之外的图片！");
				}
			}
			if (is_array($ids)) {
				$where = 'id in('.implode(',',$ids).')';
				$dp = M('Photo');
				//删除房源图片文件
				foreach ($ids as $value) {
					$plist = $dp->where(array('id'=>$value))->find();
					unlink('./Upload/'.$plist['gongsiid'].'/'.$plist['fybh'].'/'.$plist['image']);
					unlink('./Upload/'.$plist['gongsiid'].'/'.$plist['fybh'].'/t_'.$plist['image']);
				}
				//删除图片记录
				$dp->where($where)->delete();
				//写入删除日志
				$fyid = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('id');
				$mmzl = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('mmzl');
				if ($mmzl == 1) {
					$zyzs = "住宅（出售）";
				} elseif ($mmzl == 2) {
					$zyzs = "住宅（出租）";
				}
				data_rizhi(1,13,$fyid,$fybh,"删除了".count($ids)."张图片",U('fangyuan/neirong',array('id'=>$fyid)),$zyzs);
				//删除最后一个房源图片后给fangyun表的tupian字段置 0
				$nopic = M('Photo')->where(array('fybh'=>$fybh))->count();
				if ($nopic <= 0) {
					M('Fangyuan')->where(array('bianhao'=>$fybh))->setField('tupian',0);
				}
				M('fangyuan')->where(array('bianhao'=>$fybh))->setField('xiugaisj',time());
				$this->success('删除成功');
			} else {
				$this->error('删除失败'); 
			}
		}

		//批量下载房源图片
		public function fy_pic_downloads(){
			$is_rbac = _rbac_node_show(483,0);
			if (!$is_rbac) {
				$this->error('异常错误！');
			}
			$ids = I('fy_pic_ids');
			$fybh = M('Photo')->where(array('id'=>$ids[0]))->getField('fybh');
			$fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
			foreach ($ids as $key => $value) {
				$uid = M('photo')->where(array('id'=>$value))->getField('uid');
				$is_rbac = _rbac_btn_show(483,$fyzhuangtai,$uid);
				if (!$is_rbac) {
					$this->error("您选择了权限范围之外的图片！");
				}
			}
			$where = 'id in('.implode(',',$ids).')';
			$dp = M('Photo');
			$plist = $dp->where($where)->field('id,gongsiid,fybh,image')->select();
			$zip = new \ZipArchive;
			if ($plist) {
				//压缩文件名(临时文件)
				$filename = './Upload/'.$plist[0]['gongsiid'].'/'.$plist[0]['fybh'].'/'.md5($plist[0]['fybh']).'.zip';
				$downname = I("server.HTTP_HOST").'/Upload/'.$plist[0]['gongsiid'].'/'.$plist[0]['fybh'].'/'.md5($plist[0]['fybh']).'.zip';
			}
			//新建zip压缩包
			$zip->open($filename,\ZipArchive::OVERWRITE | \ZipArchive::CREATE);
			//把图片一张一张加进去压缩
			foreach ($plist as $value) {
				$zip->addFile('./Upload/'.$value['gongsiid'].'/'.$value['fybh'].'/'.$value['image']);
				$zip->renameName('./Upload/'.$value['gongsiid'].'/'.$value['fybh'].'/'.$value['image'],$value['image']);
			}
			//打包zip
			$zip->close();
			$fyid = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('id');
			$mmzl = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('mmzl');
			if ($mmzl == 1) {
				$zyzs = "住宅（出售）";
			} elseif ($mmzl == 2) {
				$zyzs = "住宅（出租）";
			}
			data_rizhi(1,20,$fyid,$fybh,"下载了".count($ids)."张图片",U('fangyuan/neirong',array('id'=>$fyid)),$zyzs);
			//可以直接重定向下载
			//header('Location:'.$downname);
			$this->success($downname);
		}

		//设置图片类型
		public function settupianleixing(){
			$is_rbac = _rbac_node_show(484,0);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$ids = explode(",",I('fy_pic_ids'));
				$fybh = M('Photo')->where(array('id'=>$ids[0]))->getField('fybh');
				$fyzhuangtai = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('zhuangtai');
				foreach ($ids as $key => $value) {
					$uid = M('photo')->where(array('id'=>$value))->getField('uid');
					$is_rbac = _rbac_btn_show(484,$fyzhuangtai,$uid);
					if (!$is_rbac) {
						$this->error("您选择了权限范围之外的图片！");
					}
				}
				$ids1 = I('fy_pic_ids');
				$tpleixing = I('tpleixing');
				if ($tpleixing == "") {
					$this->error("请选择图片类型");
				}
				$where = 'id in('.$ids1.')';
				$dp = M('Photo');
				$plist = $dp->where($where)->setField(array('leixing'=>$tpleixing ));
				if ($plist) {
					M('fangyuan')->where(array('bianhao'=>$fybh))->setField('xiugaisj',time());
					$fyid = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('id');
					$mmzl = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('mmzl');
					if ($mmzl == 1) {
						$zyzs = "住宅（出售）";
					} elseif ($mmzl == 2) {
						$zyzs = "住宅（出租）";
					}
					$yongtu = M('fangyuan')->where(array('bianhao'=>$fybh))->getField('yongtu');
					$pzming = "";
					switch ($yongtu) {
						case 1:
							$pzming = "zztplx"; //住宅
							break;
						case 2:
							$pzming = "bstplx"; //别墅
							break;
						case 3:
							$pzming = "sptplx"; //商铺
							break;
						case 4:
							$pzming = "cktplx"; //仓库
							break;
						case 5:
							$pzming = "chftplx"; //厂房
							break;
						case 6:
							$pzming = "tdtplx"; //土地
							break;
						case 7:
							$pzming = "chktplx"; //车库
							break;
						case 8:
							$pzming = "xzltplx"; //写字楼
							break;
						default:
							$pzming = "zztplx";
							break;
					}
					$xiugai = "设置了".count($ids)."张住宅图片的类型为".get_peizhi($pzming,$tpleixing,3);
					data_rizhi(1,25,$fyid,$fybh,$xiugai,U('fangyuan/neirong',array('id'=>$fyid)),$zyzs);
					$this->success("设置成功");
				} else {
					$this->error("设置失败");
				}
			} else {
				$this->ytlxm = get_peizhi('yongtu',I('fy_yongtu'),3);
				$pzming = "";
				switch (I('fy_yongtu')) {
					case 1:
						$pzming = "zztplx"; //住宅
						break;
					case 2:
						$pzming = "bstplx"; //别墅
						break;
					case 3:
						$pzming = "sptplx"; //商铺
						break;
					case 4:
						$pzming = "cktplx"; //仓库
						break;
					case 5:
						$pzming = "chftplx"; //厂房
						break;
					case 6:
						$pzming = "tdtplx"; //土地
						break;
					case 7:
						$pzming = "chktplx"; //车库
						break;
					case 8:
						$pzming = "xzltplx"; //写字楼
						break;
					default:
						$pzming = "zztplx";
						break;
				}
				$this->tpleixing = get_peizhi($pzming,0,1);
				$this->display();// 输出模板
			}
		}

		//房源日志
		public function rizhi(){
			if (I('is_ajax')) {
				/*权限控制开始*/
				$condition = "e.gongsiid=".session('gongsiid');
				$x = _rbac_lists_where(252,0);
				if ($x && $x != "all" && $x != "me") {
					$condition .= " and e.bumen in ({$x})";
				} elseif ($x == "me") {
					$condition .= " and e.id=".session('uid');
				} elseif ($x == false) {
					$condition .= " and e.id=0";
				}
				$is_rbac = _rbac_node_show(255);
				if (!$is_rbac) {
					$condition .= " and a.cz_type <> 7";
				}
				/*权限控制结束*/
				$sousuo = I('sousuo');
				$zy_type = I('zy_type');
				$zylxs = "1,9,13,14";
				$zylxs1 = explode(",",$zylxs);
				if (in_array($zy_type,$zylxs1)) {
					$condition .= " and a.zy_type = ".$zy_type;
				} else {
					$condition .= " and a.zy_type in (".$zylxs.")";
				}
				$shijian = I('shijian');
				if ($shijian) {
					$time_s = explode(' - ',$shijian);
					$time_s1 = strtotime($time_s[0]);
					$time_s2 = strtotime($time_s[1])+86400;
					$condition .= " and a.addtime>=".$time_s1." and a.addtime<".$time_s2;
				}
				if ($sousuo) {
					$condition .= " and (e.pinyinjs like '%$sousuo%' or e.ygmingcheng like '%$sousuo%' or a.zy_bianhao like '%$sousuo%' or a.zy_remark like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$rzpx = "order by a.".$field." ".$order;
				} else {
					$rzpx = "order by a.addtime desc";
				}
				$Model = new \Think\Model();
				$count = $Model->query("select count(*) from __RIZHI__ a join __YONGHU__ e on a.uid=e.id where {$condition}");
				$Page = new \Think\Page($count['0']['count(*)'],$limit);
				$list = "select a.*,e.ygmingcheng,e.bumen from __RIZHI__ a join __YONGHU__ e on a.uid=e.id where {$condition} ".$rzpx." limit ".$Page->firstRow.','.$Page->listRows;
				$data = $Model->query($list);
				foreach ($data as $key => $value) {
					switch ($value['zy_type']) {
						case '1':
							$fyb = M('fangyuan');
							$field = "zhuangtai,weihurenid";
							break;
						case '9':
							$fyb = M('ysfangyuan');
							$field = "xfguwens";
							break;
						case '13':
							$fyb = M('fyxiezilou');
							$field = "zhuangtai,weihurenid";
							break;
						case '14':
							$fyb = M('fyshangpu');
							$field = "zhuangtai,weihurenid";
							break;
						default:
							$fyb = "";
							break;
					}
					if ($fyb) {
						$fy = $fyb->where(array('bianhao'=>$value['zy_bianhao']))->field($field)->find();
					}
					if ($value['zy_type'] == 9) {
						$xfguwens = explode(",",$fy['xfguwens']);
						foreach ($xfguwens as $k => $val) {
							$xfgw = _rbac_btn_show(272,0,$val);
							if ($xfgw) {
								$xfgw1 = 1;
							}
						}
						$data[$key]['fyxqqx'] = $xfgw1 == 1 ? '1' : '0';
					} else {
						$data[$key]['fyxqqx'] = _rbac_btn_show(75,$fy['zhuangtai'],$fy['weihurenid']) == true ? '1' : '0';
					}
					switch ($value['cz_type']) {
						case '1':
							$data[$key]['cz_type'] = "新增";
							break;
						case '2':
							$data[$key]['cz_type'] = "基础修改";
							break;
						case '3':
							$data[$key]['cz_type'] = "抓取";
							break;
						case '4':
							$data[$key]['cz_type'] = "收藏";
							break;
						case '5':
							$data[$key]['cz_type'] = "写跟进";
							break;
						case '6':
							$data[$key]['cz_type'] = "设置全景";
							break;
						case '7':
							$data[$key]['cz_type'] = "核心修改";
							break;
						case '8':
							$data[$key]['cz_type'] = "删除";
							break;
						case '9':
							$data[$key]['cz_type'] = "变更维护人";
							break;
						case '10':
							$data[$key]['cz_type'] = "变更收钥部门";
							break;
						case '11':
							$data[$key]['cz_type'] = "变更收钥人";
							break;
						case '12':
							$data[$key]['cz_type'] = "上传图片";
							break;
						case '13':
							$data[$key]['cz_type'] = "删除图片";
							break;
						case '14':
							$data[$key]['cz_type'] = "封开盘";
							break;
						case '16':
							$data[$key]['cz_type'] = "写提醒";
							break;
						case '17':
							$data[$key]['cz_type'] = "写带看";
							break;
						case '18':
							$data[$key]['cz_type'] = "审核";
							break;
						case '20':
							$data[$key]['cz_type'] = "下载图片";
							break;
						case '24':
							$data[$key]['cz_type'] = "变更状态";
							break;
						case '25':
							$data[$key]['cz_type'] = "设置图片类型";
							break;
						case '28':
							$data[$key]['cz_type'] = "设置外网同步";
							break;
						case '29':
							$data[$key]['cz_type'] = "设置推荐";
							break;
						case '30':
							$data[$key]['cz_type'] = "设置图片封面";
							break;
						case '31':
							$data[$key]['cz_type'] = "设置视频";
							break;
						default:
							$data[$key]['cz_type'] = "——";
							break;
					}
					$data[$key]['bumen'] = zym($value['bumen'],6);
					$data[$key]['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();// 输出模板
			}
		}

	}