...
|
...
|
@@ -25,12 +25,7 @@ class Study extends Backend |
|
|
$this->view->assign("genderList", $this->model->getGenderList());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 导入
|
|
|
*/
|
|
|
public function import(){
|
|
|
return parent::import();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
...
|
...
|
@@ -56,15 +51,15 @@ class Study extends Backend |
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
|
|
|
$list = $this->model
|
|
|
->with(['team','user'])
|
|
|
->with(['school','team'])
|
|
|
->where($where)
|
|
|
->order($sort, $order)
|
|
|
->paginate($limit);
|
|
|
|
|
|
foreach ($list as $row) {
|
|
|
|
|
|
$row->getRelation('team')->visible(['title']);
|
|
|
$row->getRelation('user')->visible(['username']);
|
|
|
$row->getRelation('school')->visible(['title']);
|
|
|
$row->getRelation('team')->visible(['title']);
|
|
|
}
|
|
|
|
|
|
$result = array("total" => $list->total(), "rows" => $list->items());
|
...
|
...
|
@@ -76,17 +71,12 @@ class Study extends Backend |
|
|
|
|
|
//导出数据
|
|
|
public function export(){
|
|
|
if ($this->request->isPost()){
|
|
|
set_time_limit(0);//设置时间限制
|
|
|
$ids = $this->request->post('ids'); //获取数据的所有id
|
|
|
$excel = new \PHPExcel(); // 生成新的excel对象
|
|
|
$excel->getProperties()
|
|
|
->setCreator("FastAdmin") //设置作者
|
|
|
->setLastModifiedBy("FastAdmin") //设置上次修改者
|
|
|
->setTitle("积分表") //设置表格标题
|
|
|
->setSubject("Subject"); //设置主题
|
|
|
$excel->getDefaultStyle()->getFont()->setName('楷体'); //设置默认字体
|
|
|
$excel->getDefaultStyle()->getFont()->setSize(15); //设置默认字体大小
|
|
|
if ($this->request->isPost()) {
|
|
|
set_time_limit(0);
|
|
|
$ids = $this->request->post('ids');
|
|
|
|
|
|
$excel = new \PHPExcel();
|
|
|
$excel->getProperties()->setTitle("学校+积分表");
|
|
|
$excel->getActiveSheet()->getColumnDimension('A')->setWidth(10);
|
|
|
$excel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
|
|
|
$excel->getActiveSheet()->getColumnDimension('C')->setWidth(10);
|
...
|
...
|
@@ -97,9 +87,9 @@ class Study extends Backend |
|
|
$excel->getActiveSheet()->getColumnDimension('H')->setWidth(10);
|
|
|
// 开始操作excel表
|
|
|
$worksheet = $excel->setActiveSheetIndex(0) //操作第一个工作表
|
|
|
->setCellValue('A1','序号') //设置表格标题名称
|
|
|
->setCellValue('B1','姓名') //设置表格标题名称
|
|
|
->setCellValue('C1','性别')
|
|
|
->setCellValue('A1','序号') //设置表格标题名称
|
|
|
->setCellValue('B1','姓名') //设置表格标题名称
|
|
|
->setCellValue('C1','性别')
|
|
|
->setCellValue('D1','班级')
|
|
|
->setCellValue('E1','学校')
|
|
|
->setCellValue('F1','手环ID')
|
...
|
...
|
@@ -124,19 +114,21 @@ class Study extends Backend |
|
|
->setCellValue('H'.$k,$val['earn_score']);
|
|
|
}
|
|
|
|
|
|
$excel->createSheet(); //创建excel表
|
|
|
$title = "学生成绩".date("Y-m-dHis"); //考勤打卡数据_2023-01-07145656.xlsx
|
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');//表明当前文件是.xlsx
|
|
|
header('Content-Disposition: attachment;filename="'.$title.'.xlsx"');//文件名称[考勤打卡数据_2023-01-07145656.xlsx]
|
|
|
header('Cache-Control: max-age=0'); //禁用缓存
|
|
|
header('Cache-Control: max-age=1'); //通知浏览器:1 秒之内不要烦我,自己从缓冲区中刷新。
|
|
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // 缓存过期时间(禁用缓存)
|
|
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // 上一次修改时间
|
|
|
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 缓存控制:必须重新验证
|
|
|
header('Pragma: public'); // 可被任何缓存所缓存 http1.0协议
|
|
|
$excel->createSheet();
|
|
|
$title = "学生成绩记录" . date("YmdHis");
|
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
|
|
|
header('Cache-Control: max-age=0');
|
|
|
header('Cache-Control: max-age=1');
|
|
|
|
|
|
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
|
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
|
|
|
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
|
|
header('Pragma: public'); // HTTP/1.0
|
|
|
$objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
|
|
|
$objWriter->save('php://output'); //保存地址
|
|
|
$objWriter->save('php://output');
|
|
|
exit;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|