feat(百家乐): AI小班长改用AI接口预测路单走势下注

- 新增 BaccaratPredictionService,调用 AI 厂商(OpenAI 兼容协议)
  根据近期 20 局路单给出预测(大/小/豹子)
- AiBaccaratBetJob 优先使用 AI 预测结果;
  AI 不可用(超时/无配置)时自动回退本地路单统计决策
- 复用 AiProviderConfig 多厂商配置与故障转移逻辑
- AI 调用结果写入 ai_usage_logs(action=baccarat_predict)
This commit is contained in:
2026-03-28 20:35:43 +08:00
parent e515a1429c
commit 887fc5c7ef
2 changed files with 245 additions and 18 deletions
+23 -18
View File
@@ -6,7 +6,7 @@
* 在每局百家乐开启时延迟调度执行:
* 1. 检查是否存在连输休息惩罚(1小时)
* 2. 检查可用金币,确保留存底金
* 3. 获取近期路单进行简单决策
* 3. 调用 AI 接口预测路单走势决定下注方向(AI 不可用时回退本地决策
* 4. 提交下注
*
* @author ChatRoom Laravel
@@ -22,6 +22,7 @@ use App\Models\BaccaratRound;
use App\Models\GameConfig;
use App\Models\Sysparam;
use App\Models\User;
use App\Services\BaccaratPredictionService;
use App\Services\UserCurrencyService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -82,30 +83,34 @@ class AiBaccaratBetJob implements ShouldQueue
return;
}
// 4. 决策逻辑:简单分析近期路单
// 取最近 10 局
// 4. 获取近期路单(最多取 20 局)
$recentResults = BaccaratRound::query()
->where('status', 'settled')
->orderByDesc('id')
->limit(10)
->limit(20)
->pluck('result')
->toArray();
$bigCount = count(array_filter($recentResults, fn ($r) => $r === 'big'));
$smallCount = count(array_filter($recentResults, fn ($r) => $r === 'small'));
// 5. 优先调用 AI 接口预测下注方向
$predictionService = app(BaccaratPredictionService::class);
$betType = $predictionService->predict($recentResults);
// 基础策略:追逐热点 (跟大部队) 或 均值回归 (逆势)
// 这里做一个简单的随机倾向:
$strategy = rand(1, 100);
if ($strategy <= 10) {
$betType = 'triple'; // 10% 概率博豹子
} elseif ($bigCount > $smallCount) {
// 大偏热,70%概率顺势买大,30%逆势买小
$betType = rand(1, 100) <= 70 ? 'big' : 'small';
} elseif ($smallCount > $bigCount) {
$betType = rand(1, 100) <= 70 ? 'small' : 'big';
} else {
$betType = rand(0, 1) ? 'big' : 'small';
// AI 不可用时回退本地路单决策(保底逻辑)
if ($betType === null) {
$bigCount = count(array_filter($recentResults, fn (string $r) => $r === 'big'));
$smallCount = count(array_filter($recentResults, fn (string $r) => $r === 'small'));
$strategy = rand(1, 100);
if ($strategy <= 10) {
$betType = 'triple'; // 10% 概率博豹子
} elseif ($bigCount > $smallCount) {
// 大偏热:70% 概率顺势买大,30% 逆势买小
$betType = rand(1, 100) <= 70 ? 'big' : 'small';
} elseif ($smallCount > $bigCount) {
$betType = rand(1, 100) <= 70 ? 'small' : 'big';
} else {
$betType = rand(0, 1) ? 'big' : 'small';
}
}
// 5. 执行下注 (同 BaccaratController::bet 逻辑)