From e1d5cee52e8699bdc7e3d1be39c0ada4cf55d858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 17 Mar 2026 18:04:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(bas):=20dispatch=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E7=94=9F=E6=88=90run=5Fid=E5=B9=B6=E9=80=8F=E4=BC=A0=E5=88=B0j?= =?UTF-8?q?ob=E4=BE=BF=E4=BA=8E=E5=A4=8D=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/PlatformOrderController.php | 7 ++++++- app/Jobs/BatchActivateSubscriptionsJob.php | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 63a0a49..38cd771 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -1620,6 +1620,10 @@ class PlatformOrderController extends Controller return redirect()->back()->with('warning', '检测到刚刚已提交过同一批次的 BAS 任务(1 分钟内)。为避免重复投递,本次未再次提交。'); } + // run_id:用于把一次批量执行关联起来,便于后续追溯/筛选/可观测。 + // 说明:run_id 在投递阶段就生成,这样运营在页面成功提示里即可复制 run_id 并进入批次复盘页。 + $runId = 'BAS' . now()->format('YmdHis') . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT); + \App\Jobs\BatchActivateSubscriptionsJob::dispatch( $orderIds, (int) $admin->id, @@ -1628,9 +1632,10 @@ class PlatformOrderController extends Controller (int) $limit, (int) $matchedTotal, (int) $processed, + (string) $runId, ); - return redirect()->back()->with('success', '批量同步订阅任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ')。'); + return redirect()->back()->with('success', '批量同步订阅任务已提交到队列:命中 ' . $matchedTotal . ' 条,本次处理 ' . $processed . ' 条(limit=' . $limit . ',run_id=' . $runId . ')。'); } public function batchMarkPaidAndActivate(Request $request, SubscriptionActivationService $service): RedirectResponse diff --git a/app/Jobs/BatchActivateSubscriptionsJob.php b/app/Jobs/BatchActivateSubscriptionsJob.php index 8b995b2..3e314bd 100644 --- a/app/Jobs/BatchActivateSubscriptionsJob.php +++ b/app/Jobs/BatchActivateSubscriptionsJob.php @@ -29,6 +29,8 @@ class BatchActivateSubscriptionsJob implements ShouldQueue public int $processed; + public string $runId; + /** * @param int[] $orderIds */ @@ -40,6 +42,7 @@ class BatchActivateSubscriptionsJob implements ShouldQueue int $limit, int $matchedTotal, int $processed, + string $runId = '', ) { $this->orderIds = array_values(array_map('intval', $orderIds)); $this->adminId = $adminId; @@ -48,12 +51,17 @@ class BatchActivateSubscriptionsJob implements ShouldQueue $this->limit = $limit; $this->matchedTotal = $matchedTotal; $this->processed = $processed; + + // 说明:优先使用投递时生成的 run_id(便于控制台立即可见/可复制);若未提供则在 job 内兜底生成。 + $this->runId = trim($runId) !== '' + ? (string) $runId + : ('BAS' . now()->format('YmdHis') . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT)); } public function handle(SubscriptionActivationService $service): void { // 批次号:用于把一次队列批量执行关联起来,便于后续追溯/筛选/可观测。 - $runId = 'BAS' . now()->format('YmdHis') . str_pad((string) random_int(1, 9999), 4, '0', STR_PAD_LEFT); + $runId = (string) $this->runId; $success = 0; $failed = 0;