easyUI导出数据

easyUI导出数据模式

后台:

  1 //导出数据
  2     public function index_doExport() 
  3     {
  4         $search['diqu']=$_POST['diqu'];
  5         $search['start']=$_POST['start'];
  6         $search['end']=$_POST['end'];
  7         
  8         $search['diqu']=$search['diqu']?$search['diqu']:0;
  9         $search['start']=$search['start']?strtotime($search['start']):1;
 10         $search['end']=$search['end']?strtotime("+1 day",strtotime($end)):strtotime("+1 day",strtotime(date("Y-m-d")));
 11 
 12         $this->success(U('Human/index_doExport_action',$search));
 13     }
 14 
 15     public function index_doExport_action() 
 16     {
 17         $search=$_GET;
 18         $branchid=$search['diqu'];
 19         $time1 = $search['start'];
 20         $time2 =$search['end'];
 21         
 22         //做一个空数组存储数据
 23         $attr = array();
 24             
 25         if($branchid==0)
 26         {
 27             //取网点
 28             $arr = M('branchs')->where("level = '服务处' ")->select();
 29             
 30             //一个地区的数据统计
 31             foreach($arr as $v)
 32             {
 33                 $attr1 = array();    //缓存,临时
 34                 $attr1['branchid'] = $v['id'];    //地区id
 35                 $branchid = $v['id'];
 36                 
 37                 $attr1['branchname'] = $v['name'];    //地区名字
 38                 
 39                 $attr2 = M('admin')->where(" roleid = 8 and branchid = $branchid ")->select();    //一个服务处所有的理财经理
 40                 $manager = count($attr2);
 41                 $attr1['manager'] = $manager;    //理财经理
 42                 
 43                 
 44                 $attr3 = array();    //一个服务处所有注册客户
 45                 $attr31 = M('users')->where(" isqiye=0 and isloanuser = 0 and isdanbao = 0 and branchid = $branchid ")->select();    
 46                 foreach($attr31 as $a)
 47                 {
 48                     array_push($attr3,$a['user_id']);    
 49                 }
 50                 $attr32= D('UserdcView')->where("Users.branchid = $branchid ")->select();
 51                 foreach($attr32 as $b)
 52                 {
 53                     array_push($attr3,$b['user_id']);    
 54                 }
 55                 array_unique($attr3);
 56                 $zhuce = count($attr3);    
 57                 $attr1['zhuce'] = $zhuce;    //注册的投资客户
 58                 
 59                 $money=0;    //充值金额
 60                 $count = 0;        //有充值记录客户
 61                 foreach($attr3 as $t)
 62                 {
 63                     $attr4 = M('recharge')->where(" uid = $t ")->select();
 64                     $a = count($attr4);
 65                     if($a>0)
 66                     {
 67                         $count++;        
 68                         foreach($attr4 as $tt)
 69                         {
 70                             $money += $tt['bzmoney'];
 71                         }
 72                     }
 73                 }
 74                 $attr1['touzi'] = $count;
 75                 $attr1['money'] = $money;
 76                 array_push($attr,$attr1);
 77             }
 78         }
 79         else
 80         {
 81             $att['branchid']=$branchid;
 82             
 83             $branchname = M('branchs')->where(" id = $branchid")->getField("name");
 84             $att['branchname'] = $branchname;    //地区名字
 85             
 86             $attr2 = M('admin')->where(" roleid = 8 and branchid = $branchid  ")->select();    //指定服务处所有的理财经理
 87             $manager = 0;
 88             foreach($attr2 as $v)
 89             {
 90                 $time = strtotime($v['regtime']);    
 91                 if( $time >= $time1 && $time <= $time2)
 92                 {
 93                     $manager++;    
 94                 }
 95             }
 96             $att['manager'] = $manager;    //理财经理
 97             
 98             
 99             $attr3 = array();    //指定服务处所有注册客户
100             $attr31 = M('users')->where(" isqiye=0 and isloanuser = 0 and isdanbao = 0 and branchid = $branchid and regtime >= $time1 and regtime <= $time2 ")->select();    
101             foreach($attr31 as $a)
102             {
103                 array_push($attr3,$a['user_id']);    
104             }
105             $attr32= D('UserdcView')->where("Users.branchid = $branchid ")->select();
106             foreach($attr32 as $b)
107             {
108                 array_push($attr3,$b['user_id']);    
109             }
110             array_unique($attr3);
111             $zhuce = count($attr3);    
112             $att['zhuce'] = $zhuce;    //注册的投资客户
113             
114             $money=0;    //充值金额
115             $count = 0;        //有充值记录客户
116             foreach($attr3 as $t)
117             {
118                 $attr4 = M('recharge')->where(" uid = $t ")->select();
119                 $a = count($attr4);
120                 if($a>0)
121                 {
122                     $count++;        
123                     foreach($attr4 as $tt)
124                     {
125                         $money += $tt['bzmoney'];
126                     }
127                 }
128             }
129             $att['touzi'] = $count;
130             $att['money'] = $money;
131             
132             array_push($attr,$att);
133         }
134         
135         $list=$attr;
136         $list=keysortExcel($list,array('branchname','manager','zhuce','touzi','money'));
137         exportexcel($list,array('服务处网点','理财经理','注册会员','投资人数','标准业绩'),'人力资源统计-'.time());
138     }
139     

前台代码:

 1 //导出数据
 2 function doExport(that){
 3     var diqu=$("#branchid").combobox('getValue');
 4     var start=$("#a").datebox('getValue');
 5     var end  =$("#b").datebox('getValue');    
 6     $.post('<{:U('Human/index_doExport')}>', {diqu:diqu,start:start,end:end}, function(res){
 7             if(!res.status){
 8                 $.messager.alert('提示信息', res.info, 'error');
 9             }else{
10                  window.open(res.info,'_blank');
11             }
12     }, 'json');
13 }

 

posted @ 2017-03-06 11:56  万里冰封  阅读(2003)  评论(0编辑  收藏  举报