<?php

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

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

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

		//添加客源
		public function addKeyuan(){
			$is_rbac = _rbac_btn_show(68,0);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$dianhua = I('dianhua');
				$cfky = M('kyjinrong')->where(array('dianhua'=>$dianhua))->getField('dianhua');
				if ($cfky) {
					$this->error('客源已存在！');
				}
				$zijinxq = I('zijinxq');
				$renshu = I('renshu');
				$qqhao = I('qqhao');
				$youxiang = I('youxiang');
				$sfzheng = I('sfzheng');
				$zijinyt = preg_replace("/\s(?=\s)/","\\1",I('zijinyt'));
				$beizhu = preg_replace("/\s(?=\s)/","\\1",I('beizhu'));
				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}$/",$dianhua)) {
					$this->error('手机请输入正确的手机号码或电话号码！');
				}
				if (!preg_match("/^([1-9][0-9]{0,4})$|^(1[0]{5})$/",$zijinxq)) {
					$this->error('资金需求请输入＞0≤十亿的整数！');
				}
				if (!preg_match("/^$|^([1-9][0-9]{0,3})$|^(1[0]{4})$/",$renshu)) {
					$this->error('人数请输入＞0≤一万的整数！');
				}
				if (!preg_match("/^$|^[1-9][0-9]{4,}$/",$qqhao)) {
					$this->error('QQ请输入正确的QQ号！');
				}
				if (!preg_match("/^$|^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/",$youxiang)) {
					$this->error('邮箱请输入正确的邮箱！');
				}
				if (!preg_match("/^$|^$|^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$|^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/",$sfzheng)) {
					$this->error('身份证请输入正确的身份证号！');
				}
				if (!I('zichan')) {
					$this->error('请输入资产！');
				}
				if (!$zijinyt) {
					$this->error('请输入资金用途！');
				}
				if (!preg_match("/^$|^[\s\S]{0,300}$/",$zijinyt)) {
					$this->error('资金用途只能输入300个字符！');
				}
				if (!preg_match("/^$|^[\s\S]{0,300}$/",$beizhu)) {
					$this->error('备注只能输入300个字符！');
				}
				$bhao = 'JR';
				$bh = M('bianhao')->where(array('id'=>2))->setInc('bianhao');
				$bh1 = M('bianhao')->where(array('id'=>2))->getField('bianhao');
				if (I('jiqie')) {
					$jiqie = 1;
				} else {
					$jiqie = 0;
				}
				$zc1 = array_keys(I('zichan'));
				$zc2 = implode(',',$zc1);
				$data['gongsiid'] = session('gongsiid');
				$data['zhuangtai'] = get_options('chengjiao_options','kysike_zhuangtai');
				$data['kydengji'] = I('kydengji');
				$data['xqbianhao'] = $bhao.$bh1;
				$data['zijinxq'] = $zijinxq;
				$data['daikuanfs'] = I('daikuanfs');
				$data['renshu'] = $renshu;
				$data['zichan'] = $zc2;
				$data['zijinyt'] = $zijinyt;
				$data['xuyaosj'] = date("Y-m-d",I('xuyaosj'));
				$data['beizhu'] = $beizhu;
				$data['jiqie'] = $jiqie;
				$data['gtjieduan'] = I('gtjieduan');
				$data['khlaiyuan'] = I('khlaiyuan');
				$data['khxingming'] = I('khxingming');
				$data['dianhua'] = $dianhua;
				$data['sfzheng'] = $sfzheng;
				$data['qqhao'] = $qqhao;
				$data['youxiang'] = $youxiang;
				$data['weixin'] = I('weixin');
				$data['chexing'] = I('chexing');
				$data['jtgongju'] = I('jtgongju');
				$data['guoji'] = I('guoji');
				$data['minzu'] = I('minzu');
				$data['xflinian'] = I('xflinian');
				$data['kehulx'] = I('kehulx');
				$data['weihuren'] = session('ygmingcheng');
				$data['weihurenid'] = session('uid');
				$data['lururenid'] = session('uid');
				$data['lurusj'] = time();
				$data['xiugaisj'] = time();
				$data['zhgjsj'] = time();
				$isok = M('kyjinrong')->add($data);
				if ($isok) {
					if (I('khxqid')) {
						$xiugai = "客户需求转入商机中心（金融客源）。";
						$data_khxq['zybh'] = $data['xqbianhao'];
						$data_khxq['zylj'] = U('kyjinrong/neirong',array('id'=>$isok));
						$data_khxq['zrsjzx'] = "已被".zym(session('uid'),5)."转入商机中心（金融客源）。";
						M('fabufy')->where(array("id"=>I('khxqid')))->save($data_khxq);
						data_rizhi(5,1,$isok,$data['xqbianhao'],$xiugai,U('kyjinrong/neirong',array('id'=>$isok)),"外网客户");
					} else {
						$xiugai = "添加了一条客源数据。";
						data_fkywhr(18,$isok,session('uid'));
					}
					data_rizhi(18,1,$isok,$data['xqbianhao'],$xiugai,U('kyjinrong/neirong',array('id'=>$isok)),"金融客源");
					$this->success('已添加，请等待审核！');
				} else {
					$this->error('添加失败！');
				}
			} else {
				$this->zichan = get_peizhi('zichan',0,1);
				$this->daikuanfs = get_peizhi('daikuanfs',0,1);
				$this->kehulx = get_peizhi('yezhulx',0,1);
				$this->laiyuan = get_peizhi('laiyuan',0,1);
				$this->xflinian = get_peizhi('xflinian',0,1);
				$this->guoji = get_peizhi('guoji',0,1);
				$this->minzu = get_peizhi('minzu',0,1);
				$this->kydengji = get_peizhi('kydengji',0,1);
				$this->khzhuangtai = get_peizhi('khzhuangtai',0,1);
				$this->jtgongju = get_peizhi('jtgongju',0,1);
				$this->gtjieduan = get_peizhi('gtjieduan',0,1);
				$this->display();
			}
		}

		//客源内容页
		public function neirong(){
			$id = I('id');
			$kybh = I('xqbianhao');
			if ($id) {
				$keyuan = M('kyjinrong')->where(array('id'=>$id))->find();
			} elseif ($kybh) {
				$keyuan = M('kyjinrong')->where(array('xqbianhao'=>$kybh))->find();
			}
			if (!$keyuan) {
				$this->error('未找到客源！');
			}
			$is_rbac = _rbac_btn_show(75,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$is_rbacfck = _rbac_node_show(865);
			if (!$is_rbacfck && ($keyuan['fpck'] != 2)) {
				$this->redirect('Index/error');
			}
			$options_arr = get_options('chengjiao_options',0);
			$this->options_arr = $options_arr;
			$this->assign('keyuan',$keyuan);
			$this->lrdh = zym($keyuan['lururenid'],14);
			$this->whdh = zym($keyuan['weihurenid'],14);
			$this->fpdh = zym($keyuan['fengpanrenid'],14);
			$id = I('id');
			$iskzq = 1;
			$kywxzt = get_options('chengjiao_options','kyfengpan_zhuangtai');
			if (!in_array($keyuan['zhuangtai'],$kywxzt)) {
				$kywhrs = M('fkywhr')->where(array('zylx'=>18,'id'=>$keyuan['id']))->select();
				foreach ($kywhrs as $key => $value) {
					if ($value['whrid'] == session('uid')) {
						$iskzq = 2;
					}
				}
			}
			if ($keyuan['zichan']) {
				$Model = new \Think\Model();
				$condition1 = "pzming = 'zichan' and lxid in (".$keyuan['zichan'].")";
				$zichan1 = $Model->query("select * from __PEIZHI__ where {$condition1} order by xsshunxu asc");
				$zichan2 = array();
				foreach ($zichan1 as $key => $value) {
					$zichan2[$key] = $value['lxming'];
				}
				$this->zichan = implode('；',$zichan2);
			}
			$this->iskzq = $iskzq;
			$this->guoji = get_peizhi('guoji',$keyuan['guoji'],3);
			$this->minzu = get_peizhi('minzu',$keyuan['minzu'],3);
			$this->kehulx = get_peizhi('yezhulx',$keyuan['kehulx'],3);
			$this->jtgongju = get_peizhi('jtgongju',$keyuan['jtgongju'],3);
			$this->kydengji = get_peizhi('kydengji',$keyuan['kydengji'],3);
			$this->xflinian = get_peizhi('xflinian',$keyuan['xflinian'],3);
			$this->khlaiyuan = get_peizhi('laiyuan',$keyuan['khlaiyuan'],3);
			$this->daikuanfs = get_peizhi('daikuanfs',$keyuan['daikuanfs'],3);
			$this->gtjieduan = get_peizhi('gtjieduan',$keyuan['gtjieduan'],3);
			$today = "kyjr".date("m-d");
			if (!cookie($today)) {
				cookie($today,$id,3600*24);
			} else {
				$value = cookie($today);
				$val = $value.','.$id;
				cookie($today,$val,3600*24);
			}
			$this->kygenjin = M('kygenjin')->where(array('kylx'=>18,'kyid'=>$keyuan['id']))->order('gjshijian desc')->select();
			$this->kytixing = M('kytixing')->where(array('kylx'=>18,'kyid'=>$keyuan['id']))->order('txshijian desc')->select();
			$this->volist = M('rizhi')->where(array('zy_type'=>18,'zy_bianhao'=>$keyuan['xqbianhao']))->order('id desc')->select();
			$this->display();
		}

		// 客源审核
		public function kyshenhe(){
			$id = I('id');
			$ky1 = M('kyjinrong')->where(array('id'=>$id))->field('weihurenid,isdel')->find();
			$is_rbac = _rbac_btn_show(955,0,$ky1['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($ky1['isdel'] == 1) {
				$this->error('客源已删除！');
			}
			if (IS_POST) {
				$shtype = I('shtype');
				$cfsh = M('kyjinrong')->where(array('id'=>$id))->getField('shtype');
				if ($cfsh == 1 || $cfsh == 2){
					$this->error('已审核！');
				}
				if ($shtype == ""){
					$this->error('请选择审核意见！');
				}
				$isok = M('kyjinrong')->where(array('id'=>$id))->setField('shtype',$shtype);
				if ($isok) {
					$kybh = M('kyjinrong')->where(array('id'=>$id))->getField('xqbianhao');
					if ($shtype == 1) {
						$xiugai = "通过了";
					}
					if ($shtype == 2) {
						$xiugai = "驳回了";
					}
					$xiugai .= $kybh."的添加。";
					data_rizhi(18,18,$id,$kybh,$xiugai,U('kyjinrong/neirong',array('id'=>$id)),"金融客源");
					$this->success('审核成功');
				} else {
					$this->error('审核失败！');
				}
			} else {
				$this->display();
			}
		}

		//更新客源
		public function editKeyuan(){
			$ky1 = M('kyjinrong')->where(array('id'=>I('id')))->find();
			$is_rbac = _rbac_btn_show(79,$ky1['zhuangtai'],$ky1['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($ky1['isdel'] == 1) {
				$this->error('客源已删除！');
			}
			if ($ky1['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if (IS_POST) {
				$zijinxq = I('zijinxq');
				$renshu = I('renshu');
				$qqhao = I('qqhao');
				$youxiang = I('youxiang');
				$sfzheng = I('sfzheng');
				$zijinyt = preg_replace("/\s(?=\s)/","\\1",I('zijinyt'));
				$beizhu = preg_replace("/\s(?=\s)/","\\1",I('beizhu'));
				if (!preg_match("/^([1-9][0-9]{0,4})$|^(1[0]{5})$/",$zijinxq)) {
					$this->error('资金需求请输入＞0≤十亿的整数！');
				}
				if (!preg_match("/^$|^([1-9][0-9]{0,3})$|^(1[0]{4})$/",$renshu)) {
					$this->error('人数请输入＞0≤一万的整数！');
				}
				if (!preg_match("/^$|^[1-9][0-9]{4,}$/",$qqhao)) {
					$this->error('QQ请输入正确的QQ号！');
				}
				if (!preg_match("/^$|^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/",$youxiang)) {
					$this->error('邮箱请输入正确的邮箱！');
				}
				if (!preg_match("/^$|^$|^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$|^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/",$sfzheng)) {
					$this->error('身份证请输入正确的身份证号！');
				}
				if (!preg_match("/^$|^[\s\S]{0,300}$/",$zijinyt)) {
					$this->error('资金用途只能输入300个字符！');
				}
				if (!preg_match("/^$|^[\s\S]{0,300}$/",$beizhu)) {
					$this->error('备注只能输入300个字符！');
				}
				$bhao = 'MK';
				$bh = M('bianhao')->where(array('id'=>2))->setInc('bianhao');
				$bh1 = M('bianhao')->where(array('id'=>2))->getField('bianhao');
				if (I('jiqie')) {
					$jiqie = 1;
				} else {
					$jiqie = 0;
				}
				$zc1 = array_keys(I('zichan'));
				$zc2 = implode(',',$zc1);
				$data['zhuangtai'] = get_options('chengjiao_options','kysike_zhuangtai');
				$data['kydengji'] = I('kydengji');
				$data['xqbianhao'] = $bhao.$bh1;
				$data['zijinxq'] = $zijinxq;
				$data['daikuanfs'] = I('daikuanfs');
				$data['renshu'] = $renshu;
				$data['zichan'] = $zc2;
				$data['zijinyt'] = $zijinyt;
				$data['xuyaosj'] = date("Y-m-d",I('xuyaosj'));
				$data['beizhu'] = $beizhu;
				$data['jiqie'] = $jiqie;
				$data['gtjieduan'] = I('gtjieduan');
				$data['khlaiyuan'] = I('khlaiyuan');
				$data['khxingming'] = I('khxingming');
				$data['sfzheng'] = $sfzheng;
				$data['qqhao'] = $qqhao;
				$data['youxiang'] = $youxiang;
				$data['weixin'] = I('weixin');
				$data['chexing'] = I('chexing');
				$data['jtgongju'] = I('jtgongju');
				$data['guoji'] = I('guoji');
				$data['minzu'] = I('minzu');
				$data['xflinian'] = I('xflinian');
				$data['kehulx'] = I('kehulx');
				$data['xiugaisj'] = time();
				$xiugai = "";
				if ($ky1['khxingming'] != I('khxingming') && ($ky1['khxingming'] || I('khxingming'))) {
					$xiugai .= "客户姓名：[".$ky1['khxingming']."]=>[".I('khxingming')."]；";
				}
				if ($ky1['kehulx'] != I('kehulx') && ($ky1['kehulx'] || I('kehulx'))) {
					$xiugai .= get_xiugai($ky1['kehulx'],I('kehulx'),'yezhulx');
				}
				if ($ky1['khlaiyuan'] != I('khlaiyuan') && ($ky1['khlaiyuan'] || I('khlaiyuan'))) {
					$xiugai .= get_xiugai($ky1['khlaiyuan'],I('khlaiyuan'),'laiyuan');
				}
				if ($ky1['jiqie'] != $jiqie && ($ky1['jiqie'] || $jiqie)) {
					$xin1 = $ky1['xinzheng'] ? "是" : "否";
					$xin2 = $jiqie ? "是" : "否";
					$xiugai .= "急切：[".$xin1."]=>[".$xin2."]；";
				}
				if ($ky1['zijinxq'] != $zijinxq && ($ky1['zijinxq'] || $zijinxq)) {
					$xiugai .= "资金需求：[".$ky1['zijinxq']."万]=>[".$zijinxq."万];";
				}
				if ($ky1['daikuanfs'] != I('daikuanfs') && ($ky1['daikuanfs'] || I('daikuanfs'))) {
					$xiugai .= get_xiugai($ky1['daikuanfs'],I('daikuanfs'),'daikuanfs');
				}
				if ($ky1['renshu'] != $renshu && ($ky1['renshu'] || $renshu)) {
					$xiugai .= "人数：[".$ky1['renshu']."人]=>[".$renshu."人];";
				}
				if ($ky1['zichan'] != $zc2 && ($ky1['zichan'] || $zc2)) {
					if ($ky1['zichan']) {
						$condition1 = "pzming = 'zichan' and lxid in (".$ky1['zichan'].")";
						$zichan1 = $Model->query("select * from __PEIZHI__ where {$condition1} order by xsshunxu asc");
						$kyzc1 = array();
						foreach ($zichan1 AS $key => $val) {
							$kyzc1[] = $val['lxming'];
						}
						$kyzcs1 = implode("；",$kyzc1);
					}
					if ($zc2) {
						$condition2 = "pzming = 'zichan' and lxid in (".$zc2.")";
						$zichan2 = $Model->query("select * from __PEIZHI__ where {$condition2} order by xsshunxu asc");
						$kyzc2 = array();
						foreach ($zichan2 AS $key => $val) {
							$kyzc2[] = $val['lxming'];
						}
						$kyzcs2 = implode("；",$kyzc2);
					}
					$xiugai .= "资产：[".$kyzcs1."]=>[".$kyzcs2."]；";
				}
				if ($ky1['zijinyt'] != $zijinyt && ($ky1['zijinyt'] || $zijinyt)) {
					$xiugai .= "资金用途：[".$ky1['zijinyt']."]=>[".$zijinyt."]；";
				}
				if ($ky1['xuyaosj'] != I('xuyaosj') && ($ky1['xuyaosj'] || I('xuyaosj'))) {
					if ($ky1['xuyaosj']) {
						$xuyaosj = date('Y-m-d',$ky1['xuyaosj']);
					}
					$xiugai .= "需要时间：[".$xuyaosj."]=>[".I('xuyaosj')."]；";
				}
				if ($ky1['gtjieduan'] != I('gtjieduan') && ($ky1['gtjieduan'] || I('gtjieduan'))) {
					$xiugai .= get_xiugai($ky1['gtjieduan'],I('gtjieduan'),'gtjieduan');
				}
				if ($ky1['guoji'] != I('guoji') && ($ky1['guoji'] || I('guoji'))) {
					$xiugai .= get_xiugai($ky1['guoji'],I('guoji'),'guoji');
				}
				if ($ky1['minzu'] != I('minzu') && ($ky1['minzu'] || I('minzu'))) {
					$xiugai .= get_xiugai($ky1['minzu'],I('minzu'),'minzu');
				}
				if ($ky1['xflinian'] != I('xflinian') && ($ky1['xflinian'] || I('xflinian'))) {
					$xiugai .= get_xiugai($ky1['xflinian'],I('xflinian'),'xflinian');
				}
				if ($ky1['kydengji'] != I('kydengji') && ($ky1['kydengji'] || I('kydengji'))) {
					$xiugai .= get_xiugai($ky1['kydengji'],I('kydengji'),'kydengji');
				}
				if ($ky1['sfzheng'] != I('sfzheng') && ($ky1['sfzheng'] || I('sfzheng'))) {
					$xiugai .= "身份证：[".$ky1['sfzheng']."]=>[".I('sfzheng')."]；";
				}
				if ($ky1['qqhao'] != I('qqhao') && ($ky1['qqhao'] || I('qqhao'))) {
					$xiugai .= "QQ号：[".$ky1['qqhao']."]=>[".I('qqhao')."]；";
				}
				if ($ky1['youxiang'] != I('youxiang') && ($ky1['youxiang'] || I('youxiang'))) {
					$xiugai .= "邮箱：[".$ky1['youxiang']."]=>[".I('youxiang')."]；";
				}
				if ($ky1['weixin'] != I('weixin') && ($ky1['weixin'] || I('weixin'))) {
					$xiugai .= "微信：[".$ky1['weixin']."]=>[".I('weixin')."]；";
				}
				if ($ky1['jtgongju'] != I('jtgongju') && ($ky1['jtgongju'] || I('jtgongju'))) {
					$xiugai .= get_xiugai($ky1['jtgongju'],I('jtgongju'),'jtgongju');
				}
				if ($ky1['chexing'] != I('chexing') && ($ky1['chexing'] || I('chexing'))) {
					$xiugai .= "车型：[".$ky1['chexing']."]=>[".I('chexing')."]；";
				}
				if ($ky1['beizhu'] != I('beizhu') && ($ky1['beizhu'] || I('beizhu'))) {
					$xiugai .= "备注：[".$ky1['beizhu']."]=>[".I('beizhu')."]；";
				}
				$isok = M('kyjinrong')->where(array('id'=>$id))->save($data);
				if ($isok) {
					data_rizhi(18,2,$id,$ky1['xqbianhao'],$xiugai,U('kyjinrong/neirong',array('id'=>$id)),"金融客源");
					if ($ky1['shtype'] == 2) {
						M('kyjinrong')->where(array('id'=>$id))->setField('shtype',3);
						$this->success('已更新，请等待审核！');
					} else {
						$this->success('更新成功');
					}
				} else {
					$this->error('更新失败！');
				}
			} else {
				$this->keyuan = $ky1;
				$this->zichan = get_peizhi('zichan',0,1);
				$this->daikuanfs = get_peizhi('daikuanfs',0,1);
				$this->kehulx = get_peizhi('yezhulx',0,1);
				$this->laiyuan = get_peizhi('laiyuan',0,1);
				$this->xflinian = get_peizhi('xflinian',0,1);
				$this->guoji = get_peizhi('guoji',0,1);
				$this->minzu = get_peizhi('minzu',0,1);
				$this->kydengji = get_peizhi('kydengji',0,1);
				$this->khzhuangtai = get_peizhi('khzhuangtai',0,1);
				$this->jtgongju = get_peizhi('jtgongju',0,1);
				$this->gtjieduan = get_peizhi('gtjieduan',0,1);
				$this->zichan2 = explode(",", $ky1['zichan']);
				$this->display();
			}
		}

		//变更状态
		public function bgkyzt(){
			$id = I('id');
			$keyuan = M('kyjinrong')->where(array('id'=>I('id')))->find();
			$is_rbac = _rbac_btn_show(697,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($keyuan['isdel'] == 1) {
				$this->error('客源已删除！');
			}
			if ($keyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($keyuan['shtype'] == 2) {
				$this->error('客源已驳回！');
			}
			$kycjzt = get_options('chengjiao_options','kychengjiao_zhuangtai');
			if ($keyuan['zhuangtai'] == $kycjzt){
				$this->error('客源已成交！');
			}
			if (IS_POST) {
				$data['zhuangtai'] = I('zhuangtai');
				$data['xiugaisj'] = time();
				$isok = M('kyjinrong')->where(array('id'=>$keyuan['id']))->save($data);
				if ($isok) {
					$xiugai = "变更".get_xiugai($keyuan['zhuangtai'],I('zhuangtai'),'khzhuangtai');
					data_rizhi(18,24,$keyuan['id'],$keyuan['xqbianhao'],$xiugai,U('kyjinrong/neirong',array('id'=>$keyuan['id'])),"金融客源");
					$this->success('变更成功');
				} else {
					$this->error('变更失败！');
				}
			} else {
				$this->kyzt = $keyuan['zhuangtai'];
				$this->zhuangtai = get_peizhi('khzhuangtai',0,1);
				$this->display();
			}
		}

		//变更维护人
		public function bgwhr(){
			$keyuan = M('kyjinrong')->where(array('id'=>I('id')))->find();
			$is_rbac = _rbac_btn_show(89,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($keyuan['isdel'] == 1) {
				$this->error('客源已删除！');
			}
			if ($keyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($keyuan['shtype'] == 2) {
				$this->error('客源已驳回！');
			}
			if (IS_POST) {
				$ysyr = M('yonghu')->where(array('id'=>$keyuan['weihurenid']))->getField('ygmingcheng');
				$xsyr = M('yonghu')->where(array('id'=>I('weihurenid')))->getField('ygmingcheng');
				$data['weihurenid'] = I('weihurenid');
				$data['weihuren'] = $xsyr;
				$data['xiugaisj'] = time();
				$isok = M("kyjinrong")->where(array('id'=>$keyuan['id']))->save($data);
				if ($isok){
					data_fkywhr(18,$keyuan['id'],I('weihurenid'));
					$xiugai = "变更维护人：[".$ysyr."]=>[".$xsyr."]";
					data_rizhi(18,9,$keyuan['id'],$keyuan['xqbianhao'],$xiugai,U('kyjinrong/neirong',array('id'=>$keyuan['id'])),"金融客源");
					$this->success('修改成功');
				}else{
					$this->error('修改失败！');
				}
			} else {
				$this->weihu=M('Yonghu')->where(array('id'=>$keyuan['weihurenid']))->getField('ygmingcheng');
				$this->display();
			}
		}

		//查看客户详细信息
		public function ckkhxxxx(){
			$keyuan = M('kyjinrong')->where(array('id'=>I('id')))->find();
			$is_rbac = _rbac_btn_show(440,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$is_rbacfdh = _rbac_node_show(864);
			if ($is_rbacfdh || ($keyuan['fpdh'] == 2)) {
				$this->is_rbacfdh=1;
			}
			$id = I('id');
			$Model = new \Think\Model();
			if ($keyuan['khaihao']) {
				$condition1 = "pzming = 'khaihao' and lxid in (".$keyuan['khaihao'].")";
				$khaihao1 = $Model->query("select * from __PEIZHI__ where {$condition1} order by xsshunxu asc");
				$khaihao2 = array();
				foreach ($khaihao1 as $key => $value) {
					$khaihao2[$key] = $value['lxming'];
				}
				$this->khaihao = implode('；',$khaihao2);
			}
			if ($keyuan['khjtzcph']) {
				$condition2 = "pzming = 'khjtzcph' and lxid in (".$keyuan['khjtzcph'].")";
				$khjtzcph1 = $Model->query("select * from __PEIZHI__ where {$condition2} order by xsshunxu asc");
				$khjtzcph2 = array();
				foreach ($khjtzcph1 as $key => $value) {
					$khjtzcph2[$key] = $value['lxming'];
				}
				$this->khjtzcph = implode('；',$khjtzcph2);
			}
			if ($keyuan['khjqzdsx']) {
				$condition3 = "pzming = 'khjqzdsx' and lxid in (".$keyuan['khjqzdsx'].")";
				$khjqzdsx1 = $Model->query("select * from __PEIZHI__ where {$condition3} order by xsshunxu asc");
				$khjqzdsx2 = array();
				foreach ($khjqzdsx1 as $key => $value) {
					$khjqzdsx2[$key] = $value['lxming'];
				}
				$this->khjqzdsx = implode('；',$khjqzdsx2);
			}
			$this->keyuan = $keyuan;
			$this->khzhiwu = get_peizhi('khzhiwu',$keyuan['khzhiwu'],3);
			$this->khjiaoyu = get_peizhi('khjiaoyu',$keyuan['khjiaoyu'],3);
			$this->khhunyin = get_peizhi('khhunyin',$keyuan['khhunyin'],3);
			$this->khshouru = get_peizhi('khshouru',$keyuan['khshouru'],3);
			$this->khjzquyu = get_peizhi('khjzquyu',$keyuan['khjzquyu'],3);
			$this->khgzquyu = get_peizhi('khgzquyu',$keyuan['khgzquyu'],3);
			$this->khnianling = get_peizhi('khnianling',$keyuan['khnianling'],3);
			$this->khjzmianji = get_peizhi('khjzmianji',$keyuan['khjzmianji'],3);
			$this->khsjpinpai = get_peizhi('khsjpinpai',$keyuan['khsjpinpai'],3);
			$this->khsshangye = get_peizhi('khsshangye',$keyuan['khsshangye'],3);
			$this->display();
		}

		//修改客户详细信息
		public function xgkhxxxx(){
			$keyuan = M('kyjinrong')->where(array('id'=>I('id')))->find();
			$is_rbac = _rbac_btn_show(438,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($keyuan['isdel'] == 1) {
				$this->error('客源已删除！');
			}
			if ($keyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($keyuan['shtype'] == 2) {
				$this->error('客源已驳回！');
			}
			$is_rbacfdh = _rbac_node_show(864);
			if ($is_rbacfdh || ($keyuan['fpdh'] == 2)) {
				$this->is_rbacfdh=1;
			}
			if (IS_POST) {
				if ($is_rbacfdh || ($keyuan['fpdh'] == 2)) {
					$dianhua = I('dianhua');
					$cfky = M('kyjinrong')->where(array('dianhua'=>$dianhua,'id'=>array('neq',I('id'))))->getField('dianhua');
					if ($cfky) {
						$this->error('客源已存在！');
					}
					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}$/",$dianhua)) {
						$this->error('联系方式请输入正确的手机号码或电话号码！');
					}
					$data['dianhua'] = $dianhua;
				}
				$ah1 = array_keys(I('khaihao'));
				$ah2 = implode(',',$ah1);
				$data['khaihao'] = $ah2;
				$ph1 = array_keys(I('khjtzcph'));
				$ph2 = implode(',',$ph1);
				$data['khjtzcph'] = $ph2;
				$sx1 = array_keys(I('khjqzdsx'));
				$sx2 = implode(',',$sx1);
				$data['khjqzdsx'] = $sx2;
				$data['khzhiwu'] = I('khzhiwu');
				$data['khbeizhu'] = I('khbeizhu');
				$data['khjiaoyu'] = I('khjiaoyu');
				$data['khhunyin'] = I('khhunyin');
				$data['khshouru'] = I('khshouru');
				$data['khjzquyu'] = I('khjzquyu');
				$data['khgzquyu'] = I('khgzquyu');
				$data['khnianling'] = I('khnianling');
				$data['khjzxiaoqu'] = I('khjzxiaoqu');
				$data['khjzmianji'] = I('khjzmianji');
				$data['khsjpinpai'] = I('khsjpinpai');
				$data['khsshangye'] = I('khsshangye');
				$data['khsfbeizhu'] = I('khsfbeizhu');
				$data['khsjxinghao'] = I('khsjxinghao');
				$data['khjtchengyuan'] = I('khjtchengyuan');
				$data['xiugaisj'] = time();
				$Model = new \Think\Model();
				$xiugai = "";
				if ($is_rbacfdh || ($keyuan['fpdh'] == 2)) {
					if ($keyuan['dianhua'] != $dianhua && ($keyuan['dianhua'] || $dianhua)) {
						$xiugai .= "手机：[".$keyuan['dianhua']."]=>[".$dianhua."]；";
					}
				}
				if (I('khnianling') != $keyuan['khnianling'] && ($keyuan['khnianling'] || I('khgzquyu'))) {
					$xiugai .= get_xiugai($keyuan['khnianling'],I('khnianling'),'khnianling');
				}
				if (I('khjiaoyu') != $keyuan['khjiaoyu'] && ($keyuan['khjiaoyu'] || I('khjiaoyu'))) {
					$xiugai .= get_xiugai($keyuan['khjiaoyu'],I('khjiaoyu'),'khjiaoyu');
				}
				if (I('khhunyin') != $keyuan['khhunyin'] && ($keyuan['khhunyin'] || I('khhunyin'))) {
					$xiugai .= get_xiugai($keyuan['khhunyin'],I('khhunyin'),'khhunyin');
				}
				if (I('khshouru') != $keyuan['khshouru'] && ($keyuan['khshouru'] || I('khshouru'))) {
					$xiugai .= get_xiugai($keyuan['khshouru'],I('khshouru'),'khshouru');
				}
				if (I('khjzquyu') != $keyuan['khjzquyu'] && ($keyuan['khjzquyu'] || I('khjzquyu'))) {
					$xiugai .= get_xiugai($keyuan['khjzquyu'],I('khjzquyu'),'khjzquyu');
				}
				if (I('khjzmianji') != $keyuan['khjzmianji'] && ($keyuan['khjzmianji'] || I('khjzmianji'))) {
					$xiugai .= get_xiugai($keyuan['khjzmianji'],I('khjzmianji'),'khjzmianji');
				}
				if ($keyuan['khjzxiaoqu'] != I('khjzxiaoqu') && ($keyuan['khjzxiaoqu'] || I('khjzxiaoqu'))) {
					$xiugai .= "居住楼盘：[".$keyuan['khjzxiaoqu']."]=>[".I('khjzxiaoqu')."]；";
				}
				if (I('khsjpinpai') != $keyuan['khsjpinpai'] && ($keyuan['khsjpinpai'] || I('khsjpinpai'))) {
					$xiugai .= get_xiugai($keyuan['khsjpinpai'],I('khsjpinpai'),'khsjpinpai');
				}
				if ($keyuan['khsjxinghao'] != I('khsjxinghao') && ($keyuan['khsjxinghao'] || I('khsjxinghao'))) {
					$xiugai .= "手机型号：[".$keyuan['khsjxinghao']."]=>[".I('khsjxinghao')."]；";
				}
				if (I('khgzquyu') != $keyuan['khgzquyu'] && ($keyuan['khgzquyu'] || I('khgzquyu'))) {
					$xiugai .= get_xiugai($keyuan['khgzquyu'],I('khgzquyu'),'khgzquyu');
				}
				if (I('khsshangye') != $keyuan['khsshangye'] && ($keyuan['khsshangye'] || I('khsshangye'))) {
					$xiugai .= get_xiugai($keyuan['khsshangye'],I('khsshangye'),'khsshangye');
				}
				if (I('khzhiwu') != $keyuan['khzhiwu'] && ($keyuan['khzhiwu'] || I('khzhiwu'))) {
					$xiugai .= get_xiugai($keyuan['khzhiwu'],I('khzhiwu'),'khzhiwu');
				}
				if ($keyuan['khsfbeizhu'] != I('khsfbeizhu') && ($keyuan['khsfbeizhu'] || I('khsfbeizhu'))) {
					$xiugai .= "身份备注：[".$keyuan['khsfbeizhu']."]=>[".I('khsfbeizhu')."]；";
				}
				if ($keyuan['khjtchengyuan'] != I('khjtchengyuan') && ($keyuan['khjtchengyuan'] || I('khjtchengyuan'))) {
					$xiugai .= "家庭成员：[".$keyuan['khjtchengyuan']."]=>[".I('khjtchengyuan')."]；";
				}
				if ($keyuan['khaihao'] != $ah2 && ($keyuan['khaihao'] || $ah2)) {
					if ($keyuan['khaihao']) {
						$condition1 = "pzming = 'khaihao' and lxid in (".$keyuan['khaihao'].")";
						$khaihao1 = $Model->query("select * from __PEIZHI__ where {$condition1} order by xsshunxu asc");
						$khahsz1 = array();
						foreach ($khaihao1 AS $key => $val) {
							$khahsz1[] = $val['lxming'];
						}
						$khahs1 = implode("；",$khahsz1);
					}
					if ($ah2) {
						$condition2 = "pzming = 'khaihao' and lxid in (".$ah2.")";
						$khaihao2 = $Model->query("select * from __PEIZHI__ where {$condition2} order by xsshunxu asc");
						$khahsz2 = array();
						foreach ($khaihao2 AS $key => $val) {
							$khahsz2[] = $val['lxming'];
						}
						$khahs2 = implode("；",$khahsz2);
					}
					$xiugai .= "个人爱好：[".$khahs1."]=>[".$khahs2."]；";
				}
				if ($keyuan['khjtzcph'] != $ph2 && ($keyuan['khjtzcph'] || $ph2)) {
					if ($keyuan['khjtzcph']) {
						$condition3 = "pzming = 'khjtzcph' and lxid in (".$keyuan['khjtzcph'].")";
						$khjtzcph1 = $Model->query("select * from __PEIZHI__ where {$condition3} order by xsshunxu asc");
						$khzcsz1 = array();
						foreach ($khjtzcph1 AS $key => $val) {
							$khzcsz1[] = $val['lxming'];
						}
						$khzcs1 = implode("；",$khzcsz1);
					}
					if ($ph2) {
						$condition4 = "pzming = 'khjtzcph' and lxid in (".$ph2.")";
						$khjtzcph2 = $Model->query("select * from __PEIZHI__ where {$condition4} order by xsshunxu asc");
						$khzcsz2 = array();
						foreach ($khjtzcph2 AS $key => $val) {
							$khzcsz2[] = $val['lxming'];
						}
						$khzcs2 = implode("；",$khzcsz2);
					}
					$xiugai .= "支出偏好：[".$khzcs1."]=>[".$khzcs2."]；";
				}
				if ($keyuan['khjqzdsx'] != $sx2 && ($keyuan['khjqzdsx'] || $sx2)) {
					if ($keyuan['khjqzdsx']) {
						$condition5 = "pzming = 'khjqzdsx' and lxid in (".$keyuan['khjqzdsx'].")";
						$khjqzdsx1 = $Model->query("select * from __PEIZHI__ where {$condition5} order by xsshunxu asc");
						$zdsxsz1 = array();
						foreach ($khjqzdsx1 AS $key => $val) {
							$zdsxsz1[] = $val['lxming'];
						}
						$zdsxs1 = implode("；",$zdsxsz1);
					}
					if ($sx2) {
						$condition6 = "pzming = 'khjqzdsx' and lxid in (".$sx2.")";
						$khjqzdsx2 = $Model->query("select * from __PEIZHI__ where {$condition6} order by xsshunxu asc");
						$zdsxsz2 = array();
						foreach ($khjqzdsx2 AS $key => $val) {
							$zdsxsz2[] = $val['lxming'];
						}
						$zdsxs2 = implode("；",$zdsxsz2);
					}
					$xiugai .= "近期重大事项：[".$zdsxs1."]=>[".$zdsxs2."]；";
				}
				if ($keyuan['khbeizhu'] != I('khbeizhu') && ($keyuan['khbeizhu'] || I('khbeizhu'))) {
					$xiugai .= "备注：[".$keyuan['khbeizhu']."]=>[".I('khbeizhu')."]；";
				}
				$isok = M('kyjinrong')->where(array('id'=>I('id')))->save($data);
				if ($isok){
					data_rizhi(18,7,$keyuan['id'],$keyuan['xqbianhao'],$xiugai,U('kyjinrong/neirong',array('id'=>$keyuan['id'])),"金融客源");
					$this->success('修改成功');
				} else {
					$this->error('修改失败！');
				}
			} else {
				$this->keyuan = $keyuan;
				$this->khaihao = get_peizhi('khaihao',0,1);
				$this->khzhiwu = get_peizhi('khzhiwu',0,1);
				$this->khjiaoyu = get_peizhi('khjiaoyu',0,1);
				$this->khhunyin = get_peizhi('khhunyin',0,1);
				$this->khshouru = get_peizhi('khshouru',0,1);
				$this->khjzquyu = get_peizhi('khjzquyu',0,1);
				$this->khgzquyu = get_peizhi('khgzquyu',0,1);
				$this->khjtzcph = get_peizhi('khjtzcph',0,1);
				$this->khjqzdsx = get_peizhi('khjqzdsx',0,1);
				$this->khnianling = get_peizhi('khnianling',0,1);
				$this->khjzmianji = get_peizhi('khjzmianji',0,1);
				$this->khsjpinpai = get_peizhi('khsjpinpai',0,1);
				$this->khsshangye = get_peizhi('khsshangye',0,1);
				$this->khaihao2 = explode(",", $keyuan['khaihao']);
				$this->khjtzcph2 = explode(",", $keyuan['khjtzcph']);
				$this->khjqzdsx2 = explode(",", $keyuan['khjqzdsx']);
				$this->display();
			}
		}

		//写跟进
		public function genjin(){
			$kyid = I('kyid');
			$keyuan = M('kyjinrong')->where(array('id'=>$kyid))->find();
			$is_rbac = _rbac_btn_show(85,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($keyuan['isdel'] == 1) {
				$this->error('客源已删除！');
			}
			if ($keyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($keyuan['shtype'] == 2) {
				$this->error('客源已驳回！');
			}
			$gjid = I('gjid');
			$kybh = $keyuan['xqbianhao'];
			$gongsiid = session('gongsiid');
			//音频操作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.'/keyuan/'.$kybh.'/';
					$upload->autoSub = false;
					$uplaod->replace = true; //存在同名文件是否是覆盖，默认为false
					$upload->saveName = 'gj'.$gjid;
					//开始上传音频文件
					$info = $upload->upload();
					if (!$info) {
						$this->error($upload->getError());
					} else {
						M('kygenjin')->where(array('kylx'=>18,'id'=>$gjid))->setField(array('gjvoice'=>1));
						data_rizhi(18,5,$gjid,$kybh,"上传跟进语音",U('kyjinrong/neirong',array('id'=>$kyid)),"金融客源");
						$this->success($info);
					}
					break;
				case '2':
					$isok = unlink('./Upload/Genjin/'.$gongsiid.'/keyuan/'.$kybh.'/gj'.$gjid.'.mp3');
					if ($isok) {
						M('kygenjin')->where(array('kylx'=>18,'id'=>$gjid))->setField(array('gjvoice'=>null)); 
					}
					data_rizhi(18,5,$gjid,$kybh,"删除跟进语音",U('kyjinrong/neirong',array('id'=>$kyid)),"金融客源");
					$this->success('删除语音成功！');
					break;
				default:
					break;
			}
			if (IS_POST) {
				$data['kylx'] = 18;
				$data['kyid'] = $kyid;
				$data['kybh'] = $kybh;
				$data['genjinfs'] = I('genjinfs');
				$data['gjneirong'] = I('gjneirong');
				$data['gjshijian'] = strtotime(I('gjshijian'));
				$data['time'] = time();
				$data['gjuid'] = session('uid');
				$data['gongsiid'] = session('gongsiid');
				$isok = M('kygenjin')->add($data);
				if ($isok) {
					data_rizhi(18,5,$isok,$kybh,I('gjneirong'),U('kyjinrong/neirong',array('id'=>$kyid)),"金融客源");
					$data_genjin['zhgjsj'] = time();
					$data_genjin['xiugaisj']=time();
					M('kyjinrong')->where(array('id'=>$kyid))->save($data_genjin);
					$this->success('添加成功');
				} else {
					$this->error('添加失败！');
				}
			} else {
				$this->kybh = $kybh;
				$this->genjinfs = get_peizhi('genjinfs',0,1);
				$this->display();
			}
		}

		//抓取客源
		public function sike(){
			$keyuan = M('kyjinrong')->where(array('id'=>I('id')))->find();
			$is_rbac = _rbac_btn_show(83,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			if ($keyuan['isdel'] == 1) {
				$this->error('客源已删除！');
			}
			if ($keyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($keyuan['shtype'] == 2) {
				$this->error('客源已驳回！');
			}
			$options_arr = get_options('chengjiao_options',0);
			if ($keyuan['zhuangtai'] == $options_arr['kychengjiao_zhuangtai']){
				$this->error('客源已成交！');
			}
			$fywhrs = M('fkywhr')->where(array('zylx'=>2,'id'=>I('id')))->select();
			foreach ($fywhrs as $key => $value) {
				if ($value['whrid'] == session('uid')) {
					$this->error('您不能抓取此客源！');
				}
			}
			$data['zhuangtai'] = $options_arr['kysike_zhuangtai'];
			$data['weihurenid'] = session("uid");
			$data['weihuren'] = session("ygmingcheng");
			$data['xiugaisj'] = time();
			$isok = M('kyjinrong')->where(array('id'=>$keyuan['id']))->save($data);
			if ($isok) {
				M('kyjinrong')->where(array('id'=>$keyuan['id']))->setField('xiugaisj',time());
				data_fkywhr(18,$keyuan['id'],session('uid'));
				$xiugai = session("ygmingcheng")."抓取客源".$keyuan['xqbianhao']."为私客";
				data_rizhi(18,3,$keyuan['id'],$keyuan['xqbianhao'],$xiugai,U('kyjinrong/neirong',array('id'=>$keyuan['id'])),"金融客源");
				$this->success('修改成功');
			} else {
				$this->error('修改失败！');
			}
		}

		//写提醒
		public function tixing(){
			$kyid = I('kyid');
			$keyuan = M('kyjinrong')->where(array('id'=>$kyid))->find();
			$is_rbac = _rbac_btn_show(302,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if ($keyuan['isdel'] == 1) {
				$this->error('客源已删除！');
			}
			if ($keyuan['shtype'] == 3) {
				$this->error('请等待审核！');
			}
			if ($keyuan['shtype'] == 2) {
				$this->error('客源已驳回！');
			}
			if (IS_POST) {
				$kybh = $keyuan['xqbianhao'];
				$data['kylx'] = 18;
				$data['kyid'] = $kyid;
				$data['kybh'] = $kybh;
				$data['txuid'] = I('txuid');
				$data['txshijian'] = strtotime(I('txshijian'));
				$data['txneirong'] = I('txneirong');
				$data['time'] = time();
				$data['adduid'] = session('uid');
				$data['gongsiid'] = session('gongsiid');
				$isok = M('kytixing')->add($data);
				if ($isok) {
					data_rizhi(18,16,$isok,$kybh,I('txneirong'),U('kyjinrong/neirong',array('id'=>$kyid)),"金融客源");
					M('kyjinrong')->where(array('id'=>I('kyid')))->setField('xiugaisj',time());
					$this->success('添加成功');
				} else {
					$this->error('添加失败');
				}
			} else {
				$this->display();
			}
		}

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

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

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

		// 恢复客源
		public function huifuky(){
			$id = I('id');
			$keyuan = M('kyjinrong')->where(array('id'=>$id))->find();
			$is_rbac = _rbac_btn_show(771,$keyuan['zhuangtai'],$keyuan['weihurenid']);
			if (!$is_rbac) {
				$this->error("异常错误！");
			}
			if($keyuan['isdel'] == 2){
				$this->error('客源已还原！');
			}
			$this->error('请联系客服（19965783436）获取正式版功能！');
		}

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

	}