Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Padilo300/27ce6439e48ecf83570d68f3ad88f98d to your computer and use it in GitHub Desktop.
Save Padilo300/27ce6439e48ecf83570d68f3ad88f98d to your computer and use it in GitHub Desktop.
создание сделки проверка на дубликат контакта
<?php
require_once "Crest/crest.php";
$phone = $_REQUEST['phone'];
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$contactListPhone = CRest::call("crm.duplicate.findbycomm",[
"entity_type" => "CONTACT",
"type" => "PHONE",
"values" => [$phone],
]);
$contactListEmail = CRest::call("crm.duplicate.findbycomm",[
"entity_type" => "CONTACT",
"type" => "EMAIL",
"values" => [$email],
]);
if(isset($contactListPhone['result']['CONTACT']) && count($contactListPhone['result']['CONTACT'])){
$contactID = $contactListPhone['result']['CONTACT'][0];
}elseif (isset($contactListEmail['result']['CONTACT']) && count($contactListEmail['result']['CONTACT'])){
$contactID = $contactListEmail['result']['CONTACT'][0];
} else{
$contactID = CRest::call("crm.contact.add",[
"fields" => [
"NAME" => $name,
"TYPE_ID" => "CLIENT",
"PHONE" => [ ["VALUE" => $phone, "VALUE_TYPE" => "WORK" ] ],
"EMAIL" => [ ["VALUE" => $email, "VALUE_TYPE" => "WORK" ] ],
"UTM_CAMPAIGN" => $_COOKIE['utm_campaign'],
"UTM_CONTENT" => $_COOKIE['utm_content'],
"UTM_MEDIUM" => $_COOKIE['utm_medium'],
"UTM_SOURCE" => $_COOKIE['utm_source'],
"UTM_TERM" => $_COOKIE['utm_term'],
]
])['result'];
}
CRest::call('crm.deal.add',[
'fields' => [
'TITLE' => "{$_REQUEST['name']} Регистрация franchglobal.ru",
"STAGE_ID" => "C20:2",
"CONTACT_ID" => $contactID,
"OPENED" => "Y",
"CATEGORY_ID" => 20,
"ASSIGNED_BY_ID" => 102,
'COMMENTS' => $_REQUEST['text'],
'UTM_CAMPAIGN' => $_COOKIE['utm_campaign'] ,
'UTM_CONTENT' => $_COOKIE['utm_content'] ,
'UTM_MEDIUM' => $_COOKIE['utm_medium'] ,
'UTM_SOURCE' => $_COOKIE['utm_source'] ,
'UTM_TERM' => $_COOKIE['utm_term'] ,
]
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment