fix(百家乐AI预测): ai_usage_logs 使用 AI小班长真实 user_id
- 新增 resolveAiUserId() 按 username 查询 AI小班长 ID(惰性/缓存) - 原先硬编码 null,改为正确关联到 AI小班长用户记录
This commit is contained in:
@@ -37,6 +37,11 @@ class BaccaratPredictionService
|
|||||||
*/
|
*/
|
||||||
private const PREFERRED_MODEL = 'glm-5.1-free';
|
private const PREFERRED_MODEL = 'glm-5.1-free';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI小班长的用户 ID(惰性加载,首次使用时查询一次)
|
||||||
|
*/
|
||||||
|
private ?int $aiUserId = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用 AI 接口预测百家乐下注方向
|
* 调用 AI 接口预测百家乐下注方向
|
||||||
*
|
*
|
||||||
@@ -248,7 +253,7 @@ PROMPT;
|
|||||||
): void {
|
): void {
|
||||||
try {
|
try {
|
||||||
AiUsageLog::create([
|
AiUsageLog::create([
|
||||||
'user_id' => null, // AI 系统行为,无对应用户
|
'user_id' => $this->resolveAiUserId(),
|
||||||
'provider' => $config->provider,
|
'provider' => $config->provider,
|
||||||
'model' => $config->model,
|
'model' => $config->model,
|
||||||
'action' => 'baccarat_predict',
|
'action' => 'baccarat_predict',
|
||||||
@@ -263,4 +268,19 @@ PROMPT;
|
|||||||
Log::error('百家乐 AI 预测日志记录失败', ['error' => $e->getMessage()]);
|
Log::error('百家乐 AI 预测日志记录失败', ['error' => $e->getMessage()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询 AI小班长的用户 ID
|
||||||
|
*
|
||||||
|
* 加载结果以属性形式缓存,同一个服务实例内只查一次。
|
||||||
|
* 查不到时返回 null,避免破坏外键约束。
|
||||||
|
*/
|
||||||
|
private function resolveAiUserId(): ?int
|
||||||
|
{
|
||||||
|
if ($this->aiUserId === null) {
|
||||||
|
$this->aiUserId = \App\Models\User::where('username', 'AI小班长')->value('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->aiUserId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user