123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use fast\Tree;
- /**
- * 用户岗位
- */
- class Usergangwei extends Backend
- {
- protected $model = null;
- protected $categorylist = [];
- protected $noNeedRight = ['selectpage'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\common\model\Usergangwei;
- $tree = Tree::instance();
- $tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
- $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
- $categorydata = [0 => ['name' => __('None')]];
- foreach ($this->categorylist as $k => $v) {
- $categorydata[$v['id']] = $v;
- }
- $this->view->assign("parentList", $categorydata);
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- $list = $this->categorylist;
- $total = count($list);
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 编辑
- */
- 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)) {
- if (!in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- }
- if ($this->request->isPost()) {
- $this->token();
- $params = $this->request->post("row/a");
- if ($params) {
- $params = $this->preExcludeFields($params);
- if ($params['pid'] != $row['pid']) {
- $childrenIds = Tree::instance()->init(collection(\app\common\model\Usergangwei::select())->toArray())->getChildrenIds($row['id'], true);
- if (in_array($params['pid'], $childrenIds)) {
- $this->error(__('Can not change the parent to child or itself'));
- }
- }
- 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->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- if ($result !== false) {
- $this->success();
- } else {
- $this->error($row->getError());
- }
- } catch (\think\exception\PDOException $e) {
- $this->error($e->getMessage());
- } catch (\think\Exception $e) {
- $this->error($e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $this->view->assign("row", $row);
- return $this->view->fetch();
- }
- /**
- * Selectpage搜索
- *
- * @internal
- */
- public function selectpage()
- {
- return parent::selectpage();
- }
- }
|