作者 开飞机的舒克

大屏管理优化

... ... @@ -5,6 +5,10 @@ namespace app\admin\controller;
use app\admin\model\item\ronda\Rel;
use app\common\controller\Backend;
use mysql_xdevapi\DocResult;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 数据大屏管理
... ... @@ -53,15 +57,15 @@ class Screen extends Backend
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['campus'])
->with(['ronda'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id', 'title', 'campus_id', 'images', 'starttime', 'endtime', 'is_view']);
$row->visible(['campus']);
$row->getRelation('campus')->visible(['title']);
$row->visible(['id', 'ronda_id', 'campus', 'images', 'starttime', 'endtime', 'is_view']);
$row->visible(['ronda']);
$row->getRelation('ronda')->visible(['title']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
... ... @@ -72,6 +76,104 @@ class Screen extends Backend
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$result = $this->model->allowField(true)->save($params);
$rid = $this->model->ronda_id;
$cid = \db('ronda')->where('id',$rid)->value('campus_id');
$data = \db('campus')->where('id',$cid)->value('title');
$this->model->allowField(true)->save(['campus'=>$data]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
$id = $row->id;
$rid = \db('screen')->where('id',$id)->value('ronda_id');
$cid = \db('ronda')->where('id',$rid)->value('campus_id');
$data = \db('campus')->where('id',$cid)->value('title');
$this->model->allowField(true)->save(['campus'=>$data],['id'=>$id]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
/**
* 战队排行
*/
public function details($ids)
... ... @@ -84,7 +186,7 @@ class Screen extends Backend
$this->success("Ajax请求成功", null, ['id' => $ids]);
}
$data = $row->toArray();
$res = db('study_score_log l')
$res = db('stud y_score_log l')
->whereIn('campus_ids', $data['campus_id'])
->field('l.team,sum(l.score) as sum_score')
->group('l.team')
... ...
... ... @@ -204,7 +204,7 @@ class Study extends Backend
->paginate($limit);
foreach ($list as $row) {
$row->visible(['id','avatar','name','gender','birthday','grade','school','team','team_rank','earn_score','phone','unique','barcode']);
$row->visible(['id','avatar','name','gender','birthday','grade','school','team','team_rank','ronda','earn_score','phone','unique']);
// $row->visible(['team']);
// $row->getRelation('team')->visible(['title']);
}
... ... @@ -334,10 +334,10 @@ class Study extends Backend
$this->model->validateFailException()->validate($validate);
}
$result = $this->model->allowField(true)->save($params);
$id = $this->model->id;
$res = str_pad($id,8,"0",STR_PAD_LEFT);
$barpath = Resource::StudyBar($res);
$this->model->save(['barcode'=>$barpath,'unique'=>$res],['id'=>$id]);
// $id = $this->model->id;
//// $res = str_pad($id,8,"0",STR_PAD_LEFT);
//// $barpath = Resource::StudyBar($res);
// $this->model->save(['barcode'=>$barpath,'unique'=>$res],['id'=>$id]);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
... ...
<?php
return [
'Title' => '活动标题',
'Campus_id' => '届次名称',
'Ronda_id' => '场次ID',
'Ronda_title' => '场次标题',
'Campus' => '届次名称',
'Images' => '背景图',
'Starttime' => '开始时间',
'Endtime' => '结束时间',
... ...
... ... @@ -16,7 +16,7 @@ return [
'Earn_score' => '总积分',
'Phone' => '手机号',
'Unique' => '手环ID',
'Barcode' => '条形码',
'Ronda' => '场次',
'Createtime' => '创建时间',
'Updatetime' => '更新时间',
'Grade' => '班级名称',
... ...
... ... @@ -29,10 +29,15 @@ class Screen extends Model
'endtime_text',
'is_view_text',
'count_time',
'ronda_title'
];
public function getRondaTitleAttr($value,$data){
$value = db('ronda')->where('id',$data['ronda_id'])->value('title');
return $value;
}
public function getIsViewList()
{
return ['0' => __('Is_view 0'), '1' => __('Is_view 1')];
... ... @@ -85,8 +90,8 @@ class Screen extends Model
return $list;
}
public function campus()
public function ronda()
{
return $this->belongsTo('Campus', 'campus_id', 'id', [], 'LEFT')->setEagerlyType(0);
return $this->belongsTo('Ronda', 'ronda_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
... ... @@ -27,7 +27,7 @@ class Study extends Model
protected $append = [
'gender_text',
'team_rank',
'barcode_images',
'rank'
];
... ... @@ -70,11 +70,11 @@ class Study extends Model
return $order;
}
public function getBarcodeImagesAttr($value,$data){
$list = $this->where('id',$data['id'])->value('barcode');
$order = 'http://campus.shs.broing.cn'.$list;
return $order;
}
// public function getBarcodeImagesAttr($value,$data){
// $list = $this->where('id',$data['id'])->value('barcode');
// $order = 'http://campus.shs.broing.cn'.$list;
// return $order;
// }
//
// public function grade()
... ...
<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>
<label class="control-label col-xs-12 col-sm-2">{:__('Ronda_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-title" class="form-control" name="row[title]" type="text">
<input id="c-ronda_id" class="form-control" data-source="ronda/index" data-field="title" name="row[ronda_id]" type="text">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Campus_id')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('Campus')}:</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="">
<input id="c-campus" data-rule="required" class="form-control" disabled name="row[campus]" type="text" value="">
</div>
</div>
<div class="form-group">
... ...
<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>
<label class="control-label col-xs-12 col-sm-2">{:__('Ronda_id')}:</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}">
<input id="c-ronda_id" class="form-control selectpage" data-source="ronda/index" name="row[ronda_id]" type="text" data-field="title" value="{$row.ronda_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Campus_id')}:</label>
<label class="control-label col-xs-12 col-sm-2">{:__('Campus')}:</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" data-field="title" name="row[campus_id]" type="text" value="{$row.campus_id|htmlentities}">
<input id="c-campus" disabled data-rule="required" class="form-control" type="text" value="{$row.campus|htmlentities}">
</div>
</div>
<div class="form-group">
... ...
... ... @@ -7,6 +7,7 @@
<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('screen/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<div class="dropdown btn-group {:$auth->check('screen/multi')?'':'hide'}">
... ...
... ... @@ -32,10 +32,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('ID'), operate: false},
{field: 'title', title: __('Title'), operate: 'LIKE'},
//{field: 'ronda_id', title: __('Ronda_id'), operate: 'LIKE'},
{field: 'ronda_title', title: __('Ronda_title'), operate: 'LIKE'},
{field: 'count_time', title: __('倒计时')},
//{field: 'campus_id', title: __('Campus_id')},
{field: 'campus.title', title: __('Campus.title'), operate: 'LIKE'},
{field: 'campus', title: __('Campus'), operate: 'LIKE'},
{field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
//{field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
//{field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
... ...
... ... @@ -98,7 +98,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'birthday', title: __('Birthday'),operate:false},
{field: 'grade', title: __('Grade'), operate: 'LIKE'},
{field: 'school', title: __('School'), operate: 'LIKE'},
// {field: 'team_id', title: __('Team_id')},
{field: 'ronda', title: __('Ronda'),operate:false},
{field: 'earn_score', title: __('Earn_score'),operate:false},
{field: 'unique', title: __('Unique'), operate:false},
//{field: 'barcode_images', title: __('Barcode'),events: Table.api.events.image, formatter: Table.api.formatter.image, operate:false},
... ... @@ -106,36 +106,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
// {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
// buttons: [
// {
// name: 'click',
// title: __('下载'),
// text: __('下载'),
// classname: 'btn btn-xs btn-info btn-click',
// icon: 'fa fa-leaf',
// // dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
// click: function (e, data) {
//
// $.ajax({
// type: 'get',
// url: 'study/down',
// data: {id: data.id},
// success: function (res) {
// if (res.code === 1) {
// var domain = window.location.href.split(':')[0] + '://' + document.domain;
// var url = domain + data.barcode;
// var link = document.createElement('a');
// link.setAttribute("download", data.name);
// link.href = url;
// link.click();
// $(".btn-refresh").trigger("click");
// }
// }
// });
//
// }
// },
// ],
formatter: Table.api.formatter.operate}
]
]
... ...