diff --git a/include/Webservices/CreateWebContact.php b/include/Webservices/CreateWebContact.php index db1ecb89..667e2855 100644 --- a/include/Webservices/CreateWebContact.php +++ b/include/Webservices/CreateWebContact.php @@ -53,6 +53,8 @@ function vtws_createwebcontact($mobile, $firstname = '', $lastname = '', $email global $adb, $current_user; + $isNew = false; // Флаг: создан ли контакт сейчас + // Проверяем существование контакта по номеру телефона $query = "select c.contactid from vtiger_contactdetails c @@ -64,6 +66,7 @@ function vtws_createwebcontact($mobile, $firstname = '', $lastname = '', $email if ($adb->num_rows($result) > 0) { // Контакт существует - ПРОСТО ВОЗВРАЩАЕМ ID (НЕ обновляем!) $output = $adb->query_result($result, 0, 'contactid'); + $isNew = false; $logstring = date('Y-m-d H:i:s').' ✅ Контакт найден с id '.$output.' (БЕЗ обновления)'.PHP_EOL; file_put_contents('logs/CreateWebContact.log', $logstring, FILE_APPEND); } else { @@ -98,6 +101,7 @@ function vtws_createwebcontact($mobile, $firstname = '', $lastname = '', $email try { $contact = vtws_create('Contacts', $params, $current_user); $output = substr($contact['id'], 3); + $isNew = true; // Контакт только что создан! $logstring = date('Y-m-d H:i:s').' ✅ Создан новый Web Контакт с id '.$output.PHP_EOL; file_put_contents('logs/CreateWebContact.log', $logstring, FILE_APPEND); } catch (WebServiceException $ex) { @@ -107,7 +111,16 @@ function vtws_createwebcontact($mobile, $firstname = '', $lastname = '', $email } } - return $output; + // Возвращаем JSON с флагом is_new + $result = array( + 'contact_id' => $output, + 'is_new' => $isNew + ); + + $logstring = date('Y-m-d H:i:s').' Return: '.json_encode($result).PHP_EOL; + file_put_contents('logs/CreateWebContact.log', $logstring, FILE_APPEND); + + return json_encode($result); } ?>