From 592b1610f9ea7a0c576f52b6099d950289912adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 15:30:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=89=B9=E9=87=8F=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8A=95=E9=80=92=E5=8E=BB=E9=87=8D=E9=94=81=E6=8F=90?= =?UTF-8?q?=E7=82=BCBatchDispatchLock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 22 ++++++++++--- app/Support/BatchDispatchLock.php | 31 +++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 app/Support/BatchDispatchLock.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 186dd15..63a0a49 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1608,8 +1608,15 @@ class PlatformOrderController extends Controller // 幂等/防抖(最小实现):避免运营短时间内重复点击导致重复投递同一批次。 // 说明:这里做“短 TTL 的一次性锁”,不引入新表;后续可演进为批次表 + 幂等 key。 // key 口径:scope + filters + ids + limit(同一集合的重复点击会被拦截)。 - $lockKey = 'admin:bas:dispatch:' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit); - if (! Cache::add($lockKey, '1', 60)) { + if (! \App\Support\BatchDispatchLock::acquire( + 'admin:bas:dispatch', + $scope, + (string) $filterSummary, + $orderIds, + (int) $limit, + 60, + '1', + )) { return redirect()->back()->with('warning', '检测到刚刚已提交过同一批次的 BAS 任务(1 分钟内)。为避免重复投递,本次未再次提交。'); } @@ -1729,8 +1736,15 @@ class PlatformOrderController extends Controller // 幂等/防抖(最小实现):避免运营短时间内重复点击导致重复投递同一批次。 // 说明:这里做“短 TTL 的一次性锁”,不引入新表;后续可演进为批次表 + 幂等 key。 // key 口径:scope + filters + ids + limit(同一集合的重复点击会被拦截)。 - $lockKey = 'admin:bmpa:dispatch:' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit); - if (! Cache::add($lockKey, $runId, 60)) { + if (! \App\Support\BatchDispatchLock::acquire( + 'admin:bmpa:dispatch', + $scope, + (string) $filterSummary, + $orderIds, + (int) $limit, + 60, + (string) $runId, + )) { return redirect()->back()->with('warning', '检测到刚刚已提交过同一批次的 BMPA 任务(1 分钟内)。为避免重复投递,本次未再次提交。'); } diff --git a/app/Support/BatchDispatchLock.php b/app/Support/BatchDispatchLock.php new file mode 100644 index 0000000..14f8c90 --- /dev/null +++ b/app/Support/BatchDispatchLock.php @@ -0,0 +1,31 @@ +