diff --git a/app/Jobs/CloseBaccaratRoundJob.php b/app/Jobs/CloseBaccaratRoundJob.php index bbb52b0..7ef0266 100644 --- a/app/Jobs/CloseBaccaratRoundJob.php +++ b/app/Jobs/CloseBaccaratRoundJob.php @@ -90,11 +90,18 @@ class CloseBaccaratRoundJob implements ShouldQueue $bets = BaccaratBet::query()->where('round_id', $round->id)->where('status', 'pending')->with('user')->get(); $totalPayout = 0; - DB::transaction(function () use ($bets, $result, $config, $currency, &$totalPayout) { + // 收集各用户输赢结果,用于公屏展示 + $winners = []; + $losers = []; + + DB::transaction(function () use ($bets, $result, $config, $currency, &$totalPayout, &$winners, &$losers) { foreach ($bets as $bet) { + $username = $bet->user->username ?? '匿名'; + if ($result === 'kill') { // 庄家收割:全灭无退款 $bet->update(['status' => 'lost', 'payout' => 0]); + $losers[] = "{$username}-{$bet->amount}"; continue; } @@ -113,8 +120,10 @@ class CloseBaccaratRoundJob implements ShouldQueue "百家乐 #{$this->round->id} 押 {$bet->betTypeLabel()} 中奖", ); $totalPayout += $payout; + $winners[] = "{$username}+".number_format($payout); } else { $bet->update(['status' => 'lost', 'payout' => 0]); + $losers[] = "{$username}-".number_format($bet->amount); } } }); @@ -137,20 +146,23 @@ class CloseBaccaratRoundJob implements ShouldQueue broadcast(new BaccaratRoundSettled($round)); // ── 公屏公告 ───────────────────────────────────────────────── - $this->pushResultMessage($round, $chatState); + $this->pushResultMessage($round, $chatState, $winners, $losers); } /** - * 向公屏发送开奖结果系统消息。 + * 向公屏发送开奖结果系统消息(含各用户输赢情况)。 + * + * @param array $winners 中奖用户列表,格式 "用户名+金额" + * @param array $losers 未中奖用户列表,格式 "用户名-金额" */ - private function pushResultMessage(BaccaratRound $round, ChatStateService $chatState): void + private function pushResultMessage(BaccaratRound $round, ChatStateService $chatState, array $winners = [], array $losers = []): void { $diceStr = "【{$round->dice1}】【{$round->dice2}】【{$round->dice3}】"; $resultText = match ($round->result) { 'big' => "🔵 大({$round->total_points} 点)", 'small' => "🟡 小({$round->total_points} 点)", - 'triple' => "💥 豹子!({$round->dice1}{$round->dice1}{$round->dice1})", + 'triple' => "💥 豹子!({$round->dice1}{$round->dice2}{$round->dice3})", 'kill' => "☠️ 庄家收割!({$round->total_points} 点)全灭", default => '', }; @@ -159,7 +171,18 @@ class CloseBaccaratRoundJob implements ShouldQueue ? '共派发 🪙'.number_format($round->total_payout).' 金币' : '本局无人获奖'; - $content = "🎲 【百家乐】第 #{$round->id} 局开奖!{$diceStr} 总点 {$round->total_points} → {$resultText}!{$payoutText}。"; + // 拼接用户输赢明细(最多显示 10 人,防止消息过长) + $detailParts = []; + if ($winners) { + $detailParts[] = '🏆 中奖:'.implode('、', array_slice($winners, 0, 10)).' 🪙'; + } + if ($losers) { + $detailParts[] = '😔 未中:'.implode('、', array_slice($losers, 0, 10)); + } + + $detail = $detailParts ? ' '.implode(' ', $detailParts) : ''; + + $content = "🎲 【百家乐】第 #{$round->id} 局开奖!{$diceStr} 总点 {$round->total_points} → {$resultText}!{$payoutText}。{$detail}"; $msg = [ 'id' => $chatState->nextMessageId(1),