diff --git a/app/Jobs/AiBaccaratBetJob.php b/app/Jobs/AiBaccaratBetJob.php
index 2cc308a..33441a6 100644
--- a/app/Jobs/AiBaccaratBetJob.php
+++ b/app/Jobs/AiBaccaratBetJob.php
@@ -50,33 +50,39 @@ class AiBaccaratBetJob implements ShouldQueue
return;
}
- $round = $this->round->fresh();
- if (! $round || ! $round->isBettingOpen()) {
- return;
- }
-
$user = User::where('username', 'AI小班长')->first();
if (! $user) {
return;
}
- // 2. 检查连输惩罚超时
+ $chatState = app(ChatStateService::class);
+
+ // 2. 资金管理:自动存款与领取补偿
+ $this->manageFinances($user, $chatState);
+
+ $round = $this->round->fresh();
+ if (! $round || ! $round->isBettingOpen()) {
+ return;
+ }
+
+ // 3. 检查连输惩罚超时
if (Redis::exists('ai_baccarat_timeout')) {
return; // 还在禁赛期
}
- // 3. 检查余额与限额
+ // 4. 检查余额与限额
$config = GameConfig::forGame('baccarat')?->params ?? [];
$minBet = (int) ($config['min_bet'] ?? 100);
$maxBet = (int) ($config['max_bet'] ?? 50000);
- // 至少保留 2000 金币底仓
- $availableGold = ($user->jjb ?? 0) - 2000;
+ // 至少保留 5000 金币底仓(随着目标提升,底仓也适当调高)
+ $reserve = ($user->bank_jjb >= 10000000) ? 20000 : 5000;
+ $availableGold = ($user->jjb ?? 0) - $reserve;
if ($availableGold < $minBet) {
return; // 资金不足以支撑最小下注
}
- // 4. 获取近期路单和 AI 历史下注
+ // 5. 获取近期路单和 AI 历史下注
$recentResults = BaccaratRound::query()
->where('status', 'settled')
->orderByDesc('id')
@@ -282,14 +288,11 @@ class AiBaccaratBetJob implements ShouldQueue
string $decisionSource,
): void {
$chatState = app(ChatStateService::class);
-
$labelMap = ['big' => '大', 'small' => '小', 'triple' => '豹子'];
- $betLabel = $labelMap[$betType] ?? $betType;
- $sourceTag = $decisionSource === 'ai' ? '🤖 AI分析' : '📊路单统计';
- $formattedAmount = number_format($amount);
+ $label = $labelMap[$betType] ?? $betType;
- // 格式:🌟 🎲 【百家乐】 娜姐 押注了 119 金币(大)!✨ [🤖 AI分析]
- $content = "🌟 🎲 【百家乐】 {$user->username} 押注了 {$formattedAmount} 金币({$betLabel})!✨ [{$sourceTag}]";
+ $sourceText = $decisionSource === 'ai' ? '🤖 经过深度算法预测,本局我看好:' : '📊 观察了下最近的路单,这把我觉得是:';
+ $content = "🌟 🎲 【百家乐】 {$user->username} 已下注:{$label} (".number_format($amount)." 金币)
{$sourceText} {$label}!";
$msg = [
'id' => $chatState->nextMessageId($roomId),
@@ -298,13 +301,91 @@ class AiBaccaratBetJob implements ShouldQueue
'to_user' => '大家',
'content' => $content,
'is_secret' => false,
- 'font_color' => '#d97706',
- 'action' => '',
+ 'font_color' => '#8b5cf6',
+ 'action' => '动态播报',
'sent_at' => now()->toDateTimeString(),
];
-
$chatState->pushMessage($roomId, $msg);
broadcast(new MessageSent($roomId, $msg));
SaveMessageJob::dispatch($msg);
}
+
+ /**
+ * AI 资金管理逻辑:自动存款、领取买单补偿
+ */
+ private function manageFinances(User $user, ChatStateService $chatState): void
+ {
+ // 1. 检查是否有“买单”活动补偿可领取 (jjb 较低时优先领取)
+ if ($user->jjb < 20000) {
+ $lossCoverService = app(\App\Services\BaccaratLossCoverService::class);
+ $pendingEvents = \App\Models\BaccaratLossCoverEvent::where('status', 'claimable')->get();
+ foreach ($pendingEvents as $event) {
+ $record = \App\Models\BaccaratLossCoverRecord::where('event_id', $event->id)
+ ->where('user_id', $user->id)
+ ->where('claim_status', 'pending')
+ ->first();
+
+ if ($record && $record->compensation_amount > 0) {
+ $lossCoverService->claim($event, $user);
+ Log::channel('daily')->info("AI小班长自动领取活动补偿: Event #{$event->id}, Amount: {$record->compensation_amount}");
+ }
+ }
+ }
+
+ // 2. 自动存款逻辑:长期目标 1000万 / 3000万
+ $bankTarget1 = 10000000;
+ $bankTarget2 = 30000000;
+ $currentBank = (int) $user->bank_jjb;
+
+ // 如果手上金币超过 10万,且存款未达 3000万,则进行存款
+ if ($user->jjb > 100000 && $currentBank < $bankTarget2) {
+ $depositAmount = $user->jjb - 50000; // 留 5万在手上作为本金
+
+ // 如果存款快到目标了,按需存入
+ if ($currentBank < $bankTarget1 && ($currentBank + $depositAmount) > $bankTarget1) {
+ $depositAmount = $bankTarget1 - $currentBank;
+ }
+
+ DB::transaction(function () use ($user, $depositAmount, $currentBank, $bankTarget1, $bankTarget2, $chatState) {
+ $user->decrement('jjb', $depositAmount);
+ $user->increment('bank_jjb', $depositAmount);
+ $newBank = $user->bank_jjb;
+
+ \App\Models\BankLog::create([
+ 'user_id' => $user->id,
+ 'type' => 'deposit',
+ 'amount' => $depositAmount,
+ 'balance_after' => $newBank,
+ ]);
+
+ // 达成阶段性目标时大声宣布
+ $milestone = 0;
+ if ($currentBank < $bankTarget1 && $newBank >= $bankTarget1) {
+ $milestone = 1000; // 1000万
+ } elseif ($currentBank < $bankTarget2 && $newBank >= $bankTarget2) {
+ $milestone = 3000; // 3000万
+ }
+
+ if ($milestone > 0) {
+ $content = "🏆 🎉 【全站公告】 恭喜 AI小班长 达成理财新高度!
他在银行的存款已成功突破 {$milestone}万 金币!💰✨";
+ $msg = [
+ 'id' => $chatState->nextMessageId(1),
+ 'room_id' => 1,
+ 'from_user' => '系统传音',
+ 'to_user' => '大家',
+ 'content' => $content,
+ 'is_secret' => false,
+ 'font_color' => '#f59e0b',
+ 'action' => '大声宣告',
+ 'sent_at' => now()->toDateTimeString(),
+ ];
+ $chatState->pushMessage(1, $msg);
+ broadcast(new MessageSent(1, $msg));
+ SaveMessageJob::dispatch($msg);
+ }
+ });
+
+ Log::channel('daily')->info("AI小班长自动存款: Amount: {$depositAmount}, New Bank Balance: {$user->bank_jjb}");
+ }
+ }
}
diff --git a/app/Models/User.php b/app/Models/User.php
index 2165bd2..156040f 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -61,6 +61,10 @@ class User extends Authenticatable
'question',
'answer',
'has_received_new_gift',
+ 'jjb',
+ 'bank_jjb',
+ 'meili',
+ 'exp_num',
'in_time', // 进房时间(用于勤务日志 login_at 基准)
'out_time', // 离房时间
];