feat(bmpa): dedupe dispatch within 1 minute to avoid double submit
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\SiteSubscription;
|
||||
use App\Support\BackUrl;
|
||||
use App\Support\SubscriptionActivationService;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -1717,6 +1718,14 @@ class PlatformOrderController extends Controller
|
||||
// 队列化(M3 可运维化第二步):把批量 BMPA 投递为一个 Job,避免请求超时,并对齐 BAS 的批次可观测模式。
|
||||
$orderIds = $orders->pluck('id')->map(fn ($id) => (int) $id)->values()->all();
|
||||
|
||||
// 幂等/防抖(最小实现):避免运营短时间内重复点击导致重复投递同一批次。
|
||||
// 说明:这里做“短 TTL 的一次性锁”,不引入新表;后续可演进为批次表 + 幂等 key。
|
||||
// key 口径:scope + filters + ids + limit(同一集合的重复点击会被拦截)。
|
||||
$lockKey = 'admin:bmpa:dispatch:' . md5($scope . '|' . $filterSummary . '|' . implode(',', $orderIds) . '|' . $limit);
|
||||
if (! Cache::add($lockKey, $runId, 60)) {
|
||||
return redirect()->back()->with('warning', '检测到刚刚已提交过同一批次的 BMPA 任务(1 分钟内)。为避免重复投递,本次未再次提交。');
|
||||
}
|
||||
|
||||
\App\Jobs\BatchMarkPaidAndActivateJob::dispatch(
|
||||
$orderIds,
|
||||
(int) $admin->id,
|
||||
|
||||
Reference in New Issue
Block a user