123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733 |
- <?php
- namespace app\admin\controller;
- use think\Db;
- use think\Exception;
- class OrderStatistics extends Auth
- {
- public function repairItems(){
- $start = input('start',date('Y-m-d',strtotime('-7 day')));
- $end = input('end',date('Y-m-d'));
- if(request()->isAjax()){
- $sTime = $start.' 00:00:00';
- $eTime = $end.' 23:59:59';
- $list = Db::name('order_type')
- ->field('id,title')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('parent_id','>',0)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['nums'] = Db::name('orders')
- ->alias('o')
- ->join('order_repair or','or.order_id=o.id')
- ->where('or.type_id',$v['id'])
- ->where('o.del',0)
- ->where('o.create_time','>=',$sTime)
- ->where('o.create_time','<=',$eTime)
- ->count();
- }
- $data = list_sort_by($list,'nums','desc');
- $result['rows'] = $data;
- return json($result);
- }else{
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- }
- public function repairItemsExport(){
- $start = input('start',date('Y-m-d',strtotime('-7 day')));
- $end = input('end',date('Y-m-d'));
- $sTime = $start.' 00:00:00';
- $eTime = $end.' 23:59:59';
- $list = Db::name('order_type')
- ->field('id,title')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('parent_id','>',0)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['nums'] = Db::name('orders')
- ->alias('o')
- ->join('order_repair or','or.order_id=o.id')
- ->where('or.type_id',$v['id'])
- ->where('o.del',0)
- ->where('o.create_time','>=',$sTime)
- ->where('o.create_time','<=',$eTime)
- ->count();
- }
- $data = list_sort_by($list,'nums','desc');
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '报修事项')
- ->setCellValue('B1', '总数');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($data); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $data[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $data[$i]['nums']);
- }
- //设置保存的Excel表格名称
- $filename = '报修事项统计报表_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('报修事项统计报表');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function repairCate(){
- $start = input('start',date('Y-m-d',strtotime('-7 day')));
- $end = input('end',date('Y-m-d'));
- if(request()->isAjax()){
- $sTime = $start.' 00:00:00';
- $eTime = $end.' 23:59:59';
- $list = Db::name('order_type')
- ->field('id,title,parent_id')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('parent_id','=',0)
- ->select();
- foreach ($list as $k=>$v){
- $type = Db::name('order_type')
- ->field('id')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('parent_id',$v['id'])
- ->select();
- $ids = [];
- foreach ($type as $kk=>$vv){
- $ids[$kk] = $vv['id'];
- }
- $list[$k]['ids'] = $ids;
- }
- foreach ($list as $k=>$v){
- $list[$k]['nums'] = Db::name('orders')
- ->alias('o')
- ->join('order_repair or','or.order_id=o.id')
- ->whereIn('or.type_id',$v['ids'])
- ->where('o.del',0)
- ->where('o.org_id',$this->orgId)
- ->where('o.create_time','>=',$sTime)
- ->where('o.create_time','<=',$eTime)
- ->count();
- }
- $data = list_sort_by($list,'nums','desc');
- $result['rows'] = $data;
- return json($result);
- }else{
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- }
-
- public function repairCateExport(){
- $start = input('start',date('Y-m-d',strtotime('-7 day')));
- $end = input('end',date('Y-m-d'));
- $sTime = $start.' 00:00:00';
- $eTime = $end.' 23:59:59';
- $list = Db::name('order_type')
- ->field('id,title,parent_id')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('parent_id','=',0)
- ->select();
- foreach ($list as $k=>$v){
- $type = Db::name('order_type')
- ->field('id')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('parent_id',$v['id'])
- ->select();
- $ids = [];
- foreach ($type as $kk=>$vv){
- $ids[$kk] = $vv['id'];
- }
- $list[$k]['ids'] = $ids;
- }
- foreach ($list as $k=>$v){
- $list[$k]['nums'] = Db::name('orders')
- ->alias('o')
- ->join('order_repair or','or.order_id=o.id')
- ->whereIn('or.type_id',$v['ids'])
- ->where('o.del',0)
- ->where('o.org_id',$this->orgId)
- ->where('o.create_time','>=',$sTime)
- ->where('o.create_time','<=',$eTime)
- ->count();
- }
- $data = list_sort_by($list,'nums','desc');
-
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '报修类型')
- ->setCellValue('B1', '总数');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($data); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $data[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $data[$i]['nums']);
- }
- //设置保存的Excel表格名称
- $filename = '报修类型统计报表_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('报修类型统计报表');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function repairWorkload($mode){
- $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
- $end = input('end',date('Y-m-d 23:59:59'));
- $mode = input('mode');
- $lists = $this->repairWorkloadData($start,$end,$mode);
- $this->assign('list',$lists['list']);
- $this->assign('totalList',$lists['totalList']);
- if($mode == 1){
- $title = '报修工作量统计报表';
- }elseif ($mode == 2){
- $title = '保洁工作量统计报表';
- }elseif ($mode == 3){
- $title = '运送工作量统计报表';
- }elseif ($mode == 4){
- $title = '应急工作量统计报表';
- }elseif ($mode == 0){
- $title = '一键呼叫工作量统计报表';
- }
- $this->assign('mode',$mode);
- $this->assign('title',$title);
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- public function repairWorkloadData($start,$end,$mode){
- // $sTime = $start.' 00:00:00';
- // $eTime = $end.' 23:59:59';
- $sTime = $start;
- $eTime = $end;
- $list = Db::name('todo')
- ->field('id,to_user_id')
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->where('work_type_mode',$mode)
- ->group('to_user_id')
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
- $list[$k]['score'] = 0;
- if($mode==3){
- $list[$k]['score'] = Db::name('todo')
- ->alias('a')
- ->join('order_convey b','a.order_id=b.order_id')
- ->where('a.del',0)
- ->where('a.to_user_id',$v['to_user_id'])
- ->where('a.org_id',$this->orgId)
- ->where('a.create_time','>=',$sTime)
- ->where('a.create_time','<=',$eTime)
- ->where('a.work_type_mode',$mode)
- ->where('a.todo_mode',3)
- ->sum('b.score');
- }
- $list[$k]['nums'] =Db::name('todo')
- ->where('del',0)
- ->where('to_user_id',$v['to_user_id'])
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->where('work_type_mode',$mode)
- ->count();
- $list[$k]['nums1'] =Db::name('todo')
- ->where('del',0)
- ->where('to_user_id',$v['to_user_id'])
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->where('work_type_mode',$mode)
- ->where('todo_mode',1)
- ->count();
- $list[$k]['nums2'] =Db::name('todo')
- ->where('del',0)
- ->where('to_user_id',$v['to_user_id'])
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->where('work_type_mode',$mode)
- ->where('todo_mode',2)
- ->count();
- $list[$k]['nums3'] =Db::name('todo')
- ->where('del',0)
- ->where('to_user_id',$v['to_user_id'])
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->where('work_type_mode',$mode)
- ->where('todo_mode',3)
- ->count();
- $list[$k]['nums4'] =Db::name('todo')
- ->where('del',0)
- ->where('to_user_id',$v['to_user_id'])
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->where('work_type_mode',$mode)
- ->where('todo_mode',4)
- ->count();
- $list[$k]['nums5'] =Db::name('todo')
- ->where('del',0)
- ->where('to_user_id',$v['to_user_id'])
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->where('work_type_mode',$mode)
- ->where('todo_mode',5)
- ->count();
- $list[$k]['nums6'] =Db::name('todo')
- ->where('del',0)
- ->where('to_user_id',$v['to_user_id'])
- ->where('org_id',$this->orgId)
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->where('work_type_mode',$mode)
- ->where('todo_mode',6)
- ->count();
- }
- $list = $list ? list_sort_by($list,'nums','desc'):[];
- $totalList = [
- array_sum(array_column($list,'score')),
- array_sum(array_column($list,'nums')),
- array_sum(array_column($list,'nums1')),
- array_sum(array_column($list,'nums2')),
- array_sum(array_column($list,'nums3')),
- array_sum(array_column($list,'nums4')),
- array_sum(array_column($list,'nums5')),
- array_sum(array_column($list,'nums6')),
- ];
- if($mode!=3){
- unset($totalList[0]);
- }
- return ['list'=>$list,'totalList'=>$totalList];
- }
- public function repairWorkloadExport(){
- $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
- $end = input('end',date('Y-m-d 23:59:59'));
- $mode = input('mode');
- $ret = $this->repairWorkloadData($start,$end,$mode);
- $list = $ret['list'];
- $totalList = $ret['totalList'];
- $title = '';
- if($mode == 1){
- $title = '报修工作量统计报表';
- }elseif ($mode == 2){
- $title = '保洁工作量统计报表';
- }elseif ($mode == 3){
- $title = '运送工作量统计报表';
- }elseif ($mode == 4){
- $title = '应急工作量统计报表';
- }elseif ($mode == 0){
- $title = '一键呼叫工作量统计报表';
- }
- set_time_limit(0);
- ini_set("memory_limit", "1024M");
- header("Content-type: application/vnd.ms-excel");
- header("Content-Type: application/force-download");
- header("Content-Disposition: attachment; filename=".$title.".xls");
- header('Expires:0');
- header('Pragma:public');
- $res = '';
- $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
- $res.='<tr style="background: #ffffff;">';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">姓名</th>';
- if($mode==3){
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">累计运送积分</th>';
- }
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总数</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">待接单</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">已接单</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">已完成</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">被员工驳回</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">客观原因无法完成</th>';
- $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">已取消</th>';
- $res.='</tr>';
- foreach ($list as $k=>$v){
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['user_name'].'</td>';
- if($mode==3){
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['score'].'</td>';
- }
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums1'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums2'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums3'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums4'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums5'].'</td>';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums6'].'</td>';
- $res.='</tr>';
- }
- $res.='<tr style="background: #ffffff;">';
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" >合计:</td>';
- foreach ($totalList as $k=>$v){
- $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" >'.$v.'</td>';
- }
- $res.='</tr>';
- echo $res;
- }
- public function conveyCateWorkload(){
- $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
- $end = input('end',date('Y-m-d 23:59:59'));
- $lists = $this->conveyCateWorkloadData($start,$end);
- $this->assign('list',$lists);
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- public function conveyCateWorkloadData($start,$end){
- // $sTime = $start.' 00:00:00';
- // $eTime = $end.' 23:59:59';
- $sTime = $start;
- $eTime = $end;
- $list = Db::name('address')
- ->field('id,title')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('find_in_set(2,types)')
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['nums'] = Db::name('order_convey_lis')
- ->where('org_id',$this->orgId)
- ->where('addr_id',$v['id'])
- ->where('create_time','>=',$sTime)
- ->where('create_time','<=',$eTime)
- ->count();
- }
- return $list;
- }
- public function conveyCateWorkloadExport(){
- $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
- $end = input('end',date('Y-m-d 23:59:59'));
- $list = $this->conveyCateWorkloadData($start,$end);
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '运送地点')
- ->setCellValue('B1', '标本');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($list); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['nums']);
- }
- //设置保存的Excel表格名称
- $filename = '运送类型工作量统计_'. date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('运送类型工作量统计_');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- public function conveyCateTodo(){
- $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
- $end = input('end',date('Y-m-d 23:59:59'));
- $ret = $this->conveyCateTodoData($start,$end);
- $this->assign('list',$ret);
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- public function conveyCateTodoData($start,$end){
- // $sTime = $start.' 00:00:00';
- // $eTime = $end.' 23:59:59';
- $sTime = $start;
- $eTime = $end;
- $list = Db::name('convey_cate')
- ->field('id,title')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->select();
- foreach ($list as $k=>$v){
- $todo = Db::name('todo')
- ->alias('t')
- ->field('t.wc_time')
- ->join('order_convey oc','oc.order_id=t.order_id')
- ->where('oc.type',$v['id'])
- ->where('t.del',0)
- ->where('t.create_time','>=',$sTime)
- ->where('t.create_time','<=',$eTime)
- ->where('t.todo_mode',3)
- ->select();
- $todoCount = Db::name('todo')
- ->alias('t')
- ->field('t.wc_time')
- ->join('order_convey oc','oc.order_id=t.order_id')
- ->where('oc.type',$v['id'])
- ->where('t.del',0)
- ->where('t.create_time','>=',$sTime)
- ->where('t.create_time','<=',$eTime)
- ->where('t.todo_mode',3)
- ->count();
- $totalTime = 0;
- foreach ($todo as $key=>$val){
- $totalTime +=$val['wc_time'];
- }
- $aveTime = $totalTime>0?round($totalTime/$todoCount/60,2):0;
- $list[$k]['count'] = isset($todoCount)?$todoCount:0;
- $list[$k]['total_time'] = isset($totalTime)?round($totalTime/60,2):0;
- $list[$k]['ave_time'] = isset($aveTime)&&$aveTime>0?$aveTime:0;
- }
- $list = $list?arraySequence($list,'count','SORT_DESC'):[];
- return $list;
- }
- public function conveyCateTodoExport(){
- $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
- $end = input('end',date('Y-m-d 23:59:59'));
- $list = $this->conveyCateTodoData($start,$end);
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel =new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '运送类型')
- ->setCellValue('B1', '工单数')
- ->setCellValue('C1', '总时长(分)')
- ->setCellValue('D1', '平均时长(分)');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($list); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['count']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $list[$i]['total_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $list[$i]['ave_time']);
- }
- //设置保存的Excel表格名称
- $filename = '运送类型工单统计_'. date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('运送类型工单统计_');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- }
|