model = new \app\admin\model\yq\base_config\Perimeter; $this->assign('stopList', $this->model->getStopList()); $this->assign('banList', $this->model->getBanList()); $this->assign('hazardList', $this->model->getHazardList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ // 周界配置 public function config() { if ($this->request->isAjax() && $this->request->isPost()) { $params = $this->request->post(); if (empty($params['info']) || empty($params['perimeter_id'])) { $this->error('请先画区域~'); } $info_arr = json_decode($params['info'], true); $str = ''; foreach ($info_arr as $key => $value) { $str .= $value['lng'] . ',' . $value['lat'] . ';'; } $str = rtrim($str, ';'); // 112.18721,31.052017;112.179486,31.050105;112.176567,31.043561;112.175967,31.036354;112.176911,31.028705;112.17837,31.022527;112.183863,31.017525;112.186695,31.016422;112.193819,31.01576;112.202402,31.015686;112.211243,31.016569;112.220684,31.017893;112.228581,31.02032;112.231671,31.024145;112.233559,31.031426;112.233301,31.038781;112.235104,31.045105;112.23416,31.051944;112.226692,31.054664;112.21871,31.055988;112.209784,31.057679;112.203518,31.059958;112.197424,31.05937;112.190901,31.057679;112.186867,31.05187 halt($str); $res = \app\admin\model\yq\base_config\Perimeter::update(['info' => $str, 'id' => $params['perimeter_id']]); if ($res) { $this->error('设置成功~'); } else { $this->error('设置失败~'); } } if (!$this->model->get(input('ids'))) { $this->error('数据不存在'); } $res = $this->model->where('is_del', 1)->order('id')->select(); foreach ($res as $key => &$value) { switch ($value['region_lv']) { case 21: $value['region_lv'] = 1; break; case 22: $value['region_lv'] = 2; break; default : $value['region_lv'] = 0; break; } } $this->assign('data', json_encode($res)); $this->assign('perimeter_id', input('ids')); $this->view->engine->layout(false); return $this->view->fetch(); } public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model ->with(['parent', 'typeo', 'typet']) ->where($where) ->order($sort, $order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } 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 (!$params['region_lv'] || $params['region_lv'] == '') { $this->error('请选择周界等级~'); } if (!$params['region_type'] || $params['region_type'] == '') { $this->error('请选择周界区域~'); } if ($params['region_lv'] == 21) { if (empty($params['pid'])) { $this->error('当前为三级周界等级,请选择二级周界~'); } if (empty($params['stop_vehicle']) && $params['stop_vehicle'] != 0) { $this->error('当前为三级周界等级,请设置可停车辆数~'); } if (empty($params['feasible_vehicle']) && $params['feasible_vehicle'] != 0) { $this->error('当前为三级周界等级,请设置可行车辆数~'); } if (empty($params['max_speed']) && $params['max_speed'] != 0) { $this->error('当前为三级周界等级,请设置最大限速~'); } } 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); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('No rows were inserted')); } $this->success(); } 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); if (!$params['region_lv'] || $params['region_lv'] == '') { $this->error('请选择周界等级~'); } if (!$params['region_type'] || $params['region_type'] == '') { $this->error('请选择周界区域~'); } if ($params['region_lv'] == 21) { if (empty($params['pid'])) { $this->error('当前为三级周界等级,请选择二级周界~'); } if (empty($params['stop_vehicle']) && $params['stop_vehicle'] != 0) { $this->error('当前为三级周界等级,请设置可停车辆数~'); } if (empty($params['feasible_vehicle']) && $params['feasible_vehicle'] != 0) { $this->error('当前为三级周界等级,请设置可行车辆数~'); } if (empty($params['max_speed']) && $params['max_speed'] != 0) { $this->error('当前为三级周界等级,请设置最大限速~'); } } $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); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } }