|
@@ -69,6 +69,7 @@ class OrderStatistics extends Auth
|
|
|
}
|
|
|
$data = list_sort_by($list,'nums','desc');
|
|
|
|
|
|
+
|
|
|
include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
|
|
|
//实例化PHPExcel类
|
|
|
$objPHPExcel =new \PHPExcel();
|
|
@@ -164,7 +165,6 @@ class OrderStatistics extends Auth
|
|
|
}
|
|
|
$data = list_sort_by($list,'nums','desc');
|
|
|
$result['rows'] = $data;
|
|
|
-
|
|
|
return json($result);
|
|
|
}else{
|
|
|
$this->assign('start',$start);
|
|
@@ -173,6 +173,102 @@ class OrderStatistics extends Auth
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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'));
|