|
@@ -0,0 +1,197 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\manage\controller;
|
|
|
+
|
|
|
+use think\Controller;
|
|
|
+use think\Db;
|
|
|
+use think\Session;
|
|
|
+use think\Config;
|
|
|
+use think\Cookie;
|
|
|
+use think\Request;
|
|
|
+use app\common\library\SysLogs;
|
|
|
+use app\common\library\UUIDs;
|
|
|
+
|
|
|
+class Statistics extends Base {
|
|
|
+
|
|
|
+ public function index() {
|
|
|
+
|
|
|
+ return $this->fetch('index');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function datas(){
|
|
|
+ $admin = Session::get('session_manager');
|
|
|
+ $institution_id = $admin['institution_id'];
|
|
|
+ $doctor = DB::table('doctors')->where('institution_id',$institution_id)->field('realname,id')->select();
|
|
|
+ $request = Request::instance();
|
|
|
+ $params = $request->param();
|
|
|
+ $where = array();
|
|
|
+ foreach ($params as $k=>$v) {
|
|
|
+ switch($k){
|
|
|
+ case 'upload1':
|
|
|
+ if($params['upload1'] == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $where[] = ' report_datetime > \''.$params['upload1'].' 00:00:00\' ';
|
|
|
+ break;
|
|
|
+ case 'upload2':
|
|
|
+ if($params['upload2'] == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $where[] = ' report_datetime < \''.$params['upload2'].' 23:59:59\' ';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(count($where) <= 1){
|
|
|
+ $where1 = implode('',$where);
|
|
|
+ $search = $where1;
|
|
|
+ }else{
|
|
|
+ $where1 = implode(' and ',$where);
|
|
|
+ $search = $where1;
|
|
|
+ }
|
|
|
+ if($search == ''){
|
|
|
+ $time1 = date('Y-m-d 00:00:00',time());
|
|
|
+ $time2 = date('Y-m-d 23:59:59',time());
|
|
|
+ $search = 'report_datetime >\''.$time1.'\' and report_datetime < \''.$time2.'\'';
|
|
|
+ }
|
|
|
+ $report_num = 0;
|
|
|
+ $review_num = 0;
|
|
|
+ $list = [];
|
|
|
+ foreach($doctor as $k=>$v){
|
|
|
+ $report = DB::table('report')->where('report_doctor_id',$v['id'])->where($search)->count();
|
|
|
+ $review = DB::table('report')->where('review_doctor_id',$v['id'])->where($search)->count();
|
|
|
+ $list[$k]['name'] = $v['realname'];
|
|
|
+ $list[$k]['report'] = $report;
|
|
|
+ $list[$k]['review'] = $review;
|
|
|
+ $report_num = $report_num + $report;
|
|
|
+ $review_num = $review_num + $review;
|
|
|
+ }
|
|
|
+ $num = count($doctor);
|
|
|
+ $list[$num]['name'] = '统计';
|
|
|
+ $list[$num]['report'] = $report_num;
|
|
|
+ $list[$num]['review'] = $review_num;
|
|
|
+ echo json_encode($list);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function out() {
|
|
|
+ $admin = Session::get('session_manager');
|
|
|
+ $institution_id = $admin['institution_id'];
|
|
|
+ $doctor = DB::table('doctors')->where('institution_id',$institution_id)->field('realname,id')->select();
|
|
|
+ $request = Request::instance();
|
|
|
+ $params = $request->param();
|
|
|
+ $where = array();
|
|
|
+ $begin = '';
|
|
|
+ $finish = '';
|
|
|
+ foreach ($params as $k=>$v) {
|
|
|
+ switch($k){
|
|
|
+ case 'upload1':
|
|
|
+ if($params['upload1'] == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $where[] = ' report_datetime > \''.$params['upload1'].' 00:00:00\' ';
|
|
|
+ $begin = $params['upload1'];
|
|
|
+ break;
|
|
|
+ case 'upload2':
|
|
|
+ if($params['upload2'] == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $where[] = ' report_datetime < \''.$params['upload2'].' 23:59:59\' ';
|
|
|
+ $finish = $params['upload2'];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(count($where) <= 1){
|
|
|
+ $where1 = implode('',$where);
|
|
|
+ $search = $where1;
|
|
|
+ }else{
|
|
|
+ $where1 = implode(' and ',$where);
|
|
|
+ $search = $where1;
|
|
|
+ }
|
|
|
+ if($search == ''){
|
|
|
+ $time1 = date('Y-m-d 00:00:00',time());
|
|
|
+ $time2 = date('Y-m-d 23:59:59',time());
|
|
|
+ $search = 'report_datetime >\''.$time1.'\' and report_datetime < \''.$time2.'\'';
|
|
|
+ $begin = date('Y-m-d',time());
|
|
|
+ $finish = date('Y-m-d',time());
|
|
|
+ }
|
|
|
+ $report_num = 0;
|
|
|
+ $review_num = 0;
|
|
|
+ $list = [];
|
|
|
+ foreach($doctor as $k=>$v){
|
|
|
+ $report = DB::table('report')->where('report_doctor_id',$v['id'])->where($search)->count();
|
|
|
+ $review = DB::table('report')->where('review_doctor_id',$v['id'])->where($search)->count();
|
|
|
+ $list[$k]['name'] = $v['realname'];
|
|
|
+ $list[$k]['report'] = $report;
|
|
|
+ $list[$k]['review'] = $review;
|
|
|
+ $report_num = $report_num + $report;
|
|
|
+ $review_num = $review_num + $review;
|
|
|
+ }
|
|
|
+ $num = count($doctor);
|
|
|
+ $list[$num]['name'] = '统计';
|
|
|
+ $list[$num]['report'] = $report_num;
|
|
|
+ $list[$num]['review'] = $review_num;
|
|
|
+ if($begin == $finish){
|
|
|
+ $filename = $begin."数据统计表";
|
|
|
+ }else{
|
|
|
+ $filename = $begin.'至'.$finish."数据统计表";
|
|
|
+ }
|
|
|
+ $headArr = array("医生姓名","已书写报告数量", "已审核报告数量");
|
|
|
+ $this->getExcel($filename, $headArr, $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getExcel($fileName, $headArr, $data) {
|
|
|
+ //对数据进行检验
|
|
|
+ if (empty($data) || !is_array($data)) {
|
|
|
+ die("data must be a array");
|
|
|
+ }
|
|
|
+ //检查文件名
|
|
|
+ if (empty($fileName)) {
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ $date = date("Y_m_d", time());
|
|
|
+ $fileName .= ".xls";
|
|
|
+
|
|
|
+ //创建PHPExcel对象,注意,不能少了\
|
|
|
+ $objPHPExcel = new \PHPExcel();
|
|
|
+ $objProps = $objPHPExcel->getProperties();
|
|
|
+
|
|
|
+ $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
|
|
|
+ $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
|
|
|
+ $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
|
|
|
+ //设置表头
|
|
|
+ $key = ord("A");
|
|
|
+ foreach ($headArr as $v) {
|
|
|
+ $colum = chr($key);
|
|
|
+ $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
|
|
|
+ $key += 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ $column = 2;
|
|
|
+ $objActSheet = $objPHPExcel->getActiveSheet();
|
|
|
+ foreach ($data as $key => $rows) { //行写入
|
|
|
+ $span = ord("A");
|
|
|
+ foreach ($rows as $keyName => $value) {// 列写入
|
|
|
+ $j = chr($span);
|
|
|
+ $objActSheet->setCellValue($j . $column, $value);
|
|
|
+ $span++;
|
|
|
+ }
|
|
|
+ $column++;
|
|
|
+ }
|
|
|
+
|
|
|
+ $fileName = iconv("utf-8", "gb2312", $fileName);
|
|
|
+ //重命名表
|
|
|
+ // $objPHPExcel->getActiveSheet()->setTitle('test');
|
|
|
+ //设置活动单指数到第一个表,所以Excel打开这是第一个表
|
|
|
+ $objPHPExcel->setActiveSheetIndex(0);
|
|
|
+ header('Content-Type: application/vnd.ms-excel');
|
|
|
+ header("Content-Disposition: attachment;filename=\"$fileName\"");
|
|
|
+ header('Cache-Control: max-age=0');
|
|
|
+
|
|
|
+ $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
|
|
|
+ $objWriter->save('php://output'); //文件通过浏览器下载
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|