作者 景琛

战队分数与大屏分数改变

@@ -3,6 +3,10 @@ @@ -3,6 +3,10 @@
3 namespace app\admin\controller; 3 namespace app\admin\controller;
4 4
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
  6 +use think\Db;
  7 +use think\exception\DbException;
  8 +use think\exception\PDOException;
  9 +use think\exception\ValidateException;
6 10
7 /** 11 /**
8 * 战队管理 12 * 战队管理
@@ -33,5 +37,54 @@ class Team extends Backend @@ -33,5 +37,54 @@ class Team extends Backend
33 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 37 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
34 */ 38 */
35 39
  40 + /**
  41 + * 编辑
  42 + *
  43 + * @param $ids
  44 + * @return string
  45 + * @throws DbException
  46 + * @throws \think\Exception
  47 + */
  48 + public function edit($ids = null)
  49 + {
  50 + $row = $this->model->get($ids);
  51 + if (!$row) {
  52 + $this->error(__('No Results were found'));
  53 + }
  54 + $adminIds = $this->getDataLimitAdminIds();
  55 + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  56 + $this->error(__('You have no permission'));
  57 + }
  58 + if (false === $this->request->isPost()) {
  59 + $this->view->assign('row', $row);
  60 + return $this->view->fetch();
  61 + }
  62 + $params = $this->request->post('row/a');
  63 + if (empty($params)) {
  64 + $this->error(__('Parameter %s can not be empty', ''));
  65 + }
  66 + $params = $this->preExcludeFields($params);
  67 + $result = false;
  68 + Db::startTrans();
  69 + try {
  70 + //是否采用模型验证
  71 + if ($this->modelValidate) {
  72 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  73 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  74 + $row->validateFailException()->validate($validate);
  75 + }
  76 + $result = $row->allowField(true)->save($params);
  77 + $id = \db('team')->where('title',$params['title'])->value('id');
  78 + \db('team_score')->where('team_id',$id)->update(['score'=>$params['score']]);
  79 + Db::commit();
  80 + } catch (ValidateException|PDOException|Exception $e) {
  81 + Db::rollback();
  82 + $this->error($e->getMessage());
  83 + }
  84 + if (false === $result) {
  85 + $this->error(__('No rows were updated'));
  86 + }
  87 + $this->success();
  88 + }
36 89
37 } 90 }