feat(百家乐): AI小班长下注后在聊天室发送普通聊天消息

- 下注成功后调用 broadcastBetMessage() 向聊天室广播
- 消息格式:「🤖 AI分析 小班长投了 N 金币,压【大/小/豹子】,大家加油!🎲」
- 发送者 AI小班长,发送对象 大家,action=说(普通聊天)
- AI 预测时显示「🤖 AI分析」标签,本地兜底时显示「📊路单统计」
This commit is contained in:
2026-03-28 21:38:34 +08:00
parent aa760b14a2
commit 7bb7f1f4fd

View File

@@ -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);
}
}