<?php

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

namespace Admin\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){
        $role_id=M('role_user')->where(array('user_id'=>session('uid')))->getField('role_id');
        $sql = "select a.* from  
            (select * from __MENU__ where status=1 ) as a , 
            (select * from __ACCESS__ where role_id = '".$role_id."') as b where a.node_id=b.node_id  ORDER BY a.listorder ASC";
        $Model = new \Think\Model();
        $smenu=$Model->query($sql);
        $pmenu=M('Menu')->where(array('type'=>array('neq',2),'status'=>1))->select();
        $menu=array_merge_recursive($smenu,$pmenu);
        $menu=array_sort($menu,'listorder','asc');
        if(session(C('ADMIN_AUTH_KEY'))){
            $result=M('menu')->where(array('status'=>1))->order('listorder asc')->select();
        }else{
            $result=$menu;
        }
        foreach ($result as $n=> $r) {
            if ($r['type']==2) {
                $name = ucwords($r['app']);
                $model = ucwords($r['model']);
                $action = $r['action'];
                //附带参数
                $params = "";
                if ($r['data']) {
                    $params = "?" . htmlspecialchars_decode($r['data']);
                }
                $result[$n]['url'] = U("{$name}/{$model}/{$action}{$params}");
            }elseif ($r['type']==3) {
                if ($r['blank']) {
                    $params =  htmlspecialchars_decode($r['blank']);
                }
                $result[$n]['url'] = $params;
            }
        }
        $tree = new \Org\Util\Tree();
        $tree->init($result);
        $categorys = $tree->get_tree_array(0);
        foreach ($categorys as $key => $value) {
            foreach ($value['child'] as $key1 => $value1) {
                if ($value1['child']==null) {
                    unset($categorys[$key]['child'][$key1]);
                }
            }
        }
        foreach ($categorys as $key => $value) {
            if ($value['child']==null) {
                unset($categorys[$key]);
            }
        }
        $this->categorys = $categorys;
        $this->user = M('yonghu')->where('id='.session('uid'))->find();
        $this->zdkp();
        $this->fkypz();
        $this->display('index1');
    }
    public function zdkp(){
        $jintian=date("Y-m-d",time());
        $jinri=strtotime($jintian);
        $zhkpsj=M("fkypz")->where(array('id'=>1))->getField('zhkpsj');
        if ($jinri != $zhkpsj) {
            $fpkp=M("fpkp")->where(array('gongsiid'=>session('gongsiid'),'endunix'=>$jinri,'czlx'=>1,'type'=>array('neq',2)))->select();
            foreach ($fpkp as $key => $value) {
                if ($value['zylx'] == 1) {
                    $zyb=M('fangyuan');
                } else if ($value['zylx'] == 2) {
                    $zyb=M('keyuan');
                }
                if ($value['fkplx'] == 1) {
                    $fpzd="fpdh";
                } else if ($value['fkplx'] == 2) {
                    $fpzd="fpdz";
                } else if ($value['fkplx'] == 3) {
                    $fpzd="fpdj";
                } else if ($value['fkplx'] == 4) {
                    $fpzd="fpdq";
                } else if ($value['fkplx'] == 5) {
                    $fpzd="fpck";
                }
                $zyb->where(array('id'=>$value['zyid']))->setField($fpzd,2);
                $zyb->where(array('id'=>$value['zyid']))->setField('fengpanrenid','');
            }
        }
        M("fkypz")->where(array('id'=>1))->setField('zhkpsj',$jinri);
    }
    public function fkypz(){
        $fkypz=M("fkypz")->where(array('id'=>1))->find();
        $xzshijian=time();
        $jintian=date("Y-m-d",$xzshijian);
        $jinri=strtotime($jintian);
        $options_arr = get_options('chengjiao_options',0);
        if ($jinri != $fkypz['zhzxsj']) {
            if($fkypz['csgj'] == 1){
                $csgjsj=$xzshijian-$fkypz['csgjsj'];
                $csgjwcj=M("fyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and zhgjsj < ".$csgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $csgjwcj=M("fyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and zhgjsj < ".$csgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $csgjwcj=M("fangyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and zhgjsj < ".$csgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
            }
            if(($fkypz['csgj'] == 0) && ($fkypz['csxz'] == 1)){
                $csxzsj=$xzshijian-$fkypz['csxzsj'];
                $csxzwcj=M("fyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and xiugaisj < ".$csxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $csxzwcj=M("fyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and xiugaisj < ".$csxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $csxzwcj=M("fangyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and xiugaisj < ".$csxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
            }
            if(($fkypz['csgj'] == 0) && ($fkypz['csxz'] == 0) && ($fkypz['cslr'] == 1)){
                $cslrsj=$xzshijian-$fkypz['cslrsj'];
                $cslrwcj=M("fyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and lurusj < ".$cslrsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $cslrwcj=M("fyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and lurusj < ".$cslrsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $cslrwcj=M("fangyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and lurusj < ".$cslrsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
            }
            if($fkypz['czgj'] == 1){
                $czgjsj=$xzshijian-$fkypz['czgjsj'];
                $czgjwcj=M("fyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and zhgjsj <".$czgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $czgjwcj=M("fyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and zhgjsj <".$czgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $czgjwcj=M("fangyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and zhgjsj <".$czgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
            }
            if(($fkypz['czgj'] == 0) && ($fkypz['czxz'] == 1)){
                $czxzsj=$xzshijian-$fkypz['czxzsj'];
                $czxzwcj=M("fyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and xiugaisj <".$czxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $czxzwcj=M("fyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and xiugaisj <".$czxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $czxzwcj=M("fangyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and xiugaisj <".$czxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
            }
            if(($fkypz['czgj'] == 0) && ($fkypz['czxz'] == 0) && ($fkypz['czlr'] == 1)){
                $czlrsj=$xzshijian-$fkypz['czlrsj'];
                $czlrwcj=M("fyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and lurusj <".$czlrsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $czlrwcj=M("fyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and lurusj <".$czlrsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
                $czlrwcj=M("fangyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['fysipan_zhuangtai']." and lurusj <".$czlrsj." and isdel = 2")->setField('zhuangtai',$options_arr['fygongpan_zhuangtai']);
            }
            if($fkypz['qggj'] == 1){
                $qggjsj=$xzshijian-$fkypz['qggjsj'];
                $qggjwcj=M("kyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qggjwcj=M("kyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qggjwcj=M("keyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qggjwcj=M("kyxinfang")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qggjwcj=M("kyjinrong")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qggjwcj=M("kyzhuangxiu")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qggjwcj=M("kygongshang")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qggjwcj=M("kykuaiji")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qggjwcj=M("kyjiaju")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qggjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
            }
            if(($fkypz['qggj'] == 0) && ($fkypz['qgxz'] == 1)){
                $qgxzsj=$xzshijian-$fkypz['qgxzsj'];
                $qgxzwcj=M("kyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qgxzwcj=M("kyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qgxzwcj=M("keyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qgxzwcj=M("kyxinfang")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qgxzwcj=M("kyjinrong")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qgxzwcj=M("kyzhuangxiu")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qgxzwcj=M("kygongshang")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qgxzwcj=M("kykuaiji")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qgxzwcj=M("kyjiaju")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qgxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
            }
            if(($fkypz['qggj'] == 0) && ($fkypz['qgxz'] == 0) && ($fkypz['qglr'] == 1)){
                $qglrsj=$xzshijian-$fkypz['qglrsj'];
                $qglrwcj=M("kyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qglrwcj=M("kyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qglrwcj=M("keyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 1 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qglrwcj=M("kyxinfang")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qglrwcj=M("kyjinrong")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qglrwcj=M("kyzhuangxiu")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qglrwcj=M("kygongshang")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qglrwcj=M("kykuaiji")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qglrwcj=M("kyjiaju")->where("gongsiid = ".session('gongsiid')." and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qglrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
            }
            if($fkypz['qzgj'] == 1){
                $qzgjsj=$xzshijian-$fkypz['qzgjsj'];
                $qzgjwcj=M("kyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qzgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qzgjwcj=M("kyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qzgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qzgjwcj=M("keyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and zhgjsj < ".$qzgjsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
            }
            if(($fkypz['qzgj'] == 0) && ($fkypz['qzxz'] == 1)){
                $qzxzsj=$xzshijian-$fkypz['qzxzsj'];
                $qzxzwcj=M("kyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qzxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qzxzwcj=M("kyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qzxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qzxzwcj=M("keyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and xiugaisj < ".$qzxzsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
            }
            if(($fkypz['qzgj'] == 0) && ($fkypz['qzxz'] == 0) && ($fkypz['qzlr'] == 1)){
                $qzlrsj=$xzshijian-$fkypz['qzlrsj'];
                $qzlrwcj=M("kyxiezilou")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qzlrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qzlrwcj=M("kyshangpu")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qzlrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
                $qzlrwcj=M("keyuan")->where("gongsiid = ".session('gongsiid')." and mmzl = 2 and zhuangtai = ".$options_arr['kysipan_zhuangtai']." and lurusj < ".$qzlrsj." and isdel = 2")->setField('zhuangtai',$options_arr['kygongpan_zhuangtai']);
            }
            M("fkypz")->where(array('id'=>1))->setField('zhzxsj',$jinri);
        }
    }
    public function xiaoxi(){
        $Model = new \Think\Model();
        $map10 = "gongsiid=".session('gongsiid');
        $map10 .= " and txuid=".session('uid');
        $map10 .= " and txshijian<".time();
        $map10 .= " and isyidu=0";
        $sqlcount10 = "select count(*) FROM __KYTIXING__ where {$map10}";
        $countb10=$Model->query($sqlcount10);
        $sh_count10=$countb10[0]['count(*)'];
        $arr['sh_count10']=$sh_count10;
        if ($is_rbac12) {
            $map12 = "gongsiid=".session('gongsiid');
            $x12 = _rbac_lists_where(841,0);
            if ($x12 && $x12 != "all" && $x12 != "me") {
                $map12 .= " and bumen in ({$x12})";
            }elseif ($x12 == "me") {
                $map12 .= " and id=".session('uid');
            }elseif ($x12 == false) {
                $map12 .= " and id=0";
            }
            $sqlcount12 = "select count(*) FROM __FPKP__ as a join (select id from __YONGHU__ where {$map12}) as b on a.uid=b.id where type=3";
            $countb12=$Model->query($sqlcount12);
            $sh_count12=$countb12[0]['count(*)'];
            $arr['sh_count12']=$sh_count12;
        }
        $is_rbac13 = _rbac_node_show(844);
        if ($is_rbac13) {
            $map13 = "gongsiid=".session('gongsiid');
            $x13 = _rbac_lists_where(844,0);
            if ($x13 && $x13 != "all" && $x13 != "me") {
                $map13 .= " and bumen in ({$x13})";
            }elseif ($x13 == "me") {
                $map13 .= " and id=".session('uid');
            }elseif ($x13 == false) {
                $map13 .= " and id=0";
            }
            $sqlcount13 = "select count(*) FROM __FPKP__ as a join (select id from __YONGHU__ where {$map13}) as b on a.uid=b.id where zylx=1 and czlx=1 and type=3";
            $countb13=$Model->query($sqlcount13);
            $sh_count13=$countb13[0]['count(*)'];
            $arr['sh_count13']=$sh_count13;
        }
        $is_rbac14 = _rbac_node_show(847);
        if ($is_rbac14) {
            $map14 = "gongsiid=".session('gongsiid');
            $x14 = _rbac_lists_where(847,0);
            if ($x14 && $x14 != "all" && $x14 != "me") {
                $map14 .= " and bumen in ({$x14})";
            }elseif ($x14 == "me") {
                $map14 .= " and id=".session('uid');
            }elseif ($x14 == false) {
                $map14 .= " and id=0";
            }
            $sqlcount14 = "select count(*) FROM __FPKP__ as a join (select id from __YONGHU__ where {$map14}) as b on a.uid=b.id where zylx=1 and czlx=2 and type=3";
            $countb14=$Model->query($sqlcount14);
            $sh_count14=$countb14[0]['count(*)'];
            $arr['sh_count14']=$sh_count14;
        }
        $is_rbac15 = _rbac_node_show(850);
        if ($is_rbac15) {
            $map15 = "gongsiid=".session('gongsiid');
            $x15 = _rbac_lists_where(850,0);
            if ($x15 && $x15 != "all" && $x15 != "me") {
                $map15 .= " and bumen in ({$x15})";
            }elseif ($x15 == "me") {
                $map15 .= " and id=".session('uid');
            }elseif ($x15 == false) {
                $map15 .= " and id=0";
            }
            $sqlcount15 = "select count(*) FROM __FPKP__ as a join (select id from __YONGHU__ where {$map15}) as b on a.uid=b.id where zylx=2 and czlx=1 and type=3";
            $countb15=$Model->query($sqlcount15);
            $sh_count15=$countb15[0]['count(*)'];
            $arr['sh_count15']=$sh_count15;
        }
        $is_rbac16 = _rbac_node_show(853);
        if ($is_rbac16) {
            $map16 = "gongsiid=".session('gongsiid');
            $x16 = _rbac_lists_where(853,0);
            if ($x16 && $x16 != "all" && $x16 != "me") {
                $map16 .= " and bumen in ({$x16})";
            }elseif ($x16 == "me") {
                $map16 .= " and id=".session('uid');
            }elseif ($x16 == false) {
                $map16 .= " and id=0";
            }
            $sqlcount16 = "select count(*) FROM __FPKP__ as a join (select id from __YONGHU__ where {$map16}) as b on a.uid=b.id where zylx=2 and czlx=2 and type=3";
            $countb16=$Model->query($sqlcount16);
            $sh_count16=$countb16[0]['count(*)'];
            $arr['sh_count16']=$sh_count16;
        }
        if ($sh_count12) {
            $fkpshzs=$sh_count12;
        } else {
            $fkpshzs=$sh_count13+$sh_count14+$sh_count15+$sh_count16;
        }
        $arr['sh_countz']=$sh_count10+$fkpshzs;
        $data=array('data'=>$arr);
        header("Content-type: application/json");
        exit(json_encode($data));
    }
    public function validatepass(){
        $passwd = trim(I('passwd'));
        if (!$passwd) {
            $this->error('密码不能为空');
        }
        $r = M('Yonghu')->where(array('id'=>session('uid'),'mima'=>md5($passwd)))->getField('id');
        //返回查询结果到异步json
        $data=array('r'=>$r);
        header("Content-type: application/json");
        exit(json_encode($data));
    }
    public function updatepass(){
        if (IS_POST) {
            $ymima=I('ymima');
            $xmima=I('xmima');
            $qrmima=I('qrmima');
            $yymima=M('Yonghu')->where(array('id'=>session('uid')))->getField('mima');
            if ($yymima!=md5($ymima)) {
                $this->error('原密码错误!');
            }
            if ($xmima!=$qrmima) {
                $this->error('两次密码不匹配!');
            }
            $passwd = md5($xmima);
            $uid = session('uid');
            $r = M('Yonghu')->where(array('id'=>$uid))->setField(array('mima'=>$passwd));
            if ($r) {
                data_rizhi(8,2,session("uid"),zym(session('uid'),15),"修改密码","","用户");
                $this->success('成功');
            }else{
                $this->error('失败');
            }
        }else{
            $this->display();
        }
    }
    public function welcome(){
        $Model = new \Think\Model();
        //用户信息显示
        $this->yhtx = M('yonghu')->where(array('gongsiid'=>session("gongsiid"),'id'=>session('uid')))->getField('touxiang');
        $this->remark = M('role')->where(array('id'=>session('role')))->getField('remark');
        //准意向客户
        $tme = time();
        $tmb = $tme-604800;
        $yixiang = "select count(*) as count,kybh,kylx,dkshijian from __KYDAIKAN__ where dkuid=".session('uid')." and dkshijian>".$tmb." and dkshijian<".$tme." group by kyid order by count desc limit 5 ";
        foreach ($yixiang as $key => $value) {
            switch ($value['kylx']) {
                case '2':
                    $kylj = U('keyuan1/neirong1',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('keyuan')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                case '15':
                    $kylj = U('kyxiezilou/neirong',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('kyxiezilou')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                case '16':
                    $kylj = U('kyshangpu/neirong',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('kyshangpu')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                case '17':
                    $kylj = U('kyxinfang/neirong',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('kyxinfang')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                case '18':
                    $kylj = U('kyjinrong/neirong',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('kyjinrong')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                case '19':
                    $kylj = U('kyzhuangxiu/neirong',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('kyzhuangxiu')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                case '20':
                    $kylj = U('kygongshang/neirong',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('kygongshang')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                case '21':
                    $kylj = U('kykuaiji/neirong',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('kykuaiji')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                case '22':
                    $kylj = U('kyjiaju/neirong',array('xqbianhao'=>$value['kybh']));
                    $keyuan = M('kyjiaju')->where(array('xqbianhao'=>$value['kybh']))->field('khxingming,kehulx')->find();
                    break;
                default:
                    $kylj = "";
                    $keyuan = "";
                    break;
            }
            $yixiang[$key]['kylj'] = $kylj;
            $yixiang[$key]['kyxm'] = $keyuan['khxingming'].get_peizhi('yezhulx',$keyuan['kehulx'],3);
        }
        $yixiang=$Model->query($yixiang);
        $this->assign('yixiang',$yixiang);
        //显示模板
        $this->display();
    }
    //显示头像页面
    public function avatar(){
        $yhtx = '/Upload/Avatar/'.session("gongsiid").'/'.session('username').'_200.jpg';
        if (file_exists('.'.$yhtx)){
            $this->touxiang = $yhtx;
        }
        $this->display();
    }
    //计算器
    public function tool(){
        $this->mianji=I('mianji');
        $this->shoujia=I('shoujia');
        $this->display();
    }
    public function getMonth($m) {
        $m = $m ? $m : date("Y-m-d");
        $startDate=date('Y-m-01', strtotime($m));
        $endDate = date('Y-m-d', strtotime("$startDate +1 month -1 day"));
        return array(strtotime($startDate),strtotime($endDate));
    }
    public function get_fy_line_data(){
        $month = I('month');
        $ThisMonth = $this->getMonth($month);
        $month_start_time = $ThisMonth[0];
        $month_end_time = $ThisMonth[1]+3600*24;
        $s = date('d',$ThisMonth[1]);
        for ($i=1; $i <= $s; $i++) { 
            $thisMonth[] = date('Y-m-d',strtotime(date('Y-m-'.$i,$ThisMonth[0])));
        }
        $Model = new \Think\Model();
        $sql1 = "select FROM_UNIXTIME(lurusj, '%Y-%m-%d') as create_date,count(id) as value from __FANGYUAN__ WHERE lurusj >= {$month_start_time} and lurusj < {$month_end_time} group by create_date";
        $data1 = $Model->query($sql1);
        $arr1 = array();
        foreach ($data1 as $key => $value) {
            $arr1[$value['create_date']] = $value;
        }
        $sql2 = "select FROM_UNIXTIME(lurusj, '%Y-%m-%d') as create_date,count(id) as value from __FYSHANGPU__ WHERE lurusj >= {$month_start_time} and lurusj < {$month_end_time} group by create_date";
        $data2 = $Model->query($sql2);
        $arr2 = array();
        foreach ($data2 as $key => $value) {
            $arr2[$value['create_date']] = $value;
        }
        $sql3 = "select FROM_UNIXTIME(lurusj, '%Y-%m-%d') as create_date,count(id) as value from __FYXIEZILOU__ WHERE lurusj >= {$month_start_time} and lurusj < {$month_end_time} group by create_date";
        $data3 = $Model->query($sql3);
        $arr3 = array();
        foreach ($data3 as $key => $value) {
            $arr3[$value['create_date']] = $value;
        }
        $xAxis = array();
        foreach ($thisMonth as $k => $v) {
            $xAxis[] = $v;
            $series1[] = $arr1[$v]['value']?$arr1[$v]['value'] : '0';
            $series2[] = $arr2[$v]['value']?$arr2[$v]['value'] : '0';
            $series3[] = $arr3[$v]['value']?$arr3[$v]['value'] : '0';
        }
        $return_data = array(
            'status'=>1,
            'info'=>'',
            'data'=>array(
                'xAxis'=>$xAxis,
                'series1'=>$series1,
                'series2'=>$series2,
                'series3'=>$series3
            )
        );
        $this->ajaxReturn($return_data);
    }
    public function get_fy_pie_data(){
        $month = I('month');
        $ThisMonth = $this->getMonth($month);
        $month_start_time = $ThisMonth[0];
        $month_end_time = $ThisMonth[1]+3600*24;
        $s = date('d',$ThisMonth[1]);
        for ($i=1; $i <= $s; $i++) { 
            $thisMonth[] = date('Y-m-d',strtotime(date('Y-m-'.$i,$ThisMonth[0])));
        }
        $Model = new \Think\Model();
        $sql1 = "select count(id) as value from __FANGYUAN__ WHERE lurusj >= {$month_start_time} and lurusj < {$month_end_time} ";
        $data1 = $Model->query($sql1);
        $sql2 = "select count(id) as value from __FYSHANGPU__ WHERE lurusj >= {$month_start_time} and lurusj < {$month_end_time} ";
        $data2 = $Model->query($sql2);
        $sql3 = "select count(id) as value from __FYXIEZILOU__ WHERE lurusj >= {$month_start_time} and lurusj < {$month_end_time} ";
        $data3 = $Model->query($sql3);
        $value1 = $data1[0]['value'];
        $value2 = $data2[0]['value'];
        $value3 = $data3[0]['value'];
        $return_data = array(
            'status'=>1,
            'info'=>'',
            'data'=>array(
                'value1'=>$value1,
                'value2'=>$value2,
                'value3'=>$value3
            )
        );
        $this->ajaxReturn($return_data);
    }
}