HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.fpngv.com/application/admin/model/AuthGroup.php
<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2007 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 御宅男 <530765310@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\model;

use think\Db;
use think\Model;

/**
 * 用户组模型类
 * Class AuthGroupModel
 */
class AuthGroup extends Model
{
    const TYPE_ADMIN                = 1; // 管理员用户组类型标识
    const MEMBER                    = 'admin';
    const AUTH_EXTEND               = 'auth_extend'; // 动态权限扩展信息表
    const AUTH_GROUP                = 'auth_group'; // 用户组表名
    const AUTH_EXTEND_CATEGORY_TYPE = 1; // 分类权限标识
    const AUTH_EXTEND_MODEL_TYPE    = 2; //分类权限标识

    protected $resultSetType = 'collection';

    /**
     * 根据角色Id获取角色名
     * @param int $Groupid 角色id
     * @return string 返回角色名
     */
    public function getRoleIdName($Groupid)
    {
        return $this->where(array('id' => $Groupid))->value('title');
    }

    /**
     * 通过递归的方式获取该角色下的全部子角色
     * @param type $id
     * @return string
     */
    public function getArrchildid($id)
    {
        if (empty($this->roleList)) {
            $this->roleList = $this->order(array("id" => "desc"))->column('*', 'id');
        }
        $arrchildid = $id;
        if (is_array($this->roleList)) {
            foreach ($this->roleList as $k => $cat) {
                if ($cat['parentid'] && $k != $id && $cat['parentid'] == $id) {
                    $arrchildid .= ',' . $this->getArrchildid($k);
                }
            }
        }
        return $arrchildid;
    }

    /**
     * 删除角色
     * @param int $Groupid 角色ID
     * @return boolean
     */
    public function GroupDelete($Groupid)
    {
        if (empty($Groupid) || $Groupid == 1) {
            $this->error = '超级管理员角色不能被删除!';
            return false;
        }
        $admin = Db::name('Admin')->where('roleid', $Groupid)->find();
        if ($admin) {
            $this->error = '该角色下有管理员!';
            return false;
        }
        //角色信息
        $info = $this->where(array('id' => $Groupid))->find();
        if (empty($info)) {
            $this->error = '该角色不存在!';
            return false;
        }
        //子角色列表
        $child = explode(',', $this->getArrchildid($Groupid));
        if (count($child) > 1) {
            $this->error = '该角色下有子角色,请删除子角色才可以删除!';
            return false;
        }
        return $this->where(array('id' => $Groupid))->delete() !== false ? true : false;
    }

}