Merge branch 'master' of https://github.com/Evolyuciya/evoleasing-public
This commit is contained in:
commit
3a2ebe16b6
409
api/index.php
409
api/index.php
@ -119,11 +119,17 @@ function checkRecaptchaRequest($token, $ipAddress)
|
||||
return $response_decoded['success'];
|
||||
}
|
||||
|
||||
function getCompaniesForUser($user_id)
|
||||
function getCompaniesForUser($user_id, $except_company_id = null)
|
||||
{
|
||||
if(CModule::IncludeModule('iblock'))
|
||||
{
|
||||
$existed_client_as_user_res = CIBlockElement::GetList([ 'id' => 'desc' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'PROPERTY_USERS' => $user_id ], false, []);
|
||||
$filter = [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'PROPERTY_USERS' => $user_id ];
|
||||
if($except_company_id !== null)
|
||||
{
|
||||
$filter['!ID'] = $except_company_id;
|
||||
}
|
||||
|
||||
$existed_client_as_user_res = CIBlockElement::GetList([ 'id' => 'desc' ], $filter, false, []);
|
||||
|
||||
$companies = [];
|
||||
|
||||
@ -215,6 +221,80 @@ function getUsersForCompany($code)
|
||||
return [];
|
||||
}
|
||||
|
||||
function setCompanyForUser($ID, $REQ, $replace = false)
|
||||
{
|
||||
$user_properties = [
|
||||
'COMPANY' => (string)$REQ['org_title'],
|
||||
'INN' => (string)$REQ['inn'],
|
||||
'KPP' => (string)$REQ['kpp'],
|
||||
'OGRN' => (string)$REQ['ogrn'],
|
||||
'ADMINS' => [ $ID ],
|
||||
'USERS' => [ $ID ],
|
||||
];
|
||||
|
||||
$ar_new_client = [
|
||||
'IBLOCK_ID' => IBLOCK_ID_CLIENTS,
|
||||
'NAME' => $REQ['org_title'],
|
||||
'CODE' => $REQ['crm_id'],
|
||||
'PROPERTY_VALUES' => $user_properties,
|
||||
'ACTIVE' => 'Y', // активен
|
||||
];
|
||||
|
||||
$admins_to_remove = [];
|
||||
|
||||
$new_client = new CIBlockElement;
|
||||
if($new_client_id = $new_client->Add($ar_new_client))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
$existed_client_res = CIBlockElement::GetList([ 'id' => 'desc' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $REQ['crm_id'] ], false, []);
|
||||
while ($existed_client_element = $existed_client_res->GetNextElement())
|
||||
{
|
||||
$existed_client_record = $existed_client_element->GetFields();
|
||||
$existed_client_record['PROPERTIES'] = $existed_client_element->GetProperties();
|
||||
|
||||
if($replace)
|
||||
{
|
||||
$admins = [];
|
||||
$users = [];
|
||||
|
||||
$admins_to_remove = $existed_client_record['PROPERTIES']['ADMINS']['VALUE'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$admins = $existed_client_record['PROPERTIES']['ADMINS']['VALUE'];
|
||||
$users = $existed_client_record['PROPERTIES']['USERS']['VALUE'];
|
||||
}
|
||||
|
||||
array_push($admins, $ID);
|
||||
array_push($users, $ID);
|
||||
|
||||
$admins = array_unique($admins);
|
||||
$users = array_unique($users);
|
||||
|
||||
$updated_fields = [
|
||||
'PROPERTY_VALUES' => [
|
||||
'ADMINS' => $admins,
|
||||
'USERS' => $users,
|
||||
]
|
||||
];
|
||||
|
||||
CIBlockElement::SetPropertyValuesEx($existed_client_record['ID'], IBLOCK_ID_CLIENTS, [ 'ADMINS' => $admins, 'USERS' => $users, ]);
|
||||
|
||||
foreach($admins_to_remove AS $admin_to_remove_id)
|
||||
{
|
||||
$another_user_companies = getCompaniesForUser($admin_to_remove_id, $existed_client_record['ID']);
|
||||
|
||||
if(count($another_user_companies) === 0)
|
||||
{
|
||||
\CUser::Delete($admin_to_remove_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($_SERVER['REMOTE_USER'] && strpos($_SERVER['REMOTE_USER'], "Bearer") > -1)
|
||||
{
|
||||
$token = str_replace("Bearer ", "", $_SERVER['REMOTE_USER']);
|
||||
@ -292,33 +372,12 @@ switch($PARAM_1)
|
||||
{
|
||||
if($auth['username'] !== 'crm') { header('HTTP/1.0 401 Unauthorized'); print json_encode(["status" => "error", "error" => "unauthorized", "message" => "Unauthorized"]); die(); }
|
||||
|
||||
$user_registered = false;
|
||||
|
||||
$existed_users_res = \CUser::GetList(["ID" => "ASC"], false, [ "XML_ID" => $REQ['crm_id'] ], []);
|
||||
while($existed_user = $existed_users_res->Fetch())
|
||||
{
|
||||
$user_registered = true;
|
||||
}
|
||||
|
||||
if($user_registered)
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "user_already_registered",
|
||||
"message" => "User already registered",
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$user = new \CUser;
|
||||
$profile = [
|
||||
"XML_ID" => $REQ['crm_id'],
|
||||
"LOGIN" => $REQ['email'],
|
||||
"NAME" => $REQ['firstname'],
|
||||
"SECOND_NAME" => $REQ['secondname'],
|
||||
"LAST_NAME" => $REQ['lastname'],
|
||||
"PASSWORD" => $REQ['password'],
|
||||
"CONFIRM_PASSWORD" => $REQ['password'],
|
||||
"EMAIL" => $REQ['email'],
|
||||
"UF_ORG_TITLE" => (string)$REQ['org_title'],
|
||||
"UF_INN" => (string)$REQ['inn'],
|
||||
@ -327,6 +386,69 @@ switch($PARAM_1)
|
||||
"UF_PHONE_NUMBER" => (int)$REQ['phone'],
|
||||
];
|
||||
|
||||
$user_registered_id = null;
|
||||
$company_registered_id = null;
|
||||
|
||||
$existed_users_res = \CUser::GetList(["ID" => "ASC"], false, [ "LOGIN" => $REQ['email'] ], []);
|
||||
while($existed_user = $existed_users_res->Fetch())
|
||||
{
|
||||
$user_registered_id = $existed_user["ID"];
|
||||
}
|
||||
|
||||
$existed_client_as_admin_res = CIBlockElement::GetList([ 'ID' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $REQ['crm_id'] ], false, []);
|
||||
while ($existed_client_as_admin_element = $existed_client_as_admin_res->GetNextElement())
|
||||
{
|
||||
$existed_client_as_admin_record = $existed_client_as_admin_element->GetFields();
|
||||
$company_registered_id = $existed_client_as_admin_record['ID'];
|
||||
}
|
||||
|
||||
if($user_registered_id !== null)
|
||||
{
|
||||
//user exists
|
||||
|
||||
if($company_registered_id === null)
|
||||
{
|
||||
//new company for user
|
||||
setCompanyForUser($user_registered_id, $REQ);
|
||||
|
||||
$company_message = "Вам предоставлен доступ к Личному кабинету следующей организации:<br><br>\n\n";
|
||||
$company_message .= $REQ['org_title'].", ИНН: ".$REQ['inn']."<br>\n";
|
||||
|
||||
\Bitrix\Main\Mail\Event::send([
|
||||
"EVENT_NAME" => "CLIENT_USER_INVITE",
|
||||
"LID" => "s1",
|
||||
"C_FIELDS" => Array(
|
||||
"EMAIL" => $REQ['email'],
|
||||
"COMPANIES" => $company_message,
|
||||
)
|
||||
]);
|
||||
|
||||
print json_encode([
|
||||
"status" => "success"
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "company_already_registered",
|
||||
"message" => "Company already registered",
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($company_registered_id === null)
|
||||
{
|
||||
$user = new \CUser;
|
||||
|
||||
$profile["PASSWORD"] = $REQ['password'];
|
||||
$profile["CONFIRM_PASSWORD"] = $REQ['password'];
|
||||
|
||||
$ID = $user->Add($profile);
|
||||
if (intval($ID) > 0)
|
||||
{
|
||||
@ -341,58 +463,14 @@ switch($PARAM_1)
|
||||
)
|
||||
]);
|
||||
|
||||
$user_properties = [
|
||||
'COMPANY' => $REQ['org_title'],
|
||||
'INN' => (string)$REQ['inn'],
|
||||
'KPP' => (string)$REQ['kpp'],
|
||||
'OGRN' => (string)$REQ['ogrn'],
|
||||
'ADMINS' => [ $ID ],
|
||||
'USERS' => [ $ID ],
|
||||
];
|
||||
|
||||
$ar_new_client = [
|
||||
'IBLOCK_ID' => IBLOCK_ID_CLIENTS,
|
||||
'NAME' => $REQ['org_title'],
|
||||
'CODE' => $REQ['crm_id'],
|
||||
'PROPERTY_VALUES' => $user_properties,
|
||||
'ACTIVE' => 'Y', // активен
|
||||
];
|
||||
|
||||
$new_client = new CIBlockElement;
|
||||
if($new_client_id = $new_client->Add($ar_new_client))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
$existed_client_res = CIBlockElement::GetList([ 'id' => 'desc' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $REQ['crm_id'] ], false, []);
|
||||
while ($existed_client_element = $existed_client_res->GetNextElement())
|
||||
{
|
||||
$existed_client_record = $existed_client_element->GetFields();
|
||||
$existed_client_record['PROPERTIES'] = $existed_client_element->GetProperties();
|
||||
|
||||
$admins = $existed_client_record['PROPERTIES']['ADMINS']['VALUE'];
|
||||
$users = $existed_client_record['PROPERTIES']['USERS']['VALUE'];
|
||||
|
||||
array_push($admins, $ID);
|
||||
array_push($users, $ID);
|
||||
|
||||
$admins = array_unique($admins);
|
||||
$users = array_unique($users);
|
||||
|
||||
$updated_fields = [
|
||||
'PROPERTY_VALUES' => [
|
||||
'ADMINS' => $admins,
|
||||
'USERS' => $users,
|
||||
]
|
||||
];
|
||||
|
||||
CIBlockElement::SetPropertyValuesEx($existed_client_record['ID'], IBLOCK_ID_CLIENTS, [ 'ADMINS' => $admins, 'USERS' => $users, ]);
|
||||
}
|
||||
}
|
||||
//new user & new company
|
||||
setCompanyForUser($ID, $REQ);
|
||||
|
||||
print json_encode([
|
||||
"status" => "success"
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -405,6 +483,19 @@ switch($PARAM_1)
|
||||
"error" => "wrong_payload",
|
||||
"message" => $error,
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "company_already_registered",
|
||||
"message" => "Company already registered",
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,22 +507,12 @@ switch($PARAM_1)
|
||||
{
|
||||
if($auth['username'] !== 'crm') { header('HTTP/1.0 401 Unauthorized'); print json_encode(["status" => "error", "error" => "unauthorized", "message" => "Unauthorized"]); die(); }
|
||||
|
||||
$user_registered = false;
|
||||
|
||||
$existed_users_res = \CUser::GetList(["ID" => "ASC"], false, [ "XML_ID" => $REQ['crm_id'] ], []);
|
||||
while($existed_user = $existed_users_res->Fetch())
|
||||
{
|
||||
$user_registered = true;
|
||||
|
||||
$user = new \CUser;
|
||||
$profile = [
|
||||
"XML_ID" => $REQ['crm_id'],
|
||||
"LOGIN" => $REQ['email'],
|
||||
"NAME" => $REQ['firstname'],
|
||||
"SECOND_NAME" => $REQ['secondname'],
|
||||
"LAST_NAME" => $REQ['lastname'],
|
||||
"PASSWORD" => $REQ['password'],
|
||||
"CONFIRM_PASSWORD" => $REQ['password'],
|
||||
"EMAIL" => $REQ['email'],
|
||||
"UF_ORG_TITLE" => (string)$REQ['org_title'],
|
||||
"UF_INN" => (string)$REQ['inn'],
|
||||
@ -440,18 +521,37 @@ switch($PARAM_1)
|
||||
"UF_PHONE_NUMBER" => (int)$REQ['phone'],
|
||||
];
|
||||
|
||||
$user->Update($existed_user['ID'], $profile);
|
||||
$user_registered = null;
|
||||
$company_registered_id = null;
|
||||
$company_registered = null;
|
||||
|
||||
if($user->LAST_ERROR)
|
||||
$existed_users_res = \CUser::GetList(["ID" => "ASC"], false, [ "LOGIN" => $REQ['email'] ], []);
|
||||
while($existed_user = $existed_users_res->Fetch())
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_payload",
|
||||
"message" => $user->LAST_ERROR,
|
||||
]);
|
||||
$user_registered = $existed_user['ID'];
|
||||
}
|
||||
else
|
||||
|
||||
$existed_client_as_admin_res = CIBlockElement::GetList([ 'ID' => 'ASC' ], [ 'IBLOCK_ID' => IBLOCK_ID_CLIENTS, 'CODE' => $REQ['crm_id'] ], false, []);
|
||||
while ($existed_client_as_admin_element = $existed_client_as_admin_res->GetNextElement())
|
||||
{
|
||||
$existed_client_as_admin_record = $existed_client_as_admin_element->GetFields();
|
||||
$company_registered_id = $existed_client_as_admin_record['ID'];
|
||||
}
|
||||
|
||||
if($user_registered !== null)
|
||||
{
|
||||
// user exists
|
||||
|
||||
if($company_registered_id !== null)
|
||||
{
|
||||
//existed company
|
||||
|
||||
$profile["PASSWORD"] = $REQ['password'];
|
||||
$profile["CONFIRM_PASSWORD"] = $REQ['password'];
|
||||
|
||||
$user = new \CUser;
|
||||
$user->Update($user_registered, $profile);
|
||||
|
||||
\Bitrix\Main\Mail\Event::send([
|
||||
"EVENT_NAME" => "USER_INFO",
|
||||
"LID" => "s1",
|
||||
@ -463,22 +563,127 @@ switch($PARAM_1)
|
||||
)
|
||||
]);
|
||||
|
||||
//"PASSWORD" => $REQ['password'],
|
||||
//"CONFIRM_PASSWORD" => $REQ['password'],
|
||||
|
||||
//print json_encode([
|
||||
// "status" => "error",
|
||||
// "error" => "company_already_registered",
|
||||
// "message" => "Company already registered",
|
||||
//]);
|
||||
|
||||
print json_encode([
|
||||
"status" => "success"
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
//new company
|
||||
//setCompanyForUser($user_registered_id, $REQ);
|
||||
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "no_company_for_update",
|
||||
"message" => "No company for update",
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// new user
|
||||
|
||||
if($company_registered_id !== null)
|
||||
{
|
||||
//existed company
|
||||
//THIS!
|
||||
|
||||
$profile["PASSWORD"] = $REQ['password'];
|
||||
$profile["CONFIRM_PASSWORD"] = $REQ['password'];
|
||||
|
||||
$user = new \CUser;
|
||||
$ID = $user->Add($profile);
|
||||
|
||||
if (intval($ID) > 0)
|
||||
{
|
||||
//new user & new company
|
||||
setCompanyForUser($ID, $REQ, true);
|
||||
|
||||
\Bitrix\Main\Mail\Event::send([
|
||||
"EVENT_NAME" => "USER_INFO",
|
||||
"LID" => "s1",
|
||||
"C_FIELDS" => Array(
|
||||
"EMAIL" => $REQ['email'],
|
||||
"ORG_NAME" => $REQ['org_title'],
|
||||
"LOGIN" => $REQ['email'],
|
||||
"PASS" => $REQ['password'],
|
||||
)
|
||||
]);
|
||||
|
||||
print json_encode([
|
||||
"status" => "success"
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_payload",
|
||||
"message" => $user->LAST_ERROR,
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//no company
|
||||
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "no_company_for_update",
|
||||
"message" => "No company for update",
|
||||
]);
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
/* *******************************
|
||||
\Bitrix\Main\Mail\Event::send([
|
||||
"EVENT_NAME" => "USER_INFO",
|
||||
"LID" => "s1",
|
||||
"C_FIELDS" => Array(
|
||||
"EMAIL" => $REQ['email'],
|
||||
"ORG_NAME" => (string)$REQ['org_title'],
|
||||
"LOGIN" => $REQ['email'],
|
||||
"PASS" => $REQ['password'],
|
||||
)
|
||||
]);
|
||||
|
||||
if($user->LAST_ERROR)
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "wrong_payload",
|
||||
"message" => $user->LAST_ERROR,
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "success"
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$user_registered)
|
||||
{
|
||||
print json_encode([
|
||||
"status" => "error",
|
||||
"error" => "unknown_user",
|
||||
"message" => "Unknown user",
|
||||
]);
|
||||
}
|
||||
|
||||
die();
|
||||
******************************* */
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@ -821,8 +1026,10 @@ switch($PARAM_1)
|
||||
|
||||
if(count($user_companies) === 0)
|
||||
{
|
||||
$user = new CUser;
|
||||
$user->Update($removed_user_id, [ "BLOCKED" => "Y" ]);
|
||||
\CUser::Delete($removed_user_id);
|
||||
|
||||
//$user = new CUser;
|
||||
//$user->Update($removed_user_id, [ "BLOCKED" => "Y" ]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ $this->setFrameMode(true);
|
||||
<span>путь развития</span>
|
||||
</p>
|
||||
<? if(!empty($arParams['PRESENTATION_URL'])): ?>
|
||||
<a href="<?= $arParams['PRESENTATION_URL']; ?>" class="button button-blue">Скачать презентацию</a>
|
||||
<a href="<?= $arParams['PRESENTATION_URL']; ?>" class="button button-blue" target="_blank">Скачать презентацию</a>
|
||||
<? endif; ?>
|
||||
</div>
|
||||
<div class="history">
|
||||
@ -31,7 +31,7 @@ $this->setFrameMode(true);
|
||||
<? foreach($periods AS $period): ?>
|
||||
<div class="month">
|
||||
<p><?= $period['PROPERTIES']['MONTH']['VALUE']; ?></p>
|
||||
<p><?= $period['PREVIEW_TEXT']; ?></p>
|
||||
<p><?= str_replace(["<p>", "</p>"], ["", "<br>"], $period['PREVIEW_TEXT']); ?></p>
|
||||
</div>
|
||||
<? endforeach; ?>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user