getTypeList(); foreach ($list as $k=>$v) { $where = []; $where = $this->getNewGroupPid($v['pid']); $groupList = db('admin_group')->where($where)->select() ? : []; $list[$k]['list'] = $groupList ? : []; } } else { $where = []; if (isset($param['type'])) { $where['pid'] = $param['pid']; $where['type'] = $param['type']; } else { $where = $this->getNewGroupPid($param['pid']); } $list = db('admin_group')->where($where)->select() ? : []; if ($param['rules'] == 1) { //角色权限分类关系 $ruleTypes = $ruleModel->groupsToRules($param['pid']); if ($ruleTypes) { foreach ($list as $key => $val) { $dataRules = []; $biRules = []; $rules = stringToArray($val['rules']) ? : []; foreach ($rules as $k1=>$v1) { $ruleInfo = []; $ruleInfo = db('admin_rule')->where(['id' => $v1])->find(); if ($ruleInfo['types'] == $ruleTypes[0]) { $dataRules[] = $v1; } elseif ($ruleInfo['types'] == $ruleTypes[1]) { $biRules[] = $v1; } } $list[$key]['rules'] = []; $list[$key]['rules']['data'] = $dataRules ? : []; $list[$key]['rules']['bi'] = $biRules ? : []; if ($val['pid'] == 1 || $val['pid'] == 5 || $val['pid'] == 6 || $val['pid'] == 9) { $list[$key]['type'] = 0; } } } } } return $list ? : []; } //新建角色 public function createData($param) { unset($param['types']); if ($param['pid'] == 5 && $param['type'] == 'work') { //项目模块下角色 $param['type'] = 0; } $userInfo=new ApiCommon(); $user_id=$userInfo->userInfo; $flag = $this->insertGetId($param); if ($flag) { return $flag; } else { $this->error = '操作失败'; return false; } } //编辑角色 public function updateDataById($param,$group_id) { $dataInfo = $this->get($group_id); if(!$dataInfo){ $this->error = '该角色不存在或已删除'; return false; } unset($param['types']); # 处理编辑时,前端可能不传父id的问题(admin_rule表level为1的主键) if (!empty($param['rules'])) { $rulesParam = stringToArray($param['rules']); $rulesList = db('admin_rule')->field(['id', 'level', 'pid'])->whereIn('id', $rulesParam)->select(); foreach ($rulesList AS $key => $value) { if (!empty($value['level']) && $value['level'] == 2) $rulesParam[] = $value['pid']; if (!empty($value['level']) && $value['level'] == 3) { $rulesParam[] = $value['pid']; $rulesParam[] = db('admin_rule')->where('id', $value['pid'])->value('pid'); } } $param['rules'] = arrayToString(array_unique($rulesParam)); } if($param['title']){ unset($param['rules']); } $flag = $this->where('id = '.$group_id)->update($param); if ($flag) { $user=new ApiCommon(); $user_id=$user->userInfo; SystemActionLog($user_id['id'], 'admin_group','role', $group_id, 'update', $dataInfo['title'], '', '','编辑了:'.$dataInfo['title']); return true; } else { $this->error = '操作失败'; return false; } } //删除角色 public function delGroupById($group_id = '') { $dataInfo = $this->get($group_id); if(!$dataInfo){ $this->error = '该角色不存在或已删除'; return false; } if ($dataInfo['types']) { $this->error = '系统角色不能删除'; return false; } $flag = $this->where('id = '.$group_id)->delete(); if ($flag) { # 系统操作记录 $user=new ApiCommon(); $user_id=$user->userInfo; SystemActionLog($user_id['id'], 'admin_group','role', $group_id, 'update', $dataInfo['title'], '', '','删除了角色:'.$dataInfo['title']); return true; } else { $this->error = '删除失败'; return false; } } /** * [getTypeList 获取分类列表] * @param 备注:原自定义角色0,人事管理角色3,财务管理角色4,划分至客户管理角色中 * @return [array] */ public function getTypeList() { $list = ['0' => ['name' => '系统管理角色','pid' => 1],'1' => ['name' => '办公管理角色','pid' => 6],'2' => ['name' => '客户管理角色','pid' => 2],'3' => ['name' => '项目管理角色','pid' => '9']]; return $list ? : []; } /** * [getNewGroupPid 兼容9.0.5版本group pid对应关系] * @param 备注:原自定义角色0,人事管理角色3,财务管理角色4,划分至客户管理角色中 * @return [array] */ protected function getNewGroupPid($pid) { switch ($pid) { case '1' : $where['pid'] = 1; $where['types'] = ['not in',['7']]; break; case '2' : $where = function($query) { $query->where(['pid' => ['in',['0','2','3','4']]]) ->whereOr('type != 0 AND pid = 5'); }; break; case '9' : $where = function($query) { $query->where(['pid' => 9]) ->whereOr('types = 7 AND pid = 1'); }; break; default : $where['pid'] = $pid; break; } return $where ? : []; } }