BAS批量同步订阅:增加60秒去重锁(对齐BMPA)

This commit is contained in:
萝卜
2026-03-17 15:27:18 +08:00
parent 224176cea6
commit c2e41917ed
2 changed files with 92 additions and 0 deletions

View File

@@ -1605,6 +1605,14 @@ class PlatformOrderController extends Controller
// 注意:当前阶段仍由 Job 内逐条写 meta 与错误原因;后续可再升级为分片 Job + 结果聚合。
$orderIds = $orders->pluck('id')->map(fn ($id) => (int) $id)->values()->all();
// 幂等/防抖(最小实现):避免运营短时间内重复点击导致重复投递同一批次。
// 说明:这里做“短 TTL 的一次性锁”,不引入新表;后续可演进为批次表 + 幂等 key。
// key 口径scope + filters + ids + limit同一集合的重复点击会被拦截
$lockKey = 'admin:bas:dispatch:' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit);
if (! Cache::add($lockKey, '1', 60)) {
return redirect()->back()->with('warning', '检测到刚刚已提交过同一批次的 BAS 任务1 分钟内)。为避免重复投递,本次未再次提交。');
}
\App\Jobs\BatchActivateSubscriptionsJob::dispatch(
$orderIds,
(int) $admin->id,