优化 你玩游戏我买单 页面

This commit is contained in:
2026-04-13 17:55:00 +08:00
parent 2eb732642b
commit 596c7f357f
3 changed files with 55 additions and 3 deletions
@@ -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<string>
*/
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";
}
}
@@ -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'
}
@@ -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 小班长派发自动领取任务。
*/