feat: autotransfer
This commit is contained in:
@@ -12,7 +12,7 @@ class SystemSettingsController extends Controller
|
||||
public function index(SettingsService $settings, TelegramNotifier $telegram)
|
||||
{
|
||||
$form = $settings->effectiveForForm();
|
||||
$token = trim((string) ($form['telegram.bot_token'] ?? ''));
|
||||
$token = trim((string) config('coruna.telegram.bot_token', ''));
|
||||
$username = trim((string) ($form['telegram.bot_username'] ?? ''));
|
||||
if ($token !== '' && $username === '') {
|
||||
$fetched = $telegram->fetchBotUsername($token);
|
||||
@@ -33,48 +33,48 @@ class SystemSettingsController extends Controller
|
||||
public function update(Request $request, SettingsService $settings, TelegramNotifier $telegram)
|
||||
{
|
||||
$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'],
|
||||
'panel_admin_hosts' => ['nullable', 'string', 'max:4000'],
|
||||
'panel_agent_hosts' => ['nullable', 'string', 'max:4000'],
|
||||
'auto_transfer_enabled' => ['nullable', 'in:0,1'],
|
||||
'auto_transfer_threshold_usdt' => ['nullable', 'numeric', 'min:0'],
|
||||
'auto_transfer_threshold_trx' => ['nullable', 'numeric', 'min:0'],
|
||||
'auto_transfer_threshold_eth' => ['nullable', 'numeric', 'min:0'],
|
||||
'auto_transfer_threshold_btc' => ['nullable', 'numeric', 'min:0'],
|
||||
'transfer_fee_address_tron' => ['nullable', 'string', 'max:128'],
|
||||
'transfer_fee_private_key_tron' => ['nullable', 'string', 'max:255'],
|
||||
'transfer_fee_topup_trx' => ['nullable', 'numeric', 'min:0.000001'],
|
||||
]);
|
||||
|
||||
$domains = SettingsService::parseDomains($data['channels_domains'] ?? null);
|
||||
$adminHosts = SettingsService::parseDomains($data['panel_admin_hosts'] ?? null);
|
||||
$agentHosts = SettingsService::parseDomains($data['panel_agent_hosts'] ?? null);
|
||||
$threshold = static function (?string $v): ?string {
|
||||
if ($v === null || trim($v) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$token = trim((string) ($data['telegram_bot_token'] ?? ''));
|
||||
$username = '';
|
||||
return trim($v);
|
||||
};
|
||||
|
||||
$username = ltrim((string) config('coruna.telegram.bot_username', ''), '@');
|
||||
$token = trim((string) config('coruna.telegram.bot_token', ''));
|
||||
$note = '';
|
||||
if ($token !== '') {
|
||||
if ($token !== '' && $username === '') {
|
||||
$fetched = $telegram->fetchBotUsername($token);
|
||||
if ($fetched !== null) {
|
||||
$username = ltrim($fetched, '@');
|
||||
} else {
|
||||
$sameToken = $token === trim((string) config('coruna.telegram.bot_token', ''));
|
||||
$previous = ltrim((string) config('coruna.telegram.bot_username', ''), '@');
|
||||
if ($sameToken && $previous !== '') {
|
||||
$username = $previous;
|
||||
} else {
|
||||
$note = ';未能从 Token 读取 Bot 用户名,请确认 Token 有效';
|
||||
}
|
||||
$note = ';未能从 .env Token 读取 Bot 用户名,请确认 TELEGRAM_BOT_TOKEN 有效';
|
||||
}
|
||||
}
|
||||
|
||||
$settings->putMany([
|
||||
'telegram.bot_token' => $token !== '' ? $token : null,
|
||||
'telegram.bot_username' => $username !== '' ? $username : 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),
|
||||
// Empty = no Host restriction for that panel.
|
||||
'panel.admin_hosts' => $adminHosts === [] ? '' : implode(',', $adminHosts),
|
||||
'panel.agent_hosts' => $agentHosts === [] ? '' : implode(',', $agentHosts),
|
||||
'auto_transfer.enabled' => (($data['auto_transfer_enabled'] ?? '0') === '1') ? '1' : '0',
|
||||
'auto_transfer.threshold_usdt' => $threshold($data['auto_transfer_threshold_usdt'] ?? null) ?? '',
|
||||
'auto_transfer.threshold_trx' => $threshold($data['auto_transfer_threshold_trx'] ?? null) ?? '',
|
||||
'auto_transfer.threshold_eth' => $threshold($data['auto_transfer_threshold_eth'] ?? null) ?? '',
|
||||
'auto_transfer.threshold_btc' => $threshold($data['auto_transfer_threshold_btc'] ?? null) ?? '',
|
||||
'transfer.fee_address_tron' => $threshold($data['transfer_fee_address_tron'] ?? null) ?? '',
|
||||
'transfer.fee_private_key_tron' => $threshold($data['transfer_fee_private_key_tron'] ?? null),
|
||||
'transfer.fee_topup_trx' => $threshold($data['transfer_fee_topup_trx'] ?? null) ?? '20',
|
||||
]);
|
||||
|
||||
$display = $telegram->formatBotUsername($username);
|
||||
@@ -93,17 +93,14 @@ class SystemSettingsController extends Controller
|
||||
{
|
||||
$data = $request->validate([
|
||||
'chat_id' => ['nullable', 'string', 'max:64'],
|
||||
'bot_token' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$chatId = trim((string) ($data['chat_id'] ?? ''));
|
||||
if ($chatId === '') {
|
||||
$chatId = trim((string) config('coruna.telegram.owner_chat_id', ''));
|
||||
}
|
||||
$token = trim((string) ($data['bot_token'] ?? ''));
|
||||
$token = $token !== '' ? $token : null;
|
||||
|
||||
$result = $telegram->sendTest($chatId, '官方通知群推送正常。', $token);
|
||||
$result = $telegram->sendTest($chatId, '官方通知群推送正常。');
|
||||
|
||||
return response()->json([
|
||||
'code' => $result['ok'] ? 0 : 1,
|
||||
|
||||
Reference in New Issue
Block a user