123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\AuthGroup;
- use app\admin\model\AuthGroupAccess;
- use app\common\controller\Backend;
- use think\Db;
- use think\Session;
- /**
- *
- *
- * @icon fa fa-circle-o
- */
- class Intention extends Backend
- {
- //快速搜索的字段
- protected $searchFields = ['unit_name','contacts'];
- /**
- * 无需鉴权的方法,但需要登录
- * @var array
- */
- protected $noNeedRight = ['unittypelist'];
-
- /**
- * Intention模型对象
- * @var \app\admin\model\Intention
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Intention');
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax())
- {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField'))
- {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $list = collection($list)->toArray();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost())
- {
- $params = $this->request->post("row/a");
- if ($params)
- {
- if ($this->dataLimit && $this->dataLimitFieldAutoFill)
- {
- $params[$this->dataLimitField] = $this->auth->id;
- }
- try
- {
- //是否采用模型验证
- if ($this->modelValidate)
- {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
- $this->model->validate($validate);
- }
- $params['usr_id'] = Session::get('admin')['id']; //usr id
- $params['usr_nickname'] = Session::get('admin')['nickname']; //nickname
- $params['created_at'] = date('Y-m-d H:i:s'); //创建时间
- $params['usr_depart'] = Session::get('admin')['usr_depart']; //获取所属组名
- $params['depart_id'] = Session::get('admin')['depart_id']; //获取所属组id
- \app\admin\model\Intention::addUnitType($params['unit_type']);
- $result = $this->model->allowField(true)->save($params);
- if ($result !== false)
- {
- $this->success();
- }
- else
- {
- $this->error($this->model->getError());
- }
- }
- catch (\think\exception\PDOException $e)
- {
- $this->error($e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- return $this->view->fetch();
- }
- /**
- * 性质列表
- */
- public function unitTypeList()
- {
- $list = Db::table('unit_type')
- ->select();
- $searchlist = [];
- foreach ($list as $key => $value)
- {
- $searchlist[] = ['id'=>$value['name'], 'name' => $value['name']];
- }
- $data = ['rows' => $searchlist];
- return $data;
- }
-
- }
|