作者 景琛

后台控制大屏显示内容

@@ -6,6 +6,7 @@ use app\admin\model\item\ronda\Rel; @@ -6,6 +6,7 @@ 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; 8 use think\Db;
  9 +use think\Exception;
9 use think\exception\DbException; 10 use think\exception\DbException;
10 use think\exception\PDOException; 11 use think\exception\PDOException;
11 use think\exception\ValidateException; 12 use think\exception\ValidateException;
@@ -231,4 +232,56 @@ class Screen extends Backend @@ -231,4 +232,56 @@ class Screen extends Backend
231 return $this->view->fetch(); 232 return $this->view->fetch();
232 } 233 }
233 234
  235 + /**
  236 + * 批量修改
  237 + */
  238 + public function multi($ids = NULL){
  239 + if (!$this->request->isPost()) {
  240 + $this->error(__("Invalid parameters"));
  241 + }
  242 + $ids = $ids ? $ids : $this->request->post("ids");
  243 + $ids = $ids ?: $this->request->post('ids');
  244 + if (empty($ids)) {
  245 + $this->error(__('Parameter %s can not be empty', 'ids'));
  246 + }
  247 +
  248 + if (false === $this->request->has('params')) {
  249 + $this->error(__('No rows were updated'));
  250 + }
  251 + parse_str($this->request->post('params'), $values);
  252 + $values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
  253 + if (empty($values)) {
  254 + $this->error(__('You have no permission'));
  255 + }
  256 + $adminIds = $this->getDataLimitAdminIds();
  257 + if (is_array($adminIds)) {
  258 + $this->model->where($this->dataLimitField, 'in', $adminIds);
  259 + }
  260 + $count = 0;
  261 + Db::startTrans();
  262 + try {
  263 + $list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
  264 + $res = $this->model->where('is_view',1)->find()->toArray();
  265 + foreach ($list as $item) {
  266 + //注意:修改区域!!!!!!!!!!!!
  267 + if ($values['is_view'] == 1) {
  268 + if (!empty($res)){
  269 + $this->error('当前已有显示内容,不能重复选择');
  270 + }else{
  271 + $values['is_view'] = 1;
  272 + }
  273 + }
  274 + $count += $item->allowField(true)->isUpdate(true)->save($values);
  275 + }
  276 + Db::commit();
  277 + } catch (PDOException|Exception $e) {
  278 + Db::rollback();
  279 + $this->error($e->getMessage());
  280 + }
  281 + if ($count) {
  282 + $this->success();
  283 + }
  284 + $this->error(__('No rows were updated'));
  285 + }
  286 +
234 } 287 }