відновлюємо невалідні ліди юзерів

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
CModule::IncludeModule('nbsriter');
CModule::IncludeModule('nbs_extended_api');
CModule::IncludeModule('nbs_ad_campaign');
CModule::IncludeModule('crm');
if(!CModule::IncludeModule("refcode"))
exit ("Ref code");
if(!CModule::IncludeModule("nbs_crm_sync"))
echo "Модуль не установлен! ";
$rsUsers = CUser::GetList(($by="id"), ($order="desc"), array()); // выбираем пользователей
while($arFields = $rsUsers->GetNext())
{
if(UserLead::getLeadID($arFields['ID']) == false)
{
run($arFields['ID']);
}
else
{
$crmLead = new CAllCrmLead(false);
$res = $crmLead->GetByID($arFields['ID']);
if(!$res)
{
run($arFields['ID']);
}
}
}
function run($userID)
{
$contactID = UserCRM::getUserContactID($userID);
$crm = new CCrmContact(false);
$crm = $crm->GetByID($contactID, false);
UserLead::addUserToLead($userID, $crm['ASSIGNED_BY_ID'], $contactID);
$us = new CUser;
$fields = Array(
"PERSONAL_FAX" => "іі",
);
$us->Update($userID, $fields);
var_dump($userID);
checkBP($userID);
checkISIF($userID);
etap2Lead($userID);
}
function checkBP($userID)
{
$arSelect = Array("ID", "PROPERTY_S_USER", "PROPERTY_BP_REG", "PROPERTY_BP_ANKETA");
$arFilter = Array("IBLOCK_ID" => 107, "=PROPERTY_S_USER" => $userID);
$result = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
if($res = $result->GetNext())
{
$res = ( !empty($res['PROPERTY_BP_REG_VALUE']) )? $res['PROPERTY_BP_REG_VALUE'] : "Нет";
if($res == "Да")
{
UserLead::onUserPastAnketing($userID);
UserLead::onUserStartAnketing($userID);
}
else
{
if(!$res['PROPERTY_BP_ANKETA_VALUE'])
UserLead::onUserStartAnketing($userID);
}
//1422
}
}
function checkISIF($userID)
{
$arSelect = Array("ID", "PROPERTY_user_id");
$arFilter = Array("IBLOCK_ID" => 115, "=PROPERTY_user_id" => $userID);
$result = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
if($res = $result->GetNext())
{
if($res['PROPERTY_USER_ID_VALUE'] == $userID)
UserLead::onUserGoToISIF($userID);
}
}
function etap2Lead($userID)
{
$el = CIBlockElement::GetList(array("ID"=>"DESC"), array( "IBLOCK_ID" => 107, "PROPERTY_S_USER"=> $userID), false, false,
array("ID","NAME", "PROPERTY_S_USER", "PROPERTY_S_EVENT", "PROPERTY_BP_REG", "PROPERTY_BP_ZDOROVIE", "PROPERTY_BP_ANKETA"));
while($userD = $el->Fetch())
{
if($userD['PROPERTY_BP_ANKETA_VALUE'] != NULL)
{
UserLead::onUserStartAnketing($userD['PROPERTY_S_USER_VALUE']);
}
if($userD['PROPERTY_BP_ZDOROVIE_VALUE'] !=NULL )
{
UserLead::onUserEnteringZdorovie($userD['PROPERTY_BP_ZDOROVIE_VALUE'], $userD['PROPERTY_S_USER_VALUE']);
}
}
}
NBSExtendedAPI::xvardump("USer imported in CRM =)");