'json' ]; const TYPE_MENU = 1; const TYPE_BTN = 2; public static function checkNameIsUnique($name, $ignore_id = 0) { return self::query()->where('name', $name)->where('type', self::TYPE_MENU)->where('id', '<>', $ignore_id)->exists(); } public static function checkBtnPathIsUnique($path, $ignore_id = 0) { return self::query()->where('path', $path)->where('type', self::TYPE_BTN)->where('id', '<>', $ignore_id)->exists(); } /** * 是否存在这个安全权限 * @param $user_id * @param $btn_id * @return bool */ public static function checkUserIsBtn($btn_id = 150, $admin_id = 0) { if (!$admin_id) $admin_id = login_admin_id(); if (in_array($admin_id, config('site.superAdmin_ids', [1]))) return true; $roleIds = DB::table('base_roles_menus')->where('menu_id', $btn_id)->pluck('role_id'); if (!count($roleIds)) return false; return DB::table('base_model_has_roles')->where('model_id', $admin_id)->whereIn('role_id', $roleIds)->exists(); } }