|  | @@ -53,17 +53,20 @@ class Exams extends Backend
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public function index()
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | +        //查询最后一场考试id
 | 
	
		
			
				|  |  | +        $exam_collection_id = $this->model->where($this->whereExtend)->order('exam_id desc')->value('exam_collection_id');
 | 
	
		
			
				|  |  | +        $collection_name = $this->model->where(['exam_collection_id'=>$exam_collection_id])->value('exam_collection_name');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //设置过滤方法
 | 
	
		
			
				|  |  |          $this->request->filter(['strip_tags', 'trim']);
 | 
	
		
			
				|  |  |          if (false === $this->request->isAjax()) {
 | 
	
		
			
				|  |  | +            $this->assignConfig('collection_name', $collection_name);
 | 
	
		
			
				|  |  |              return $this->view->fetch();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //如果发送的来源是 Selectpage,则转发到 Selectpage
 | 
	
		
			
				|  |  |          if ($this->request->request('keyField')) {
 | 
	
		
			
				|  |  |              return $this->selectpage();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //查询最后一场考试id
 | 
	
		
			
				|  |  | -        $exam_collection_id = $this->model->where($this->whereExtend)->order('exam_id desc')->value('exam_collection_id');
 | 
	
		
			
				|  |  |          //查询考试
 | 
	
		
			
				|  |  |          $filter = $this->request->get("filter", '');
 | 
	
		
			
				|  |  |          $filter = (array)json_decode($filter, true);
 | 
	
	
		
			
				|  | @@ -503,14 +506,24 @@ class Exams extends Backend
 | 
	
		
			
				|  |  |          $op = $this->request->get("op", '');
 | 
	
		
			
				|  |  |          $op = (array)json_decode($op, true);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        if(isset($filter) &&!empty($filter['exam_collection_name'])){
 | 
	
		
			
				|  |  | +            $this->whereExtend['exam_collection_name'] = $filter['exam_collection_name'];
 | 
	
		
			
				|  |  | +            $this->request->get(['filter'=>json_encode($filter),'op'=>json_encode($op)]);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          [$where, $sort, $order, $offset, $limit] = $this->buildparams();
 | 
	
		
			
				|  |  |          $list = $this->model
 | 
	
		
			
				|  |  |              ->where($where)->where($this->whereExtend)
 | 
	
		
			
				|  |  |              ->order($sort, $order)
 | 
	
		
			
				|  |  |              ->paginate($limit);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        $depart_ids = [];
 | 
	
		
			
				|  |  | +        foreach ($list as $k => $v){
 | 
	
		
			
				|  |  | +            if(!in_array($v['user_depart_id'],$depart_ids)){
 | 
	
		
			
				|  |  | +                $depart_ids[] = $v['user_depart_id'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          $xlsName = '学员成绩信息';
 | 
	
		
			
				|  |  | -        $this->exportExcel($xlsName,'Excel2007', $list);
 | 
	
		
			
				|  |  | +        $this->exportExcel($xlsName,'Excel2007', $list,$depart_ids);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -518,7 +531,7 @@ class Exams extends Backend
 | 
	
		
			
				|  |  |       * @param string $fileName 文件名
 | 
	
		
			
				|  |  |       * @param string $fileType 文件类型
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    function exportExcel($fileName, $fileType,$data)
 | 
	
		
			
				|  |  | +    function exportExcel($fileName, $fileType,$data,$depart_ids)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          //文件名称校验
 | 
	
		
			
				|  |  |          if (!$fileName) {
 | 
	
	
		
			
				|  | @@ -546,28 +559,55 @@ class Exams extends Backend
 | 
	
		
			
				|  |  |          $spreadsheet = new Spreadsheet();
 | 
	
		
			
				|  |  |          $worksheet = $spreadsheet->getActiveSheet();
 | 
	
		
			
				|  |  |          $worksheet->getColumnDimension('A')->setWidth(15);
 | 
	
		
			
				|  |  | -        $worksheet->getColumnDimension('B')->setWidth(15);
 | 
	
		
			
				|  |  | -        $worksheet->getColumnDimension('C')->setWidth(15);
 | 
	
		
			
				|  |  | -        $worksheet->getColumnDimension('D')->setWidth(15);
 | 
	
		
			
				|  |  | +        $worksheet->getColumnDimension('B')->setWidth(20);
 | 
	
		
			
				|  |  | +        $worksheet->getColumnDimension('C')->setWidth(20);
 | 
	
		
			
				|  |  | +        $worksheet->getColumnDimension('D')->setWidth(25);
 | 
	
		
			
				|  |  | +        $worksheet->getColumnDimension('E')->setWidth(30);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        $worksheet->getRowDimension('1')->setRowHeight(25);
 | 
	
		
			
				|  |  | +        $worksheet->getRowDimension('1')->setRowHeight(40);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //设置工作表标题名称
 | 
	
		
			
				|  |  |          $worksheet->setTitle('学员成绩信息');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        $worksheet->setCellValue('A1',"序号");
 | 
	
		
			
				|  |  | -        $worksheet->setCellValue('B1',"学员账号");
 | 
	
		
			
				|  |  | -        $worksheet->setCellValue('C1',"学员姓名");
 | 
	
		
			
				|  |  | -        $worksheet->setCellValue('D1',"总分");
 | 
	
		
			
				|  |  | +        //1745459433
 | 
	
		
			
				|  |  | +        $kaoshi = isset($data[0]['endtime']) ? date('Y-m-d',$data[0]['endtime']) : '';
 | 
	
		
			
				|  |  | +        $a = '';
 | 
	
		
			
				|  |  | +        foreach ($depart_ids as $k1=>$v1){
 | 
	
		
			
				|  |  | +            $wu = Db::name('department')->where('id',$v1)->find();
 | 
	
		
			
				|  |  | +            $si = Db::name('department')->where('id',$wu['parent_id'])->find();
 | 
	
		
			
				|  |  | +            $san = Db::name('department')->where('id',$si['parent_id'])->find();
 | 
	
		
			
				|  |  | +            $er = Db::name('department')->where('id',$san['parent_id'])->find();
 | 
	
		
			
				|  |  | +            $yi = Db::name('department')->where('id',$er['parent_id'])->find();
 | 
	
		
			
				|  |  | +            $a = $a.$yi['name']."/".$er['name']."/".$san['name']."/".$si['name']."/".$wu['name']."\n";
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +//        $a = "预选军士\n预选军士一区队";
 | 
	
		
			
				|  |  | +        $worksheet->setCellValue('A1',$a);
 | 
	
		
			
				|  |  | +        $worksheet->mergeCells('A1:D1');
 | 
	
		
			
				|  |  | +        $worksheet->setCellValue('E1',"考试日期 ".$kaoshi);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $worksheet->setCellValue('A2',"序号");
 | 
	
		
			
				|  |  | +        $worksheet->setCellValue('B2',"学员账号");
 | 
	
		
			
				|  |  | +        $worksheet->setCellValue('C2',"学员姓名");
 | 
	
		
			
				|  |  | +        $worksheet->setCellValue('D2',"模拟器类型");
 | 
	
		
			
				|  |  | +        $worksheet->setCellValue('E2',"总分");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          foreach ($data as $ky => $value)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            $lie = $ky+2;
 | 
	
		
			
				|  |  | +            $lie = $ky+3;
 | 
	
		
			
				|  |  | +            $sim_type= '';
 | 
	
		
			
				|  |  | +            if($value['sim_type'] == '0001'){
 | 
	
		
			
				|  |  | +                $sim_type = 'FZD04B型侦毒器';
 | 
	
		
			
				|  |  | +            }else if($value['sim_type'] == '0002'){
 | 
	
		
			
				|  |  | +                $sim_type = 'FZB006型毒剂报警器';
 | 
	
		
			
				|  |  | +            }else if($value['sim_type'] == '0003'){
 | 
	
		
			
				|  |  | +                $sim_type = '防化兵用毒剂报警器';
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              $worksheet->setCellValue('A'.$lie,++$ky);
 | 
	
		
			
				|  |  |              $worksheet->setCellValue('B'.$lie,$value['user_username']);
 | 
	
		
			
				|  |  |              $worksheet->setCellValue('C'.$lie,$value['user_nickname']);
 | 
	
		
			
				|  |  | -            $worksheet->setCellValue('D'.$lie,$value['total_score']);
 | 
	
		
			
				|  |  | +            $worksheet->setCellValue('D'.$lie,$sim_type);
 | 
	
		
			
				|  |  | +            $worksheet->setCellValue('E'.$lie,$value['total_score']);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -577,12 +617,24 @@ class Exams extends Backend
 | 
	
		
			
				|  |  |                  'size' => 14
 | 
	
		
			
				|  |  |              ],
 | 
	
		
			
				|  |  |          ];
 | 
	
		
			
				|  |  | +        $titlestyleArray2 = [
 | 
	
		
			
				|  |  | +            'font' => [
 | 
	
		
			
				|  |  | +                'size' => 12
 | 
	
		
			
				|  |  | +            ],
 | 
	
		
			
				|  |  | +        ];
 | 
	
		
			
				|  |  |          $headerStyleArray = [
 | 
	
		
			
				|  |  |              'font' => [
 | 
	
		
			
				|  |  |                  'name' => '方正小标宋简体',
 | 
	
		
			
				|  |  |                  'size' => 18
 | 
	
		
			
				|  |  |              ],
 | 
	
		
			
				|  |  |          ];
 | 
	
		
			
				|  |  | +        $headStyleArray1 = [
 | 
	
		
			
				|  |  | +            'alignment' => [
 | 
	
		
			
				|  |  | +                'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
 | 
	
		
			
				|  |  | +                'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
 | 
	
		
			
				|  |  | +                'wrapText' => true,
 | 
	
		
			
				|  |  | +            ],
 | 
	
		
			
				|  |  | +        ];
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          $commonStyleArray = [
 | 
	
		
			
				|  |  |              'alignment' => [
 | 
	
	
		
			
				|  | @@ -606,12 +658,15 @@ class Exams extends Backend
 | 
	
		
			
				|  |  |                  'wrapText' => true,
 | 
	
		
			
				|  |  |              ]
 | 
	
		
			
				|  |  |          ];
 | 
	
		
			
				|  |  | -        $worksheet->getStyle('A1:D1')->applyFromArray($titlestyleArray);
 | 
	
		
			
				|  |  | -        $worksheet->getStyle('A1:D1')->applyFromArray($commonStyleArray);
 | 
	
		
			
				|  |  | -        foreach ($data as $k=>$v){
 | 
	
		
			
				|  |  | -            $kk  = $k+2;
 | 
	
		
			
				|  |  | -            $worksheet->getStyle('A'.$kk.':D'.$kk)->applyFromArray($borderStyleArray);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $worksheet->getStyle('A1:E1')->applyFromArray($headStyleArray1);//换行
 | 
	
		
			
				|  |  | +        $worksheet->getStyle('A1:E1')->applyFromArray($titlestyleArray);
 | 
	
		
			
				|  |  | +        $worksheet->getStyle('A2:E2')->applyFromArray($titlestyleArray2);
 | 
	
		
			
				|  |  | +        $worksheet->getStyle('A2:E2')->applyFromArray($commonStyleArray);
 | 
	
		
			
				|  |  | +//        foreach ($data as $k=>$v){
 | 
	
		
			
				|  |  | +//            $kk  = $k+3;
 | 
	
		
			
				|  |  | +//            $worksheet->getStyle('A'.$kk.':E'.$kk)->applyFromArray($borderStyleArray);
 | 
	
		
			
				|  |  | +//        }
 | 
	
		
			
				|  |  |          // $worksheet->getStyle('A3:R3')->applyFromArray($commonStyleArray);
 | 
	
		
			
				|  |  |          // $worksheet->getStyle('A'.$footer_total.':R'.$footer_total)->applyFromArray($commonStyleArray);
 | 
	
		
			
				|  |  |          // $worksheet->getStyle('A1:C1')->applyFromArray($borderStyleArray);
 |