first(); return $param ? ($param->body ?? $default) : $default; }); } /** * 获取等级经验阈值数组 * 返回格式:[0 => 10, 1 => 50, 2 => 150, ...] 索引即为目标等级-1 * * @return array */ public static function getLevelExpThresholds(): array { $str = static::getValue('levelexp', '10,50,150,400,800,1500,3000,5000,8000,12000,18000,25000,35000,50000,80000'); return array_map('intval', explode(',', $str)); } /** * 根据经验值计算应该达到的等级 * * @param int $expNum 当前经验值 * @return int 对应的等级 */ public static function calculateLevel(int $expNum): int { $thresholds = static::getLevelExpThresholds(); $level = 0; foreach ($thresholds as $threshold) { if ($expNum >= $threshold) { $level++; } else { break; } } // 不超过最大等级 $maxLevel = (int) static::getValue('maxlevel', '99'); return min($level, $maxLevel); } /** * 清除指定参数的缓存 * * @param string $alias 参数别名 */ public static function clearCache(string $alias): void { Cache::forget("sysparam:{$alias}"); } }