优化:百家乐结算公告新增各用户输赢明细

- 结算时同步收集 winners(中奖用户+金额)和 losers(未中用户-金额)
- 公屏广播消息末尾附加:
  🏆 中奖:甲+2,000、乙+1,000 🪙
  😔 未中:丙-500、丁-1,000
- 单方向最多显示 10 人,防止消息过长
- 顺手修正豹子结果文本中 dice1 重复的 bug(dice2、dice3 显示错误)
This commit is contained in:
2026-03-04 14:41:07 +08:00
parent 16cbb32f35
commit 1c53acbd1b

View File

@@ -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<string> $winners 中奖用户列表,格式 "用户名+金额"
* @param array<string> $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),