From d7941ac8626b6b5f3e7e451ac758d5be27aa7b56 Mon Sep 17 00:00:00 2001 From: Fedor Date: Thu, 30 Oct 2025 19:49:42 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20CreateWebContact=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D1=82=20is=5Fnew=20=D1=84?= =?UTF-8?q?=D0=BB=D0=B0=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Return: {"contact_id": "123", "is_new": true/false} - is_new = true: контакт создан сейчас - is_new = false: контакт уже существовал - Логируется в CreateWebContact.log - Протестировано: * Новый 79194927999 → {contact_id: 396636, is_new: true} * Существующий 79001234567 → {contact_id: 396625, is_new: false} --- include/Webservices/CreateWebContact.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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); } ?>