...
|
...
|
@@ -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')
|
...
|
...
|
|