Compare commits

..

No commits in common. "137c89cd9d63d04db0283b96532595f14fa3176e" and "14451547e38d283e07fd9e5e72fbed06c604d28c" have entirely different histories.

7 changed files with 91 additions and 85 deletions

View File

@ -20,22 +20,16 @@ public function __invoke(Request $request)
'status' => 'new', 'status' => 'new',
'type' => 'AGENCY' 'type' => 'AGENCY'
]); ]);
$data = $request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type', 'phone'); $company = Company::create($request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type'));
$company = Company::create($data); if ($company)
if (!$company)
{ {
return back()->with('error', __('Company creation error'))->withInput(); $companyConfirmByBitrix = new SendCompany($company);
$companyConfirmByBitrix->send();
return view('company.created');
} }
$data['callback_url'] = route('company.status.update', [ else
'company' => $company->id,
'secret' => $company->secret
]);
$companyConfirmByBitrix = new SendCompany($company->id, $data);
if (!$sender = $companyConfirmByBitrix->send())
{ {
$company->delete(); return back()->withInputs();
return back()->with('error', __('Company creation error'))->withInput();
} }
return view('company.created');
} }
} }

View File

@ -49,10 +49,10 @@ public function index()
public function store(Request $request, Company $company) public function store(Request $request, Company $company)
{ {
$userId = auth()->user()->id; $userId = auth()->user()->id;
$admin = CompanyAdmin::where('user_id', $userId)->get(); $agent = Agent::where('user_id', $userId)->get();
if ($admin->count() == 1) if ($agent->count() == 1)
{ {
$agent = $admin->first(); $agent = $agent->first();
if ($agent->company_id != $company->id) if ($agent->company_id != $company->id)
{ {
return; return;
@ -62,6 +62,8 @@ public function store(Request $request, Company $company)
{ {
return back(); return back();
} }
;
$company->details = $request->all(); $company->details = $request->all();
$company->save(); $company->save();
return to_route('company.details', [ return to_route('company.details', [

View File

@ -4,16 +4,14 @@
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
class BitrixSender class BitrixSender
{ {
public $url; public $url;
public $data; public $data;
public function __construct(string $url, array $data) public function __construct($url, $data) {
{
$this->url = $url; $this->url = $url;
$this->data = $data; $this->data = $data;
} }
public function send() public function send() {
{
$postdata = http_build_query( $postdata = http_build_query(
$this->data $this->data
); );
@ -25,30 +23,24 @@ public function send()
'http' => array( 'http' => array(
'method' => 'POST', 'method' => 'POST',
'header' => 'header' =>
'Content-type: application/x-www-form-urlencoded' . "\r\n" . 'Content-type: application/x-www-form-urlencoded'."\r\n".
'', '',
'content' => $postdata 'content' => $postdata
) )
); );
try try {
{
$context = stream_context_create($opts); $context = stream_context_create($opts);
$result = file_get_contents($this->url, false, $context); $result = file_get_contents($this->url, false, $context);
$result = json_decode($result, $associative = true); $result = json_decode($result, $associative = true);
if (array_key_exists('result', $result)) if (array_key_exists('result', $result)) {
{
return $result['result']; return $result['result'];
} } else {
else
{
return false; return false;
}
} }
catch (\Exception $e) } catch (\Exception $e) {
{ dd($e);
return false; return false;
}
} }
} }
}

View File

@ -5,7 +5,7 @@
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
class SendClient class SendClient
{ {
private $IBLOCK_TYPE_ID = 'lists'; private $IBLOCK_TYPE_ID = 'lists';
//CONFIG для Альфы //CONFIG для Альфы
@ -13,7 +13,6 @@ class SendClient
private $URL = 'https://b24alfa.pro/rest/3165/v90a792nderzu0dj/lists.element.add.json'; private $URL = 'https://b24alfa.pro/rest/3165/v90a792nderzu0dj/lists.element.add.json';
private $IBLOCK_ID = 27; private $IBLOCK_ID = 27;
private $ID; private $ID;
const NAME = "NAME";
const CLIENT_SECOND_NAME = "PROPERTY_94"; const CLIENT_SECOND_NAME = "PROPERTY_94";
const CLIENT_FIRST_NAME = "PROPERTY_95"; const CLIENT_FIRST_NAME = "PROPERTY_95";
const CLIENT_PHONE = "PROPERTY_96"; const CLIENT_PHONE = "PROPERTY_96";
@ -24,38 +23,63 @@ class SendClient
const CALLBACK_URL = "PROPERTY_105"; const CALLBACK_URL = "PROPERTY_105";
private $data = []; private $data = [];
public function __construct($id, $data) public function __construct($id, $data) {
{
$this->ID = $id; $this->ID = $id;
$data = array_change_key_case($data, CASE_UPPER); $data = array_change_key_case($data, CASE_UPPER);
$finalData = []; $finalData = [];
$refl = new \ReflectionClass(__CLASS__); $refl = new \ReflectionClass(__CLASS__);
$constants = $refl->getConstants(); $constants = $refl->getConstants();
foreach ($constants as $constName => $constValue) foreach ( $constants as $constName => $constValue )
{ {
foreach ($data as $key => $value) foreach ($data as $key => $value)
{ {
if ($constName == $key) if ( $constName == $key ) {
{
$finalData[$constValue] = $value; $finalData[$constValue] = $value;
break; break;
}
} }
} }
}
$finalData['NAME'] = $finalData[self::CLIENT_FIRST_NAME] . ' ' . $finalData[self::CLIENT_SECOND_NAME]; $finalData['NAME'] = $finalData[self::CLIENT_FIRST_NAME] . ' ' . $finalData[self::CLIENT_SECOND_NAME];
$this->data = $finalData; $this->data = $finalData;
return; return;
} }
public function send() public function send() {
{ $postdata = http_build_query(
$data = [ [
'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID, 'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID,
'IBLOCK_ID' => $this->IBLOCK_ID, 'IBLOCK_ID' => $this->IBLOCK_ID,
'ELEMENT_CODE' => $this->ID, 'ELEMENT_CODE' => $this->ID,
'FIELDS' => $this->data 'FIELDS' => $this->data
]; ]
$sender = new BitrixSender($this->URL, $data); );
return $sender->send();
$opts = array(
'ssl' => array(
'verify_peer' => false,
'verify_peername' => false
),
'http' => array(
'method' => 'POST',
'header' =>
'Content-type: application/x-www-form-urlencoded'."\r\n".
'',
'content' => $postdata
)
);
return true;
try {
$context = stream_context_create($opts);
$result = file_get_contents($this->URL, false, $context);
$result = json_decode($result, $associative = true);
if (array_key_exists('result', $result)) {
return $result['result'];
} else {
return false;
}
} catch (\Exception $e) {
dd($e);
return false;
} }
} }
}

View File

@ -23,11 +23,15 @@ class SendCompany
const CALLBACK_URL = "PROPERTY_122"; const CALLBACK_URL = "PROPERTY_122";
private $data = []; private $data = [];
public function __construct($id, array $data) public function __construct(Company $company)
{ {
$this->ID = $id; $this->ID = $company->id;
$data = array_change_key_case($data, CASE_UPPER); $data = array_change_key_case($company->attributesToArray(), CASE_UPPER);
$finalData = $this->castConstants($data); $finalData = $this->castConstants($data);
$finalData[self::CALLBACK_URL] = route('company.status.update', [
'company' => $this->ID,
'secret' => $company->secret
]);
$this->data = $finalData; $this->data = $finalData;
return; return;
} }
@ -56,9 +60,10 @@ public function send()
'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID, 'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID,
'IBLOCK_ID' => $this->IBLOCK_ID, 'IBLOCK_ID' => $this->IBLOCK_ID,
'ELEMENT_CODE' => $this->ID, 'ELEMENT_CODE' => $this->ID,
'FIELDS' => $this->data 'FIELDS' => $this->data,
'PROPERTY_VALUES' => $this->data
]; ];
$sender = new BitrixSender($this->URL, $data); $sender = new BitrixSender($this->URL, $data);
return $sender->send(); $sender->send();
} }
} }

View File

@ -49,9 +49,9 @@ public function getPartialsName()
{ {
$name = explode(' ', $this->name); $name = explode(' ', $this->name);
return [ return [
'firstName' => (array_key_exists(0, $name) ? $name[0] : ''), 'firstName' => $name[0],
'secondName' => (array_key_exists(1, $name) ? $name[1] : ''), 'secondName' => $name[1],
'familyName' => (array_key_exists(2, $name) ? $name[2] : '') 'familyName' => $name[2]
]; ];
} }
} }

View File

@ -2,42 +2,31 @@
@section('content') @section('content')
<div class="container"> <div class="container">
@isset($error)
E: {{ $error }}
@endisset
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-8"> <div class="col-md-8">
<div class="card"> <div class="card">
<div class="card-header">{{ __('Create company form') }}</div> <div class="card-header">{{ __('Create company form') }}</div>
<div class="card-body"> <div class="card-body">
<form action="{{ route('company.create') }}" method="post"> <form action="{{ route('company.create') }}" method="post">
@csrf @csrf
<div class="mb-3"> <div class="mb-3">
<label for="companyName" class="form-label">Название компании</label> <label for="companyName" class="form-label">Название компании</label>
<input type="text" class="form-control" id="companyName" name="name" <input type="text" class="form-control" id="companyName" name="name">
value="{{ old('name') }}">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="companyInn" class="form-label">ИНН</label> <label for="companyInn" class="form-label">ИНН</label>
<input type="text" class="form-control" id="companyInn" name="inn" <input type="text" class="form-control" id="companyInn" name="inn">
value="{{ old('inn') }}">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="companyEmail" class="form-label">Электронная почта</label> <label for="companyEmail" class="form-label">Электронная почта</label>
<input type="text" class="form-control" id="companyEmail" name="email" <input type="text" class="form-control" id="companyEmail" name="email">
value="{{ old('email') }}">
</div>
<div class="mb-3">
<label for="companyPhone" class="form-label">Номер телефона</label>
<input type="text" class="form-control" id="companyPhone" name="phone"
value="{{ old('phone') }}">
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label for="companyLegalAddress" class="form-label">Юридический адрес</label> <label for="companyLegalAddress" class="form-label">Юридический адрес</label>
<input type="text" class="form-control" id="companyLegalAddress" name="legal_address" <input type="text" class="form-control" id="companyLegalAddress" name="legal_address">
value="{{ old('legal_address') }}">
</div> </div>
<input type="submit" class="btn btn-primary" name="Отправить заявку"> <input type="submit" class="btn btn-primary" name="Отправить заявку">