- Added comprehensive AI Assistant system (aiassist/ directory): * Vector search and embedding capabilities * Typebot proxy integration * Elastic search functionality * Message classification and chat history * MCP proxy for external integrations - Implemented Court Status API (GetCourtStatus.php): * Real-time court document status checking * Integration with external court systems * Comprehensive error handling and logging - Enhanced S3 integration: * Improved file backup system with metadata * Batch processing capabilities * Enhanced error logging and recovery * Copy operations with URL fixing - Added Telegram contact creation API - Improved error logging across all modules - Enhanced callback system for AI responses - Extensive backup file storage with timestamps - Updated documentation and README files - File storage improvements: * Thousands of backup files with proper metadata * Fix operations for broken file references * Project-specific backup and recovery systems * Comprehensive file integrity checking Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
137 lines
5.9 KiB
PHP
137 lines
5.9 KiB
PHP
<?php
|
||
|
||
include_once 'modules/Users/Users.php';
|
||
require_once 'include/Webservices/Create.php';
|
||
require_once 'includes/Loader.php';
|
||
vimport('includes.runtime.Globals');
|
||
vimport('includes.runtime.BaseModel');
|
||
vimport('includes.runtime.LanguageHandler');
|
||
|
||
// Путь к лог-файлу
|
||
$logFile = 'logs/logaudit.log';
|
||
|
||
// Функция логирования
|
||
function writeLog($message, $logFile) {
|
||
$time = date('Y-m-d H:i:s');
|
||
file_put_contents($logFile, "[$time] $message\n", FILE_APPEND);
|
||
}
|
||
|
||
// Получаем JSON-данные из тела запроса
|
||
$rawData = file_get_contents('php://input');
|
||
$data = json_decode($rawData, true);
|
||
|
||
// Проверяем, была ли ошибка декодирования JSON
|
||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||
writeLog("Ошибка декодирования JSON: " . json_last_error_msg(), $logFile);
|
||
http_response_code(400);
|
||
echo json_encode(['success' => false, 'error' => 'Некорректные данные.']);
|
||
exit;
|
||
}
|
||
|
||
// Проверка полученных данных
|
||
$test_id = $data['test_id'] ?? null;
|
||
$name = filter_var($data['name'] ?? '', FILTER_SANITIZE_STRING);
|
||
$email = filter_var($data['email'] ?? '', FILTER_SANITIZE_EMAIL);
|
||
$phone = filter_var($data['phone'] ?? '', FILTER_SANITIZE_STRING);
|
||
$percentage = $data['percentage'] ?? null;
|
||
$test_results = $data['results'] ?? null;
|
||
$recommendations = $data['solutions'] ?? null; // Переименовали переменную
|
||
$totalfine = $data['totalFine'] ?? 0;
|
||
$consent = $data['consent'] ?? 0;
|
||
$sms = $data['sms'] ?? null;
|
||
$field = $data['field'] ?? null;
|
||
|
||
writeLog("Обработка test_id: $test_id, name: $name, email: $email", $logFile);
|
||
|
||
// Проверка обязательных параметров
|
||
if (empty($test_id) || empty($name) || empty($email) || empty($phone) || empty($percentage) || empty($test_results)) {
|
||
$errorMessage = "Ошибка: Одно из обязательных полей отсутствует.";
|
||
writeLog($errorMessage, $logFile);
|
||
http_response_code(400);
|
||
echo json_encode(['success' => false, 'error' => $errorMessage]);
|
||
exit;
|
||
}
|
||
|
||
try {
|
||
// Получение активного администратора CRM
|
||
$user = Users::getActiveAdminUser();
|
||
|
||
// Подготовка данных для CRM
|
||
$crmData = [
|
||
'ticket_title' => 'Самообследование_' . $test_id,
|
||
'ticketstatus' => 'Открыто',
|
||
'ticketpriorities' => 'Высокий',
|
||
'cf_2526' => $test_id,
|
||
'cf_2574' => $sms,
|
||
'cf_2572' => $consent,
|
||
'cf_2516' => $name,
|
||
'cf_2514' => $email,
|
||
'cf_2512' => $phone,
|
||
'cf_2528' => $percentage,
|
||
'cf_2564' => $totalfine,
|
||
'cf_2524' => '00001',
|
||
'cf_2604' => $field,
|
||
'description' => generateTestResultsDescription($test_results),
|
||
'cf_2562' => generateSolutionDescription($recommendations),
|
||
'assigned_user_id' => vtws_getWebserviceEntityId('Users', $user->id),
|
||
];
|
||
|
||
writeLog("Отправка данных в CRM: " . json_encode($crmData), $logFile);
|
||
|
||
// Создание записи в CRM
|
||
$lead = vtws_create('HelpDesk', $crmData, $user);
|
||
|
||
writeLog("Запись успешно создана в CRM: " . json_encode($lead), $logFile);
|
||
|
||
echo json_encode(['success' => true, 'message' => 'Запись успешно создана.']);
|
||
} catch (WebServiceException $ex) {
|
||
$errorMessage = "Ошибка CRM: " . $ex->getMessage();
|
||
writeLog($errorMessage, $logFile);
|
||
http_response_code(500);
|
||
echo json_encode(['success' => false, 'error' => $errorMessage]);
|
||
}
|
||
|
||
// Функция для формирования описания результатов теста
|
||
function generateTestResultsDescription($testResults) {
|
||
if (empty($testResults)) {
|
||
return "Нет доступных данных о тесте.";
|
||
}
|
||
|
||
$description = "Результаты теста:\n";
|
||
foreach ($testResults as $result) {
|
||
$description .= "--------------------------------\n";
|
||
$description .= "Вопрос: {$result['question']}\n";
|
||
$description .= "Правильный ответ: {$result['correct_answer']}\n";
|
||
$description .= "Ответ пользователя: {$result['user_answer']}\n";
|
||
$description .= "--------------------------------\n";
|
||
}
|
||
return $description;
|
||
}
|
||
|
||
|
||
writeLog("Передача рекомендаций: " . json_encode($recommendations, JSON_UNESCAPED_UNICODE), $logFile);
|
||
|
||
function generateSolutionDescription($recommendations) {
|
||
if (empty($recommendations)) {
|
||
writeLog("Внимание! Массив рекомендаций пуст или недоступен!", 'logs/logaudit.log');
|
||
return "Решений для неверных ответов не найдено.";
|
||
}
|
||
|
||
writeLog("Обрабатываем рекомендации: " . json_encode($recommendations, JSON_UNESCAPED_UNICODE), 'logs/logaudit.log');
|
||
|
||
$description = "Рекомендации и ответственность по неверным ответам:\n";
|
||
foreach ($recommendations as $recommendation) {
|
||
if (!isset($recommendation['question'], $recommendation['user_answer'], $recommendation['recommendation'], $recommendation['responsibility'])) {
|
||
writeLog("Ошибка структуры массива рекомендаций: " . json_encode($recommendation, JSON_UNESCAPED_UNICODE), 'logs/logaudit.log');
|
||
continue;
|
||
}
|
||
|
||
$description .= "<b>Вопрос:</b> {$recommendation['question']}\n";
|
||
$description .= "<b>Ответ пользователя:</b> {$recommendation['user_answer']}\n";
|
||
$description .= "<b>Рекомендация:</b> {$recommendation['recommendation']}\n";
|
||
$description .= "<b>Ответственность:</b> {$recommendation['responsibility']}\n\n";
|
||
}
|
||
|
||
return $description;
|
||
}
|