优化ai小班长

This commit is contained in:
2026-04-12 22:25:18 +08:00
parent f8d5a3b250
commit ef407a8c6e
7 changed files with 608 additions and 91 deletions
+10 -1
View File
@@ -18,6 +18,7 @@ use App\Events\MessageSent;
use App\Jobs\SaveMessageJob;
use App\Models\Sysparam;
use App\Services\AiChatService;
use App\Services\AiFinanceService;
use App\Services\ChatStateService;
use App\Services\UserCurrencyService;
use Illuminate\Http\JsonResponse;
@@ -25,6 +26,9 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redis;
/**
* 处理用户与 AI小班长的对话、金币福利与上下文清理。
*/
class ChatBotController extends Controller
{
/**
@@ -34,6 +38,7 @@ class ChatBotController extends Controller
private readonly AiChatService $aiChat,
private readonly ChatStateService $chatState,
private readonly UserCurrencyService $currencyService,
private readonly AiFinanceService $aiFinance,
) {}
/**
@@ -90,7 +95,8 @@ class ChatBotController extends Controller
if ($dailyCount < $maxDailyRewards) {
$goldAmount = rand(100, $maxGold);
if ($aiUser && $aiUser->jjb >= $goldAmount) {
// 常规发福利只检查 AI 当前手上金币,不再为了维持 100 万而自动从银行提钱。
if ($aiUser && $this->aiFinance->prepareSpend($aiUser, $goldAmount)) {
Redis::incr($redisKey);
Redis::expire($redisKey, 86400); // 缓存 24 小时
@@ -129,6 +135,9 @@ class ChatBotController extends Controller
$this->chatState->pushMessage($roomId, $sysMsg);
broadcast(new MessageSent($roomId, $sysMsg));
SaveMessageJob::dispatch($sysMsg);
// 福利发放完成后,若手上金币仍高于 100 万,则把超出的部分回存银行。
$this->aiFinance->bankExcessGold($aiUser);
} else {
// 如果余额不足
$reply .= "\n\n(哎呀,我这个月的工资花光啦,没钱发金币了,大家多赏点吧~)";