<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class FyxgjiluController extends CommonController {
		// 房源修改记录列表
		public function all(){
			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";
				}
				$bumen = I('bumen');
				$sousuo = I('sousuo');
				$shijian = I('shijian');
				$zy_type = I('zy_type');
				if ($bumen) {
					$string = get_bm_sz($bumen,2);
					$condition .= " and e.bumen in ($string)";
				}
				if ($zy_type == 1) {
					$condition .= " and a.zy_type = 1";
				} elseif ($zy_type == 2) {
					$condition .= " and a.zy_type = 2";
				}
				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.ygmingcheng like '%$sousuo%' or e.pinyinjs like '%$sousuo%' or e.dianhua like '%$sousuo%' or a.zy_bianhao like '%$sousuo%')";
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$rzpx = "a.".$field." ".$order;
				} else {
					$rzpx = "a.addtime desc";
				}
				$count = M('rizhi')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id')->where($condition)->count();
				$Page = I('p');
				$data = M('rizhi')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id')->field('a.*,e.ygmingcheng,e.dianhua,e.bumen')->where($condition)->order($rzpx)->page($Page,$limit)->select();
				foreach ($data as $key => $value) {
					$data[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);
					$data[$key]['bmming'] = zym($value['bumen'],6);
					$is_rbacxq = "";
					$zyxqlj = "";
					$zylx = "";
					if ($value['zy_type'] == 1) {
						$zybh = explode("-", $value['zy_bianhao']);
						$zylx = "房源";
						$fy = M('fangyuan')->where(array('bianhao'=>$value['zy_bianhao']))->field('zhuangtai,weihurenid')->find();
						if ($fy) {
							$is_rbacxq = _rbac_btn_show(46,$fy['zhuangtai'],$fy['weihurenid']);
							$zyxqlj = U('fangyuan/neirong',array('bianhao'=>$value['zy_bianhao']));
						}
					} elseif ($value['zy_type'] == 2) {
						$zybh = explode("K", $value['zy_bianhao']);
						$zylx = "客源";
						$ky = M('keyuan')->where(array('xqbianhao'=>$value['zy_bianhao']))->field('zhuangtai,weihurenid')->find();
						if ($ky) {
							$is_rbacxq = _rbac_btn_show(75,$ky['zhuangtai'],$ky['weihurenid']);
							$zyxqlj = U('keyuan1/neirong1',array('xqbianhao'=>$value['zy_bianhao']));
						}
					}
					$data[$key]['zybh'] = $value['zy_bianhao'];
					$data[$key]['zy_bianhao'] = $zybh[1];
					$data[$key]['rbacxq'] = $is_rbacxq ? 1 : 0;
					$data[$key]['zyxqbt'] = $zylx."详情";
					$data[$key]['zyxqlj'] = $zyxqlj;
					$data[$key]['zylx'] = $zylx;
					switch ($value['cz_type']) {
						case 1:
							$cz_type = "新增";
							break;
						case 2:
							$cz_type = "基础修改";
							break;
						case 3:
							$cz_type = "转为私盘";
							break;
						case 4:
							$cz_type = "转为公盘";
							break;
						case 5:
							$cz_type = "写跟进";
							break;
						case 6:
							$cz_type = "设置全景";
							break;
						case 7:
							$cz_type = "核心修改";
							break;
						case 8:
							$cz_type = "删除";
							break;
						case 9:
							$cz_type = "变更维护人";
							break;
						case 10:
							$cz_type = "变更收钥部门";
							break;
						case 11:
							$cz_type = "变更收钥人";
							break;
						case 12:
							$cz_type = "上传图片";
							break;
						case 13:
							$cz_type = "删除图片";
							break;
						case 14:
							$cz_type = "封盘";
							break;
						case 15:
							$cz_type = "开盘";
							break;
						case 16:
							$cz_type = "写提醒";
							break;
						case 17:
							$cz_type = "写带看";
							break;
						case 18:
							$cz_type = "审核";
							break;
						case 20:
							$cz_type = "下载图片";
							break;
						case 24:
							$cz_type = "变更状态";
							break;
						case 25:
							$cz_type = "设置图片类型";
							break;
						case 30:
							$cz_type = "设置图片封面";
							break;
						default:
							$cz_type = "——";
							break;
					}
					$data[$key]['cz_type'] = $cz_type;
					$data[$key]['neirong'] = $value['neirong'] ? $value['neirong'] : "——";
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count,
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->zy_type = I('zy_type');
				$select_categorys = bumen_option( $bumen, 252);
				$this->assign("select_categorys", $select_categorys);
				$this->display();
			}
		}
		//封开盘审核列表
		public function fkpsh(){
			if (I('is_ajax')) {
				/*权限控制开始*/
				$condition = "e.gongsiid=".session('gongsiid');
				$x = _rbac_lists_where(841,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";
				}
				/*权限控制结束*/
				$zylx=I('zylx',0,'int');
				$czlx=I('czlx',0,'int');
				$type=I('type',0,'int');
				$fkplx=I('fkplx',0,'int');
				$sousuo = I('sousuo');
				$shijian = I('shijian');
				if ($zylx) {
					$condition.=" and a.zylx=".$zylx;
				}
				if ($czlx) {
					$condition.=" and a.czlx=".$czlx;
				}
				if ($type) {
					$condition.=" and a.type=".$type;
				}
				if ($fkplx) {
					$condition.=" and a.fkplx=".$fkplx;
				}
				if ($sousuo) {
					$condition .= " and (a.zybh like '%$sousuo%' or e.ygmingcheng like '%$sousuo%' or e.pinyinjs like '%$sousuo%' or e.dianhua like '%$sousuo%')";
				}
				if ($shijian) {
					$time_s = explode(' - ',$shijian);
					$condition .= " and a.addtime>=".strtotime($time_s[0])." and a.addtime<".strtotime($time_s[0])+86400;
				}
				$field = I('field'); //排序字段名
				$order = I('order'); //排序方式
				$limit = I('limit',30,'int'); //每页条数
				$limit = $limit > 150 ? 150 : $limit;
				if ($field && $order) {
					$fkpx = "a.".$field." ".$order;
				} else {
					$fkpx = "a.id desc";
				}
				$count = M('fpkp')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id')->where($condition)->count();
				$Page = I('p');
				$data = M('fpkp')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id')->field('a.*,e.ygmingcheng,e.dianhua,e.bumen')->where($condition)->order($fkpx)->page($Page,$limit)->select();
				foreach ($data as $key => $value) {
					$data[$key]['czrxx'] = $value['ygmingcheng']."/".zym($value['bumen'],6)."（".$value['dianhua']."）";
					$data[$key]['tjrxx'] = zym($value['adduid'],5)."（".zym($value['adduid'],14)."）";
					$data[$key]['addtime'] = $value['addtime'] ? date('Y-m-d H:i:s',$value['addtime']) : "——";
					$data[$key]['endunix'] = $value['endunix'] ? date('Y-m-d',$value['endunix']) : "——";
					switch ($value['type']) {
						case '1':
							$shzt = "已通过";
							break;
						case '2':
							$shzt = "已驳回";
							break;
						case '3':
							$shzt = "审核中";
							break;
						default:
							break;
					}
					switch ($value['czlx']) {
						case '1':
							$caozuo = "封盘";
							switch ($value['fkplx']) {
								case '1':
									$fkpcz = "封电话";
									break;
								case '2':
									if ($value['zylx'] == 2) {$fkpcz = "封地址";}
									break;
								case '3':
									if ($value['zylx'] == 2) {$fkpcz = "封底价";}
									break;
								case '4':
									if ($value['zylx'] == 2) {$fkpcz = "封调取";}
									break;
								case '5':
									$fkpcz = "封查看";
									break;
								default:
									break;
							}
							break;
						case '2':
							$caozuo = "开盘";
							switch ($value['fkplx']) {
								case '1':
									$fkpcz = "开电话";
									break;
								case '2':
									if ($value['zylx'] == 2) {$fkpcz = "开地址";}
									break;
								case '3':
									if ($value['zylx'] == 2) {$fkpcz = "开底价";}
									break;
								case '4':
									if ($value['zylx'] == 2) {$fkpcz = "开调取";}
									break;
								case '5':
									$fkpcz = "开查看";
									break;
								default:
									break;
							}
							break;
						default:
							break;
					}
					switch ($value['zylx']) {
						case '1':
							$ziyuan = "房源";
							break;
						case '2':
							$ziyuan = "客源";
							break;
						default:
							break;
					}
					$data[$key]['shzt'] = $shzt ? $shzt : "——";
					$data[$key]['fkpcz'] = $fkpcz ? $fkpcz : "——";
					$data[$key]['caozuo'] = $caozuo ? $caozuo : "——";
					$data[$key]['ziyuan'] = $ziyuan ? $ziyuan : "——";
					if ($value['type'] == 3) {
						if ($value['zylx'] == 1) {
							$zyb=M('fangyuan');
							$jd=856;
						} else if ($value['zylx'] == 2) {
							$zyb=M('keyuan');
							$jd=857;
						}
						$zyzt=$zyb->where(array('id'=>$value['zyid']))->getField('zhuangtai');
						$is_rbacsh = _rbac_btn_show($jd,$zyzt,$value['uid']);
						$data[$key]['rbacsh'] = $is_rbacsh ? 1 : 0;
					} else {
						$is_rbacrz = _rbac_btn_show(843,0,$value['uid']);
						$data[$key]['rbacrz'] = $is_rbacrz ? 1 : 0;
					}
				}
				$return_data = array(
					'code'=>0,
					'count'=>$count,
					'data'=>$data
				);
				$this->ajaxReturn($return_data);
			} else {
				$this->zylx = I('zylx',0,'int');
				$this->display();
			}
		}
		//封开盘审核
		public function fkpshenhe(){
			$is_rbac1 = _rbac_node_show(842);
			if (!$is_rbac1) {
				$this->redirect('Index/error');
			}
			$id=I('id');
			$fpkp=M('fpkp')->where(array('id'=>$id))->field('uid,zyid,type,fkplx,zylx,czlx')->find();
			if ($fpkp['zylx'] == 1) {
				$zyb=M('fangyuan');
				$jd=856;
			} else if ($fpkp['zylx'] == 2) {
				$zyb=M('keyuan');
				$jd=857;
			}
			$zyzt=$zyb->where(array('id'=>$fpkp['zyid']))->getField('zhuangtai');
			$is_rbac2 = _rbac_btn_show($jd,$zyzt,$fpkp['uid']);
			if (!$is_rbac2) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			}else{
				$this->display();
			}
		}
		//封开盘日志
		public function fkprizhi(){
			$rzlx = I('rzlx',0,'int');
			if ($rzlx != 1 && $rzlx != 2) {
				$rzlx == 1;
			}
			switch ($rzlx) {
				case '1':
					if (I('is_ajax')) {
						/*权限控制开始*/
						$condition = "e.gongsiid=".session('gongsiid');
						$x = _rbac_lists_where(843,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";
						}
						/*权限控制结束*/
						$zylx=I('zylx',0,'int');
						$czlx=I('czlx',0,'int');
						$type=I('type',0,'int');
						$fkplx=I('fkplx',0,'int');
						$sousuo = I('sousuo');
						$shijian = I('shijian');
						if ($zylx) {
							$condition.=" and a.zylx=".$zylx;
						}
						if ($czlx) {
							$condition.=" and a.czlx=".$czlx;
						}
						if ($type) {
							$condition.=" and a.type=".$type;
						}
						if ($fkplx) {
							$condition.=" and a.fkplx=".$fkplx;
						}
						if ($sousuo) {
							$condition .= " and (a.zybh like '%$sousuo%' or e.ygmingcheng like '%$sousuo%' or e.pinyinjs like '%$sousuo%' or e.dianhua like '%$sousuo%')";
						}
						if ($shijian) {
							$time_s = explode(' - ',$shijian);
							$condition .= " and a.addtime>=".strtotime($time_s[0])." and a.addtime<".strtotime($time_s[0])+86400;
						}
						$field = I('field'); //排序字段名
						$order = I('order'); //排序方式
						$limit = I('limit',30,'int'); //每页条数
						$limit = $limit > 150 ? 150 : $limit;
						if ($field && $order) {
							$rzpx = "a.".$field." ".$order;
						} else {
							$rzpx = "a.id desc";
						}
						$count = M('fpkp')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id')->where($condition)->count();
						$Page = I('p');
						$data = M('fpkp')->alias('a')->join('jjrxt_yonghu e on a.uid=e.id')->field('a.*,e.ygmingcheng,e.dianhua,e.bumen')->where($condition)->order($rzpx)->page($Page,$limit)->select();
						foreach ($data as $key => $value) {
							$data[$key]['czrxx'] = $value['ygmingcheng']."/".zym($value['bumen'],6)."（".$value['dianhua']."）";
							$data[$key]['tjrxx'] = zym($value['adduid'],5)."（".zym($value['adduid'],14)."）";
							$data[$key]['shrxx'] = $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]['endunix'] = $value['endunix'] ? date('Y-m-d',$value['endunix']) : "——";
							$data[$key]['shshijian'] = $value['shshijian'] ? date('Y-m-d',$value['shshijian']) : "——";
							switch ($value['type']) {
								case '1':
									$shzt = "已通过";
									break;
								case '2':
									$shzt = "已驳回";
									break;
								case '3':
									$shzt = "审核中";
									break;
								default:
									break;
							}
							switch ($value['czlx']) {
								case '1':
									$caozuo = "封盘";
									switch ($value['fkplx']) {
										case '1':
											$fkpcz = "封电话";
											break;
										case '2':
											if ($value['zylx'] == 2) {$fkpcz = "封地址";}
											break;
										case '3':
											if ($value['zylx'] == 2) {$fkpcz = "封底价";}
											break;
										case '4':
											if ($value['zylx'] == 2) {$fkpcz = "封调取";}
											break;
										case '5':
											$fkpcz = "封查看";
											break;
										default:
											break;
									}
									break;
								case '2':
									$caozuo = "开盘";
									switch ($value['fkplx']) {
										case '1':
											$fkpcz = "开电话";
											break;
										case '2':
											if ($value['zylx'] == 2) {$fkpcz = "开地址";}
											break;
										case '3':
											if ($value['zylx'] == 2) {$fkpcz = "开底价";}
											break;
										case '4':
											if ($value['zylx'] == 2) {$fkpcz = "开调取";}
											break;
										case '5':
											$fkpcz = "开查看";
											break;
										default:
											break;
									}
									break;
								default:
									break;
							}
							switch ($value['zylx']) {
								case '1':
									$ziyuan = "房源";
									break;
								case '2':
									$ziyuan = "客源";
									break;
								default:
									break;
							}
							$data[$key]['shzt'] = $shzt ? $shzt : "——";
							$data[$key]['fkpcz'] = $fkpcz ? $fkpcz : "——";
							$data[$key]['caozuo'] = $caozuo ? $caozuo : "——";
							$data[$key]['ziyuan'] = $ziyuan ? $ziyuan : "——";
							if ($value['type'] == 3) {
								if ($value['zylx'] == 1) {
									$zyb=M('fangyuan');
									$jd=856;
								} else if ($value['zylx'] == 2) {
									$zyb=M('keyuan');
									$jd=857;
								}
								$zyzt=$zyb->where(array('id'=>$value['zyid']))->getField('zhuangtai');
								$is_rbacsh = _rbac_btn_show($jd,$zyzt,$value['uid']);
								$data[$key]['rbacsh'] = $is_rbacsh ? 1 : 0;
							} else {
								$is_rbacrz = _rbac_btn_show(843,0,$value['uid']);
								$data[$key]['rbacrz'] = $is_rbacrz ? 1 : 0;
							}
						}
						$return_data = array(
							'code'=>0,
							'count'=>$count,
							'data'=>$data
						);
						$this->ajaxReturn($return_data);
					} else {
						$this->zylx = I('zylx',0,'int');
						$this->rzlx = 1;
						$this->display();
					}
					break;
				case '2':
					$fkp = M('fpkp')->where(array('id'=>I('id')))->field('shuid,shshijian,remark,type')->find();
					$this->shren = M('Yonghu')->where(array('id'=>$fkp['shuid']))->getField('ygmingcheng');
					$this->shdh = M('Yonghu')->where(array('id'=>$fkp['shuid']))->getField('dianhua');
					$this->fkp = $fkp;
					$this->rzlx = 2;
					$this->display();
					break;
			}
		}
	}