feat: CreateWebContact возвращает is_new флаг
- 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}
This commit is contained in:
@@ -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);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user