company moderation fixed
This commit is contained in:
parent
978198c332
commit
137c89cd9d
@ -20,16 +20,22 @@ public function __invoke(Request $request)
|
||||
'status' => 'new',
|
||||
'type' => 'AGENCY'
|
||||
]);
|
||||
$company = Company::create($request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type'));
|
||||
if ($company)
|
||||
$data = $request->only('name', 'email', 'inn', 'legal_address', 'secret', 'status', 'type', 'phone');
|
||||
$company = Company::create($data);
|
||||
if (!$company)
|
||||
{
|
||||
$companyConfirmByBitrix = new SendCompany($company);
|
||||
$companyConfirmByBitrix->send();
|
||||
return back()->with('error', __('Company creation error'))->withInput();
|
||||
}
|
||||
$data['callback_url'] = route('company.status.update', [
|
||||
'company' => $company->id,
|
||||
'secret' => $company->secret
|
||||
]);
|
||||
$companyConfirmByBitrix = new SendCompany($company->id, $data);
|
||||
if (!$sender = $companyConfirmByBitrix->send())
|
||||
{
|
||||
$company->delete();
|
||||
return back()->with('error', __('Company creation error'))->withInput();
|
||||
}
|
||||
return view('company.created');
|
||||
}
|
||||
else
|
||||
{
|
||||
return back()->withInputs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,10 +49,10 @@ public function index()
|
||||
public function store(Request $request, Company $company)
|
||||
{
|
||||
$userId = auth()->user()->id;
|
||||
$agent = Agent::where('user_id', $userId)->get();
|
||||
if ($agent->count() == 1)
|
||||
$admin = CompanyAdmin::where('user_id', $userId)->get();
|
||||
if ($admin->count() == 1)
|
||||
{
|
||||
$agent = $agent->first();
|
||||
$agent = $admin->first();
|
||||
if ($agent->company_id != $company->id)
|
||||
{
|
||||
return;
|
||||
@ -62,8 +62,6 @@ public function store(Request $request, Company $company)
|
||||
{
|
||||
return back();
|
||||
}
|
||||
;
|
||||
|
||||
$company->details = $request->all();
|
||||
$company->save();
|
||||
return to_route('company.details', [
|
||||
|
||||
@ -4,14 +4,16 @@
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class BitrixSender
|
||||
{
|
||||
{
|
||||
public $url;
|
||||
public $data;
|
||||
public function __construct($url, $data) {
|
||||
public function __construct(string $url, array $data)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->data = $data;
|
||||
}
|
||||
public function send() {
|
||||
public function send()
|
||||
{
|
||||
$postdata = http_build_query(
|
||||
$this->data
|
||||
);
|
||||
@ -23,24 +25,30 @@ public function send() {
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' =>
|
||||
'Content-type: application/x-www-form-urlencoded'."\r\n".
|
||||
'Content-type: application/x-www-form-urlencoded' . "\r\n" .
|
||||
'',
|
||||
'content' => $postdata
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
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)) {
|
||||
if (array_key_exists('result', $result))
|
||||
{
|
||||
return $result['result'];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
dd($e);
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class SendClient
|
||||
{
|
||||
{
|
||||
private $IBLOCK_TYPE_ID = 'lists';
|
||||
|
||||
//CONFIG для Альфы
|
||||
@ -13,6 +13,7 @@ class SendClient
|
||||
private $URL = 'https://b24alfa.pro/rest/3165/v90a792nderzu0dj/lists.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";
|
||||
@ -23,17 +24,19 @@ class SendClient
|
||||
const CALLBACK_URL = "PROPERTY_105";
|
||||
private $data = [];
|
||||
|
||||
public function __construct($id, $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 ($constants as $constName => $constValue)
|
||||
{
|
||||
foreach ($data as $key => $value)
|
||||
{
|
||||
if ( $constName == $key ) {
|
||||
if ($constName == $key)
|
||||
{
|
||||
$finalData[$constValue] = $value;
|
||||
break;
|
||||
}
|
||||
@ -44,42 +47,15 @@ public function __construct($id, $data) {
|
||||
return;
|
||||
}
|
||||
|
||||
public function send() {
|
||||
$postdata = http_build_query(
|
||||
[
|
||||
public function send()
|
||||
{
|
||||
$data = [
|
||||
'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;
|
||||
];
|
||||
$sender = new BitrixSender($this->URL, $data);
|
||||
return $sender->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,15 +23,11 @@ class SendCompany
|
||||
const CALLBACK_URL = "PROPERTY_122";
|
||||
private $data = [];
|
||||
|
||||
public function __construct(Company $company)
|
||||
public function __construct($id, array $data)
|
||||
{
|
||||
$this->ID = $company->id;
|
||||
$data = array_change_key_case($company->attributesToArray(), CASE_UPPER);
|
||||
$this->ID = $id;
|
||||
$data = array_change_key_case($data, CASE_UPPER);
|
||||
$finalData = $this->castConstants($data);
|
||||
$finalData[self::CALLBACK_URL] = route('company.status.update', [
|
||||
'company' => $this->ID,
|
||||
'secret' => $company->secret
|
||||
]);
|
||||
$this->data = $finalData;
|
||||
return;
|
||||
}
|
||||
@ -60,10 +56,9 @@ public function send()
|
||||
'IBLOCK_TYPE_ID' => $this->IBLOCK_TYPE_ID,
|
||||
'IBLOCK_ID' => $this->IBLOCK_ID,
|
||||
'ELEMENT_CODE' => $this->ID,
|
||||
'FIELDS' => $this->data,
|
||||
'PROPERTY_VALUES' => $this->data
|
||||
'FIELDS' => $this->data
|
||||
];
|
||||
$sender = new BitrixSender($this->URL, $data);
|
||||
$sender->send();
|
||||
return $sender->send();
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,31 +2,42 @@
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
@isset($error)
|
||||
E: {{ $error }}
|
||||
@endisset
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">{{ __('Create company form') }}</div>
|
||||
|
||||
<div class="card-body">
|
||||
<form action="{{ route('company.create') }}" method="post">
|
||||
@csrf
|
||||
<div class="mb-3">
|
||||
<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 class="mb-3">
|
||||
<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 class="mb-3">
|
||||
<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 class="mb-3">
|
||||
<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>
|
||||
|
||||
<input type="submit" class="btn btn-primary" name="Отправить заявку">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user