<?php

    /***************************************************************\
    |                                                               |
    |   开单大师 - 专业的房产ERP管理                                  |
    |                                                               |
    |   © 2019 http://www.kaidandashi.com All rights reserved.      |
    |                                                               |
    |   开单大师由淮南市银泰软件科技有限公司提供技术                    |
    |                                                               |
    |   QQ:984784483                                                |
    |                                                               |
    \***************************************************************/

    namespace Admin\Controller;
    use Think\Controller;
    class KyneirongController extends CommonController {
        public function editKeyuan(){
            $ky1=M('keyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(79,$ky1['zhuangtai'],$ky1['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $is_rbacfdh = _rbac_node_show(864);
            if ($is_rbacfdh || ($ky1['fpdh'] == 2)) {
                $is_rbacfdh=1;
                $this->is_rbacfdh=1;
            }
            if (IS_POST) {
                if (session('gongsiid')=="") {
                    $this->error('请重新登录');
                }
                $dianhua=I('dianhua');
                $xqhuxing1=I('xqhuxing1');
                $xqhuxing2=I('xqhuxing2');
                $xqjiage1=I('xqjiage1');
                $xqjiage2=I('xqjiage2');
                $xqmianji1=I('xqmianji1');
                $xqmianji2=I('xqmianji2');
                $louceng1=I('louceng1');
                $louceng2=I('louceng2');
                $fangling1=I('fangling1');
                $fangling2=I('fangling2');
                $qqhao=I('qqhao');
                $youxiang=I('youxiang');
                $sfzheng=I('sfzheng');
                $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]{1})$|^(1[0]{1})$/",$xqhuxing1) || !preg_match("/^([1-9]{1})$|^(1[0]{1})$/",$xqhuxing2)){
                    $this->error('户型请输入＞0≤10的整数！');
                }if ($ky1['mmzl']==1 || $ky1['mmzl']==3) {
                    if(!preg_match("/^([1-9][0-9]{0,4})$|^(1[0]{5})$/",$xqjiage1) || !preg_match("/^([1-9][0-9]{0,4})$|^(1[0]{5})$/",$xqjiage2)){
                        $this->error('价格请输入＞0≤十亿的整数！');
                    }
                } elseif ($ky1['mmzl']==2) {
                    if(!preg_match("/^([1-9][0-9]{0,4})$|^(1[0]{5})$/",$xqjiage1) || !preg_match("/^([1-9][0-9]{0,4})$|^(1[0]{5})$/",$xqjiage2)){
                        $this->error('价格请输入＞0≤十万的整数！');
                    }
                }
                if(!preg_match("/^([1-9][0-9]{0,3})$|^(1[0]{4})$/",$xqmianji1) || !preg_match("/^([1-9][0-9]{0,3})$|^(1[0]{4})$/",$xqmianji2)){
                    $this->error('面积请输入＞0≤一万的整数！');
                }
                $cx1=array_keys(I('chaoxiang'));
                $cx2=implode(',',$cx1);
                if (!$cx2) {
                    $this->error('请选择朝向！');
                }
                $zx1=array_keys(I('zhuangxiu'));
                $zx2=implode(',',$zx1);
                if (!$zx2) {
                    $this->error('请选择装修！');
                }
                $pt1=array_keys(I('peitao'));
                $pt2=implode(',',$pt1);
                if (!$pt2) {
                    $this->error('请选择配套！');
                }
                if(!preg_match("/^$|^([1-9]{1})$|^([1-9][0-9]{1})$|^(1[0-9]{2})$|^(2[0]{2})$/",$louceng1) || !preg_match("/^$|^([1-9]{1})$|^([1-9][0-9]{1})$|^(1[0-9]{2})$|^(2[0]{2})$/",$louceng2)){
                    $this->error('楼层请输入＞0≤200的整数！');
                }
                if(!preg_match("/^$|^([1-9][0-9]{0,2})$|^(1[0]{3})$/",$fangling1) || !preg_match("/^$|^([1-9][0-9]{0,2})$|^(1[0]{3})$/",$fangling2)){
                    $this->error('房龄请输入＞0≤1000的整数！');
                }
                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}$/",$beizhu)){
                    $this->error('备注只能输入300个字符！');
                }
                if(I('jiqie')){
                    $jiqie=1;
                }else{
                    $jiqie=0;
                }
                $data['chaoxiang']=$cx2;
                $data['zhuangxiu']=$zx2;
                $data['peitao']=$pt2;
                $data['jiqie']=$jiqie;
                $data['fukuan']=I('fukuan');
                $data['leixing']=I('leixing');
                $data['gongsiid']=session('gongsiid');
                if ($is_rbacfdh == 1) {
                    $data['khxingming']=I('khxingming');
                    $data['kehulx']=I('kehulx');
                    $data['dianhua']=$dianhua;
                }
                $data['xqyongtu']=I('xqyongtu');
                $data['xqquyu']=I('xqquyu');
                $xqxiaoqus=array_unique(array_filter(explode("；",I('xqxiaoqu'))));
                $xqxiaoqu=implode("；",$xqxiaoqus);
                $data['xqxiaoqu']=$xqxiaoqu;
                $data['xqhuxing1']=$xqhuxing1;
                $data['xqhuxing2']=$xqhuxing2;
                $data['xqjiage1']=$xqjiage1;
                $data['xqjiage2']=$xqjiage2;
                $data['xqmianji1']=$xqmianji1;
                $data['xqmianji2']=$xqmianji2;
                $data['louceng1']=$louceng1;
                $data['louceng2']=$louceng2;
                $data['fangling1']=$fangling1;
                $data['fangling2']=$fangling2;
                $data['xqyuanyin']=I('xqyuanyin');
                $data['khlaiyuan']=I('khlaiyuan');
                $data['sfzheng']=$sfzheng;
                $data['qqhao']=$qqhao;
                $data['guoji']=I('guoji');
                $data['minzu']=I('minzu');
                $data['youxiang']=$youxiang;
                $data['weixin']=I('weixin');
                $data['jtgongju']=I('jtgongju');
                $data['chexing']=I('chexing');
                $data['beizhu']=$beizhu;
                $data['gtjieduan']=I('gtjieduan');
                $data['xflinian']=I('xflinian');
                $data['kydengji']=I('kydengji');
                $data['xiugaisj']=time();
                if ($ky1['jiqie']!=$jiqie && ($ky1['jiqie']==true || $jiqie==true)) {
                    $xin1=$ky1['xinzheng']?"是":"否";
                    $xin2=$jiqie?"是":"否";
                    $xiugai.="急切:[".$xin1."]=>[".$xin2."];";
                }
                if ($ky1['peitao']!=$pt2) {
                    if ($ky1['peitao']) {
                        $condition1="pzming = 'peitao'";
                        $condition1.=" and lxid in (".$ky1['peitao'].")";
                        $peitao1=M('peizhi')->query("select * from __PEIZHI__ where {$condition1}");
                        $goods1 = array();
                        foreach ($peitao1 AS $key => $val)
                        {
                            $goods1[$key]['lxming'] = $val['lxming'];
                            $box1.= ",".$val['lxming'];
                        }
                    }
                    if ($pt2) {
                        $condition2="pzming = 'peitao'";
                        $condition2.=" and lxid in (".$pt2.")";
                        $peitao2=M('peizhi')->query("select * from __PEIZHI__ where {$condition2}");
                        $goods2 = array();
                        foreach ($peitao2 AS $key => $val)
                        {
                            $goods2[$key]['lxming'] = $val['lxming'];
                            $box2.= $val['lxming'].",";
                        }
                    }
                    $xiugai.="配套:[".$box1."]=>[".$box2."];";
                }
                if ($ky1['chaoxiang']!=$cx2) {
                    if ($ky1['chaoxiang']) {
                        $condition3="pzming = 'chaoxiang'";
                        $condition3.=" and lxid in (".$ky1['chaoxiang'].")";
                        $peitao3=M('peizhi')->query("select * from __PEIZHI__ where {$condition3}");
                        $goods3 = array();
                        foreach ($peitao3 AS $key => $val)
                        {
                            $goods3[$key]['lxming'] = $val['lxming'];
                            $box3.= ",".$val['lxming'];
                        }
                    }
                    if ($cx2) {
                        $condition4="pzming = 'chaoxiang'";
                        $condition4.=" and lxid in (".$cx2.")";
                        $peitao4=M('peizhi')->query("select * from __PEIZHI__ where {$condition4}");
                        $goods4 = array();
                        foreach ($peitao4 AS $key => $val)
                        {
                            $goods4[$key]['lxming'] = $val['lxming'];
                            $box4.= $val['lxming'].",";
                        }
                    }
                    $xiugai.="朝向:[".$box3."]=>[".$box4."];";
                }
                if ($ky1['zhuangxiu']!=$zx2) {
                    if ($ky1['zhuangxiu']) {
                        $condition5="pzming = 'zhuangxiu'";
                        $condition5.=" and lxid in (".$ky1['zhuangxiu'].")";
                        $peitao5=M('peizhi')->query("select * from __PEIZHI__ where {$condition5}");
                        $goods5 = array();
                        foreach ($peitao5 AS $key => $val)
                        {
                            $goods5[$key]['lxming'] = $val['lxming'];
                            $box5.= ",".$val['lxming'];
                        }
                    }
                    if ($zx2) {
                        $condition6="pzming = 'zhuangxiu'";
                        $condition6.=" and lxid in (".$zx2.")";
                        $peitao6=M('peizhi')->query("select * from __PEIZHI__ where {$condition6}");
                        $goods6 = array();
                        foreach ($peitao6 AS $key => $val)
                        {
                            $goods6[$key]['lxming'] = $val['lxming'];
                            $box6.= $val['lxming'].",";
                        }
                    }
                    $xiugai.="装修:[".$box5."]=>[".$box6."];";
                }
                if ($is_rbacfdh == 1) {
                    if ($ky1['khxingming']!=I('khxingming') && ($ky1['khxingming']==true || I('khxingming')==true)) {
                        $xiugai.="客户姓名:[".$ky1['khxingming']."]=>[".I('khxingming')."];";
                    }
                    if (I('kehulx')!=$ky1['kehulx'] && ($ky1['kehulx']==true || I('kehulx')==true)) {
                        $xiugai.=get_xiugai($ky1['kehulx'],I('kehulx'),'yezhulx');
                    }
                    if ($ky1['dianhua']!=I('dianhua') && ($ky1['dianhua']==true || I('dianhua')==true)) {
                        $xiugai.="客户电话:[".$ky1['dianhua']."]=>[".I('dianhua')."];";
                    }
                }
                if (I('xqyongtu')!=$ky1['xqyongtu'] && ($ky1['xqyongtu']==true || I('xqyongtu')==true)) {
                    $xiugai.=get_xiugai($ky1['xqyongtu'],I('xqyongtu'),'yongtu');
                }
                if ($ky1['xqquyu']!=I('xqquyu') && ($ky1['xqquyu']==true || I('xqquyu')==true)) {
                    $xiugai.="需求区域:[".$ky1['xqquyu']."]=>[".I('xqquyu')."];";
                }
                if ($ky1['xqxiaoqu']!=I('xqxiaoqu') && ($ky1['xqxiaoqu']==true || I('xqxiaoqu')==true)) {
                    $xiugai.="需求小区:[".$ky1['xqxiaoqu']."]=>[".I('xqxiaoqu')."];";
                }
                if ((($ky1['xqhuxing1']!=I('xqhuxing1') && ($ky1['xqhuxing1']==true || I('xqhuxing1')==true))) || (($ky1['xqhuxing2']!=I('xqhuxing2') && ($ky1['xqhuxing2']==true || I('xqhuxing2')==true)))){
                    $xiugai.="需求户型:[".$ky1['xqhuxing1']."-".$ky1['xqhuxing2']."]=>[".I('xqhuxing1')."-".I('xqhuxing2')."];";
                }
                if ((($ky1['xqjiage1']!=I('xqjiage1') && ($ky1['xqjiage1']==true || I('xqjiage1')==true))) || (($ky1['xqjiage2']!=I('xqjiage2') && ($ky1['xqjiage2']==true || I('xqjiage2')==true)))){
                    $xiugai.="需求价格:[".$ky1['xqjiage1']."-".$ky1['xqjiage2']."]=>[".I('xqjiage1')."-".I('xqjiage2')."];";
                }
                if ((($ky1['xqmianji1']!=I('xqmianji1') && ($ky1['xqmianji1']==true || I('xqmianji1')==true))) || (($ky1['xqmianji2']!=I('xqmianji2') && ($ky1['xqmianji2']==true || I('xqmianji2')==true)))){
                    $xiugai.="需求面积:[".$ky1['xqmianji1']."-".$ky1['xqmianji2']."]=>[".I('xqmianji1')."-".I('xqmianji2')."];";
                }
                if ((($ky1['louceng1']!=I('louceng1') && ($ky1['louceng1']==true || I('louceng1')==true))) || (($ky1['louceng2']!=I('louceng2') && ($ky1['louceng2']==true || I('louceng2')==true)))){
                    $xiugai.="需求楼层:[".$ky1['louceng1']."-".$ky1['louceng2']."]=>[".I('louceng1')."-".I('louceng2')."];";
                }
                if ((($ky1['fangling1']!=I('fangling1') && ($ky1['fangling1']==true || I('fangling1')==true))) || (($ky1['fangling2']!=I('fangling2') && ($ky1['fangling2']==true || I('fangling2')==true)))){
                    $xiugai.="需求房龄:[".$ky1['fangling1']."-".$ky1['fangling2']."]=>[".I('fangling1')."-".I('fangling2')."];";
                }
                if (I('fukuan')!=$ky1['fukuan'] && ($ky1['fukuan']==true || I('fukuan')==true)) {
                    if ($ky1['mmzl']==1) {
                        $fuk="fukuan";
                    }elseif ($ky1['mmzl']==2) {
                        $fuk="zlfukuan";
                    }
                    $xiugai.=get_xiugai($ky1['fukuan'],I('fukuan'),$fuk);
                }
                if ($ky1['xqyuanyin']!=I('xqyuanyin') && ($ky1['xqyuanyin']==true || I('xqyuanyin')==true)) {
                    $xiugai.="需求原因:[".$ky1['xqyuanyin']."]=>[".I('xqyuanyin')."];";
                }
                if (I('khlaiyuan')!=$ky1['khlaiyuan'] && ($ky1['khlaiyuan']==true || I('khlaiyuan')==true)) {
                    $xiugai.=get_xiugai($ky1['khlaiyuan'],I('khlaiyuan'),'laiyuan');
                }
                if ($ky1['sfzheng']!=I('sfzheng') && ($ky1['sfzheng']==true || I('sfzheng')==true)) {
                    $xiugai.="身份证:[".$ky1['sfzheng']."]=>[".I('sfzheng')."];";
                }
                if ($ky1['qqhao']!=I('qqhao') && ($ky1['qqhao']==true || I('qqhao')==true)) {
                    $xiugai.="QQ号:[".$ky1['qqhao']."]=>[".I('qqhao')."];";
                }
                if (I('guoji')!=$ky1['guoji'] && ($ky1['guoji']==true || I('guoji')==true)) {
                    $xiugai.=get_xiugai($ky1['guoji'],I('guoji'),'guoji');
                }
                if (I('minzu')!=$ky1['minzu'] && ($ky1['minzu']==true || I('minzu')==true)) {
                    $xiugai.=get_xiugai($ky1['minzu'],I('minzu'),'minzu');
                }
                if ($ky1['youxiang']!=I('youxiang') && ($ky1['youxiang']==true || I('youxiang')==true)) {
                    $xiugai.="邮箱:[".$ky1['youxiang']."]=>[".I('youxiang')."];";
                }
                if ($ky1['weixin']!=I('weixin') && ($ky1['weixin']==true || I('weixin')==true)) {
                    $xiugai.="微信:[".$ky1['weixin']."]=>[".I('weixin')."];";
                }
                if (I('jtgongju')!=$ky1['jtgongju'] && ($ky1['jtgongju']==true || I('jtgongju')==true)) {
                    $xiugai.=get_xiugai($ky1['jtgongju'],I('jtgongju'),'jtgongju');
                }
                if ($ky1['chexing']!=I('chexing') && ($ky1['chexing']==true || I('chexing')==true)) {
                    $xiugai.="车型:[".$ky1['chexing']."]=>[".I('chexing')."];";
                }
                if ($ky1['beizhu']!=I('beizhu') && ($ky1['beizhu']==true || I('beizhu')==true)) {
                    $xiugai.="备注:[".$ky1['beizhu']."]=>[".I('beizhu')."];";
                }
                if (I('gtjieduan')!=$ky1['gtjieduan'] && ($ky1['gtjieduan']==true || I('gtjieduan')==true)) {
                    $xiugai.=get_xiugai($ky1['gtjieduan'],I('gtjieduan'),'gtjieduan');
                }
                if (I('xflinian')!=$ky1['xflinian'] && ($ky1['xflinian']==true || I('xflinian')==true)) {
                    $xiugai.=get_xiugai($ky1['xflinian'],I('xflinian'),'xflinian');
                }
                if (I('kydengji')!=$ky1['kydengji'] && ($ky1['kydengji']==true || I('kydengji')==true)) {
                    $xiugai.=get_xiugai($ky1['kydengji'],I('kydengji'),'kydengji');
                }
                $data_rizhi=array(
                    'zy_type'=>2,
                    'uid'=>session('uid'),
                    'addtime'=>time(),
                    'cz_type'=>2,
                    'zy_bianhao'=>$ky1['xqbianhao'],
                    'zy_id'=>$ky1['id'],
                    'neirong'=>$xiugai,
                );
                $isok=M("keyuan")->where(array('id'=>I('id')))->save($data);
                if ($isok){
                    M('rizhi')->add($data_rizhi);
                    $this->success('更新成功');
                }else{
                    $this->error('更新失败');
                }
            }else{
                $keyuan=M('Keyuan')->where(array('id'=>I('id'),'gongsiid'=>session('gongsiid')))->find();
                $this->keyuan=$keyuan;
                $this->yongtu=M('Peizhi')->where(array('pzming'=>'yongtu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                if ($keyuan['mmzl']==1) {
                    $this->fukuan=M('Peizhi')->where(array('pzming'=>'fukuan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                } elseif ($keyuan['mmzl']==2) {
                    $this->fukuan=M('Peizhi')->where(array('pzming'=>'zlfukuan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                } else {
                    $this->error('异常错误');
                }
                $this->chaoxiang=M('Peizhi')->where(array('pzming'=>'chaoxiang','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->kehulx=M('Peizhi')->where(array('pzming'=>'yezhulx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->zhuangxiu=M('Peizhi')->where(array('pzming'=>'zhuangxiu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->peitao=M('Peizhi')->where(array('pzming'=>'peitao','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->laiyuan=M('Peizhi')->where(array('pzming'=>'laiyuan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->xflinian=M('Peizhi')->where(array('pzming'=>'xflinian','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->guoji=M('Peizhi')->where(array('pzming'=>'guoji','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->minzu=M('Peizhi')->where(array('pzming'=>'minzu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->kydengji=M('Peizhi')->where(array('pzming'=>'kydengji','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->jtgongju=M('Peizhi')->where(array('pzming'=>'jtgongju','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->gtjieduan=M('Peizhi')->where(array('pzming'=>'gtjieduan','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $id=I('id');
                $chaoxiang1=M('keyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('chaoxiang');
                $this->chaoxiang2=explode(",", $chaoxiang1);
                $zhuangxiu1=M('keyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('zhuangxiu');
                $this->zhuangxiu2=explode(",", $zhuangxiu1);
                $peitao1=M('keyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('peitao');
                $this->peitao2=explode(",", $peitao1);
                $this->display();
            }
        }
        //变更状态
        public function bgkyzt(){
            $id=I('id');
            $keyuan=M('keyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(697,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            if (IS_POST) {
                if ($keyuan['zhuangtai'] == $options_arr['kychengjiao_zhuangtai']){
                    $this->error('客源已成交');
                }
                if (C('IS_KEYUAN_SIKEXZ')==1) {
                    $keyuanshu=M('keyuan')->where(array('weihurenid'=>$keyuan['weihurenid'],'zhuangtai'=>$options_arr['kysike_zhuangtai']))->count();
                    $sikexzs=C('IS_KEYUAN_SIKES')-1;
                    if ((C('IS_KEYUAN_SIKEXZ')==1) && (I('zhuangtai')==$options_arr['kysike_zhuangtai']) && ($keyuanshu>$sikexzs)) {
                        $this->error($keyuan['weihuren'].'的私客已达上限！无法再添加私客！');
                    }
                }
                $data['zhuangtai']=I('zhuangtai');
                $data['xiugaisj']=time();
                $yzt=M('peizhi')->where(array('pzming'=>'khzhuangtai','lxid'=>$keyuan['zhuangtai']))->getField('lxming');
                $xzt=M('peizhi')->where(array('pzming'=>'khzhuangtai','lxid'=>I('zhuangtai')))->getField('lxming');
                $isok=M('keyuan')->where(array('id'=>I('id')))->save($data);
                if ($isok){
                    $data_rizhi['zy_type']=2;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=24;
                    $data_rizhi['zy_id']=I('id');
                    $data_rizhi['zy_bianhao']=$keyuan['xqbianhao'];
                    $neirong="变更状态:[".$yzt."]=>[".$xzt."]";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('变更成功');
                }else{
                    $this->error('变更失败');
                }
            }else{
                $this->kyzt=$keyuan['zhuangtai'];
                $this->zhuangtai=M('Peizhi')->where(array('pzming'=>'khzhuangtai','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display();
            }
        }
        public function sikeHandle(){
            $keyuan=M('keyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(83,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            if ($keyuan['zhuangtai'] == $options_arr['kychengjiao_zhuangtai']){
                $this->error('客源已成交');
            }
            if (C('IS_KEYUAN_SIKEXZ')==1) {
                $keyuanshu=M('keyuan')->where(array('weihurenid'=>session('uid'),'zhuangtai'=>$options_arr['kysike_zhuangtai']))->count();
                $sikexzs=C('IS_KEYUAN_SIKES')-1;
                if ((C('IS_KEYUAN_SIKEXZ')==1) && ($keyuanshu>$sikexzs)) {
                    $this->error('您的私客已达上限！无法再添加私客！');
                }
            }
            $data['zhuangtai']=$options_arr['kysike_zhuangtai'];
            $data['weihurenid']=session("uid");
            $data['weihuren']=session("ygmingcheng");
            $data['xiugaisj']=time();
            $isok=M('keyuan')->where(array('id'=>I('id')))->save($data);
            if ($isok) {
                $data_rizhi['zy_type']=2;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=3;
                $data_rizhi['zy_id']=I('id');
                $data_rizhi['zy_bianhao']=$keyuan['xqbianhao'];
                $neirong="转为私客";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('修改成功');
            }else{
                $this->error('修改失败');
            }
        }
        public function gongkeHandle(){
            $keyuan=M('keyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(84,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            if ($keyuan['zhuangtai'] == $options_arr['kychengjiao_zhuangtai']){
                $this->error('客源已成交');
            }
            $data['zhuangtai']=$options_arr['kygongke_zhuangtai'];
            $data['xiugaisj']=time();
            $isok=M('keyuan')->where(array('id'=>I('id')))->save($data);
            if ($isok) {
                $data_rizhi['zy_type']=2;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=4;
                $data_rizhi['zy_id']=I('id');
                $data_rizhi['zy_bianhao']=$keyuan['xqbianhao'];
                $neirong="转为公客";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('修改成功');
            }else{
                $this->error('修改失败');
            }
        }
        //封盘
        public function fengpan(){
            $keyuan=M('keyuan')->where(array('id'=>I('kyid')))->find();
            $is_rbac = _rbac_btn_show(171,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $fkplx=I('fkplx');
                if ((($keyuan['fpdh'] == 1) && ($fkplx == 1)) || (($keyuan['fpck'] == 1) && ($fkplx == 5))) {
                    $this->error('异常错误！');
                }
                $qs=date("Y-m-d",time()+86399);
                $js=date("Y-m-d",time()+604799);
                $endunix=strtotime(I('endunix'));
                if ((strtotime($qs) > $endunix) || (strtotime($js) < $endunix)) {
                    $this->error('结束时间异常！');
                }
                $data['zylx']=2;
                $data['czlx']=1;
                $data['type']=3;
                $data['uid']=I('uid');
                $data['fkplx']=$fkplx;
                $data['yuanyin']=I('yuanyin');
                $data['zyid']=$keyuan['id'];
                $data['zybh']=$keyuan['xqbianhao'];
                $data['addtime']=time();
                $data['adduid']=session("uid");
                $data['gongsiid']=session("gongsiid");
                $data['endunix']=$endunix;
                $isok=M('fpkp')->add($data);
                if ($isok){
                    $data_keyuan['fengpanrenid']=I('uid');
                    if ($fkplx == 1) {
                        $data_keyuan['fpdh']=1;
                    }
                    if ($fkplx == 5) {
                        $data_keyuan['fpck']=1;
                    }
                    M('keyuan')->where(array('id'=>$keyuan['id']))->save($data_keyuan);
                    $data_rizhi['zy_type']=2;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=14;
                    $data_rizhi['zy_id']=$keyuan['id'];
                    $data_rizhi['zy_bianhao']=$keyuan['xqbianhao'];
                    $neirong="封盘";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('已提交申请');
                }else{
                    $this->error('申请失败');
                }
            }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('keyuan')->where(array('id'=>I('kyid')))->find();
            $is_rbac = _rbac_btn_show(173,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $fkplx=I('fkplx');
                if ((($keyuan['fpdh'] == 2) && ($fkplx == 1)) || (($keyuan['fpck'] == 2) && ($fkplx == 5))) {
                    $this->error('异常错误！');
                }
                $data['zylx']=2;
                $data['czlx']=2;
                $data['type']=3;
                $data['uid']=I('uid');
                $data['fkplx']=$fkplx;
                $data['yuanyin']=I('yuanyin');
                $data['zyid']=$keyuan['id'];
                $data['zybh']=$keyuan['xqbianhao'];
                $data['addtime']=time();
                $data['adduid']=session("uid");
                $data['gongsiid']=session("gongsiid");
                $isok=M('fpkp')->add($data);
                if ($isok){
                    $data_rizhi['zy_type']=2;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=15;
                    $data_rizhi['zy_id']=$keyuan['id'];
                    $data_rizhi['zy_bianhao']=$keyuan['xqbianhao'];
                    $neirong="开盘";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('已提交申请');
                }else{
                    $this->error('申请失败');
                }
            }else{
                if ($keyuan['fpdh'] == 1) {
                    $this->kdh=1;
                }
                if ($keyuan['fpck'] == 1) {
                    $this->kck=1;
                }
                $this->kyid=I('kyid');
                $this->display();
            }
        }
        //封盘审核列表
        public function fpsh(){
            $map .= " where gongsiid=".session('gongsiid');
            $x = _rbac_lists_where(850,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";
            }
            $condition = " where gongsiid=".session('gongsiid');
            $condition.=" and zylx=2 and czlx=1";
            $type=I('type');
            if ($type) {
                $condition.=" and type=".$type;
                $this->type=$type;
            } else {
                $condition.="";
                $this->type=0;
            }
            $fkplx=I('fkplx');
            if ($fkplx) {
                $condition.=" and fkplx=".$fkplx;
                $this->fkplx=$fkplx;
            } else {
                $condition.="";
                $this->fkplx=0;
            }
            $shijian1=I('shijian1');
            $shijian2=I('shijian2');
            if ($shijian1) {
                $this->shijian1=$shijian1;
                $shijian3=strtotime($shijian1);
            }
            if ($shijian2) {
                $this->shijian2=$shijian2;
                $shijian4=strtotime($shijian2)+86400;
            }
            if ($shijian3 and $shijian4){
                if ($shijian1 > $shijian2){
                    $condition.=" and addtime>".$shijian4." and addtime<".$shijian3;
                    $this->shijian1=$shijian2;
                    $this->shijian2=$shijian1;
                } else {
                    $condition.=" and addtime>".$shijian3." and addtime<".$shijian4;
                }
            } elseif ($shijian3) {
                $condition.=" and addtime>".$shijian3;
            } elseif ($shijian4) {
                $condition.=" and addtime<".$shijian4;
            }
            $count=M('fpkp')->query("select count(*) from (select * from __FPKP__ {$condition}) a join (select id as b_id from __YONGHU__ {$map}) b on a.uid = b.b_id");
            $Page=new \Think\Page($count['0']['count(*)'],20);
            $show  = $Page->show();
            $list="select d.*,c.tjren,c.tjdh from (select a.*,b.fpren,b.fpdh,b.fpbm from (select * from __FPKP__ {$condition}) a join (select id as b_id,ygmingcheng as fpren,dianhua as fpdh,bumen as fpbm from __YONGHU__ {$map}) b on a.uid = b.b_id order by a.addtime DESC limit ".$Page->firstRow.','.$Page->listRows.") d left join (select id as c_id,ygmingcheng as tjren,dianhua as tjdh from __YONGHU__) c on d.adduid = c.c_id ";
            $fengpan=M('fpkp')->query($list);
            $this->assign('firstRow',$Page->firstRow);
            $this->assign('fengpan',$fengpan);
            $this->assign('count',$count);
            $this->assign('page',$show);
            $this->display();
        }
        //封盘审核
        public function fpshenhe(){
            $id=I('id');
            $fpkp=M('fpkp')->where(array('id'=>$id,'zylx'=>2,'czlx'=>1))->field('uid,zyid,type,fkplx')->find();
            $kyzt=M('keyuan')->where(array('id'=>$fpkp['zyid']))->getField('zhuangtai');
            $is_rbac = _rbac_btn_show(851,$kyzt,$fpkp['uid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $type=I('type');
                if ($fpkp['type'] != 3){
                    $this->error('已审核！');
                }
                if ($type==""){
                    $this->error('请选择审核意见！');
                }
                if ($type!=1 && $type!=2){
                    $this->error('审核意见异常！');
                }
                $data['type']=$type;
                $data['remark']=I('remark');
                $data['shshijian']=time();
                $data['shuid']=session('uid');
                $isok=M('fpkp')->where(array('id'=>$id,'zylx'=>2,'czlx'=>1))->save($data);
                if ($isok){
                    if ($type==2) {
                        $data_keyuan['fengpanrenid']="";
                        if ($fpkp['fkplx'] == 1) {
                            $data_keyuan['fpdh']=2;
                        }
                        if ($fpkp['fkplx'] == 5) {
                            $data_keyuan['fpck']=2;
                        }
                        M('keyuan')->where(array('id'=>$fpkp['zyid']))->save($data_keyuan);
                    }
                    $this->success('审核成功');
                }else{
                    $this->error('审核失败');
                }
            }else{
                $this->display();
            }
        }
        //封盘日志
        public function fprizhi(){
            $rzlx=I('rzlx');
            if ($rzlx == 1) {
                $map .= " where gongsiid=".session('gongsiid');
                $x = _rbac_lists_where(852,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";
                }
                $condition = " where gongsiid=".session('gongsiid');
                $condition.=" and zylx=2 and czlx=1";
                $type=I('type');
                if ($type) {
                    $condition.=" and type=".$type;
                    $this->type=$type;
                } else {
                    $condition.="";
                    $this->type=0;
                }
                $fkplx=I('fkplx');
                if ($fkplx) {
                    $condition.=" and fkplx=".$fkplx;
                    $this->fkplx=$fkplx;
                } else {
                    $condition.="";
                    $this->fkplx=0;
                }
                $shijian1=I('shijian1');
                $shijian2=I('shijian2');
                if ($shijian1) {
                    $this->shijian1=$shijian1;
                    $shijian3=strtotime($shijian1);
                }
                if ($shijian2) {
                    $this->shijian2=$shijian2;
                    $shijian4=strtotime($shijian2)+86400;
                }
                if ($shijian3 and $shijian4){
                    if ($shijian1 > $shijian2){
                        $condition.=" and addtime>".$shijian4." and addtime<".$shijian3;
                        $this->shijian1=$shijian2;
                        $this->shijian2=$shijian1;
                    } else {
                        $condition.=" and addtime>".$shijian3." and addtime<".$shijian4;
                    }
                } elseif ($shijian3) {
                    $condition.=" and addtime>".$shijian3;
                } elseif ($shijian4) {
                    $condition.=" and addtime<".$shijian4;
                }
                $count=M('fpkp')->query("select count(*) from (select * from __FPKP__ {$condition}) a join (select id as b_id from __YONGHU__ {$map}) b on a.uid = b.b_id");
                $Page=new \Think\Page($count['0']['count(*)'],20);
                $show  = $Page->show();
                $list="select e.*,c.tjren,c.tjdh,d.shren,d.shdh from (select a.*,b.fpren,b.fpdh,b.fpbm from (select * from __FPKP__ {$condition}) a join (select id as b_id,ygmingcheng as fpren,dianhua as fpdh,bumen as fpbm from __YONGHU__ {$map}) b on a.uid = b.b_id order by a.addtime DESC limit ".$Page->firstRow.','.$Page->listRows.") e left join (select id as c_id,ygmingcheng as tjren,dianhua as tjdh from __YONGHU__) c on e.adduid = c.c_id left join (select id as d_id,ygmingcheng as shren,dianhua as shdh from __YONGHU__) d on e.shuid = d.d_id ";
                $fengpan=M('fpkp')->query($list);
                $this->assign('firstRow',$Page->firstRow);
                $this->assign('fengpan',$fengpan);
                $this->assign('count',$count);
                $this->assign('page',$show);
            } elseif ($rzlx == 2) {
                $kyfp=M('fpkp')->where(array('id'=>I('id'),'zylx'=>2,'czlx'=>1))->field('shuid,shshijian,remark,type')->find();
                $this->shren=M('Yonghu')->where(array('id'=>$kyfp['shuid']))->getField('ygmingcheng');
                $this->shdh=M('Yonghu')->where(array('id'=>$kyfp['shuid']))->getField('dianhua');
                $this->kyfp=$kyfp;
            }
            $this->rzlx=$rzlx;
            $this->display();
        }
        //开盘审核列表
        public function kpsh(){
            $map .= " where gongsiid=".session('gongsiid');
            $x = _rbac_lists_where(853,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";
            }
            $condition = " where gongsiid=".session('gongsiid');
            $condition.=" and zylx=2 and czlx=2";
            $type=I('type');
            if ($type) {
                $condition.=" and type=".$type;
                $this->type=$type;
            } else {
                $condition.="";
                $this->type=0;
            }
            $fkplx=I('fkplx');
            if ($fkplx) {
                $condition.=" and fkplx=".$fkplx;
                $this->fkplx=$fkplx;
            } else {
                $condition.="";
                $this->fkplx=0;
            }
            $shijian1=I('shijian1');
            $shijian2=I('shijian2');
            if ($shijian1) {
                $this->shijian1=$shijian1;
                $shijian3=strtotime($shijian1);
            }
            if ($shijian2) {
                $this->shijian2=$shijian2;
                $shijian4=strtotime($shijian2)+86400;
            }
            if ($shijian3 and $shijian4){
                if ($shijian1 > $shijian2){
                    $condition.=" and addtime>".$shijian4." and addtime<".$shijian3;
                    $this->shijian1=$shijian2;
                    $this->shijian2=$shijian1;
                } else {
                    $condition.=" and addtime>".$shijian3." and addtime<".$shijian4;
                }
            } elseif ($shijian3) {
                $condition.=" and addtime>".$shijian3;
            } elseif ($shijian4) {
                $condition.=" and addtime<".$shijian4;
            }
            $count=M('fpkp')->query("select count(*) from (select * from __FPKP__ {$condition}) a join (select id as b_id from __YONGHU__ {$map}) b on a.uid = b.b_id");
            $Page=new \Think\Page($count['0']['count(*)'],20);
            $show  = $Page->show();
            $list="select d.*,c.tjren,c.tjdh from (select a.*,b.kpren,b.kpdh,b.kpbm from (select * from __FPKP__ {$condition}) a join (select id as b_id,ygmingcheng as kpren,dianhua as kpdh,bumen as kpbm from __YONGHU__ {$map}) b on a.uid = b.b_id order by a.addtime DESC limit ".$Page->firstRow.','.$Page->listRows.") d left join (select id as c_id,ygmingcheng as tjren,dianhua as tjdh from __YONGHU__) c on d.adduid = c.c_id ";
            $kaipan=M('fpkp')->query($list);
            $this->assign('firstRow',$Page->firstRow);
            $this->assign('kaipan',$kaipan);
            $this->assign('count',$count);
            $this->assign('page',$show);
            $this->display();
        }
        //开盘审核
        public function kpshenhe(){
            $id=I('id');
            $fpkp=M('fpkp')->where(array('id'=>$id,'zylx'=>2,'czlx'=>2))->field('uid,zyid,type,fkplx')->find();
            $kyzt=M('keyuan')->where(array('id'=>$fpkp['zyid']))->getField('zhuangtai');
            $is_rbac = _rbac_btn_show(854,$kyzt,$fpkp['uid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $type=I('type');
                if ($fpkp['type'] != 3){
                    $this->error('已审核！');
                }
                if ($type==""){
                    $this->error('请选择审核意见！');
                }
                if ($type!=1 && $type!=2){
                    $this->error('审核意见异常！');
                }
                $data['type']=$type;
                $data['remark']=I('remark');
                $data['shshijian']=time();
                $data['shuid']=session('uid');
                $isok=M('fpkp')->where(array('id'=>$id,'zylx'=>2,'czlx'=>2))->save($data);
                if ($isok){
                    if ($type==1) {
                        $data_keyuan['fengpanrenid']="";
                        if ($fpkp['fkplx'] == 1) {
                            $data_keyuan['fpdh']=2;
                        }
                        if ($fpkp['fkplx'] == 5) {
                            $data_keyuan['fpck']=2;
                        }
                        M('keyuan')->where(array('id'=>$fpkp['zyid']))->save($data_keyuan);
                    }
                    $this->success('审核成功');
                }else{
                    $this->error('审核失败');
                }
            }else{
                $this->display();
            }
        }
        //开盘日志
        public function kprizhi(){
            $rzlx=I('rzlx');
            if ($rzlx == 1) {
                $map .= " where gongsiid=".session('gongsiid');
                $x = _rbac_lists_where(855,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";
                }
                $condition = " where gongsiid=".session('gongsiid');
                $condition.=" and zylx=2 and czlx=2";
                $type=I('type');
                if ($type) {
                    $condition.=" and type=".$type;
                    $this->type=$type;
                } else {
                    $condition.="";
                    $this->type=0;
                }
                $fkplx=I('fkplx');
                if ($fkplx) {
                    $condition.=" and fkplx=".$fkplx;
                    $this->fkplx=$fkplx;
                } else {
                    $condition.="";
                    $this->fkplx=0;
                }
                $shijian1=I('shijian1');
                $shijian2=I('shijian2');
                if ($shijian1) {
                    $this->shijian1=$shijian1;
                    $shijian3=strtotime($shijian1);
                }
                if ($shijian2) {
                    $this->shijian2=$shijian2;
                    $shijian4=strtotime($shijian2)+86400;
                }
                if ($shijian3 and $shijian4){
                    if ($shijian1 > $shijian2){
                        $condition.=" and addtime>".$shijian4." and addtime<".$shijian3;
                        $this->shijian1=$shijian2;
                        $this->shijian2=$shijian1;
                    } else {
                        $condition.=" and addtime>".$shijian3." and addtime<".$shijian4;
                    }
                } elseif ($shijian3) {
                    $condition.=" and addtime>".$shijian3;
                } elseif ($shijian4) {
                    $condition.=" and addtime<".$shijian4;
                }
                $count=M('fpkp')->query("select count(*) from (select * from __FPKP__ {$condition}) a join (select id as b_id from __YONGHU__ {$map}) b on a.uid = b.b_id");
                $Page=new \Think\Page($count['0']['count(*)'],20);
                $show  = $Page->show();
                $list="select e.*,c.tjren,c.tjdh,d.shren,d.shdh from (select a.*,b.kpren,b.kpdh,b.kpbm from (select * from __FPKP__ {$condition}) a join (select id as b_id,ygmingcheng as kpren,dianhua as kpdh,bumen as kpbm from __YONGHU__ {$map}) b on a.uid = b.b_id order by a.addtime DESC limit ".$Page->firstRow.','.$Page->listRows.") e left join (select id as c_id,ygmingcheng as tjren,dianhua as tjdh from __YONGHU__) c on e.adduid = c.c_id left join (select id as d_id,ygmingcheng as shren,dianhua as shdh from __YONGHU__) d on e.shuid = d.d_id ";
                $kaipan=M('fpkp')->query($list);
                $this->assign('firstRow',$Page->firstRow);
                $this->assign('kaipan',$kaipan);
                $this->assign('count',$count);
                $this->assign('page',$show);
            } elseif ($rzlx == 2) {
                $kykp=M('fpkp')->where(array('id'=>I('id'),'zylx'=>2,'czlx'=>2))->field('shuid,shshijian,remark,type')->find();
                $this->shren=M('Yonghu')->where(array('id'=>$kykp['shuid']))->getField('ygmingcheng');
                $this->shdh=M('Yonghu')->where(array('id'=>$kykp['shuid']))->getField('dianhua');
                $this->kykp=$kykp;
            }
            $this->rzlx=$rzlx;
            $this->display();
        }
        //写跟进
        public function genjin(){
            $keyuan=M('keyuan')->where(array('id'=>I('kyid')))->find();
            $is_rbac = _rbac_btn_show(85,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $gjid = I('gjid');
            $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['xqbianhao'].'/';
                    $upload->autoSub = false;
                    $uplaod->replace = true;    //存在同名文件是否是覆盖，默认为false
                    $upload->saveName = $gjid;
                    //开始上传音频文件
                    $info = $upload->upload();
                    if (!$info) {
                        $this->error($upload->getError());
                    }else{
                        M('kygenjin')->where(array('id'=>$gjid))->setField(array('gjvoice'=>1));
                        $this->success($info);
                    }
                    break;
                case '2':
                    $isok = unlink('./Upload/Genjin/'.$gongsiid.'/'.$keyuan['xqbianhao'].'/'.$gjid.'.mp3');
                    if ($isok) {
                        M('kygenjin')->where(array('id'=>$gjid))->setField(array('gjvoice'=>null)); 
                    }
                    $this->success('删除语音成功！');
                    break;
                default:
                    break;
            }
            if (IS_POST) {
                $data['kybh']=I('kybh');
                $data['kyid']=I('kyid');
                $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['zy_type']=2;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=5;
                    $data_rizhi['zy_id']=I('kyid');
                    $data_rizhi['zy_bianhao']=I('kybh');
                    $neirong=I('gjneirong');
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $data_genjin['zhgjsj']=time();
                    $data_genjin['xiugaisj']=time();
                    $this->success('添加成功');
                }else{
                    $this->error('添加失败');
                }
            }else{
                $this->genjinfs=M('Peizhi')->where(array('pzming'=>'genjinfs','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->display();
            }
        }
        //写提醒
        public function tixing(){
            $keyuan=M('keyuan')->where(array('id'=>I('kyid')))->find();
            $is_rbac = _rbac_btn_show(302,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $data['kybh']=I('kybh');
                $data['kyid']=I('kyid');
                $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) {
                    M('keyuan')->where(array('id'=>I('kyid')))->setField('xiugaisj',time());
                    $data_rizhi['zy_type']=2;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=16;
                    $data_rizhi['zy_id']=I('kyid');
                    $data_rizhi['zy_bianhao']=I('kybh');
                    $neirong=I('txneirong');
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('添加成功');
                }else{
                    $this->error('添加失败');
                }
            }else{
                $this->display();
            }
        }
        //写带看
        public function daikan(){
            $id=I('kyid');
            $keyuan=M('keyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(87,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $mmzl=I('mmzl');
                $newstr = substr(I('dkfangyuan'),0,strlen($str)-1);
                $aaa=array_unique(array_filter(explode(";",$newstr)));
                $s=count($aaa);
                for ($i=0; $i < $s; $i++) {
                    $fyid=M('fangyuan')->where(array('bianhao'=>$aaa[$i]))->getField('id');
                    if (!$fyid) {
                        $this->error('未找到房源'.$aaa[$i].'！');
                    }
                }
                for ($i=0; $i < $s; $i++) {
                    $fyid=M('fangyuan')->where(array('bianhao'=>$aaa[$i]))->getField('id');
                    $data['kyid']=$id;
                    $data['fyid']=$fyid;
                    $data['fybh']=$aaa[$i];
                    $data['kybh']=I('kybh');
                    $data['kehupj']=I('kehupj');
                    $data['peikanid']=I('peikanid');
                    $data['time']=time();
                    $data['dkuid']=session('uid');
                    $data['gongsiid']=session('gongsiid');
                    $data['dkshijian']=strtotime(I('dkshijian'));
                    M('kydaikan')->add($data);
                }
                $map['daikan']=1;
                $isok=M('Keyuan')->where(array('gongsiid'=>session('gongsiid'),'id'=>$id))->save($map);
                if ($isok){
                    M('keyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
                    $data_rizhi['zy_type']=2;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=17;
                    $data_rizhi['zy_id']=$id;
                    $data_rizhi['zy_bianhao']=I('kybh');
                    $neirong="客户评价：".I('kehupj');
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                }
                $this->success('添加成功');
            }else{
                $this->display();
            }
        }
        //变更维护人
        public function bgwhr(){
            $keyuan=M('keyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(89,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $keyuan1=M("keyuan")->where(array('id'=>I('id')))->find();
                $ysyr=M('yonghu')->where(array('id'=>$keyuan1['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("keyuan")->where(array('id'=>I('id')))->save($data);
                if ($isok){
                    $data_rizhi['zy_type']=2;
                    $data_rizhi['uid']=session("uid");
                    $data_rizhi['addtime']=time();
                    $data_rizhi['cz_type']=9;
                    $data_rizhi['zy_id']=I('id');
                    $data_rizhi['zy_bianhao']=$keyuan1['xqbianhao'];
                    $neirong="变更维护人:[".$ysyr."]=>[".$xsyr."]";
                    $data_rizhi['neirong']=$neirong;
                    M('rizhi')->add($data_rizhi);
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败');
                }
            } else {
                $this->weihu=M('Yonghu')->where(array('id'=>$keyuan['weihurenid']))->getField('ygmingcheng');
                $this->display();
            }
        }
        //修改客户详细信息
        public function xgkhxxxx(){
            $keyuan=M('keyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(438,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if (IS_POST) {
                $keyuan=M("keyuan");
                $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();
                $ky1=$keyuan->where(array('id'=>I('id')))->find();
                $isok=$keyuan->where(array('id'=>I('id')))->save($data);
                if ($ky1['khaihao']!=$ah2) {
                    if ($ky1['khaihao']) {
                        $condition1="pzming = 'khaihao'";
                        $condition1.=" and lxid in (".$ky1['khaihao'].")";
                        $peitao1=M('peizhi')->query("select * from __PEIZHI__ where {$condition1}");
                        $goods1 = array();
                        foreach ($peitao1 AS $key => $val)
                        {
                            $goods1[$key]['lxming'] = $val['lxming'];
                            $box1.= ",".$val['lxming'];
                        }
                    }
                    if ($ah2) {
                        $condition2="pzming = 'khaihao'";
                        $condition2.=" and lxid in (".$ah2.")";
                        $peitao2=M('peizhi')->query("select * from __PEIZHI__ where {$condition2}");
                        $goods2 = array();
                        foreach ($peitao2 AS $key => $val)
                        {
                            $goods2[$key]['lxming'] = $val['lxming'];
                            $box2.= $val['lxming'].",";
                        }
                    }
                    $xiugai.="个人爱好:[".$box1."]=>[".$box2."];";
                }
                if ($ky1['khjtzcph']!=$ph2) {
                    if ($ky1['khjtzcph']) {
                        $condition3="pzming = 'khjtzcph'";
                        $condition3.=" and lxid in (".$ky1['khjtzcph'].")";
                        $peitao3=M('peizhi')->query("select * from __PEIZHI__ where {$condition3}");
                        $goods3 = array();
                        foreach ($peitao3 AS $key => $val)
                        {
                            $goods3[$key]['lxming'] = $val['lxming'];
                            $box3.= ",".$val['lxming'];
                        }
                    }
                    if ($ph2) {
                        $condition4="pzming = 'khjtzcph'";
                        $condition4.=" and lxid in (".$ph2.")";
                        $peitao4=M('peizhi')->query("select * from __PEIZHI__ where {$condition4}");
                        $goods4 = array();
                        foreach ($peitao4 AS $key => $val)
                        {
                            $goods4[$key]['lxming'] = $val['lxming'];
                            $box4.= $val['lxming'].",";
                        }
                    }
                    $xiugai.="支出偏好:[".$box3."]=>[".$box4."];";
                }
                if ($ky1['khjqzdsx']!=$sx2) {
                    if ($ky1['khjqzdsx']) {
                        $condition5="pzming = 'khjqzdsx'";
                        $condition5.=" and lxid in (".$ky1['khjqzdsx'].")";
                        $peitao5=M('peizhi')->query("select * from __PEIZHI__ where {$condition5}");
                        $goods5 = array();
                        foreach ($peitao5 AS $key => $val)
                        {
                            $goods5[$key]['lxming'] = $val['lxming'];
                            $box5.= ",".$val['lxming'];
                        }
                    }
                    if ($sx2) {
                        $condition6="pzming = 'khjqzdsx'";
                        $condition6.=" and lxid in (".$sx2.")";
                        $peitao6=M('peizhi')->query("select * from __PEIZHI__ where {$condition6}");
                        $goods6 = array();
                        foreach ($peitao6 AS $key => $val)
                        {
                            $goods6[$key]['lxming'] = $val['lxming'];
                            $box6.= $val['lxming'].",";
                        }
                    }
                    $xiugai.="近期重大事项:[".$box5."]=>[".$box6."];";
                }
                if (I('khzhiwu')!=$ky1['khzhiwu'] && ($ky1['khzhiwu']==true || I('khzhiwu')==true)) {
                    $xiugai.=get_xiugai($ky1['khzhiwu'],I('khzhiwu'),'khzhiwu');
                }
                if ($ky1['khbeizhu']!=I('khbeizhu') && ($ky1['khbeizhu']==true || I('khbeizhu')==true)) {
                    $xiugai.="备注:[".$ky1['khbeizhu']."]=>[".I('khbeizhu')."];";
                }
                if (I('khjiaoyu')!=$ky1['khjiaoyu'] && ($ky1['khjiaoyu']==true || I('khjiaoyu')==true)) {
                    $xiugai.=get_xiugai($ky1['khjiaoyu'],I('khjiaoyu'),'khjiaoyu');
                }
                if (I('khhunyin')!=$ky1['khhunyin'] && ($ky1['khhunyin']==true || I('khhunyin')==true)) {
                    $xiugai.=get_xiugai($ky1['khhunyin'],I('khhunyin'),'khhunyin');
                }
                if (I('khshouru')!=$ky1['khshouru'] && ($ky1['khshouru']==true || I('khshouru')==true)) {
                    $xiugai.=get_xiugai($ky1['khshouru'],I('khshouru'),'khshouru');
                }
                if (I('khjzquyu')!=$ky1['khjzquyu'] && ($ky1['khjzquyu']==true || I('khjzquyu')==true)) {
                    $xiugai.=get_xiugai($ky1['khjzquyu'],I('khjzquyu'),'khjzquyu');
                }
                if (I('khgzquyu')!=$ky1['khgzquyu'] && ($ky1['khgzquyu']==true || I('khgzquyu')==true)) {
                    $xiugai.=get_xiugai($ky1['khgzquyu'],I('khgzquyu'),'khgzquyu');
                }
                if (I('khnianling')!=$ky1['khnianling'] && ($ky1['khnianling']==true || I('khgzquyu')==true)) {
                    $xiugai.=get_xiugai($ky1['khnianling'],I('khnianling'),'khnianling');
                }
                if ($ky1['khjzxiaoqu']!=I('khjzxiaoqu') && ($ky1['khjzxiaoqu']==true || I('khjzxiaoqu')==true)) {
                    $xiugai.="居住小区:[".$ky1['khjzxiaoqu']."]=>[".I('khjzxiaoqu')."];";
                }
                if (I('khjzmianji')!=$ky1['khjzmianji'] && ($ky1['khjzmianji']==true || I('khjzmianji')==true)) {
                    $xiugai.=get_xiugai($ky1['khjzmianji'],I('khjzmianji'),'khjzmianji');
                }
                if (I('khsjpinpai')!=$ky1['khsjpinpai'] && ($ky1['khsjpinpai']==true || I('khsjpinpai')==true)) {
                    $xiugai.=get_xiugai($ky1['khsjpinpai'],I('khsjpinpai'),'khsjpinpai');
                }
                if (I('khsshangye')!=$ky1['khsshangye'] && ($ky1['khsshangye']==true || I('khsshangye')==true)) {
                    $xiugai.=get_xiugai($ky1['khsshangye'],I('khsshangye'),'khsshangye');
                }
                if ($ky1['khsfbeizhu']!=I('khsfbeizhu') && ($ky1['khsfbeizhu']==true || I('khsfbeizhu')==true)) {
                    $xiugai.="身份备注:[".$ky1['khsfbeizhu']."]=>[".I('khsfbeizhu')."];";
                }
                if ($ky1['khsjxinghao']!=I('khsjxinghao') && ($ky1['khsjxinghao']==true || I('khsjxinghao')==true)) {
                    $xiugai.="手机型号:[".$ky1['khsjxinghao']."]=>[".I('khsjxinghao')."];";
                }
                if ($ky1['khjtchengyuan']!=I('khjtchengyuan') && ($ky1['khjtchengyuan']==true || I('khjtchengyuan')==true)) {
                    $xiugai.="家庭成员:[".$ky1['khjtchengyuan']."]=>[".I('khjtchengyuan')."];";
                }
                $data_rizhi=array(
                        'zy_type'=>2,
                        'uid'=>session('uid'),
                        'addtime'=>time(),
                        'cz_type'=>7,
                        'zy_bianhao'=>$ky1['xqbianhao'],
                        'zy_id'=>$ky1['id'],
                        'neirong'=>$xiugai,
                    );

                if ($isok){
                    M('rizhi')->add($data_rizhi);
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败');
                }
            } else {
                $this->keyuan=M('keyuan')->where(array('id'=>I('id'),'gongsiid'=>session('gongsiid')))->find();
                $this->khaihao=M('peizhi')->where(array('pzming'=>'khaihao','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khzhiwu=M('peizhi')->where(array('pzming'=>'khzhiwu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khjiaoyu=M('peizhi')->where(array('pzming'=>'khjiaoyu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khhunyin=M('peizhi')->where(array('pzming'=>'khhunyin','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khshouru=M('peizhi')->where(array('pzming'=>'khshouru','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khjzquyu=M('peizhi')->where(array('pzming'=>'khjzquyu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khgzquyu=M('peizhi')->where(array('pzming'=>'khgzquyu','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khjtzcph=M('peizhi')->where(array('pzming'=>'khjtzcph','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khjqzdsx=M('peizhi')->where(array('pzming'=>'khjqzdsx','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khnianling=M('peizhi')->where(array('pzming'=>'khnianling','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khjzmianji=M('peizhi')->where(array('pzming'=>'khjzmianji','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khsjpinpai=M('peizhi')->where(array('pzming'=>'khsjpinpai','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $this->khsshangye=M('peizhi')->where(array('pzming'=>'khsshangye','zhuangtai'=>1))->order('xsshunxu asc')->select();
                $id=I('id');
                $khaihao1=M('keyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('khaihao');
                $this->khaihao2=explode(",", $khaihao1);
                $khjtzcph1=M('keyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('khjtzcph');
                $this->khjtzcph2=explode(",", $khjtzcph1);
                $khjqzdsx1=M('keyuan')->where(array('id'=>$id,'gongsiid'=>session('gongsiid')))->getField('khjqzdsx');
                $this->khjqzdsx2=explode(",", $khjqzdsx1);
                $this->display();
            }
        }
        //查看客户详细信息
        public function ckkhxxxx(){
            $keyuan=M('keyuan')->where(array('id'=>I('id')))->find();
            $is_rbac = _rbac_btn_show(440,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $id=I('id');
            $khaihao1=M('keyuan')->where(array('id'=>$id))->getField('khaihao');
            if ($khaihao1) {
                $condition="pzming = 'khaihao'";
                $condition.=" and lxid in ($khaihao1)";
                $this->khaihao=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
            }
            $khjtzcph1=M('keyuan')->where(array('id'=>$id))->getField('khjtzcph');
            if ($khjtzcph1) {
                $condition="pzming = 'khjtzcph'";
                $condition.=" and lxid in ($khjtzcph1)";
                $this->khjtzcph=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
            }
            $khjqzdsx1=M('keyuan')->where(array('id'=>$id))->getField('khjqzdsx');
            if ($khjqzdsx1) {
                $condition="pzming = 'khjqzdsx'";
                $condition.=" and lxid in ($khjqzdsx1)";
                $this->khjqzdsx=M('peizhi')->query("select * from __PEIZHI__ where {$condition}");
            }
            $keyuan=M('keyuan')->where(array('id'=>I('id'),'gongsiid'=>session('gongsiid')))->find();
            $this->keyuan=$keyuan;
            $this->khzhiwu=M('peizhi')->where(array('pzming'=>'khzhiwu','lxid'=>$keyuan['khzhiwu']))->getField('lxming');
            $this->khjiaoyu=M('peizhi')->where(array('pzming'=>'khjiaoyu','lxid'=>$keyuan['khjiaoyu']))->getField('lxming');
            $this->khhunyin=M('peizhi')->where(array('pzming'=>'khhunyin','lxid'=>$keyuan['khhunyin']))->getField('lxming');
            $this->khshouru=M('peizhi')->where(array('pzming'=>'khshouru','lxid'=>$keyuan['khshouru']))->getField('lxming');
            $this->khjzquyu=M('peizhi')->where(array('pzming'=>'khjzquyu','lxid'=>$keyuan['khjzquyu']))->getField('lxming');
            $this->khgzquyu=M('peizhi')->where(array('pzming'=>'khgzquyu','lxid'=>$keyuan['khgzquyu']))->getField('lxming');
            $this->khnianling=M('peizhi')->where(array('pzming'=>'khnianling','lxid'=>$keyuan['khnianling']))->getField('lxming');
            $this->khjzmianji=M('peizhi')->where(array('pzming'=>'khjzmianji','lxid'=>$keyuan['khjzmianji']))->getField('lxming');
            $this->khsjpinpai=M('peizhi')->where(array('pzming'=>'khsjpinpai','lxid'=>$keyuan['khsjpinpai']))->getField('lxming');
            $this->khsshangye=M('peizhi')->where(array('pzming'=>'khsshangye','lxid'=>$keyuan['khsshangye']))->getField('lxming');
            $this->display();
        }
        public function delkeyuan(){
            $id=I('id');
            $keyuan=M('keyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(501,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->error('异常错误！');
            }
            $id=I('id');
            $isok=M('keyuan')->where(array('id'=>$id))->setField('isdel',1);
            if($isok){
                M('keyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
                $data_rizhi['zy_type']=2;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=8;
                $data_rizhi['zy_id']=$id;
                $data_rizhi['zy_bianhao']=$keyuan['xqbianhao'];
                $neirong="删除";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }
        public function huifuky(){
            $id=I('id');
            $keyuan=M('keyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(771,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            if($keyuan['isdel'] == 2){
                $this->error('客源已还原！');
            }
            $isok=M('keyuan')->where(array('id'=>$id))->setField('isdel',2);
            if ($isok) {
                M('keyuan')->where(array('id'=>$id))->setField('xiugaisj',time());
                $data_rizhi['zy_type']=2;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=8;
                $data_rizhi['zy_id']=$id;
                $data_rizhi['zy_bianhao']=$keyuan['xqbianhao'];
                $neirong="还原删除客源";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('还原成功');
            }else{
                $this->error('还原失败');
            }
        }
        public function yjdelky(){
            $id=I('id');
            $keyuan=M('keyuan')->where(array('id'=>$id))->find();
            $is_rbac = _rbac_btn_show(772,$keyuan['zhuangtai'],$keyuan['weihurenid']);
            if (!$is_rbac) {
                $this->redirect('Index/error');
            }
            $isok=M('keyuan')->where(array('id'=>$id))->delete();
            if ($isok) {
                $data_rizhi['zy_type']=2;
                $data_rizhi['uid']=session("uid");
                $data_rizhi['addtime']=time();
                $data_rizhi['cz_type']=8;
                $data_rizhi['zy_id']=$id;
                $data_rizhi['zy_bianhao']=$keyuan['xqbianhao'];
                $neirong="永久删除";
                $data_rizhi['neirong']=$neirong;
                M('rizhi')->add($data_rizhi);
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }
    }
?>