123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\index\model;
- use think\Model;
- use app\index\model\NodeModel;
- class RoleModel extends Model{
- // 确定链接表名
- protected $name = 'role';
- /**
- * 获取角色信息
- * @param $id
- */
- public function getRoleInfo($id)
- {
- $result = $this->where('id', $id)->find()->toArray();
- // 超级管理员权限是 *
- if(empty($result['rule'])){
- $result['action'] = '';
- return $result;
- }else if('*' == $result['rule']){
- $where = '';
- }else{
- $where = 'id in(' . $result['rule'] . ')';
- }
- // 查询权限节点
- $nodeModel = new NodeModel();
- $res = $nodeModel->getActions($where);
- foreach($res as $key=>$vo){
- if('#' != $vo['action_name']){
- $result['action'][] = $vo['control_name'] . '/' . $vo['action_name'];
- }
- }
- return $result;
- }
- /**
- * 根据搜索条件获取角色列表信息
- * @param $where
- * @param $offset
- * @param $limit
- */
- public function getRoleByWhere($where, $offset, $limit)
- {
- return $this->where($where)->limit($offset, $limit)->order('id desc')->select();
- }
- /**
- * 根据搜索条件获取所有的角色数量
- * @param $where
- */
- public function getAllRole($where)
- {
- return $this->where($where)->count();
- }
- /**
- * 插入角色信息
- * @param $param
- */
- public function insertRole($param)
- {
- try{
- $param['create_timestamp'] = $param['update_timestamp'] = date('Y-m-d H:i:s');
- $result = $this->save($param);
- if(false === $result){
- // 验证失败 输出错误信息
- return msg(-1, '', $this->getError());
- }else{
- return msg(1, '', '添加角色成功');
- }
- }catch(PDOException $e){
- return msg(-2, '', $e->getMessage());
- }
- }
- /**
- * 删除角色
- * @param $id
- */
- public function delRole($id)
- {
- try{
- $this->where('id', $id)->delete();
- return msg(1, '', '删除角色成功');
- }catch(PDOException $e){
- return msg(-1, '', $e->getMessage());
- }
- }
- // 获取所有的角色信息
- public function getRole()
- {
- return $this->select();
- }
- }
|