| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\admin\controller\stock;
- use app\common\controller\Backend;
- use fast\Tree;
- /**
- * 字典数据
- *
- * @icon fa fa-circle-o
- */
- class Datadictitem extends Backend {
- /**
- * Datadictitem模型对象
- * @var \app\admin\model\stock\Datadictitem
- */
- protected $model = null;
- protected $relationSearch = true;
- protected $searchFields = 'name,value';
- public function _initialize() {
- parent::_initialize();
- $this->model = model('\app\admin\model\stock\Datadictitem');
- $dataDiclist = collection(model('\app\admin\model\stock\Datadict')->order('weigh', 'desc')->select())->toArray();
- Tree::instance()->init($dataDiclist);
- $this->dataDiclist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
- foreach ($this->dataDiclist as $k => &$v) {
- $dataDicdata[$v['id']] = $v['name'];
- }
- $this->view->assign('dataDicdata', $dataDicdata);
- $this->view->assign("enabledList", $this->model->getEnabledList());
- }
- /**
- * 查看
- */
- 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();
- $datadict_id = $this->request->request('datadict_id');
- if ($datadict_id) {
- $total = $this->model->where($where)->where('datadict_id', 'in', $datadict_id)->order($sort, $order)->count();
- $list = $this->model->where($where)->where('datadict_id', 'in', $datadict_id)->order($sort, $order)->limit($offset, $limit)->select();
- } else {
- // $total = $this->model->where($where)->count();
- // $list = $this->model->where($where)->order($sort, $order)->limit($offset, $limit)->select();
- $total = [];
- $list = [];
- }
- $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);
- }
- $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', ''));
- }
- $datadict_id = $this->request->param("datadict_id");
- $this->view->assign("datadict_id", $datadict_id);
- return $this->view->fetch();
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- }
|