功能:全局奖励接收次数上限(职务管理页配置)

新增全局 sysparam 配置 reward_recipient_daily_max:
- 控制每位用户单日内从所有职务持有者处累计接收奖励的最高次数
- 0 = 不限制

后端变更:
- PositionController::saveRewardConfig() 保存配置
- POST admin/positions/reward-config 路由
- AdminCommandController::reward() 新增第④层校验:
  全局次数上限(优先级低于职务级别的 recipient_daily_limit)

视图变更:
- 职务管理页顶部加橙色配置卡片(行内表单,即改即存)
- 显示当前全局配置值
This commit is contained in:
2026-03-01 11:22:02 +08:00
parent a145c6fc0a
commit baaa7087b0
4 changed files with 79 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Department;
use App\Models\Position;
use App\Models\Sysparam;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
@@ -34,7 +35,10 @@ class PositionController extends Controller
// 全部职务(供任命白名单多选框使用)
$allPositions = Position::with('department')->orderByDesc('rank')->get();
return view('admin.positions.index', compact('departments', 'allPositions'));
// 全局奖励接收次数上限0 = 不限)
$globalRecipientDailyMax = (int) Sysparam::getValue('reward_recipient_daily_max', '0');
return view('admin.positions.index', compact('departments', 'allPositions', 'globalRecipientDailyMax'));
}
/**
@@ -68,6 +72,36 @@ class PositionController extends Controller
return redirect()->route('admin.positions.index')->with('success', "职务【{$data['name']}】创建成功!");
}
/**
* 保存全局奖励金币接收次数上限
*
* 控制每位用户单日内可从所有职务持有者处累计接收奖励的最高次数。
* 0 表示不限制,保存到 sysparam 表中key: reward_recipient_daily_max
*/
public function saveRewardConfig(Request $request): RedirectResponse
{
$request->validate([
'reward_recipient_daily_max' => 'required|integer|min:0|max:9999',
]);
$value = (string) $request->integer('reward_recipient_daily_max');
Sysparam::updateOrCreate(
['alias' => 'reward_recipient_daily_max'],
[
'body' => $value,
'guidetxt' => '用户单日最多接收奖励金币次数0=不限,统计所有职务持有者的发放总次数)',
]
);
Sysparam::clearCache('reward_recipient_daily_max');
$label = $value === '0' ? '不限' : "{$value}";
return redirect()->route('admin.positions.index')
->with('success', "全局接收次数上限已更新为:{$label}");
}
/**
* 更新职务(含任命白名单同步)
*/

View File

@@ -499,6 +499,22 @@ class AdminCommandController extends Controller
}
}
// ④ 全局系统级别:每位用户单日最多接收奖励次数(后台职务管理页统一配置)
$globalMax = (int) Sysparam::getValue('reward_recipient_daily_max', '0');
if ($globalMax > 0) {
$globalCount = PositionAuthorityLog::where('target_user_id', $target->id)
->where('action_type', 'reward')
->whereDate('created_at', today())
->count();
if ($globalCount >= $globalMax) {
return response()->json([
'status' => 'error',
'message' => "{$targetUsername} 今日已累计接收 {$globalCount} 次奖励,已达全局每日上限({$globalMax}",
], 422);
}
}
// 发放金币(通过 UserCurrencyService 原子性更新 + 写流水)
$this->currencyService->change(
$target,