/** * 可添加的角色组 */ public function filterCanAddRole($list) { $userData = CSession::get('user'); $groupId = $userData['groupData']['gid']; // 超级管理员给全部资源 if (1 == $groupId) { return $list; } $category = CDatabase::getInstance()->from('admin_group')->select()->execute()->asArray(); foreach ($category as $key => $val) { $category[$key]['name'] = $val['gname']; $category[$key]['id'] = $val['gid']; } $category = TreeClass::getTree($category); // 获取其子类 $childData = $childDataVal = array(); TreeClass::getCatTree($groupId, $category, $childData, $childDataVal); foreach ($list as $key => $val) { if (!in_array($val['gid'], $childData)) { unset($list[$key]); } } return $list; }
/** * 获取所有用户名 以gid排序 */ public function getGroupList() { return CDatabase::getInstance()->from($this->tableName())->select()->execute()->getKey('gid'); }
/** * 删除记录 */ public function delete($where) { try { $tableName = $this->tableName(); $data = CDatabase::getInstance()->delete()->from($tableName)->where($where)->execute(); return $data->isSuccess(); } catch (CDbException $e) { $this->_lastError = $e->getMessage(); return false; } }
/** * 用户管理 */ public function Action_userList() { $where['gid'] = $this->Args('gid', 'int'); $where['username'] = $this->Args('username'); // 用户 $list = CDatabase::getInstance()->from('admin_user')->select()->limit(50000); if (!empty($where['gid']) && $where['gid'] != '-1') { $list = $list->where('groupId', '=', $where['gid']); } if (!empty($where['username'])) { $list = $list->where('username', 'LIKE', '%' . $where['username'] . '%'); } $list = $list->execute()->asArray(); // 过滤用户 $list = CModel::factory('adminUserModel')->filterUser($list); // 组 $group = CModel::factory('adminRoleModel')->findAll()->asArray(); $groupKeyArr = array(); foreach ($group as $val) { $groupKeyArr[$val['gid']] = $val; } $canGroup = CModel::factory('adminRoleModel')->findAll()->asArray(); $canGroup = CModel::factory('adminRoleModel')->filterCanAddRole($group); $this->assign('where', $where); $this->assign('canGroup', $canGroup); $this->assign('list', $list); $this->assign('group', $groupKeyArr); $this->display(); }
/** * 过滤权限 */ public function filterUser($list) { $userData = CSession::get('user'); $groupId = $userData['groupData']['gid']; if (1 == $groupId) { return $list; } $category = CDatabase::getInstance()->from('admin_group')->select()->execute()->asArray(); foreach ($category as $key => $val) { $category[$key]['name'] = $val['gname']; $category[$key]['id'] = $val['gid']; } $category = TreeClass::getTree($category); // 获取该组ID阔以查看的所有子组ID $childData = $childDataVal = array(); TreeClass::getCatTree($groupId, $category, $childData, $childDataVal); // 可以查询的子组ID序列 $groupList = array(); foreach ($childDataVal as $key => $val) { $groupList[] = $val['gid']; } foreach ($list as $key => $val) { if (!in_array($val['groupId'], $groupList)) { unset($list[$key]); } } return $list; }
public function getCount($setWhere) { $list = CDatabase::getInstance()->from($this->tableName())->select(array("count(`{$this->pkName()}`)" => 'num')); // 筛选条件 $list = $this->setWhere($list, $setWhere); $list = $list->execute()->current(); return isset($list['num']) ? $list['num'] : 0; }