From 4ae241231c8ad8e0bc2cbe4474d12f784f802f7e Mon Sep 17 00:00:00 2001 From: liyinglin Date: Tue, 19 Mar 2024 17:13:01 +0800 Subject: [PATCH] 1 --- .../Admin/StatisticsController.php | 30 +++++++++++++++++++ .../views/admin/statistics/bed.blade.php | 10 +++++++ 2 files changed, 40 insertions(+) diff --git a/app/Http/Controllers/Admin/StatisticsController.php b/app/Http/Controllers/Admin/StatisticsController.php index 46dc30c..afc57c1 100755 --- a/app/Http/Controllers/Admin/StatisticsController.php +++ b/app/Http/Controllers/Admin/StatisticsController.php @@ -29,6 +29,8 @@ use App\Scopes\AdminProjectScope; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use Spatie\Permission\Models\Role; class StatisticsController extends CommonController @@ -448,6 +450,7 @@ class StatisticsController extends CommonController */ public function bed() { + $is_export = \request('is_export',0); $projects = $this->_checkProjects(); if (!$projects->count()) { return $this->error($this->noProjects); @@ -483,6 +486,33 @@ class StatisticsController extends CommonController $item->rate = round($item->order_total / $bedsIdTemp->count(), 4) * 100; } } + + // 导出 + if($is_export){ + $area = $area->toArray(); + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $sheet->setCellValue('A1', '病区'); + $sheet->setCellValue('B1', '床位数量'); + $sheet->setCellValue('C1', '床位占比'); + $sheet->setCellValue('D1', '订单数量'); + $sheet->setCellValue('E1', '护工配比'); + + $count = count($area); //计算有多少条数据 + for ($i = 2; $i <= $count + 1; $i++) { + $sheet->setCellValue('A' . $i, $area[$i - 2]['name']); + $sheet->setCellValue('B' . $i, $area[$i - 2]['beds_count']); + $sheet->setCellValue('C' . $i, $area[$i - 2]['bed_rate']); + $sheet->setCellValue('D' . $i, $area[$i - 2]['order_total']); + $sheet->setCellValue('E' . $i, $area[$i - 2]['rate']); + } + header('Content-Type: application/vnd.ms-excel'); + header('Content-Disposition: attachment;filename="' . $project->name . '_' . date('YmdHis') . '.xlsx"'); + header('Cache-Control: max-age=0'); + $writer = new Xlsx($spreadsheet); + $writer->save('php://output'); + exit; + } return view($this->bladePath . ".bed", compact("area", "orderTotal", "totalBed", "project", "project_id", "month", "projects")); } diff --git a/resources/views/admin/statistics/bed.blade.php b/resources/views/admin/statistics/bed.blade.php index e06fc4a..72c2d2a 100755 --- a/resources/views/admin/statistics/bed.blade.php +++ b/resources/views/admin/statistics/bed.blade.php @@ -23,6 +23,7 @@ @endforeach + @@ -52,4 +53,13 @@ + @endsection