Compare commits
2 Commits
14451547e3
...
137c89cd9d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
137c89cd9d | ||
|
|
978198c332 |
@ -20,16 +20,22 @@ public function __invoke(Request $request)
|
|||||||
'status' => 'new',
|
'status' => 'new',
|
||||||
'type' => 'AGENCY'
|
'type' => 'AGENCY'
|
||||||
]);
|
]);
|
||||||
$company = Company::create($request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type'));
|
$data = $request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type', 'phone');
|
||||||
if ($company)
|
$company = Company::create($data);
|
||||||
|
if (!$company)
|
||||||
{
|
{
|
||||||
$companyConfirmByBitrix = new SendCompany($company);
|
return back()->with('error', __('Company creation error'))->withInput();
|
||||||
$companyConfirmByBitrix->send();
|
|
||||||
return view('company.created');
|
|
||||||
}
|
}
|
||||||
else
|
$data['callback_url'] = route('company.status.update', [
|
||||||
|
'company' => $company->id,
|
||||||
|
'secret' => $company->secret
|
||||||
|
]);
|
||||||
|
$companyConfirmByBitrix = new SendCompany($company->id, $data);
|
||||||
|
if (!$sender = $companyConfirmByBitrix->send())
|
||||||
{
|
{
|
||||||
return back()->withInputs();
|
$company->delete();
|
||||||
|
return back()->with('error', __('Company creation error'))->withInput();
|
||||||
}
|
}
|
||||||
|
return view('company.created');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
$agent = Agent::where('user_id', $userId)->get();
|
$admin = CompanyAdmin::where('user_id', $userId)->get();
|
||||||
if ($agent->count() == 1)
|
if ($admin->count() == 1)
|
||||||
{
|
{
|
||||||
$agent = $agent->first();
|
$agent = $admin->first();
|
||||||
if ($agent->company_id != $company->id)
|
if ($agent->company_id != $company->id)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -62,8 +62,6 @@ 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', [
|
||||||
|
|||||||
@ -4,14 +4,16 @@
|
|||||||
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($url, $data) {
|
public function __construct(string $url, array $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
|
||||||
);
|
);
|
||||||
@ -22,25 +24,31 @@ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -5,14 +5,15 @@
|
|||||||
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 для Альфы
|
||||||
|
|
||||||
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";
|
||||||
@ -23,63 +24,38 @@ 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)
|
|
||||||
{
|
{
|
||||||
if ( $constName == $key ) {
|
foreach ($data as $key => $value)
|
||||||
|
{
|
||||||
|
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() {
|
|
||||||
$postdata = http_build_query(
|
|
||||||
[
|
|
||||||
'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID,
|
|
||||||
'IBLOCK_ID' => $this->IBLOCK_ID,
|
|
||||||
'ELEMENT_CODE' => $this->ID,
|
|
||||||
'FIELDS' => $this->data
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,15 +23,11 @@ class SendCompany
|
|||||||
const CALLBACK_URL = "PROPERTY_122";
|
const CALLBACK_URL = "PROPERTY_122";
|
||||||
private $data = [];
|
private $data = [];
|
||||||
|
|
||||||
public function __construct(Company $company)
|
public function __construct($id, array $data)
|
||||||
{
|
{
|
||||||
$this->ID = $company->id;
|
$this->ID = $id;
|
||||||
$data = array_change_key_case($company->attributesToArray(), CASE_UPPER);
|
$data = array_change_key_case($data, 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;
|
||||||
}
|
}
|
||||||
@ -60,10 +56,9 @@ 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);
|
||||||
$sender->send();
|
return $sender->send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,9 +49,9 @@ public function getPartialsName()
|
|||||||
{
|
{
|
||||||
$name = explode(' ', $this->name);
|
$name = explode(' ', $this->name);
|
||||||
return [
|
return [
|
||||||
'firstName' => $name[0],
|
'firstName' => (array_key_exists(0, $name) ? $name[0] : ''),
|
||||||
'secondName' => $name[1],
|
'secondName' => (array_key_exists(1, $name) ? $name[1] : ''),
|
||||||
'familyName' => $name[2]
|
'familyName' => (array_key_exists(2, $name) ? $name[2] : '')
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,31 +2,42 @@
|
|||||||
|
|
||||||
@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="Отправить заявку">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user