123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- <?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 repairWorkload($mode){
- $start = input('start',date('Y-m-d',strtotime('-7 day')));
- $end = input('end',date('Y-m-d'));
- $mode = input('mode');
- if(request()->isAjax()){
- $sTime = $start.' 00:00:00';
- $eTime = $end.' 23:59:59';
- $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]['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();
- }
- $result['rows'] = $list;
- return json($result);
- }else{
- 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 repairWorkloadExport(){
- $start = input('start',date('Y-m-d',strtotime('-7 day')));
- $end = input('end',date('Y-m-d'));
- $mode = input('mode');
- $sTime = $start.' 00:00:00';
- $eTime = $end.' 23:59:59';
- if($mode == 1){
- $title = '报修工作量统计报表';
- }elseif ($mode == 2){
- $title = '保洁工作量统计报表';
- }elseif ($mode == 3){
- $title = '运送工作量统计报表';
- }elseif ($mode == 4){
- $title = '应急工作量统计报表';
- }elseif ($mode == 0){
- $title = '一键呼叫工作量统计报表';
- }
- $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]['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();
- }
- 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', '已接单')
- ->setCellValue('E1', '已完成')
- ->setCellValue('F1', '被员工驳回')
- ->setCellValue('G1', '客观原因无法完成')
- ->setCellValue('H1', '已取消');
- // 设置表格头水平居中
- $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('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->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)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->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);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(30);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($list); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['user_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['nums']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $list[$i]['nums1']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $list[$i]['nums2']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $list[$i]['nums3']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $list[$i]['nums4']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $list[$i]['nums5']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $list[$i]['nums6']);
- }
- //设置保存的Excel表格名称
- $filename = $title.'_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle($title);
- //设置浏览器窗口下载表格
- 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 conveyCateWorkload(){
- $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('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();
- }
- $result['rows'] = $list;
- return json($result);
- }else{
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- }
- public function conveyCateWorkloadExport(){
- $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('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();
- }
- 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',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('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;
- }
- $result['rows'] = $list;
- return json($result);
- }else{
- $this->assign('start',$start);
- $this->assign('end',$end);
- return $this->fetch();
- }
- }
- public function conveyCateTodoExport(){
- $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('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;
- }
- 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('B' . ($i + 2), $list[$i]['total_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($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');
- }
- }
|