123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use app\admin\logic\ActionLogic;
- use app\model\ActionModel;
- use app\model\AdminMenuModel;
- use app\model\CommonModel;
- use think\exception\ValidateException;
- use think\facade\Config;
- use think\facade\Validate;
- //功能权限
- class Action extends BaseController
- {
- //获取权限列表
- public function list()
- {
- $menuid = $this->request->post('menuid', 0);
- return ActionLogic::list($menuid);
- }
- //添加权限
- public function add()
- {
- $param = $this->request->only(['menuid', 'action_code', 'status' => CommonModel::$status_normal], 'post');
- $val = Validate::rule(Config::get('validate_rules.actionAdd'));
- if (!$val->check($param)) throw new ValidateException($val->getError());
- return ActionLogic::add($param);
- }
- // //获取权限详情
- // public function Read()
- // {
- // $id = $this->request->post('id/d', 0);
- //
- // return ActionLogic::read($id);
- // }
- //编辑权限
- public function edit()
- {
- $param = $this->request->only(['id', 'action_code'], 'post');
- $val = Validate::rule([
- 'id' => 'require|number|gt:0',
- 'action_code|按钮编码' => 'require',
- ]);
- if (!$val->check($param)) throw new ValidateException($val->getError());
- return ActionLogic::edit($param);
- }
- //删除权限
- public function delete()
- {
- $id = $this->request->post('id/d', 0);
- return ActionLogic::delete($id);
- }
- //启禁用权限
- public function status()
- {
- $param = $this->request->only(['id', 'status'], 'post');
- $val = Validate::rule(Config::get('validate_rules.status'));
- if (!$val->check($param)) throw new ValidateException($val->getError());
- return ActionLogic::status($param);
- }
- //获取所有菜单下的所有按钮
- public function index()
- {
- $list = AdminMenuModel::field('id,menu_name,menu_type,menu_img,menu_route,menu_url,status,weight,addtime,is_private private')
- ->where(['pid' => 0, 'is_show' => AdminMenuModel::$show])
- ->append(['child'])
- ->withAttr('child', function ($val, $data) {
- return AdminMenuModel::field('id,menu_name,menu_type,menu_img,menu_route,menu_url,status,weight,addtime,is_private private,pid')
- ->where(['pid' => $data['id'], 'is_show' => AdminMenuModel::$show])
- ->append(['action'])
- ->withAttr('action', function ($v, $d) {
- return ActionModel::alias('a')
- ->leftJoin('action_list l', 'a.action_code=l.action_code')
- ->field('a.*,action_name')
- ->where(['a.menuid' => $d['id'], 'a.status' => CommonModel::$status_normal])
- ->select()
- ->toArray();
- })
- ->order('weight', 'desc')
- ->select()
- ->toArray();
- })
- ->order('weight', 'desc')
- ->select()
- ->toArray();
- return json_show(CommonModel::$success, '获取成功', $list);
- }
- }
|