diff --git a/app/Jobs/AiBaccaratBetJob.php b/app/Jobs/AiBaccaratBetJob.php index f2a53e8..896a805 100644 --- a/app/Jobs/AiBaccaratBetJob.php +++ b/app/Jobs/AiBaccaratBetJob.php @@ -17,12 +17,14 @@ namespace App\Jobs; use App\Enums\CurrencySource; +use App\Events\MessageSent; use App\Models\BaccaratBet; use App\Models\BaccaratRound; use App\Models\GameConfig; use App\Models\Sysparam; use App\Models\User; use App\Services\BaccaratPredictionService; +use App\Services\ChatStateService; use App\Services\UserCurrencyService; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -171,5 +173,51 @@ class AiBaccaratBetJob implements ShouldQueue // 广播各选项的最新押注人数(让前台看到 AI 下注的人数增长) event(new \App\Events\BaccaratPoolUpdated($round)); }); + + // 下注成功后,在聊天室发送一条普通聊天消息告知大家 + $this->broadcastBetMessage($user, $round->room_id ?? 1, $betType, $amount, $decisionSource); + } + + /** + * 广播 AI小班长本次下注情况到聊天室 + * + * 以普通聊天消息形式发送,发送对象为大家。 + * + * @param User $user AI小班长用户对象 + * @param int $roomId 目标房间 ID + * @param string $betType 下注方向:big|small|triple + * @param int $amount 下注金额 + * @param string $decisionSource 决策来源:ai | local + */ + private function broadcastBetMessage( + User $user, + int $roomId, + string $betType, + int $amount, + string $decisionSource, + ): void { + $chatState = app(ChatStateService::class); + + $labelMap = ['big' => '大【骰子点数 11~17】', 'small' => '小【骰子点数 4~10】', 'triple' => '豹子【三骰同点】']; + $betLabel = $labelMap[$betType] ?? $betType; + $sourceTag = $decisionSource === 'ai' ? '🤖 AI分析' : '📊路单统计'; + + $content = "{$sourceTag} 小班长投了 {$amount} 金币,压【{$betLabel}】,大家加油!🎲"; + + $msg = [ + 'id' => $chatState->nextMessageId($roomId), + 'room_id' => $roomId, + 'from_user' => $user->username, + 'to_user' => '大家', + 'content' => $content, + 'is_secret' => false, + 'font_color' => null, + 'action' => '说', + 'sent_at' => now()->toDateTimeString(), + ]; + + $chatState->pushMessage($roomId, $msg); + broadcast(new MessageSent($roomId, $msg)); + SaveMessageJob::dispatch($msg); } }