* Class PdmFootprint * @package app\admin\controller */ class PdmFootprint extends AdminController { /** * PdmFootprint模型对象 * @var \app\admin\model\PdmFootprint */ public function __construct() { parent::__construct(); $this->model = new PdmFootprintModel; } /** * 默认生成的方法为index/add/edit/del/status 五个方法 * 当创建CURD的时候,DIY的函数体和模板为空,请自行编写代码 */ /** * 获取资源列表 * return Response */ public function index(): Response { if (request()->isAjax()) { list($count, $list) = PdmFootprint::dataList(request()->all()); // $rules = list_to_tree($list,'id','pid','children',0); $lists = list_to_tree($list,'id','pid','children',0); return $this->success('获取成功', '/',$lists, $count); // return $this->success('获取成功', '/'); } return view('/pdm_footprint/index'); } /** * 获取资源列表 * @param array $params * @return array * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public static function dataList(array $params): array { $where = array(); if (!empty($params['footprint'])) { $where[] = ['footprint','like','%'.$params['footprint'].'%']; } if (!empty($params['content'])) { $where[] = ['content','like','%'.$params['content'].'%']; } $model = new PdmFootprintModel(); // $model = $this->model; $count = $model->where($where)->count(); // $list = $model->where($where)->order('sort asc')->select()->toArray(); $list = $model->where($where)->order('sort asc')->select(); foreach($list as $key => $value){ // throw new \Exception(json_encode($value)); // throw new \Exception(json_encode($list[$key]->admin['nickname'])); $list[$key]['creator'] =__($list[$key]->admin['nickname']); } return [$count, $list->toArray()]; } /** * 添加节点数据 * @return Response */ public function add(): Response { if (request()->isPost()) { $post = \request()->post(); // validate(\app\common\validate\system\AdminRules::class . '.add')->check($post); $userid = get_admin_id(); $post['creatorid'] = $userid ; if ($this->model->create($post)) { return $this->success('添加FootPrint成功!'); } } $data = $this->getTableFields(); $data['pid'] = input('pid', 0); // $data['auth'] = 1; // $data['type'] = 1; list($count, $list) = PdmFootprint::dataList(request()->all()); return view('/pdm_footprint/add', [ 'data' => $data, 'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE), ]); } /** * 编辑节点数据 * @return Response * @throws DbException * @throws DataNotFoundException * @throws ModelNotFoundException */ public function edit(): Response { $id = input('id', 0); $data = $this->model->find($id); if (request()->isPost()) { $post = \request()->post(); // validate(\app\common\validate\system\AdminRules::class . '.edit')->check($post); if ($this->model->update($post)) { return $this->success('更新FootPrint成功!'); } } list($count, $list) = PdmFootprint::dataList(request()->all()); return view('/pdm_footprint/add', [ 'data' => $data, 'rules' => json_encode( list_to_tree($list), JSON_UNESCAPED_UNICODE), ]); } /** * 删除节点数据 * @return Response * @throws DbException */ public function del(): Response { $id = input('id'); if (!empty($id)) { // 查询子节点 if ($this->model->where('pid',$id)->count()) { return $this->error('当前分类存在子项!'); } // 删除单个 if ($this->model::destroy($id)) { return $this->success('删除FootPrint成功!'); } } return $this->error('删除失败,请检查您的参数!'); } }