123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\admin\controller;
- use app\admin\logic\RoleLogic;
- use app\BaseController;
- use think\exception\ValidateException;
- use think\facade\Config;
- use think\facade\Validate;
- //角色
- class Role extends BaseController
- {
- //获取角色列表
- public function List()
- {
- $param = $this->request->only([
- 'page'=>1,
- 'size'=>10,
- 'name'=>'',
- 'level'=>'',
- 'status'=>''
- ],'post');
- $val= Validate::rule(array_merge(Config::get('validate_rules.common'),Config::get('validate_rules.roleList')));
- if(!$val->check($param)) throw new ValidateException($val->getError());
- return RoleLogic::List($param);
- }
- //添加角色
- public function Add()
- {
- $param = $this->request->only(['name','level','remark','action_data'],'post');
- $val= Validate::rule(Config::get('validate_rules.RoleAdd'));
- if(!$val->check($param)) throw new ValidateException($val->getError());
- return RoleLogic::Add($param);
- }
- //获取角色详情
- public function Read()
- {
- $id=$this->request->post('id/d',0);
- return RoleLogic::Read($id);
- }
- //编辑角色
- public function Edit()
- {
- $param = $this->request->only(['id','name','level','remark','action_data'],'post');
- $val= Validate::rule(array_merge(Config::get('validate_rules.RoleAdd'),['id'=>'require|number|gt:0']));
- if(!$val->check($param)) throw new ValidateException($val->getError());
- return RoleLogic::Edit($param);
- }
- //删除角色
- public function Delete()
- {
- $id = $this->request->post('id/d', 0);
- return RoleLogic::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 RoleLogic::Status($param);
- }
- }
|