Files
chatroom/app/Models/SysParam.php
lkddi ea06328885 功能:字体颜色持久化、等级体系升级至99级、钓鱼小游戏、补充系统参数
- 字体颜色:s_color 改为 varchar,发消息时保存颜色,进入聊天室自动恢复
- 等级体系:maxlevel 15→99,superlevel 16→100,99级经验阶梯(幂次曲线)
- 管理权限等级按比例调整:禁言50、踢人60、设公告60、封号80、封IP90
- 钓鱼小游戏:FishingController(抛竿扣金币+收竿随机结果+广播)
- 补充6个缺失的 sysparam 参数 + 4个钓鱼参数
- 用户列表点击用户名后自动聚焦输入框
- Pint 格式化
2026-02-26 21:10:34 +08:00

91 lines
2.3 KiB
PHP

<?php
/**
* 文件功能:系统参数模型
* 对应原版 ASP 聊天室的 sysparam 配置表
* 管理员可在后台修改等级经验阈值等系统参数
*
* @package App\Models
* @author ChatRoom Laravel
* @version 1.0.0
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
class Sysparam extends Model
{
/** @var string 表名 */
protected $table = 'sysparam';
/** @var array 可批量赋值的字段 */
protected $fillable = ['alias', 'body', 'guidetxt'];
/**
* 获取指定参数的值
* 带缓存,避免频繁查库
*
* @param string $alias 参数别名
* @param string $default 默认值
* @return string
*/
public static function getValue(string $alias, string $default = ''): string
{
return Cache::remember("sysparam:{$alias}", 300, function () use ($alias, $default) {
$param = static::where('alias', $alias)->first();
return $param ? ($param->body ?? $default) : $default;
});
}
/**
* 获取等级经验阈值数组
* 返回格式:[0 => 10, 1 => 50, 2 => 150, ...] 索引即为目标等级-1
*
* @return array<int, int>
*/
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}");
}
}