修复:心跳存点经验增加加入30秒冷却间隔
- 用 Redis setex 设置30秒冷却,防止频繁点击存点刷经验 - 冷却期内点击存点仍正常保存数据,但不增加经验
This commit is contained in:
@@ -149,10 +149,18 @@ class ChatController extends Controller
|
||||
return response()->json(['status' => 'error'], 401);
|
||||
}
|
||||
|
||||
// 1. 每次心跳增加经验(可在 sysparam 后台配置),VIP 倍率加成
|
||||
$expGain = (int) Sysparam::getValue('exp_per_heartbeat', '1');
|
||||
$expMultiplier = $this->vipService->getExpMultiplier($user);
|
||||
$user->exp_num += (int) round($expGain * $expMultiplier);
|
||||
// 1. 心跳经验:通过 Redis 限制最小间隔(默认30秒),防止频繁点击刷经验
|
||||
$expCooldownKey = "heartbeat_exp:{$user->id}";
|
||||
$canGainExp = ! Redis::exists($expCooldownKey);
|
||||
|
||||
if ($canGainExp) {
|
||||
$expGain = (int) Sysparam::getValue('exp_per_heartbeat', '1');
|
||||
$expMultiplier = $this->vipService->getExpMultiplier($user);
|
||||
$user->exp_num += (int) round($expGain * $expMultiplier);
|
||||
|
||||
// 设置冷却(30秒内不再给经验)
|
||||
Redis::setex($expCooldownKey, 30, 1);
|
||||
}
|
||||
|
||||
// 2. 使用 sysparam 表中可配置的等级-经验阈值计算等级
|
||||
// 管理员(superlevel 及以上)不参与自动升降级,等级由后台手动设置
|
||||
|
||||
Reference in New Issue
Block a user