From 442ca0e1e2237f3cba78596e08cf303e5d0a105f Mon Sep 17 00:00:00 2001 From: lkddi Date: Mon, 27 Apr 2026 13:22:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ai=E5=B0=8F=E7=8F=AD=E9=95=BF?= =?UTF-8?q?=20=E6=A0=B9=E6=8D=AE=E8=81=8A=E5=A4=A9=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=A1=AE=E5=AE=9A=E6=80=BB=E9=80=81=E9=87=91=E5=B8=81=E6=95=B0?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ChatBotController.php | 11 +++++++---- app/Services/AiChatService.php | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ChatBotController.php b/app/Http/Controllers/ChatBotController.php index 3e7d9c5..fd979ec 100644 --- a/app/Http/Controllers/ChatBotController.php +++ b/app/Http/Controllers/ChatBotController.php @@ -85,19 +85,22 @@ class ChatBotController extends Controller $reply = $result['reply']; - // 检查 AI 是否决定给用户发金币 - if (str_contains($reply, '[ACTION:GIVE_GOLD]')) { - $reply = str_replace('[ACTION:GIVE_GOLD]', '', $reply); + // 检查 AI 是否决定给用户发金币(新格式:[ACTION:GIVE_GOLD:金额]) + if (preg_match('/\[ACTION:GIVE_GOLD:(\d+)\]/', $reply, $matches)) { + $aiGoldAmount = (int) $matches[1]; + $reply = preg_replace('/\[ACTION:GIVE_GOLD:\d+\]/', '', $reply); $reply = trim($reply); $maxDailyRewards = (int) Sysparam::getValue('chatbot_max_daily_rewards', '1'); $maxGold = (int) Sysparam::getValue('chatbot_max_gold', '5000'); + // 校验 AI 给出的金额在合理范围内 + $goldAmount = max(100, min($aiGoldAmount, $maxGold)); + $redisKey = 'ai_chat:give_gold:'.date('Ymd').':'.$user->id; $dailyCount = (int) Redis::get($redisKey); if ($dailyCount < $maxDailyRewards) { - $goldAmount = rand(100, $maxGold); // 常规发福利只检查 AI 当前手上金币,不再为了维持 100 万而自动从银行提钱。 if ($aiUser && $this->aiFinance->prepareSpend($aiUser, $goldAmount)) { diff --git a/app/Services/AiChatService.php b/app/Services/AiChatService.php index 6b4e1c1..a61fcf5 100644 --- a/app/Services/AiChatService.php +++ b/app/Services/AiChatService.php @@ -88,6 +88,9 @@ class AiChatService // 动态获取由 guide 页面提取出的最新纯文本规则 $guideRulesText = $this->getDynamicGuideRules(); + // 动态获取金币福利上限,告知 AI 自行决定金额 + $maxGold = (int) \App\Models\Sysparam::getValue('chatbot_max_gold', '5000'); + return <<