正在显示
5 个修改的文件
包含
124 行增加
和
31 行删除
| @@ -235,5 +235,56 @@ class Department extends Backend | @@ -235,5 +235,56 @@ class Department extends Backend | ||
| 235 | public function downloadexcel($id) | 235 | public function downloadexcel($id) |
| 236 | { | 236 | { |
| 237 | $department = Db::name("department")->where('id', $id)->find(); | 237 | $department = Db::name("department")->where('id', $id)->find(); |
| 238 | + $workinghours=Db::name("workinghours") | ||
| 239 | + ->alias("a") | ||
| 240 | + ->join("user b","a.user_id=b.id") | ||
| 241 | + ->join("project c","a.project_id=c.id") | ||
| 242 | + ->where("a.department_id",$id) | ||
| 243 | + ->field("project_name,working_hours,reporttime,username") | ||
| 244 | + ->select(); | ||
| 245 | + $file=$this->projectexcel($workinghours,$department); | ||
| 246 | + | ||
| 247 | + } | ||
| 248 | + /** | ||
| 249 | + *导出表 | ||
| 250 | + */ | ||
| 251 | + public function projectexcel($workinghours, $department) | ||
| 252 | + { | ||
| 253 | + vendor('phpoffice.phpexcel.PHPExcel'); | ||
| 254 | + Vendor('phpoffice.phpexcel.Classes.PHPExcel'); | ||
| 255 | + Vendor('phpoffice.phpexcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory'); | ||
| 256 | + //实例化 | ||
| 257 | + $objExcel = new \PHPExcel(); | ||
| 258 | + //设置文档属性 | ||
| 259 | + $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007'); | ||
| 260 | + //设置内容 | ||
| 261 | + $objActSheet = $objExcel->getActiveSheet(); | ||
| 262 | + $key = ord("A"); | ||
| 263 | + $letter = explode(',', "A,B,C,D,E,F"); | ||
| 264 | + $arrHeader = array('序号', '部门名称', '项目名称', '提交人', '工时', '提交时间'); | ||
| 265 | + //填充表头信息 | ||
| 266 | + $lenth = count($arrHeader); | ||
| 267 | + for ($i = 0; $i < $lenth; $i++) { | ||
| 268 | + $objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]"); | ||
| 269 | + }; | ||
| 270 | + //填充表格信息 | ||
| 271 | + foreach ($workinghours as $k => $v) { | ||
| 272 | + $j = $k + 1; | ||
| 273 | + $k += 2; | ||
| 274 | + | ||
| 275 | + $objActSheet->setCellValue('A' . $k, $j); | ||
| 276 | + $objActSheet->setCellValue('B' . $k, $department['name'])->getDefaultColumnDimension()->setWidth(20); | ||
| 277 | + $objActSheet->setCellValue('C' . $k, $v['project_name']); | ||
| 278 | + $objActSheet->setCellValue('D' . $k, $v['username']); | ||
| 279 | + $objActSheet->setCellValue('E' . $k, $v['working_hours']); | ||
| 280 | + $objActSheet->setCellValue('F' . $k, date("Y-m-d", $v['reporttime'])); | ||
| 281 | + } | ||
| 282 | + $outfile = $department['name'] ."-". rand(10000, 99999) . ".xlsx"; | ||
| 283 | + $objExcel->createSheet(); | ||
| 284 | + // Redirect output to a client’s web browser (Excel2007) | ||
| 285 | + $title = date("YmdHis"); | ||
| 286 | + header('Content-Disposition: attachment;filename="' . $outfile . '.xlsx"'); | ||
| 287 | + $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007'); | ||
| 288 | + $objWriter->save('php://output'); | ||
| 238 | } | 289 | } |
| 239 | } | 290 | } |
| @@ -266,17 +266,12 @@ class Project extends Backend | @@ -266,17 +266,12 @@ class Project extends Backend | ||
| 266 | $j = $k + 1; | 266 | $j = $k + 1; |
| 267 | $k += 2; | 267 | $k += 2; |
| 268 | $objActSheet->setCellValue('A' . $k, $j); | 268 | $objActSheet->setCellValue('A' . $k, $j); |
| 269 | - $objActSheet->setCellValue('B' . $k, $project['project_name']); | 269 | + $objActSheet->setCellValue('B' . $k, $project['project_name'])->getDefaultColumnDimension()->setWidth(20); |
| 270 | $objActSheet->setCellValue('C' . $k, $v['username']); | 270 | $objActSheet->setCellValue('C' . $k, $v['username']); |
| 271 | $objActSheet->setCellValue('D' . $k, $v['working_hours']); | 271 | $objActSheet->setCellValue('D' . $k, $v['working_hours']); |
| 272 | $objActSheet->setCellValue('E' . $k, date("Y-m-d", $v['reporttime'])); | 272 | $objActSheet->setCellValue('E' . $k, date("Y-m-d", $v['reporttime'])); |
| 273 | } | 273 | } |
| 274 | $outfile = $project['project_name'] ."-". rand(10000, 99999) . ".xlsx"; | 274 | $outfile = $project['project_name'] ."-". rand(10000, 99999) . ".xlsx"; |
| 275 | - $objWriter->save('./datauploads/' . $outfile); | ||
| 276 | - | ||
| 277 | - $file = '../public/datauploads/' . $outfile; // 文件路径 | ||
| 278 | - $filename = $outfile; // 下载时的文件名 | ||
| 279 | - | ||
| 280 | $objExcel->createSheet(); | 275 | $objExcel->createSheet(); |
| 281 | // Redirect output to a client’s web browser (Excel2007) | 276 | // Redirect output to a client’s web browser (Excel2007) |
| 282 | $title = date("YmdHis"); | 277 | $title = date("YmdHis"); |
| @@ -284,26 +279,5 @@ class Project extends Backend | @@ -284,26 +279,5 @@ class Project extends Backend | ||
| 284 | $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007'); | 279 | $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007'); |
| 285 | $objWriter->save('php://output'); | 280 | $objWriter->save('php://output'); |
| 286 | } | 281 | } |
| 287 | - function download( $file_url , $new_name = '' ){ | ||
| 288 | - $file_url='../public/datauploads/'.$file_url; | ||
| 289 | - if (!isset( $file_url )||trim( $file_url )== '' ){ | ||
| 290 | - echo '500' ; | ||
| 291 | - } | ||
| 292 | - if (! file_exists ( $file_url )){ //检查文件是否存在 | ||
| 293 | - echo '404' ; | ||
| 294 | - } | ||
| 295 | - $file_name = basename ( $file_url ); | ||
| 296 | - $file_type = explode ( '.' , $file_url ); | ||
| 297 | - $file_type = $file_type [ count ( $file_type )-1]; | ||
| 298 | - $file_name =trim( $new_name == '' )? $file_name :urlencode( $new_name ); | ||
| 299 | - $file_type = fopen ( $file_url , 'r' ); //打开文件 | ||
| 300 | - //输入文件标签 | ||
| 301 | - header( "Content-type: application/octet-stream" ); | ||
| 302 | - header( "Accept-Ranges: bytes" ); | ||
| 303 | - header( "Accept-Length: " . filesize ( $file_url )); | ||
| 304 | - header( "Content-Disposition: attachment; filename=" . $file_name ); | ||
| 305 | - //输出文件内容 | ||
| 306 | - echo fread ( $file_type , filesize ( $file_url )); | ||
| 307 | - fclose( $file_type ); | ||
| 308 | - } | 282 | + |
| 309 | } | 283 | } |
| @@ -199,4 +199,59 @@ class User extends Backend | @@ -199,4 +199,59 @@ class User extends Backend | ||
| 199 | { | 199 | { |
| 200 | return md5(md5($password) . $salt); | 200 | return md5(md5($password) . $salt); |
| 201 | } | 201 | } |
| 202 | + public function downloadexcel($id) | ||
| 203 | + { | ||
| 204 | + $user = Db::name("user")->where('id', $id)->find(); | ||
| 205 | + $workinghours=Db::name("workinghours") | ||
| 206 | + ->alias("a") | ||
| 207 | + ->join("department b","a.department_id=b.id") | ||
| 208 | + ->join("project c","a.project_id=c.id") | ||
| 209 | + ->field("project_name,name,working_hours,starttime,reporttime") | ||
| 210 | + ->where("a.user_id",$id) | ||
| 211 | + ->select(); | ||
| 212 | + $file=$this->projectexcel($workinghours,$user); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + *导出表 | ||
| 217 | + */ | ||
| 218 | + public function projectexcel($workinghours, $user) | ||
| 219 | + { | ||
| 220 | + vendor('phpoffice.phpexcel.PHPExcel'); | ||
| 221 | + Vendor('phpoffice.phpexcel.Classes.PHPExcel'); | ||
| 222 | + Vendor('phpoffice.phpexcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory'); | ||
| 223 | + //实例化 | ||
| 224 | + $objExcel = new \PHPExcel(); | ||
| 225 | + //设置文档属性 | ||
| 226 | + $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007'); | ||
| 227 | + //设置内容 | ||
| 228 | + $objActSheet = $objExcel->getActiveSheet(); | ||
| 229 | + $key = ord("A"); | ||
| 230 | + $letter = explode(',', "A,B,C,D,E,F"); | ||
| 231 | + $arrHeader = array('序号', '项目名称', '提交人', '部门名称', '工时', '提交时间'); | ||
| 232 | + //填充表头信息 | ||
| 233 | + $lenth = count($arrHeader); | ||
| 234 | + for ($i = 0; $i < $lenth; $i++) { | ||
| 235 | + $objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]"); | ||
| 236 | + }; | ||
| 237 | + //填充表格信息 | ||
| 238 | + foreach ($workinghours as $k => $v) { | ||
| 239 | + $j = $k + 1; | ||
| 240 | + $k += 2; | ||
| 241 | + | ||
| 242 | + $objActSheet->setCellValue('A' . $k, $j); | ||
| 243 | + $objActSheet->setCellValue('B' . $k, $v['project_name'])->getDefaultColumnDimension()->setWidth(20); | ||
| 244 | + $objActSheet->setCellValue('D' . $k, $v['name']); | ||
| 245 | + $objActSheet->setCellValue('C' . $k, $user['username']); | ||
| 246 | + $objActSheet->setCellValue('E' . $k, $v['working_hours']); | ||
| 247 | + $objActSheet->setCellValue('F' . $k, date("Y-m-d", $v['reporttime'])); | ||
| 248 | + } | ||
| 249 | + $outfile = $user['username'] ."-". rand(10000, 99999) . ".xlsx"; | ||
| 250 | + $objExcel->createSheet(); | ||
| 251 | + // Redirect output to a client’s web browser (Excel2007) | ||
| 252 | + $title = date("YmdHis"); | ||
| 253 | + header('Content-Disposition: attachment;filename="' . $outfile . '.xlsx"'); | ||
| 254 | + $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007'); | ||
| 255 | + $objWriter->save('php://output'); | ||
| 256 | + } | ||
| 202 | } | 257 | } |
| @@ -29,8 +29,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin | @@ -29,8 +29,20 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin | ||
| 29 | {field: 'mobile', title: __('Mobile'), operate: 'LIKE'}, | 29 | {field: 'mobile', title: __('Mobile'), operate: 'LIKE'}, |
| 30 | {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false}, | 30 | {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false}, |
| 31 | {field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true}, | 31 | {field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true}, |
| 32 | - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} | ||
| 33 | - ] | 32 | + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, |
| 33 | + buttons: [ | ||
| 34 | + { | ||
| 35 | + name:'下载报表', | ||
| 36 | + title: '下载报表', | ||
| 37 | + classname: 'btn btn-xs btn-info btn-click', | ||
| 38 | + icon: 'fa fa-leaf', | ||
| 39 | + // dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示 | ||
| 40 | + click: function (data,row) { | ||
| 41 | + top.location.href="user/downloadexcel?id="+row.id; | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + ]} ] | ||
| 34 | ] | 46 | ] |
| 35 | }); | 47 | }); |
| 36 | 48 |
-
请 注册 或 登录 后发表评论