- обновлена работа с администраированием агентств: сделано редактирование данных, а также управление агентами из админки (добавление, удаление)
- проведен рефакторинг компоненты создания агента - в админку добавлена работа с url на стороне битрикса - проведен рефакторинг кода по отправке данных в битрикс - разнесены оставшиеся миграции по модулям
This commit is contained in:
parent
c6d63e87f0
commit
b5b50159a7
@ -6,40 +6,34 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Modules\Bitrix\Models\BitrixWebhooks;
|
use Modules\Bitrix\Models\BitrixWebhooks;
|
||||||
|
use Modules\Bitrix\Enums\BitrixWebhooksEnum;
|
||||||
|
|
||||||
class AdminBitrixWebhooksController extends Controller
|
class AdminBitrixWebhooksController extends Controller
|
||||||
{
|
{
|
||||||
private $names = [
|
|
||||||
'CREATE_AGENT',
|
|
||||||
'CREATE_COMPANY',
|
|
||||||
'CREATE_CONTACT',
|
|
||||||
'CREATE_DEAL',
|
|
||||||
'UPDATE_DEAL',
|
|
||||||
'DEAL_SYNC'
|
|
||||||
];
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$webhooks = BitrixWebhooks::all()->keyBy('name')->toArray();
|
$webhooks = BitrixWebhooks::all()->keyBy('name')->toArray();
|
||||||
|
|
||||||
return view('admin::bitrix.webhooks', [
|
return view('admin::bitrix.webhooks', [
|
||||||
'names' => $this->names,
|
'webhooksEnumCases' => BitrixWebhooksEnum::cases(),
|
||||||
'webhooks' => $webhooks
|
'webhooks' => $webhooks
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(Request $request)
|
public function create(Request $request)
|
||||||
{
|
{
|
||||||
foreach ($this->names as $name)
|
foreach (BitrixWebhooksEnum::cases() as $webhook)
|
||||||
{
|
{
|
||||||
if ($request->has($name) && $request->$name)
|
$webhookName = $webhook->name;
|
||||||
|
if ($request->has($webhookName) && $request->$webhookName)
|
||||||
{
|
{
|
||||||
BitrixWebhooks::updateOrCreate(
|
BitrixWebhooks::updateOrCreate(
|
||||||
['name' => $name],
|
['name' => $webhookName],
|
||||||
[
|
[
|
||||||
'name' => $name,
|
'name' => $webhookName,
|
||||||
'url' => $request->$name
|
'url' => $request->$webhookName
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Modules\Main\Models\Company\Company;
|
use Modules\Main\Models\Company\Company;
|
||||||
use Modules\Main\Models\Company\CompanyStatus;
|
use Modules\Main\Models\Company\CompanyStatus;
|
||||||
|
|
||||||
|
use Modules\Main\Models\Agent\Agent;
|
||||||
class AdminCompaniesController extends Controller
|
class AdminCompaniesController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
@ -26,14 +28,16 @@ public function index(Request $request)
|
|||||||
public function edit(Company $company)
|
public function edit(Company $company)
|
||||||
{
|
{
|
||||||
return view('admin::companies.edit', [
|
return view('admin::companies.edit', [
|
||||||
'company' => $company,
|
'company' => $company,
|
||||||
|
'companyAgentsRelation' => Agent::where('company_id', $company->id)->get(),
|
||||||
|
'companyAdminsRelation' => []
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Request $request, Company $company)
|
public function update(Request $request, Company $company)
|
||||||
{
|
{
|
||||||
$company->update($request->only('name', 'email', 'phone'));
|
$company->update($request->only('name', 'email', 'phone'));
|
||||||
return to_route('admin.companies');
|
return to_route('admin.companies.edit', ['company' => $company]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
Route::get('/admin/companies', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'index'])->name('admin.companies');
|
Route::get('/admin/companies', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'index'])->name('admin.companies');
|
||||||
Route::get('/admin/companies/{company}/edit', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'edit'])->name('admin.companies.edit');
|
Route::get('/admin/companies/{company}/edit', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'edit'])->name('admin.companies.edit');
|
||||||
Route::post('/admin/companies/{company}/update', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'update'])->name('admin.companies.update');
|
Route::post('/admin/companies/{company}/update', [Modules\Admin\Http\Controllers\AdminCompaniesController::class, 'update'])->name('admin.companies.update');
|
||||||
Route::post('/admin/companies/{company}/delete', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'update'])->name('admin.companies.delete');
|
Route::post('/admin/companies/{company}/delete', [Modules\Admin\Http\Controllers\AdminUsersController::class, 'update'])->name('admin.companies.delete');
|
||||||
|
|
||||||
Route::get('/admin/cities', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'index'])->name('admin.cities');
|
Route::get('/admin/cities', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'index'])->name('admin.cities');
|
||||||
|
|||||||
@ -3,18 +3,19 @@
|
|||||||
@extends('layouts.admin')
|
@extends('layouts.admin')
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="alert alert-primary" role="alert">
|
<div class="alert alert-primary" role="alert">
|
||||||
Создайтие вебхуки на методы, указанные ниже, на стороне вашего Битрикс24. Затем укажите эти вебхуки ниже.
|
Создайтие обработчики событий на стороне вашего Битрикс24 для указанных событий.
|
||||||
</div>
|
</div>
|
||||||
<form action="{{ route('admin.bitrix.webhooks.create') }}" method="post">
|
<form action="{{ route('admin.bitrix.webhooks.create') }}" method="post">
|
||||||
@foreach ($names as $name)
|
@foreach ($webhooksEnumCases as $webhookEnum)
|
||||||
<div class="row my-2">
|
<div class="row my-2 border-bottom">
|
||||||
@csrf
|
@csrf
|
||||||
<div class="col-3">
|
<div class="col-3 vstack">
|
||||||
{{ __('admin.' . $name) }}
|
<span class="fw-bold">{{ $webhookEnum->name }}</span>
|
||||||
|
<small>{{ __('admin.' . $webhookEnum->name) . ' webhook label' }}</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-9">
|
<div class="col-9">
|
||||||
<input class="form-control" type="text" name="{{ $name }}"
|
<input class="form-control" type="text" name="{{ $webhookEnum->name }}"
|
||||||
value="{{ array_key_exists($name, $webhooks) ? $webhooks[$name]['url'] : '' }}">
|
value="{{ array_key_exists($webhookEnum->name, $webhooks) ? $webhooks[$webhookEnum->name]['url'] : '' }}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
@php($title = 'Агентства')
|
@php($title = $company->name)
|
||||||
@extends('layouts.admin')
|
@extends('layouts.admin')
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 p-3">
|
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 p-3">
|
||||||
|
|
||||||
<h4 class="fw-bold my-3">Редактировать данные пользователя</h4>
|
<h4 class="fw-bold my-3">Редактировать данные агентства</h4>
|
||||||
<form action="{{ route('admin.companies.update', ['company' => $company]) }}" method="post"
|
<form action="{{ route('admin.companies.update', ['company' => $company]) }}" method="post"
|
||||||
enctype="multipart/form-data">
|
enctype="multipart/form-data">
|
||||||
@csrf
|
@csrf
|
||||||
@ -18,15 +18,15 @@
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="emailFormControl" class="form-label">Email</label>
|
<label for="emailFormControl" class="form-label">Email</label>
|
||||||
<input type="text" class="form-control" id="emailFormControl" name="email"
|
<input type="text" class="form-control" id="emailFormControl" name="email"
|
||||||
value="{{ $user->email }}">
|
value="{{ $company->email }}">
|
||||||
@error('email')
|
@error('email')
|
||||||
<div class="text-danger">{{ $message }}</div>
|
<div class="text-danger">{{ $message }}</div>
|
||||||
@enderror
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="phoneFormControl" class="form-label">телефон</label>
|
<label for="phoneFormControl" class="form-label">Телефон</label>
|
||||||
<input type="text" class="form-control" id="phoneFormControl" name="phone"
|
<input type="text" class="form-control" id="phoneFormControl" name="phone"
|
||||||
value="{{ $user->phone }}">
|
value="{{ $company->phone }}">
|
||||||
@error('phone')
|
@error('phone')
|
||||||
<div class="text-danger">{{ $message }}</div>
|
<div class="text-danger">{{ $message }}</div>
|
||||||
@enderror
|
@enderror
|
||||||
@ -37,23 +37,33 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 mt-3 pb-3">
|
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 mt-3 pb-3">
|
||||||
<h4 class="fw-bold m-3">Роли пользователя</h4>
|
<div class="d-flex align-items-center m-3">
|
||||||
|
<h4 class="fw-bold">Агенты</h4>
|
||||||
|
<div class="ms-auto d-flex gap-3">
|
||||||
|
<a href="" class="btn btn-secondary">
|
||||||
|
<i class="bi bi-file-earmark-excel"></i> <span class="d-none d-lg-inline">Загрузить из Excel</span>
|
||||||
|
</a>
|
||||||
|
<a href="" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createAgentModal">
|
||||||
|
<i class="bi bi-person-plus-fill"></i> <span class="d-none d-lg-inline">Добавить</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<table class="table m-0">
|
<table class="table m-0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr scope="col">
|
<tr scope="col">
|
||||||
<th>Роль
|
<th>ФИО
|
||||||
<th>Когда назначена
|
<th>Когда назначен
|
||||||
<th>
|
<th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class=" ">
|
<tbody class=" ">
|
||||||
@foreach ($userRoles as $userRole)
|
@foreach ($companyAgentsRelation as $companyAgent)
|
||||||
<tr scope="row">
|
<tr scope="row">
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{ __($userRole->role->name) }}
|
{{ $companyAgent->user->name }}
|
||||||
</td>
|
</td>
|
||||||
<td class="align-middle">
|
<td class="align-middle">
|
||||||
{{ $userRole->created_at->diffForHumans() }}
|
{{ $companyAgent->created_at->diffForHumans() }}
|
||||||
</td>
|
</td>
|
||||||
<td class="text-end">
|
<td class="text-end">
|
||||||
<div class="dropdown" style="">
|
<div class="dropdown" style="">
|
||||||
@ -63,7 +73,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||||
<form method="post"
|
<form method="post"
|
||||||
action="{{ route('admin.users.role.delete', ['userRole' => $userRole]) }}">
|
action="{{ route('admin.users.role.delete', ['userRole' => 999]) }}">
|
||||||
@csrf
|
@csrf
|
||||||
<button class="dropdown-item" type="submit">Удалить</button>
|
<button class="dropdown-item" type="submit">Удалить</button>
|
||||||
</form>
|
</form>
|
||||||
@ -75,4 +85,5 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@livewire('company.agent.create', ['containerId' => 'createAgentModal', 'companyId' => $company->id])
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
DB::statement('ALTER TABLE bx_webhooks MODIFY COLUMN name VARCHAR(255)');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('bx_webhooks');
|
||||||
|
}
|
||||||
|
};
|
||||||
13
app/Modules/Bitrix/Enums/BitrixWebhooksEnum.php
Normal file
13
app/Modules/Bitrix/Enums/BitrixWebhooksEnum.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Bitrix\Enums;
|
||||||
|
enum BitrixWebhooksEnum
|
||||||
|
{
|
||||||
|
case CREATE_AGENT;
|
||||||
|
case CREATE_COMPANY;
|
||||||
|
case CREATE_CONTACT;
|
||||||
|
case CREATE_DEAL;
|
||||||
|
case ADD_CLIENT_TO_DEAL;
|
||||||
|
case DEAL_SYNC;
|
||||||
|
case CREATE_REG_MANAGER;
|
||||||
|
}
|
||||||
@ -3,17 +3,52 @@
|
|||||||
namespace Modules\Bitrix\Models;
|
namespace Modules\Bitrix\Models;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Modules\Bitrix\Enums\BitrixWebhooksEnum;
|
||||||
|
use Modules\Bitrix\Models\BitrixWebhooks;
|
||||||
|
|
||||||
class BitrixSender
|
class BitrixSender
|
||||||
{
|
{
|
||||||
protected $url;
|
|
||||||
protected $data;
|
protected $data;
|
||||||
public $resultData;
|
public $resultData;
|
||||||
public function __construct(string $url, array $data)
|
public function __construct(array $data)
|
||||||
{
|
{
|
||||||
$this->url = $url;
|
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getUrl()
|
||||||
|
{
|
||||||
|
$webhookEnumItem = false;
|
||||||
|
$childClass = get_class($this);
|
||||||
|
switch ( $childClass )
|
||||||
|
{
|
||||||
|
case SendAgent::class:
|
||||||
|
$webhookEnumItem = BitrixWebhooksEnum::CREATE_AGENT;
|
||||||
|
break;
|
||||||
|
case SendClient::class:
|
||||||
|
$webhookEnumItem = BitrixWebhooksEnum::CREATE_CONTACT;
|
||||||
|
break;
|
||||||
|
case SendCompany::class:
|
||||||
|
$webhookEnumItem = BitrixWebhooksEnum::CREATE_COMPANY;
|
||||||
|
break;
|
||||||
|
case SendDeal::class:
|
||||||
|
$webhookEnumItem = BitrixWebhooksEnum::CREATE_DEAL;
|
||||||
|
break;
|
||||||
|
case SendDealAgent::class:
|
||||||
|
$webhookEnumItem = BitrixWebhooksEnum::ADD_CLIENT_TO_DEAL;
|
||||||
|
break;
|
||||||
|
case SendDealClient::class:
|
||||||
|
$webhookEnumItem = BitrixWebhooksEnum::ADD_CLIENT_TO_DEAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($webhookEnumItem)
|
||||||
|
{
|
||||||
|
return BitrixWebhooks::getUrlByName($webhookEnumItem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new \Exception('Undefined url of webhook for ' . $childClass . ' class');
|
||||||
|
}
|
||||||
|
}
|
||||||
public function send()
|
public function send()
|
||||||
{
|
{
|
||||||
$postdata = http_build_query(
|
$postdata = http_build_query(
|
||||||
@ -35,7 +70,7 @@ public function send()
|
|||||||
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->getUrl(), false, $context);
|
||||||
$result = json_decode($result, $associative = true);
|
$result = json_decode($result, $associative = true);
|
||||||
$this->resultData = $result;
|
$this->resultData = $result;
|
||||||
if (is_array($this->resultData) && array_key_exists('result', $result))
|
if (is_array($this->resultData) && array_key_exists('result', $result))
|
||||||
|
|||||||
@ -4,16 +4,29 @@
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Modules\Bitrix\Enums\BitrixWebhooksEnum;
|
||||||
|
|
||||||
|
|
||||||
class BitrixWebhooks extends Model
|
class BitrixWebhooks extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $table = 'bx_webhooks';
|
protected $table = 'bx_webhooks';
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
'url'
|
'url'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get webhook url by its name
|
||||||
|
* @param string $name webhook name
|
||||||
|
* @return string|bool url of webhook or false
|
||||||
|
*/
|
||||||
|
public static function getUrlByName(BitrixWebhooksEnum $webhook): string|bool
|
||||||
|
{
|
||||||
|
$row = BitrixWebhooks::where('name', $webhook->name);
|
||||||
|
if ($row->count() == 1)
|
||||||
|
{
|
||||||
|
return $row->first()->url;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,5 @@ public function __construct(Agent $agent)
|
|||||||
'name' => $agent->user->name,
|
'name' => $agent->user->name,
|
||||||
'phones' => [$agent->user->phone],
|
'phones' => [$agent->user->phone],
|
||||||
];
|
];
|
||||||
dd($this->data);
|
|
||||||
$this->url = 'https://b24alfa.pro/channels/lk/createContact/';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,5 @@ public function __construct(Client $client)
|
|||||||
'name' => $client->name,
|
'name' => $client->name,
|
||||||
'phones' => [$client->phone],
|
'phones' => [$client->phone],
|
||||||
];
|
];
|
||||||
$this->url = 'https://b24alfa.pro/channels/lk/createContact/';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,13 +15,12 @@ public function __construct(Company $company)
|
|||||||
'name' => $company->name,
|
'name' => $company->name,
|
||||||
'inn' => $company->inn,
|
'inn' => $company->inn,
|
||||||
'email' => $company->email,
|
'email' => $company->email,
|
||||||
|
'phone' => $company->phone,
|
||||||
'address' => $company->legal_address,
|
'address' => $company->legal_address,
|
||||||
'callbackUrl' => route('api.company.confirm', [
|
'callbackUrl' => route('api.company.confirm', [
|
||||||
'token' => $company->secret
|
'token' => $company->secret
|
||||||
])
|
])
|
||||||
|
|
||||||
];
|
];
|
||||||
//dd($company);
|
|
||||||
$this->url = 'https://b24alfa.pro/channels/lk/createCompany/';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,5 @@ public function __construct(Deal $deal)
|
|||||||
$this->data = [
|
$this->data = [
|
||||||
'complexName' => $deal->complex->name
|
'complexName' => $deal->complex->name
|
||||||
];
|
];
|
||||||
$this->url = 'https://b24alfa.pro/channels/lk/createSmartProcess/';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,5 @@ public function __construct(Deal $deal)
|
|||||||
'contactId' => $deal->agent->bitrixId(),
|
'contactId' => $deal->agent->bitrixId(),
|
||||||
'type' => 'agent'
|
'type' => 'agent'
|
||||||
];
|
];
|
||||||
$this->url = 'https://b24alfa.pro/channels/lk/addContactToSmartProcess/';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,5 @@ public function __construct(Deal $deal, Client $client)
|
|||||||
'contactId' => $client->bitrixId(),
|
'contactId' => $client->bitrixId(),
|
||||||
'type' => 'contact'
|
'type' => 'contact'
|
||||||
];
|
];
|
||||||
$this->url = 'https://b24alfa.pro/channels/lk/addContactToSmartProcess/';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('companies', function (Blueprint $table)
|
||||||
|
{
|
||||||
|
$table->string('phone');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('companies', function (Blueprint $table)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -29,9 +29,10 @@ public function index(Request $request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return view('main::company.agents.table', [
|
return view('main::company.agents.table', [
|
||||||
'agents' => $agents->get(),
|
'agents' => $agents->get(),
|
||||||
'status' => $request->status,
|
'companyId' => $admin->company_id,
|
||||||
'cities' => City::all()
|
'status' => $request->status,
|
||||||
|
'cities' => City::all()
|
||||||
])->with('statuses', AgentStatus::class);
|
])->with('statuses', AgentStatus::class);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -4,26 +4,33 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Modules\Main\Models\Company\Company;
|
||||||
use Modules\Main\Models\Company\CompanyAdmin;
|
use Modules\Main\Models\Company\CompanyAdmin;
|
||||||
use Modules\Main\Models\Agent\Agent;
|
use Modules\Main\Models\Agent\Agent;
|
||||||
use App\Models\User;
|
use Modules\User\Models\User;
|
||||||
|
|
||||||
use App\Notifications\UserRegistered;
|
use App\Notifications\UserRegistered;
|
||||||
|
|
||||||
|
|
||||||
class CreateAgentController extends Controller
|
class CreateAgentController extends Controller
|
||||||
{
|
{
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request, Company $company)
|
||||||
{
|
{
|
||||||
//dd($request->sendToEmail);
|
if (!$company)
|
||||||
$admin = CompanyAdmin::where('user_id', auth()->id());
|
|
||||||
if (!$admin->count())
|
|
||||||
{
|
{
|
||||||
abort(404);
|
$admin = CompanyAdmin::where('user_id', auth()->id());
|
||||||
return;
|
if (!$admin->count())
|
||||||
|
{
|
||||||
|
abort(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$admin = $admin->first();
|
||||||
|
$company = Company::find($admin->company_id);
|
||||||
|
}
|
||||||
|
if (!$company)
|
||||||
|
{
|
||||||
|
return back()->with('error', 'Не удалось установить принадлежность создаваемого агента');
|
||||||
}
|
}
|
||||||
$admin = $admin->first();
|
|
||||||
|
|
||||||
$user = User::where('email', $request->email)->orWhere('phone', $request->phone)->first();
|
$user = User::where('email', $request->email)->orWhere('phone', $request->phone)->first();
|
||||||
if ($user)
|
if ($user)
|
||||||
{
|
{
|
||||||
@ -45,7 +52,7 @@ public function __invoke(Request $request)
|
|||||||
Agent::where('user_id', $user->id)->delete(); //на случай, если где-то этот пользователь уже был агентом
|
Agent::where('user_id', $user->id)->delete(); //на случай, если где-то этот пользователь уже был агентом
|
||||||
$agent = Agent::create([
|
$agent = Agent::create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'company_id' => $admin->company_id
|
'company_id' => $company->id
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
28
app/Modules/Main/Http/Livewire/CreateAgentLivewire.php
Normal file
28
app/Modules/Main/Http/Livewire/CreateAgentLivewire.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Main\Http\Livewire;
|
||||||
|
|
||||||
|
use Livewire\Component;
|
||||||
|
use Modules\Main\Models\Agent\Agent;
|
||||||
|
use Modules\Main\Models\Company\Company;
|
||||||
|
use Modules\Main\Models\Company\CompanyAdmin;
|
||||||
|
|
||||||
|
class CreateAgentLivewire extends Component
|
||||||
|
{
|
||||||
|
public $companyId;
|
||||||
|
public $containerId;
|
||||||
|
public function mount($containerId = 'createAgentModal', $companyId)
|
||||||
|
{
|
||||||
|
$this->companyId = $companyId;
|
||||||
|
$this->containerId = $containerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('main::agent.livewire.create', [
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -21,6 +21,7 @@ class Company extends Model
|
|||||||
'full_name',
|
'full_name',
|
||||||
'inn',
|
'inn',
|
||||||
'email',
|
'email',
|
||||||
|
'phone',
|
||||||
'address',
|
'address',
|
||||||
'legal_address',
|
'legal_address',
|
||||||
'details',
|
'details',
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
class ModuleServiceProvider extends ServiceProvider
|
class ModuleServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
protected String $moduleName = 'Main';
|
protected string $moduleName = 'Main';
|
||||||
|
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
@ -27,38 +27,42 @@ public function boot()
|
|||||||
|
|
||||||
protected function registerViews()
|
protected function registerViews()
|
||||||
{
|
{
|
||||||
$moduleViewsPath = __DIR__.'/../Views';
|
$moduleViewsPath = __DIR__ . '/../Views';
|
||||||
$this->loadViewsFrom(
|
$this->loadViewsFrom(
|
||||||
$moduleViewsPath, strtolower($this->moduleName)
|
$moduleViewsPath,
|
||||||
|
strtolower($this->moduleName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerLivewireViews()
|
protected function registerLivewireViews()
|
||||||
{
|
{
|
||||||
$moduleViewsPath = __DIR__.'/../Views/livewire';
|
$moduleViewsPath = __DIR__ . '/../Views/livewire';
|
||||||
$this->loadViewsFrom(
|
$this->loadViewsFrom(
|
||||||
$moduleViewsPath, strtolower($this->moduleName)
|
$moduleViewsPath,
|
||||||
|
strtolower($this->moduleName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerMigrations()
|
protected function registerMigrations()
|
||||||
{
|
{
|
||||||
$this->loadMigrationsFrom(
|
$this->loadMigrationsFrom(
|
||||||
app_path('Modules/'.$this->moduleName.'/Database/Migrations')
|
app_path('Modules/' . $this->moduleName . '/Database/Migrations')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerConfig()
|
protected function registerConfig()
|
||||||
{
|
{
|
||||||
$path = app_path('Modules/'.$this->moduleName.'/Config/config.php');
|
$path = app_path('Modules/' . $this->moduleName . '/Config/config.php');
|
||||||
$this->mergeConfigFrom(
|
$this->mergeConfigFrom(
|
||||||
$path, strtolower($this->moduleName)
|
$path,
|
||||||
|
strtolower($this->moduleName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerLivewire()
|
protected function registerLivewire()
|
||||||
{
|
{
|
||||||
//Livewire::component('<name>', \Modules\<NAME>\Http\Livewire\<NAME>::class);
|
//Livewire::component('<name>', \Modules\<NAME>\Http\Livewire\<NAME>::class);
|
||||||
|
Livewire::component('company.agent.create', \Modules\Main\Http\Livewire\CreateAgentLivewire::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerComponent()
|
protected function registerComponent()
|
||||||
|
|||||||
@ -25,7 +25,8 @@
|
|||||||
Route::get('/company/details/{company?}', [Modules\Main\Http\Controllers\Company\DetailsController::class, 'index'])->name('company.details');
|
Route::get('/company/details/{company?}', [Modules\Main\Http\Controllers\Company\DetailsController::class, 'index'])->name('company.details');
|
||||||
Route::post('/company/{company}/details/', [Modules\Main\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store');
|
Route::post('/company/{company}/details/', [Modules\Main\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store');
|
||||||
Route::get('/agents/table', [Modules\Main\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table');
|
Route::get('/agents/table', [Modules\Main\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table');
|
||||||
Route::post('/company/agents/store/', Modules\Main\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
|
//Route::post('/company/agents/store/', Modules\Main\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
|
||||||
|
Route::post('/companies/{company?}/agents/store/', Modules\Main\Http\Controllers\Company\CreateAgentController::class)->name('company.agents.store');
|
||||||
Route::post('/company/agents/{agent}/password/reset/', Modules\Main\Http\Controllers\Company\ResetAgentPasswordController::class)->name('company.agent.password.reset');
|
Route::post('/company/agents/{agent}/password/reset/', Modules\Main\Http\Controllers\Company\ResetAgentPasswordController::class)->name('company.agent.password.reset');
|
||||||
Route::get('/company/agents/{agent}/delete', Modules\Main\Http\Controllers\Company\DeleteAgentController::class)->name('company.agents.delete');
|
Route::get('/company/agents/{agent}/delete', Modules\Main\Http\Controllers\Company\DeleteAgentController::class)->name('company.agents.delete');
|
||||||
Route::get('/company/agents/{agent}/restore', Modules\Main\Http\Controllers\Company\RestoreAgentController::class)->name('company.agents.restore');
|
Route::get('/company/agents/{agent}/restore', Modules\Main\Http\Controllers\Company\RestoreAgentController::class)->name('company.agents.restore');
|
||||||
|
|||||||
42
app/Modules/Main/Views/agent/livewire/create.blade.php
Normal file
42
app/Modules/Main/Views/agent/livewire/create.blade.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<div>
|
||||||
|
<div class="modal fade" id="{{ $containerId }}" tabindex="-1" aria-labelledby="createAgentModalLabel"
|
||||||
|
aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
<form class="modal-content" action="{{ route('company.agents.store', ['company' => $companyId]) }}"
|
||||||
|
method="post">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h1 class="modal-title fs-5" id="exampleModalLabel">Новый агент</h1>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
@csrf
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="agentName" class="form-label">Полное имя (ФИО)</label>
|
||||||
|
<input type="text" class="form-control" id="agentName" name="name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="agentEmail" class="form-label">Электронная почта</label>
|
||||||
|
<input type="text" class="form-control" id="agentEmail" name="email">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="agentPhone" class="form-label">Телефон</label>
|
||||||
|
<input type="text" class="form-control" id="agentPhone" name="phone">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3 form-check form-switch">
|
||||||
|
<input class="form-check-input" type="checkbox" role="switch" id="sendEmailSwitch"
|
||||||
|
name="sendToEmail" checked>
|
||||||
|
<label class="form-check-label" for="sendEmailSwitch">Отправить учетные данные на электронную
|
||||||
|
почту</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
|
||||||
|
<input type="submit" class="btn btn-primary" value="Добавить">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@ -38,45 +38,5 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@livewire('company.agent.create', ['containerId' => 'createAgentModal', 'companyId' => $companyId])
|
||||||
|
|
||||||
<!-- Modal -->
|
|
||||||
<div class="modal fade" id="createAgentModal" tabindex="-1" aria-labelledby="createAgentModalLabel" aria-hidden="true">
|
|
||||||
<div class="modal-dialog modal-dialog-centered">
|
|
||||||
<form class="modal-content" action="{{ route('company.agents.store') }}" method="post">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h1 class="modal-title fs-5" id="exampleModalLabel">Новый агент</h1>
|
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
@csrf
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="agentName" class="form-label">Полное имя (ФИО)</label>
|
|
||||||
<input type="text" class="form-control" id="agentName" name="name">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="agentEmail" class="form-label">Электронная почта</label>
|
|
||||||
<input type="text" class="form-control" id="agentEmail" name="email">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="agentPhone" class="form-label">Телефон</label>
|
|
||||||
<input type="text" class="form-control" id="agentPhone" name="phone">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3 form-check form-switch">
|
|
||||||
<input class="form-check-input" type="checkbox" role="switch" id="sendEmailSwitch"
|
|
||||||
name="sendToEmail" checked>
|
|
||||||
<label class="form-check-label" for="sendEmailSwitch">Отправить учетные данные на электронную
|
|
||||||
почту</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
|
|
||||||
<input type="submit" class="btn btn-primary" value="Добавить">
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@ -4,18 +4,21 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row justify-content-center">
|
<div class="row justify-content-center">
|
||||||
<div class="text-success text-center">
|
<div class="text-success text-center">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="70" height="70" fill="currentColor" class="bi bi-check-circle"
|
<svg xmlns="http://www.w3.org/2000/svg" width="70" height="70" fill="currentColor"
|
||||||
viewBox="0 0 16 16">
|
class="bi bi-check-circle" viewBox="0 0 16 16">
|
||||||
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
|
<path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16" />
|
||||||
<path
|
<path
|
||||||
d="m10.97 4.97-.02.022-3.473 4.425-2.093-2.094a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05" />
|
d="m10.97 4.97-.02.022-3.473 4.425-2.093-2.094a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-1.071-1.05" />
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-success mt-3" role="alert">
|
<div class="alert alert-success mt-3" role="alert">
|
||||||
Спасибо! Мы направили Вашу заявку на модерацию. Как только заявка на подключение будет обработана, мы направим
|
Спасибо! Мы направили Вашу заявку на модерацию. Как только заявка на подключение будет обработана, мы
|
||||||
|
направим
|
||||||
Вам на электронную почту дальнейшие инструкции!
|
Вам на электронную почту дальнейшие инструкции!
|
||||||
</div>
|
</div>
|
||||||
|
<div class="d-flex justify-content-center">
|
||||||
|
<a href="route('welcome')" class="btn btn-primary">Вернуться к авторизации</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@ -93,6 +93,11 @@ class="bi bi-caret-left" viewBox="0 0 16 16">
|
|||||||
@livewire('admin.menu')
|
@livewire('admin.menu')
|
||||||
</div>
|
</div>
|
||||||
<div class="col-10 px-0 px-md-4">
|
<div class="col-10 px-0 px-md-4">
|
||||||
|
@if (session('success'))
|
||||||
|
<div class="alert alert-success">
|
||||||
|
{{ session('success') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
@foreach ($errors->all() as $error)
|
@foreach ($errors->all() as $error)
|
||||||
{{ $error }}
|
{{ $error }}
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
Route::get('/', function ()
|
Route::get('/', function ()
|
||||||
{
|
{
|
||||||
return view(view: 'welcome');
|
return view(view: 'welcome');
|
||||||
});
|
})->name('welcome');
|
||||||
|
|
||||||
Auth::routes();
|
Auth::routes();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user