作者 开飞机的舒克

后台优化

... ... @@ -53,15 +53,15 @@ class Screen extends Backend
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['campus'])
->where($where)
->order($sort, $order)
->paginate($limit);
->with(['campus'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id','title','campus_id','images','starttime','endtime','is_view']);
$row->visible(['id', 'title', 'campus_id', 'images', 'starttime', 'endtime', 'is_view']);
$row->visible(['campus']);
$row->getRelation('campus')->visible(['title']);
$row->getRelation('campus')->visible(['title']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
... ... @@ -73,7 +73,7 @@ class Screen extends Backend
public function details($ids)
{
$row = $this->model->get(['id'=>$ids]);
$row = $this->model->get(['id' => $ids]);
if (!$row) {
$this->error(__('No Results were found'));
}
... ... @@ -82,61 +82,21 @@ class Screen extends Backend
}
$data = $row->toArray();
$res = db('study_score_log l')
->join('team t','l.team_id = t.id')
->where('campus_id',$data['campus_id'])
->join('team t', 'l.team_id = t.id')
->where('campus_id', $data['campus_id'])
->field('l.team_id,sum(l.score) as sum_score,t.title')
->group('l.team_id')
->order('sum_score','desc')
->order('sum_score', 'desc')
->select();
$list = [];
// foreach ($res as $k1){
// foreach ($k1 as $k2 => $v){
//// dump($k2);
//// dump($v);
// $list['title'] = $v;
// $list['score'] = $v;
// }
// }
foreach ($res as $k => $v){
$list['title'] = $v['title'];
$list['score'] = $v['sum_score'];
foreach ($res as $k => $v) {
$list[] = [
'title' => $v['title'],
'score' => $v['sum_score'],
];
}
//dump($list);
$this->view->assign("row", $list);
return $this->view->fetch();
}
public function detail($ids)
{
$row = $this->model->get(['id'=>$ids]);
if (!$row) {
$this->error(__('No Results were found'));
}
if ($this->request->isAjax()) {
$this->success("Ajax请求成功", null, ['id' => $ids]);
}
$data = $row->toArray();
$res = db('study_score_log l')
->join('study s','l.study_id = s.id')
->where('campus_id',$data['campus_id'])
->field('l.team_id,sum(l.score) as sum_score,s.name')
->group('l.study_id')
->order('sum_score','desc')
->select();
$list = [];
// foreach ($res as $k1){
// foreach ($k1 as $k2 => $v){
//// dump($k2);
//// dump($v);
// $list['title'] = $v;
// $list['score'] = $v;
// }
// }
foreach ($res as $k => $v){
$list['name'] = $v['name'];
$list['score'] = $v['sum_score'];
}
//dump($list);
$this->view->assign("row", $list);
return $this->view->fetch();
}
}
}
\ No newline at end of file
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-title" class="form-control" name="row[title]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Campus_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-campus_id" data-rule="required" data-source="campus/index" class="form-control selectpage" name="row[campus_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Images')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-images" class="form-control" size="50" name="row[images]" type="text">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-images" class="btn btn-danger faupload" data-input-id="c-images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="true" data-preview-id="p-images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-images" class="btn btn-primary fachoose" data-input-id="c-images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-images"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-images"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Starttime')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-starttime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[starttime]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Endtime')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-endtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[endtime]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_view')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-is_view" class="form-control selectpicker" name="row[is_view]">
{foreach name="isViewList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</select>
</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">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-title" class="form-control" name="row[title]" type="text" value="{$row.title|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Campus_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-campus_id" data-rule="required" data-source="campus/index" class="form-control selectpage" name="row[campus_id]" type="text" value="{$row.campus_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Images')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-images" class="form-control" size="50" name="row[images]" type="text" value="{$row.images|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="faupload-images" class="btn btn-danger faupload" data-input-id="c-images" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="true" data-preview-id="p-images"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-images" class="btn btn-primary fachoose" data-input-id="c-images" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-images"></span>
</div>
<ul class="row list-inline faupload-preview" id="p-images"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Starttime')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-starttime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[starttime]" type="text" value="{:$row.starttime?datetime($row.starttime):''}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Endtime')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-endtime" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[endtime]" type="text" value="{:$row.endtime?datetime($row.endtime):''}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Is_view')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-is_view" class="form-control selectpicker" name="row[is_view]">
{foreach name="isViewList" item="vo"}
<option value="{$key}" {in name="key" value="$row.is_view"}selected{/in}>{$vo}</option>
{/foreach}
</select>
</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">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('data/screen/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('data/screen/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('data/screen/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<div class="dropdown btn-group {:$auth->check('data/screen/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<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('data/screen/edit')}"
data-operate-del="{:$auth->check('data/screen/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>{:__('个人名称')}</th>
<th>{:__('个人票数')}</th>
</tr>
</thead>
<tbody>
{/*{volist name="row" id="vo"&cc;
<tr>
<td>{$key&cc;</td>
<td style="word-break: break-all;">{$vo|htmlentities&cc;</td>
</tr>
{/volist&cc;*/}
<tr>
<td>{$row.name}</td>
<td style="word-break: break-all;">{$row.score}</td>
</tr>
</tbody>
</table>
<div class="hide layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="reset" class="btn btn-primary btn-embossed btn-close" onclick="Layer.closeAll();">{:__('Close')}</button>
</div>
</div>
... ... @@ -6,16 +6,12 @@
</tr>
</thead>
<tbody>
{/*{volist name="row" id="vo"&cc;
<tr>
<td>{$key&cc;</td>
<td style="word-break: break-all;">{$vo|htmlentities&cc;</td>
</tr>
{/volist&cc;*/}
{volist name="row" id="vo"}
<tr>
<td>{$row.title}</td>
<td style="word-break: break-all;">{$row.score}</td>
<td>{$vo.title}</td>
<td style="word-break: break-all;">{$vo.score}</td>
</tr>
{/volist}
</tbody>
</table>
<div class="hide layer-footer">
... ...
... ... @@ -58,17 +58,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
},
},
{
name: 'detail',
text: __('个人排行榜'),
title: __('个人排行榜'),
classname: 'btn btn-xs btn-primary btn-dialog',
icon: 'fa fa-list',
url: 'screen/detail',
callback: function (data) {
Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
},
}
],
formatter: Table.api.formatter.buttons
},
... ...