From 596c7f357f0ea8e74a35cb6c1bc545da4c9288c0 Mon Sep 17 00:00:00 2001 From: lkddi Date: Mon, 13 Apr 2026 17:55:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E4=BD=A0=E7=8E=A9?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=88=91=E4=B9=B0=E5=8D=95=20=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaccaratLossCoverController.php | 33 +++++++++++++++++-- .../games/baccarat-loss-cover-panel.blade.php | 2 +- .../BaccaratLossCoverControllerTest.php | 23 +++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/BaccaratLossCoverController.php b/app/Http/Controllers/BaccaratLossCoverController.php index 5fe2722..2821b8e 100644 --- a/app/Http/Controllers/BaccaratLossCoverController.php +++ b/app/Http/Controllers/BaccaratLossCoverController.php @@ -30,8 +30,8 @@ class BaccaratLossCoverController extends Controller { $event = BaccaratLossCoverEvent::query() ->with(['creator:id,username']) - ->whereIn('status', ['active', 'settlement_pending', 'claimable', 'scheduled']) - ->orderByRaw("CASE status WHEN 'active' THEN 0 WHEN 'settlement_pending' THEN 1 WHEN 'claimable' THEN 2 WHEN 'scheduled' THEN 3 ELSE 4 END") + ->whereIn('status', $this->summaryStatuses($request)) + ->orderByRaw($this->summaryStatusOrder($request)) ->orderByDesc('starts_at') ->first(); @@ -109,4 +109,33 @@ class BaccaratLossCoverController extends Controller ] : null, ]; } + + /** + * 按调用场景返回活动摘要允许出现的状态集合。 + * + * “当前活动”页签只展示未开始、进行中或结算中的活动, + * 避免把已结束但仍可领取的历史活动误显示在当前页签里。 + * + * @return list + */ + private function summaryStatuses(Request $request): array + { + if ($request->string('scene')->toString() === 'overview') { + return ['active', 'settlement_pending', 'scheduled']; + } + + return ['active', 'settlement_pending', 'claimable', 'scheduled']; + } + + /** + * 按调用场景生成活动状态排序规则。 + */ + private function summaryStatusOrder(Request $request): string + { + if ($request->string('scene')->toString() === 'overview') { + return "CASE status WHEN 'active' THEN 0 WHEN 'settlement_pending' THEN 1 WHEN 'scheduled' THEN 2 ELSE 3 END"; + } + + return "CASE status WHEN 'active' THEN 0 WHEN 'settlement_pending' THEN 1 WHEN 'claimable' THEN 2 WHEN 'scheduled' THEN 3 ELSE 4 END"; + } } diff --git a/resources/views/chat/partials/games/baccarat-loss-cover-panel.blade.php b/resources/views/chat/partials/games/baccarat-loss-cover-panel.blade.php index 17ae178..6500344 100644 --- a/resources/views/chat/partials/games/baccarat-loss-cover-panel.blade.php +++ b/resources/views/chat/partials/games/baccarat-loss-cover-panel.blade.php @@ -196,7 +196,7 @@ current.innerHTML = '加载中…'; try { - const response = await fetch(SUMMARY_URL, { + const response = await fetch(`${SUMMARY_URL}?scene=overview`, { headers: { 'Accept': 'application/json' } diff --git a/tests/Feature/BaccaratLossCoverControllerTest.php b/tests/Feature/BaccaratLossCoverControllerTest.php index d563645..982965f 100644 --- a/tests/Feature/BaccaratLossCoverControllerTest.php +++ b/tests/Feature/BaccaratLossCoverControllerTest.php @@ -214,6 +214,29 @@ class BaccaratLossCoverControllerTest extends TestCase $response->assertJsonPath('events.0.my_record.claimed_amount', 400); } + /** + * 验证“当前活动”页签摘要不会把可领取中的历史活动当成当前活动。 + */ + public function test_overview_summary_ignores_claimable_history_event(): void + { + $user = User::factory()->create(); + $event = BaccaratLossCoverEvent::factory()->create([ + 'status' => 'claimable', + 'starts_at' => now()->subHour(), + 'ends_at' => now()->subMinutes(20), + 'claim_deadline_at' => now()->addHours(12), + ]); + + $defaultResponse = $this->actingAs($user)->getJson(route('baccarat-loss-cover.summary')); + $defaultResponse->assertOk(); + $defaultResponse->assertJsonPath('event.id', $event->id); + $defaultResponse->assertJsonPath('event.status', 'claimable'); + + $overviewResponse = $this->actingAs($user)->getJson(route('baccarat-loss-cover.summary', ['scene' => 'overview'])); + $overviewResponse->assertOk(); + $overviewResponse->assertJsonPath('event', null); + } + /** * 验证活动进入可领取状态后会为 AI 小班长派发自动领取任务。 */