diff --git a/application/common.php b/application/common.php index 5e7c0a56..f61dc99c 100644 --- a/application/common.php +++ b/application/common.php @@ -158,3 +158,26 @@ function schlist($low='班级',$high='其它级') } +// 整理教师名 +function teacherNames($list = array()) +{ + if(count($list) == 0 ) + { + return ''; + } + + + $names = ''; + foreach ($list as $key => $value) { + if($key == 0) + { + $names = $value['teacher']['xingming']; + }else{ + $names = $names . '、'. $value['teacher']['xingming']; + } + } + + return $names; +} + + diff --git a/application/rongyu/common.php b/application/rongyu/common.php index a8143662..3e582f69 100644 --- a/application/rongyu/common.php +++ b/application/rongyu/common.php @@ -1 +1,7 @@ -field('id,rongyuce,title,bianhao,hjschool,subject,jiangxiang,hjshijian,pic') - ->with([ - 'hjJsry'=>function($query){ - $query->field('rongyuid,teacherid') - ->with(['teacher'=>function($query){ - $query->field('id,xingming'); - }]); - }, - 'cyJsry'=>function($query){ - $query->field('rongyuid,teacherid') - ->with(['teacher'=>function($query){ - $query->field('id,xingming'); - }]); - }, - 'ryTuce'=>function($query){ - $query->field('id,title,fzshijian,fzschool') - ->with(['fzSchool'=>function($q){ - $q->field('id,jiancheng'); - }]); - }, - 'rySubject'=>function($query){ - $query->field('id,title'); - } - ]) - ->select(); - $list = json($list); - - return $list; - } - // 下载荣誉信息 public function outXlsx($id) { - // 查询数据 - $list = ryinfo::where('rongyuce',$id) - ->field('id,rongyuce,title,bianhao,hjschool,subject,jiangxiang,hjshijian,pic') - // ->with([ - // 'hjJsry'=>function($query){ - // $query->field('rongyuid,teacherid') - // ->with(['teacher'=>function($query){ - // $query->field('id,xingming'); - // }]); - // }, - // 'cyJsry'=>function($query){ - // $query->field('rongyuid,teacherid') - // ->with(['teacher'=>function($query){ - // $query->field('id,xingming'); - // }]); - // }, - // 'ryTuce'=>function($query){ - // $query->field('id,title,fzshijian,fzschool') - // ->with(['fzSchool'=>function($q){ - // $q->field('id,jiancheng'); - // }]); - // }, - // 'rySubject'=>function($query){ - // $query->field('id,title'); - // } - // ]) - ->select(); - + $ryinfo = new ryinfo(); + $list = $ryinfo->srcTuceRy($id); + + // halt($list); if($list->isEmpty()) { @@ -485,51 +424,74 @@ class JsRongyuInfo extends Base return ''; }else{ $filename = $list[0]['ryTuce']['title']; + $fzschool = $list[0]['ryTuce']['fz_school']['title']; + $fzshijian = strtotime($list[0]['ryTuce']['fzshijian']); + $fzshijian = date('Ym',$fzshijian); } - - //通过工厂模式创建内容 - // $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('jsRongyu.xlsx'); + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('jsRongyu.xlsx'); + $worksheet = $spreadsheet->getActiveSheet(); - // $worksheet = $spreadsheet->getActiveSheet(); + $worksheet->getCell('A1')->setValue($filename); + $worksheet->getCell('A2')->setValue('发证单位:'.$fzschool); + $worksheet->getCell('G2')->setValue('发证时间:'.$list[0]['ryTuce']['fzshijian']); + // 循环为excel每行赋值 + foreach ($list as $key => $value) { + $myrowid = $key + 4; + $worksheet->getCell('A'.$myrowid)->setValue($key+1); + $worksheet->getCell('B'.$myrowid)->setValue($value->title); + $worksheet->getCell('C'.$myrowid)->setValue($value->hjJsName); + if($value->hj_school){ + $worksheet->getCell('D'.$myrowid)->setValue($value->hj_school->jiancheng); + } + if($value->ry_subject){ + $worksheet->getCell('E'.$myrowid)->setValue($value->ry_subject->title); + } + $worksheet->getCell('F'.$myrowid)->setValue($value->cyJsName); + if($value->jx_category){ + $worksheet->getCell('G'.$myrowid)->setValue($value->jx_category->title); + } + $worksheet->getCell('H'.$myrowid)->setValue($value->bianhao); + } + + if($key+4>9) + { + // 给单元格加边框 + $styleArray = [ + 'borders' => [ + 'allBorders' => [ + 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + 'color' => ['argb' => '00000000'], + ], + ], + ]; + $worksheet->getStyle('A10:I'.($key+4))->applyFromArray($styleArray); + // 设置行高 + for($i = 10; $i<=($key+4); $i++){ + $worksheet->getRowDimension($i)->setRowHeight(30); + } + + } + + $worksheet->getStyle('A4')->applyFromArray($styleArray); - // $worksheet->getCell('A1')->setValue($filename); - // // 循环为excel每行赋值 - // foreach ($list as $key => $value) { - // $myrowid = $key + 3; - // $worksheet->getCell('A'.$myrowid)->setValue($key+1); - // $worksheet->getCell('B'.$myrowid)->setValue($value->title); - // $worksheet->getCell('C'.$myrowid)->setValue($value->title); - // // $worksheet->getCell('D'.$myrowid)->setValue($value['fz_school']['jiancheng']); - // $worksheet->getCell('E'.$myrowid)->setValue($value->title); - // $worksheet->getCell('F'.$myrowid)->setValue($value->title); - // $worksheet->getCell('G'.$myrowid)->setValue($value->title); - // $worksheet->getCell('H'.$myrowid)->setValue($value->bianhao); - // } - dump($list); - $list = json($list); - return $list; - halt('aa'); - // return json($list); - // return true; - $worksheet->getCell('A2'); - //通过工厂模式来写内容 - $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); - ob_end_clean(); - ob_start(); //告诉浏览器输出07Excel文件 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //告诉浏览器输出浏览器名称 - header('Content-Disposition: attachment;filename=01simple.xlsx'); - header('Cache-Control: max-age=0');//禁止缓存 - - $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); + header('Content-Disposition: attachment;filename="'. $filename .$fzshijian.'.xlsx"'); + //禁止缓存 + header('Cache-Control: max-age=0'); + $writer = new Xlsx($spreadsheet); $writer->save('php://output'); - + // ob_end_clean(); + // ob_start(); + // 释放内存 $spreadsheet->disconnectWorksheets(); unset($spreadsheet); + + // return '下载后请关闭窗口'; } diff --git a/application/rongyu/model/JsRongyuInfo.php b/application/rongyu/model/JsRongyuInfo.php index fbd91d79..a2187ade 100644 --- a/application/rongyu/model/JsRongyuInfo.php +++ b/application/rongyu/model/JsRongyuInfo.php @@ -64,7 +64,7 @@ class JsRongyuInfo extends Base }, ] ) - ->append(['hjJsName']) + ->append(['hjJsName','cyJsName']) ->select(); @@ -72,6 +72,48 @@ class JsRongyuInfo extends Base } + // 获取需要下载的荣誉信息 + public function srcTuceRy($id) + { + // 查询数据 + $data =$this->where('rongyuce',$id) + ->field('id,rongyuce,title,bianhao,hjschool,subject,jiangxiang,hjshijian,pic') + ->with([ + 'hjJsry'=>function($query){ + $query->field('rongyuid,teacherid') + ->with(['teacher'=>function($query){ + $query->field('id,xingming'); + }]); + }, + 'cyJsry'=>function($query){ + $query->field('rongyuid,teacherid') + ->with(['teacher'=>function($query){ + $query->field('id,xingming'); + }]); + }, + 'ryTuce'=>function($query){ + $query->field('id,title,fzshijian,fzschool') + ->with(['fzSchool'=>function($q){ + $q->field('id,title'); + }]); + }, + 'rySubject'=>function($query){ + $query->field('id,title'); + }, + 'hjSchool'=>function($query){ + $query->field('id,jiancheng'); + }, + 'jxCategory'=>function($query){ + $query->field('id,title'); + } + ]) + ->append(['hjJsName','cyJsName']) + ->select(); + + return $data; + } + + // 荣誉图册关联 public function ryTuce() { @@ -159,18 +201,17 @@ class JsRongyuInfo extends Base public function getHjJsNameAttr($value) { $teacherList = $this->getAttr('hjJsry'); - $teachNames = ""; - $i = 0; - foreach ($teacherList as $key => $value) { - # code... - if($i == 0) - { - $teachNames = $value['teacher']['xingming']; - }else{ - $teachNames = $teachNames . '、' .$value['teacher']['xingming']; - } - $i++; - } + $teachNames = teacherNames($teacherList); + + return $teachNames; + + } + + // 获奖教师名整理 + public function getCyJsNameAttr($value) + { + $teacherList = $this->getAttr('cyJsry'); + $teachNames = teacherNames($teacherList); return $teachNames; diff --git a/application/rongyu/view/js_rongyu_info/rongyu_list.html b/application/rongyu/view/js_rongyu_info/rongyu_list.html index 6b2d44d7..9a8f2c5a 100644 --- a/application/rongyu/view/js_rongyu_info/rongyu_list.html +++ b/application/rongyu/view/js_rongyu_info/rongyu_list.html @@ -25,6 +25,11 @@ 添加教师荣誉信息 + + + + 下载荣誉信息 + 共有数据:{$list.count} 条 diff --git a/database/seeds/Rule.php b/database/seeds/Rule.php index a01f0edd..a614c785 100644 --- a/database/seeds/Rule.php +++ b/database/seeds/Rule.php @@ -181,7 +181,7 @@ class Rule extends Seeder ['title'=>'编辑','name'=>'rongyu/DwRongyu/edit','paixu'=>3,'pid'=>801,], ['title'=>'查看','name'=>'rongyu/DwRongyu/read','paixu'=>4,'pid'=>801,], ['title'=>'状态','name'=>'rongyu/DwRongyu/setStatus','paixu'=>5,'pid'=>801], - ['title'=>'批量上传','name'=>'rongyu/DwRongyu/createAll','paixu'=>6,'pid'=>801], + // ['title'=>'批量上传','name'=>'rongyu/DwRongyu/createAll','paixu'=>6,'pid'=>801], // 教师荣誉册管理 ['title'=>'添加','name'=>'rongyu/JsRongyu/create','paixu' =>1,'pid'=>802], ['title'=>'删除','name'=>'rongyu/JsRongyu/delete','paixu'=>2,'pid'=>802], @@ -195,6 +195,7 @@ class Rule extends Seeder ['title'=>'查看','name'=>'rongyu/JsRongyuInfo/read','paixu'=>4,'pid'=>803,], ['title'=>'状态','name'=>'rongyu/JsRongyuInfo/setStatus','paixu'=>5,'pid'=>803], ['title'=>'批量上传','name'=>'rongyu/JsRongyuInfo/createAll','paixu'=>6,'pid'=>803], + ['title'=>'下载表格','name'=>'rongyu/JsRongyuInfo/outXlsx','paixu'=>7,'pid'=>803], // 课题管理 diff --git a/public/jsRongyu.xlsx b/public/jsRongyu.xlsx index daed87e4..667b853e 100644 Binary files a/public/jsRongyu.xlsx and b/public/jsRongyu.xlsx differ diff --git a/public/output.xlsx b/public/output.xlsx deleted file mode 100644 index 7ab99043..00000000 Binary files a/public/output.xlsx and /dev/null differ diff --git a/route/rongyu.php b/route/rongyu.php index a107e1bf..aecbd099 100644 --- a/route/rongyu.php +++ b/route/rongyu.php @@ -16,6 +16,7 @@ Route::resource('jsryinfo','rongyu/JsRongyuInfo'); Route::get('dwry/createall','rongyu/DwRongyu/createall'); // 荣誉册中荣誉信息列表 Route::get('rylist/:id','rongyu/JsRongyuInfo/rongyuList'); +Route::get('ryout/:id','rongyu/JsRongyuInfo/outXlsx'); Route::get('jsryinfoadd/:id','rongyu/JsRongyuInfo/create'); Route::get('jsryinfoaddall/:id','rongyu/JsRongyuInfo/createall'); \ No newline at end of file