lk.zachem.info/app/Models/Bitrix/SendClient.php
2025-02-28 15:33:20 +08:00

61 lines
1.8 KiB
PHP

<?php
namespace App\Models\Bitrix;
use Illuminate\Support\Facades\Http;
class SendClient
{
private $IBLOCK_TYPE_ID = 'lists';
//CONFIG для Альфы
private $URL = 'https://b24alfa.pro/rest/3165/v90a792nderzu0dj/lists1.element.add.json';
private $IBLOCK_ID = 27;
private $ID;
const NAME = "NAME";
const CLIENT_SECOND_NAME = "PROPERTY_94";
const CLIENT_FIRST_NAME = "PROPERTY_95";
const CLIENT_PHONE = "PROPERTY_96";
const BROKER_SECOND_NAME = "PROPERTY_97";
const BROKER_FIRST_NAME = "PROPERTY_98";
const BROKER_PHONE = "PROPERTY_99";
const OBJECT_NAME = "PROPERTY_100";
const CALLBACK_URL = "PROPERTY_105";
private $data = [];
public function __construct($id, $data)
{
$this->ID = $id;
$data = array_change_key_case($data, CASE_UPPER);
$finalData = [];
$refl = new \ReflectionClass(__CLASS__);
$constants = $refl->getConstants();
foreach ($constants as $constName => $constValue)
{
foreach ($data as $key => $value)
{
if ($constName == $key)
{
$finalData[$constValue] = $value;
break;
}
}
}
$finalData['NAME'] = $finalData[self::CLIENT_FIRST_NAME] . ' ' . $finalData[self::CLIENT_SECOND_NAME];
$this->data = $finalData;
return;
}
public function send()
{
$data = [
'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID,
'IBLOCK_ID' => $this->IBLOCK_ID,
'ELEMENT_CODE' => $this->ID,
'FIELDS' => $this->data
];
$sender = new BitrixSender($this->URL, $data);
return $sender->send();
}
}