CAllCrmLead::SynchronizeCustomerType

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmLead
  4. SynchronizeCustomerType
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_lead.php
  • Класс: \CAllCrmLead
  • Вызов: CAllCrmLead::SynchronizeCustomerType
static function SynchronizeCustomerType($ID, array $fields = null)
{
	if(!is_array($fields))
	{
		$dbResult = self::GetListEx(
			array(),
			array('ID' => $ID, 'CHECK_PERMISSIONS' => 'N'),
			false,
			false,
			array('ID', 'IS_RETURN_CUSTOMER', 'STATUS_ID', 'COMPANY_ID', 'CONTACT_ID')
		);

		$fields = $dbResult->Fetch();
	}

	if(!is_array($fields))
	{
		return;
	}

	$customerType = isset($fields['IS_RETURN_CUSTOMER']) && $fields['IS_RETURN_CUSTOMER'] === 'Y'
		? CustomerType::RETURNING : CustomerType::GENERAL;

	$effectiveCustomerType = CustomerType::GENERAL;
	if(
		(isset($fields['COMPANY_ID']) && $fields['COMPANY_ID'] > 0)
		|| (isset($fields['CONTACT_ID']) && $fields['CONTACT_ID'] > 0)
	)
	{
		$effectiveCustomerType = CustomerType::RETURNING;
	}

	if($customerType === $effectiveCustomerType)
	{
		return;
	}

	$entity = new CCrmLead(false);
	$updateFields = array('IS_RETURN_CUSTOMER' => $effectiveCustomerType === CustomerType::RETURNING ? 'Y' : 'N');
	$entity->Update($ID, $updateFields, false, false);
}

Добавить комментарий