42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\SettingsService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class SystemSettingsController extends Controller
|
|
{
|
|
public function index(SettingsService $settings)
|
|
{
|
|
return view('admin.system.settings', [
|
|
'form' => $settings->effectiveForForm(),
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, SettingsService $settings)
|
|
{
|
|
$data = $request->validate([
|
|
'telegram_bot_token' => ['nullable', 'string', 'max:255'],
|
|
'telegram_owner_chat_id' => ['nullable', 'string', 'max:64'],
|
|
'channels_max_per_agent' => ['nullable', 'integer', 'min:1', 'max:100'],
|
|
'channels_domains' => ['nullable', 'string', 'max:4000'],
|
|
]);
|
|
|
|
$domains = SettingsService::parseDomains($data['channels_domains'] ?? null);
|
|
|
|
$settings->putMany([
|
|
'telegram.bot_token' => $data['telegram_bot_token'] ?? null,
|
|
'telegram.owner_chat_id' => $data['telegram_owner_chat_id'] ?? null,
|
|
'channels.max_per_agent' => isset($data['channels_max_per_agent'])
|
|
? (string) $data['channels_max_per_agent']
|
|
: null,
|
|
// Persist normalized comma-separated list (empty clears override to []).
|
|
'channels.domains' => $domains === [] ? '' : implode(',', $domains),
|
|
]);
|
|
|
|
return response()->json(['code' => 0, 'msg' => '已保存']);
|
|
}
|
|
}
|