修复:自动存点不再覆盖有职务用户的等级
AutoSaveExp::processUser() 第3步升降级逻辑重构:
- 有在职职务的用户:等级强制锁定为 position.level
(防止自动存点按经验值降低/覆盖职务对应等级)
- 管理员(>= superLevel):不变动
- 普通用户:照旧按经验自动升降级
同时在 refresh() 后加 load('activePosition.position')
确保职务关联数据已就绪。
This commit is contained in:
@@ -164,12 +164,25 @@ class AutoSaveExp extends Command
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
$user->refresh(); // 刷新获取最新属性(service 已原子更新)
|
$user->refresh(); // 刷新获取最新属性(service 已原子更新)
|
||||||
|
$user->load('activePosition.position'); // 确保职务及职位关联已加载
|
||||||
|
|
||||||
// 3. 自动升降级(管理员不参与)
|
// 3. 自动升降级逻辑
|
||||||
|
// - 有在职职务的用户:等级固定为职务对应等级,不随经验变化
|
||||||
|
// - 管理员(>= superLevel):不变动
|
||||||
|
// - 普通用户:按经验计算等级,支持升降级
|
||||||
$oldLevel = $user->user_level;
|
$oldLevel = $user->user_level;
|
||||||
$leveledUp = false;
|
$leveledUp = false;
|
||||||
|
|
||||||
if ($oldLevel < $superLevel) {
|
$activeUP = $user->activePosition; // 已在 refresh 后加载
|
||||||
|
|
||||||
|
if ($activeUP?->position) {
|
||||||
|
// 有在职职务:等级锁定为职务设定值,确保不被经验系统覆盖
|
||||||
|
$requiredLevel = (int) $activeUP->position->level;
|
||||||
|
if ($requiredLevel > 0 && $user->user_level !== $requiredLevel) {
|
||||||
|
$user->user_level = $requiredLevel;
|
||||||
|
}
|
||||||
|
} elseif ($oldLevel < $superLevel) {
|
||||||
|
// 普通用户:按经验计算并更新等级
|
||||||
$newLevel = Sysparam::calculateLevel($user->exp_num);
|
$newLevel = Sysparam::calculateLevel($user->exp_num);
|
||||||
if ($newLevel !== $oldLevel && $newLevel < $superLevel) {
|
if ($newLevel !== $oldLevel && $newLevel < $superLevel) {
|
||||||
$user->user_level = $newLevel;
|
$user->user_level = $newLevel;
|
||||||
|
|||||||
Reference in New Issue
Block a user