65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Bitrix;
|
|
use App\Models\Company\Company;
|
|
use App\Models\Bitrix\BitrixSender;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class SendCompany
|
|
{
|
|
private $IBLOCK_TYPE_ID = 'rest_entity';
|
|
|
|
//CONFIG для Альфы
|
|
|
|
private $URL = 'https://b24alfa.pro/rest/3165/v90a792nderzu0dj/lists.element.add.json';
|
|
private $IBLOCK_ID = 24;
|
|
private $ID;
|
|
const NAME = "NAME";
|
|
const INN = "PROPERTY_118";
|
|
const PHONE = "PROPERTY_121";
|
|
const EMAIL = "PROPERTY_120";
|
|
const LEGAL_ADDRESS = "PROPERTY_119";
|
|
const CALLBACK_URL = "PROPERTY_122";
|
|
private $data = [];
|
|
|
|
public function __construct(Company $company) {
|
|
$this->ID = $company->id;
|
|
$data = array_change_key_case($company->attributesToArray(), CASE_UPPER);
|
|
$finalData = $this->castConstants($data);
|
|
$finalData[self::CALLBACK_URL] = route('company.status.update', [
|
|
'company' => $this->ID
|
|
]);
|
|
$this->data = $finalData;
|
|
return;
|
|
}
|
|
|
|
private function castConstants($data) {
|
|
$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;
|
|
}
|
|
}
|
|
}
|
|
return $finalData;
|
|
}
|
|
public function send() {
|
|
$data = [
|
|
'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID,
|
|
'IBLOCK_ID' => $this->IBLOCK_ID,
|
|
'ELEMENT_CODE' => $this->ID,
|
|
'FIELDS' => $this->data,
|
|
'PROPERTY_VALUES' => $this->data
|
|
];
|
|
$sender = new BitrixSender($this->URL, $data);
|
|
$sender->send();
|
|
}
|
|
}
|