作者 开飞机的舒克

后台更新

... ... @@ -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;
}
}
}
... ...
<?php
return [
'User_id' => '用户id',
'Id' => 'ID',
'Avatar' => '头像',
'Name' => '姓名',
'Gender' => '性别',
'Gender 0' => '女',
'Gender 1' => '男',
'Birthday' => '生日',
'Grade' => '班级',
'School' => '学校',
'Sno' => '学号',
'Team_id' => '所属战队',
'Earn_score' => '总积分',
'Phone' => '手机号',
'Unique' => '手环ID',
'Barcode' => '条形码',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
'Team.title' => '战队昵称',
'User.username' => '用户名'
'User_id' => '用户id',
'Avatar' => '头像',
'Name' => '姓名',
'Gender' => '性别',
'Gender 0' => '女',
'Gender 1' => '男',
'Birthday' => '生日',
'Grade' => '班级',
'School_id' => '学校',
'Sno' => '学号',
'Team_id' => '所属战队',
'Earn_score' => '总积分',
'Phone' => '手机号',
'Unique' => '手环ID',
'Barcode' => '条形码',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
'School.title' => '校区名称',
'Team.title' => '战队昵称'
];
... ...
... ... @@ -46,14 +46,14 @@ class Study extends Model
public function team()
public function school()
{
return $this->belongsTo('Team', 'team_id', 'id', [], 'LEFT')->setEagerlyType(0);
return $this->belongsTo('School', 'school_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function user()
public function team()
{
return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
return $this->belongsTo('Team', 'team_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
... ... @@ -43,9 +43,9 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('School')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('School_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-school" class="form-control" name="row[school]" type="text">
<input id="c-school_id" data-rule="required" data-source="school/index" class="form-control selectpage" data-field="title" name="row[school_id]" type="text" value="">
</div>
</div>
<div class="form-group">
... ... @@ -66,24 +66,24 @@
<input id="c-phone" class="form-control" name="row[phone]" type="text">
</div>
</div>
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Earn_score')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-earn_score" class="form-control" step="0.01" name="row[earn_score]" type="number">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Unique')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-unique" class="form-control" name="row[unique]" type="number">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Barcode')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-barcode" class="form-control" name="row[barcode]" type="text">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Earn_score')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-earn_score" class="form-control" step="0.01" name="row[earn_score]" type="number">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Unique')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-unique" class="form-control" name="row[unique]" type="number">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Barcode')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-barcode" class="form-control" name="row[barcode]" type="text">*/}
{/* </div>*/}
{/* </div>*/}
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -44,9 +44,9 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('School')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('School_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-school" class="form-control" name="row[school]" type="text" value="{$row.school|htmlentities}">
<input id="c-school_id" data-rule="required" data-source="school/index" class="form-control selectpage" data-field="title" name="row[school_id]" type="text" value="{$row.school_id|htmlentities}">
</div>
</div>
<div class="form-group">
... ... @@ -67,24 +67,24 @@
<input id="c-phone" class="form-control" name="row[phone]" type="text" value="{$row.phone|htmlentities}">
</div>
</div>
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Earn_score')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-earn_score" class="form-control" step="0.01" name="row[earn_score]" type="number" value="{$row.earn_score|htmlentities&cc;">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Unique')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-unique" class="form-control" name="row[unique]" type="number" value="{$row.unique|htmlentities&cc;">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Barcode')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-barcode" class="form-control" name="row[barcode]" type="text" value="{$row.barcode|htmlentities&cc;">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Earn_score')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-earn_score" class="form-control" step="0.01" name="row[earn_score]" type="number" value="{$row.earn_score|htmlentities&cc;">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Unique')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-unique" class="form-control" name="row[unique]" type="number" value="{$row.unique|htmlentities&cc;">*/}
{/* </div>*/}
{/* </div>*/}
{/* <div class="form-group">*/}
{/* <label class="control-label col-xs-12 col-sm-2">{:__('Barcode')&cc;:</label>*/}
{/* <div class="col-xs-12 col-sm-8">*/}
{/* <input id="c-barcode" class="form-control" name="row[barcode]" type="text" value="{$row.barcode|htmlentities&cc;">*/}
{/* </div>*/}
{/* </div>*/}
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -12,13 +12,13 @@
<a href="javascript:;" class="btn btn-success btn-export {:$auth->check('study/export')?'':'hide'}" title="{:__('Export')}" id="btn-export-file"><i class="fa fa-download"></i> {:__('Export')}</a>
<div class="dropdown btn-group {:$auth->check('study/multi')?'':'hide'}">
<ul class="dropdown-menu text-left" role="menu">
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('study/edit')}"
... ...
... ... @@ -91,7 +91,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'team.title', title: __('Team.title'), operate: 'LIKE'},
{field: 'birthday', title: __('Birthday'),operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,datetimeFormat: "YYYY-MM-DD"},
{field: 'grade', title: __('Grade'), operate: 'LIKE'},
{field: 'school', title: __('School'), operate: 'LIKE'},
{field: 'school.title', title: __('School.title'), operate: 'LIKE'},
{field: 'sno', title: __('Sno'), operate: 'LIKE'},
// {field: 'team_id', title: __('Team_id')},
{field: 'earn_score', title: __('Earn_score'), operate:false},
... ...