作者 开飞机的舒克

大屏管理优化

@@ -5,6 +5,10 @@ namespace app\admin\controller; @@ -5,6 +5,10 @@ namespace app\admin\controller;
5 use app\admin\model\item\ronda\Rel; 5 use app\admin\model\item\ronda\Rel;
6 use app\common\controller\Backend; 6 use app\common\controller\Backend;
7 use mysql_xdevapi\DocResult; 7 use mysql_xdevapi\DocResult;
  8 +use think\Db;
  9 +use think\exception\DbException;
  10 +use think\exception\PDOException;
  11 +use think\exception\ValidateException;
8 12
9 /** 13 /**
10 * 数据大屏管理 14 * 数据大屏管理
@@ -53,15 +57,15 @@ class Screen extends Backend @@ -53,15 +57,15 @@ class Screen extends Backend
53 list($where, $sort, $order, $offset, $limit) = $this->buildparams(); 57 list($where, $sort, $order, $offset, $limit) = $this->buildparams();
54 58
55 $list = $this->model 59 $list = $this->model
56 - ->with(['campus']) 60 + ->with(['ronda'])
57 ->where($where) 61 ->where($where)
58 ->order($sort, $order) 62 ->order($sort, $order)
59 ->paginate($limit); 63 ->paginate($limit);
60 64
61 foreach ($list as $row) { 65 foreach ($list as $row) {
62 - $row->visible(['id', 'title', 'campus_id', 'images', 'starttime', 'endtime', 'is_view']);  
63 - $row->visible(['campus']);  
64 - $row->getRelation('campus')->visible(['title']); 66 + $row->visible(['id', 'ronda_id', 'campus', 'images', 'starttime', 'endtime', 'is_view']);
  67 + $row->visible(['ronda']);
  68 + $row->getRelation('ronda')->visible(['title']);
65 } 69 }
66 70
67 $result = array("total" => $list->total(), "rows" => $list->items()); 71 $result = array("total" => $list->total(), "rows" => $list->items());
@@ -72,6 +76,104 @@ class Screen extends Backend @@ -72,6 +76,104 @@ class Screen extends Backend
72 } 76 }
73 77
74 /** 78 /**
  79 + * 添加
  80 + *
  81 + * @return string
  82 + * @throws \think\Exception
  83 + */
  84 + public function add()
  85 + {
  86 + if (false === $this->request->isPost()) {
  87 + return $this->view->fetch();
  88 + }
  89 + $params = $this->request->post('row/a');
  90 + if (empty($params)) {
  91 + $this->error(__('Parameter %s can not be empty', ''));
  92 + }
  93 + $params = $this->preExcludeFields($params);
  94 +
  95 + if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  96 + $params[$this->dataLimitField] = $this->auth->id;
  97 + }
  98 + $result = false;
  99 + Db::startTrans();
  100 + try {
  101 + //是否采用模型验证
  102 + if ($this->modelValidate) {
  103 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  104 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  105 + $this->model->validateFailException()->validate($validate);
  106 + }
  107 + $result = $this->model->allowField(true)->save($params);
  108 + $rid = $this->model->ronda_id;
  109 + $cid = \db('ronda')->where('id',$rid)->value('campus_id');
  110 + $data = \db('campus')->where('id',$cid)->value('title');
  111 + $this->model->allowField(true)->save(['campus'=>$data]);
  112 + Db::commit();
  113 + } catch (ValidateException|PDOException|Exception $e) {
  114 + Db::rollback();
  115 + $this->error($e->getMessage());
  116 + }
  117 + if ($result === false) {
  118 + $this->error(__('No rows were inserted'));
  119 + }
  120 + $this->success();
  121 + }
  122 +
  123 + /**
  124 + * 编辑
  125 + *
  126 + * @param $ids
  127 + * @return string
  128 + * @throws DbException
  129 + * @throws \think\Exception
  130 + */
  131 + public function edit($ids = null)
  132 + {
  133 + $row = $this->model->get($ids);
  134 + if (!$row) {
  135 + $this->error(__('No Results were found'));
  136 + }
  137 + $adminIds = $this->getDataLimitAdminIds();
  138 + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  139 + $this->error(__('You have no permission'));
  140 + }
  141 + if (false === $this->request->isPost()) {
  142 + $this->view->assign('row', $row);
  143 + return $this->view->fetch();
  144 + }
  145 + $params = $this->request->post('row/a');
  146 + if (empty($params)) {
  147 + $this->error(__('Parameter %s can not be empty', ''));
  148 + }
  149 + $params = $this->preExcludeFields($params);
  150 + $result = false;
  151 + Db::startTrans();
  152 + try {
  153 + //是否采用模型验证
  154 + if ($this->modelValidate) {
  155 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  156 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  157 + $row->validateFailException()->validate($validate);
  158 + }
  159 + $result = $row->allowField(true)->save($params);
  160 + $id = $row->id;
  161 + $rid = \db('screen')->where('id',$id)->value('ronda_id');
  162 + $cid = \db('ronda')->where('id',$rid)->value('campus_id');
  163 + $data = \db('campus')->where('id',$cid)->value('title');
  164 + $this->model->allowField(true)->save(['campus'=>$data],['id'=>$id]);
  165 + Db::commit();
  166 + } catch (ValidateException|PDOException|Exception $e) {
  167 + Db::rollback();
  168 + $this->error($e->getMessage());
  169 + }
  170 + if (false === $result) {
  171 + $this->error(__('No rows were updated'));
  172 + }
  173 + $this->success();
  174 + }
  175 +
  176 + /**
75 * 战队排行 177 * 战队排行
76 */ 178 */
77 public function details($ids) 179 public function details($ids)
@@ -84,7 +186,7 @@ class Screen extends Backend @@ -84,7 +186,7 @@ class Screen extends Backend
84 $this->success("Ajax请求成功", null, ['id' => $ids]); 186 $this->success("Ajax请求成功", null, ['id' => $ids]);
85 } 187 }
86 $data = $row->toArray(); 188 $data = $row->toArray();
87 - $res = db('study_score_log l') 189 + $res = db('stud y_score_log l')
88 ->whereIn('campus_ids', $data['campus_id']) 190 ->whereIn('campus_ids', $data['campus_id'])
89 ->field('l.team,sum(l.score) as sum_score') 191 ->field('l.team,sum(l.score) as sum_score')
90 ->group('l.team') 192 ->group('l.team')
@@ -204,7 +204,7 @@ class Study extends Backend @@ -204,7 +204,7 @@ class Study extends Backend
204 ->paginate($limit); 204 ->paginate($limit);
205 205
206 foreach ($list as $row) { 206 foreach ($list as $row) {
207 - $row->visible(['id','avatar','name','gender','birthday','grade','school','team','team_rank','earn_score','phone','unique','barcode']); 207 + $row->visible(['id','avatar','name','gender','birthday','grade','school','team','team_rank','ronda','earn_score','phone','unique']);
208 // $row->visible(['team']); 208 // $row->visible(['team']);
209 // $row->getRelation('team')->visible(['title']); 209 // $row->getRelation('team')->visible(['title']);
210 } 210 }
@@ -334,10 +334,10 @@ class Study extends Backend @@ -334,10 +334,10 @@ class Study extends Backend
334 $this->model->validateFailException()->validate($validate); 334 $this->model->validateFailException()->validate($validate);
335 } 335 }
336 $result = $this->model->allowField(true)->save($params); 336 $result = $this->model->allowField(true)->save($params);
337 - $id = $this->model->id;  
338 - $res = str_pad($id,8,"0",STR_PAD_LEFT);  
339 - $barpath = Resource::StudyBar($res);  
340 - $this->model->save(['barcode'=>$barpath,'unique'=>$res],['id'=>$id]); 337 +// $id = $this->model->id;
  338 +//// $res = str_pad($id,8,"0",STR_PAD_LEFT);
  339 +//// $barpath = Resource::StudyBar($res);
  340 +// $this->model->save(['barcode'=>$barpath,'unique'=>$res],['id'=>$id]);
341 Db::commit(); 341 Db::commit();
342 } catch (ValidateException|PDOException|Exception $e) { 342 } catch (ValidateException|PDOException|Exception $e) {
343 Db::rollback(); 343 Db::rollback();
1 <?php 1 <?php
2 2
3 return [ 3 return [
4 - 'Title' => '活动标题',  
5 - 'Campus_id' => '届次名称', 4 + 'Ronda_id' => '场次ID',
  5 + 'Ronda_title' => '场次标题',
  6 + 'Campus' => '届次名称',
6 'Images' => '背景图', 7 'Images' => '背景图',
7 'Starttime' => '开始时间', 8 'Starttime' => '开始时间',
8 'Endtime' => '结束时间', 9 'Endtime' => '结束时间',
@@ -16,7 +16,7 @@ return [ @@ -16,7 +16,7 @@ return [
16 'Earn_score' => '总积分', 16 'Earn_score' => '总积分',
17 'Phone' => '手机号', 17 'Phone' => '手机号',
18 'Unique' => '手环ID', 18 'Unique' => '手环ID',
19 - 'Barcode' => '条形码', 19 + 'Ronda' => '场次',
20 'Createtime' => '创建时间', 20 'Createtime' => '创建时间',
21 'Updatetime' => '更新时间', 21 'Updatetime' => '更新时间',
22 'Grade' => '班级名称', 22 'Grade' => '班级名称',
@@ -29,9 +29,14 @@ class Screen extends Model @@ -29,9 +29,14 @@ class Screen extends Model
29 'endtime_text', 29 'endtime_text',
30 'is_view_text', 30 'is_view_text',
31 'count_time', 31 'count_time',
  32 + 'ronda_title'
32 ]; 33 ];
33 34
34 35
  36 + public function getRondaTitleAttr($value,$data){
  37 + $value = db('ronda')->where('id',$data['ronda_id'])->value('title');
  38 + return $value;
  39 + }
35 40
36 public function getIsViewList() 41 public function getIsViewList()
37 { 42 {
@@ -85,8 +90,8 @@ class Screen extends Model @@ -85,8 +90,8 @@ class Screen extends Model
85 return $list; 90 return $list;
86 } 91 }
87 92
88 - public function campus() 93 + public function ronda()
89 { 94 {
90 - return $this->belongsTo('Campus', 'campus_id', 'id', [], 'LEFT')->setEagerlyType(0); 95 + return $this->belongsTo('Ronda', 'ronda_id', 'id', [], 'LEFT')->setEagerlyType(0);
91 } 96 }
92 } 97 }
@@ -27,7 +27,7 @@ class Study extends Model @@ -27,7 +27,7 @@ class Study extends Model
27 protected $append = [ 27 protected $append = [
28 'gender_text', 28 'gender_text',
29 'team_rank', 29 'team_rank',
30 - 'barcode_images', 30 +
31 'rank' 31 'rank'
32 ]; 32 ];
33 33
@@ -70,11 +70,11 @@ class Study extends Model @@ -70,11 +70,11 @@ class Study extends Model
70 return $order; 70 return $order;
71 } 71 }
72 72
73 - public function getBarcodeImagesAttr($value,$data){  
74 - $list = $this->where('id',$data['id'])->value('barcode');  
75 - $order = 'http://campus.shs.broing.cn'.$list;  
76 - return $order;  
77 - } 73 +// public function getBarcodeImagesAttr($value,$data){
  74 +// $list = $this->where('id',$data['id'])->value('barcode');
  75 +// $order = 'http://campus.shs.broing.cn'.$list;
  76 +// return $order;
  77 +// }
78 78
79 // 79 //
80 // public function grade() 80 // public function grade()
1 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> 1 <form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
2 2
3 <div class="form-group"> 3 <div class="form-group">
4 - <label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label> 4 + <label class="control-label col-xs-12 col-sm-2">{:__('Ronda_id')}:</label>
5 <div class="col-xs-12 col-sm-8"> 5 <div class="col-xs-12 col-sm-8">
6 - <input id="c-title" class="form-control" name="row[title]" type="text"> 6 + <input id="c-ronda_id" class="form-control" data-source="ronda/index" data-field="title" name="row[ronda_id]" type="text">
7 </div> 7 </div>
8 </div> 8 </div>
9 <div class="form-group"> 9 <div class="form-group">
10 - <label class="control-label col-xs-12 col-sm-2">{:__('Campus_id')}:</label> 10 + <label class="control-label col-xs-12 col-sm-2">{:__('Campus')}:</label>
11 <div class="col-xs-12 col-sm-8"> 11 <div class="col-xs-12 col-sm-8">
12 - <input id="c-campus_id" data-rule="required" data-source="campus/index" class="form-control selectpage" name="row[campus_id]" type="text" value=""> 12 + <input id="c-campus" data-rule="required" class="form-control" disabled name="row[campus]" type="text" value="">
13 </div> 13 </div>
14 </div> 14 </div>
15 <div class="form-group"> 15 <div class="form-group">
1 <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> 1 <form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
2 2
3 <div class="form-group"> 3 <div class="form-group">
4 - <label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label> 4 + <label class="control-label col-xs-12 col-sm-2">{:__('Ronda_id')}:</label>
5 <div class="col-xs-12 col-sm-8"> 5 <div class="col-xs-12 col-sm-8">
6 - <input id="c-title" class="form-control" name="row[title]" type="text" value="{$row.title|htmlentities}"> 6 + <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}">
7 </div> 7 </div>
8 </div> 8 </div>
9 <div class="form-group"> 9 <div class="form-group">
10 - <label class="control-label col-xs-12 col-sm-2">{:__('Campus_id')}:</label> 10 + <label class="control-label col-xs-12 col-sm-2">{:__('Campus')}:</label>
11 <div class="col-xs-12 col-sm-8"> 11 <div class="col-xs-12 col-sm-8">
12 - <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}"> 12 + <input id="c-campus" disabled data-rule="required" class="form-control" type="text" value="{$row.campus|htmlentities}">
13 </div> 13 </div>
14 </div> 14 </div>
15 <div class="form-group"> 15 <div class="form-group">
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 <div class="widget-body no-padding"> 7 <div class="widget-body no-padding">
8 <div id="toolbar" class="toolbar"> 8 <div id="toolbar" class="toolbar">
9 <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> 9 <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  10 + <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('screen/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
10 11
11 12
12 <div class="dropdown btn-group {:$auth->check('screen/multi')?'':'hide'}"> 13 <div class="dropdown btn-group {:$auth->check('screen/multi')?'':'hide'}">
@@ -32,10 +32,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -32,10 +32,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
32 [ 32 [
33 {checkbox: true}, 33 {checkbox: true},
34 {field: 'id', title: __('ID'), operate: false}, 34 {field: 'id', title: __('ID'), operate: false},
35 - {field: 'title', title: __('Title'), operate: 'LIKE'}, 35 + //{field: 'ronda_id', title: __('Ronda_id'), operate: 'LIKE'},
  36 + {field: 'ronda_title', title: __('Ronda_title'), operate: 'LIKE'},
36 {field: 'count_time', title: __('倒计时')}, 37 {field: 'count_time', title: __('倒计时')},
37 //{field: 'campus_id', title: __('Campus_id')}, 38 //{field: 'campus_id', title: __('Campus_id')},
38 - {field: 'campus.title', title: __('Campus.title'), operate: 'LIKE'}, 39 + {field: 'campus', title: __('Campus'), operate: 'LIKE'},
39 {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images}, 40 {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
40 //{field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 41 //{field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
41 //{field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 42 //{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 @@ -98,7 +98,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
98 {field: 'birthday', title: __('Birthday'),operate:false}, 98 {field: 'birthday', title: __('Birthday'),operate:false},
99 {field: 'grade', title: __('Grade'), operate: 'LIKE'}, 99 {field: 'grade', title: __('Grade'), operate: 'LIKE'},
100 {field: 'school', title: __('School'), operate: 'LIKE'}, 100 {field: 'school', title: __('School'), operate: 'LIKE'},
101 - // {field: 'team_id', title: __('Team_id')}, 101 + {field: 'ronda', title: __('Ronda'),operate:false},
102 {field: 'earn_score', title: __('Earn_score'),operate:false}, 102 {field: 'earn_score', title: __('Earn_score'),operate:false},
103 {field: 'unique', title: __('Unique'), operate:false}, 103 {field: 'unique', title: __('Unique'), operate:false},
104 //{field: 'barcode_images', title: __('Barcode'),events: Table.api.events.image, formatter: Table.api.formatter.image, operate:false}, 104 //{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 @@ -106,36 +106,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
106 // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 106 // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
107 // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, 107 // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
108 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 108 {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
109 - // buttons: [  
110 - // {  
111 - // name: 'click',  
112 - // title: __('下载'),  
113 - // text: __('下载'),  
114 - // classname: 'btn btn-xs btn-info btn-click',  
115 - // icon: 'fa fa-leaf',  
116 - // // dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示  
117 - // click: function (e, data) {  
118 - //  
119 - // $.ajax({  
120 - // type: 'get',  
121 - // url: 'study/down',  
122 - // data: {id: data.id},  
123 - // success: function (res) {  
124 - // if (res.code === 1) {  
125 - // var domain = window.location.href.split(':')[0] + '://' + document.domain;  
126 - // var url = domain + data.barcode;  
127 - // var link = document.createElement('a');  
128 - // link.setAttribute("download", data.name);  
129 - // link.href = url;  
130 - // link.click();  
131 - // $(".btn-refresh").trigger("click");  
132 - // }  
133 - // }  
134 - // });  
135 - //  
136 - // }  
137 - // },  
138 - // ],  
139 formatter: Table.api.formatter.operate} 109 formatter: Table.api.formatter.operate}
140 ] 110 ]
141 ] 111 ]