isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','id','trim'); //排序列 $sort = input('sord','desc','trim'); //排序方式 $order = $sortRow.' '.$sort; $title = input('title','','trim'); if($title){ $map[] = ['u.real_name','like','%'.$title.'%']; } $room_id = input('room_id','','trim'); if($room_id){ $map[] = ['ma.meeting_room_id','=',$room_id]; } $map[] = ['ma.del','=',0]; $map[] = ['ma.org_id','=',cur_org_id()]; $map= empty($map) ? true: $map; //数据查询 $lists = db('meeting_apply') ->alias('ma') ->field('ma.*,u.real_name') ->join('user u','u.id=ma.user_id') ->limit($start,$length) ->where($map) ->order('id desc') ->select(); foreach ($lists as $k=>$v){ $lists[$k]['roomName'] = db('meeting_room')->where('id',$v['meeting_room_id'])->value('title'); } //数据返回 $totalCount = db('meeting_apply')->alias('ma') ->field('ma.*,u.real_name') ->join('user u','u.id=ma.user_id')->where($map)->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; return json($result); }else{ $roomList = db('meeting_room')->where('org_id',cur_org_id())->where('enable',1)->where('del',0)->select(); $this->assign('roomList',$roomList); return $this->fetch(); } } /** * 删除记录 * @param int $id */ public function del($id=0){ if(!$id){ $this->error('参数错误'); } $res = db('meeting_apply')->where('id',$id)->setField('del',1); if($res){ $this->success('删除成功'); }else{ $this->error('删除失败'); } } /** * 改变字段值 * @param int $fv * @param string $fn * @param int $fv */ public function changeField($id=0,$fn='',$fv=0){ if(!$fn||!$id){ $this->error('参数错误'); } $res = db('meeting_apply')->where('id',$id)->setField($fn,$fv); if($res){ $this->success('操作成功'); }else{ $this->error('操作失败'); } } //同意 public function agree($id=0){ if(request()->isPost()){ $res = model('MeetingApply')->agree(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('MeetingApply')->getError()); } }else{ if($id){ $info = db('meeting_apply')->where('id',$id)->find(); $this->assign('info',$info); } $userList = model('work_type_mode')->getRolesUserApp(12,cur_org_id(),-1); foreach ($userList as $k=>$v){ $userList[$k]['title']= $v['real_name']; } $this->assign('userList',$userList); return $this->fetch(); } } //拒绝 public function refuse($id=0){ if(request()->isPost()){ $res = model('MeetingApply')->refuse(); if($res){ $this->success('操作成功',url('index')); }else{ $this->error(model('MeetingApply')->getError()); } }else{ if($id){ $info = db('meeting_apply')->where('id',$id)->find(); $this->assign('info',$info); } return $this->fetch(); } } public function details($id=0){ if($id < 1 ){ $this->error('参数错误'); } $info = db('meeting_apply')->where('id',$id)->find(); $info['meeting_room'] = db('meeting_room')->where('id',$info['meeting_room_id'])->value('title'); //申请人 $info['apply_user'] = db('user')->where('id',$info['user_id'])->value('real_name'); //审批人 $info['approver_user'] = db('user')->where('id',$info['approver'])->value('real_name'); //参会设备 $meeting_devices = db('meeting_device')->whereIn('id',$info['meeting_devices'])->where('del',0)->select(); $deviceName = []; foreach ($meeting_devices as $k=>$v){ $deviceName[] = $v['title']; } $info['meeting_devices'] = $deviceName?implode(',',$deviceName):''; //参会人员 $cUser= db('user')->whereIn('id',$info['user_ids'])->where('del',0)->select(); $userName = []; foreach ($cUser as $k=>$v){ $userName[] = $v['real_name']; } $info['user_name'] = $userName?implode(',',$userName):''; $this->assign('info',$info); return $this->fetch(); } //excel导出 public function export() { include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php'; if (request()->isGet()) { $where[] = ['org_id', '=', $this->orgId]; $where[] = ['del', '=', 0]; $ret = Db::name('meeting_apply')->where($where)->select(); foreach ($ret as $k => $v) { $ret[$k]['apply_user'] = db('user')->where('id',$v['user_id'])->value('real_name'); $ret[$k]['room_name'] = db('meeting_room')->where('id',$v['meeting_room_id'])->value('title'); } //实例化PHPExcel类 $objPHPExcel =new \PHPExcel(); //激活当前的sheet表 $objPHPExcel->setActiveSheetIndex(0); //设置表格头(即excel表格的第一行) $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '编号') ->setCellValue('B1', '申请人') ->setCellValue('B1', '会议室名称') ->setCellValue('C1', '开始时间') ->setCellValue('D1', '结束时间') ->setCellValue('E1', '状态'); // 设置表格头水平居中 $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('D1')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->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)->getStyle('D')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment() ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //设置单元格宽度 $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10); $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30); $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30); $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30); $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30); $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(60); $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(30); $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(30); //循环刚取出来的数组,将数据逐一添加到excel表格。 for ($i = 0; $i < count($ret); $i++) { $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $ret[$i]['id']);//ID $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $ret[$i]['apply_user']); $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $ret[$i]['room_name']); $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $ret[$i]['start_time']); $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $ret[$i]['end_time']); if($ret[$i]['status'] == 0){ $objPHPExcel->getActiveSheet()->setCellValue('f' . ($i + 2), '审核中'); }elseif ($ret[$i]['status'] == 1){ $objPHPExcel->getActiveSheet()->setCellValue('f' . ($i + 2), '同意'); }elseif ($ret[$i]['status'] == 2){ $objPHPExcel->getActiveSheet()->setCellValue('f' . ($i + 2), '拒绝'); }elseif ($ret[$i]['status'] == 3){ $objPHPExcel->getActiveSheet()->setCellValue('f' . ($i + 2), '取消'); } } //设置保存的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'); } } }