Compare commits

..

3 Commits

15 changed files with 230 additions and 14 deletions

View File

@ -10,7 +10,6 @@ class AdminCitiesController extends Controller
public function index(Request $request)
{
$cities = City::orderBy('name');
//if ($request->filter) {
switch ( $request->filter )
{
case 'trashed':

View File

@ -35,7 +35,8 @@ public function edit(Complex $complex)
{
return view('admin::complexes.edit', [
'complex' => $complex,
'cities' => City::orderBy('name')->get()
'cities' => City::orderBy('name')->get(),
'backUrl' => route(name: 'admin.complexes')
]);
}

View File

@ -14,7 +14,9 @@ public function index()
{
return $this->goToSuperAdminCreator();
}
return view('admin::index');
return view('admin::index', [
]);
}
public function superAdminExists()

View File

@ -11,6 +11,8 @@
use Modules\User\Models\UserRole;
use Modules\User\Models\Role;
use Modules\User\Models\User;
use Modules\Main\Models\Company\CompanyAdmin;
use Modules\Main\Models\Agent\Agent;
class AdminUsersController extends Controller
{
@ -41,7 +43,10 @@ public function edit(User $user)
return view('admin::users.edit', [
'user' => $user,
'userRoles' => $roles,
'roles' => Role::class
'roles' => Role::class,
'companyAdmins' => CompanyAdmin::where('user_id', $user->id)->get(),
'companyAgents' => Agent::where('user_id', $user->id)->get(),
'backUrl' => route(name: 'admin.users')
]);
}
public function store(Request $request)
@ -52,6 +57,18 @@ public function store(Request $request)
return to_route('admin.users')->withSuccess('Учетная запись для ' . $request->name . ' создана. Пароль пользователя: ' . $password);
}
public function delete(Request $request, User $user)
{
if ($request->confirmed) {
$user->delete();
return to_route('admin.users');
} else {
return view('admin::users.confirm-delete',
['user' => $user]
);
}
return to_route('admin.users');
}
public function update(Request $request, User $user)
{
$user->update($request->only('name', 'email', 'phone'));

View File

@ -14,10 +14,11 @@
</thead>
<tbody>
@foreach ($agents as $agent)
@if($agent->user)
<tr>
<td>{{ $agent->user->name }}
<td>{{ $agent->company->name }}
<td>{{ $agent->user->phone }}
<td>{{ $agent->company?->name }}
<td>{{ $agent->user0->phone }}
<td>{{ $agent->user->email }}
<td>
<form method="post" action="{{ route('admin.bitrix.agent.set', ['agent' => $agent->id]) }}"
@ -32,6 +33,7 @@ class="input-group mb-3">
<a href="{{ route('admin.bitrix.agent.deals.sync', ['agent' => $agent->id]) }}">Sync</a>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>

View File

@ -0,0 +1,43 @@
@php($title = 'Пользователи')
@extends('layouts.admin')
@section('content')
<div>
<div class="alert alert-danger align-items-center text-center" role="alert">
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" fill="currentColor"
class="bi bi-exclamation-triangle-fill" viewBox="0 0 16 16">
<path
d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5m.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2" />
</svg>
<div class="my-3 fs-5">
Вы удаляете пользователя <b>{{ $user->name }}</b>
</div>
@if(count($user->roles) > 0)
<div class="my-2">
<div>
Проверьте назначенные данному пользователю права, которые будут аннулированы:
</div>
<div class="d-flex gap-2 justify-content-center">
@foreach($user->roles as $role)
<div class=""><b>{{ __($role->name) }}</b></div>
@endforeach
</div>
</div>
@endif
<div class="my-5">
<div class="hstack gap-3 justify-content-center">
<form method="post" action="{{ route('admin.users.delete', [
'user' => $user,
'confirmed' => true
]) }}
">
@csrf
<button class="btn btn-danger" type="submit">Продолжить удаление</button>
</form>
<a class="btn btn-light" href="{{ url()->previous() }}">Отмена</a>
</div>
</div>
</div>
</div>
@endsection

View File

@ -48,6 +48,20 @@
<tr scope="row">
<td class="align-middle">
{{ __($userRole->role->name) }}
@if($userRole->role->id == $roles::COMPANY_ADMIN)
<div class="fs-6 hstack gap-1">
@foreach($companyAdmins as $admin)
<span class="badge text-bg-secondary">{{ $admin->company->name }}</span>
@endforeach
</div>
@endif
@if($userRole->role->id == $roles::AGENT)
<div class="fs-6 hstack gap-1">
@foreach($companyAgents as $agent)
<span class="badge text-bg-secondary">{{ $agent->company->name }}</span>
@endforeach
</div>
@endif
</td>
<td class="align-middle">
{{ $userRole->created_at?->diffForHumans() }}

View File

@ -2,9 +2,7 @@
@extends('layouts.admin')
@section('content')
<div>
@if ($users->count() == 0)
<div class="text-center py-5">Нет данных для отображения</div>
@else
<form class="d-flex mb-3" method="GET" action="{{ route('admin.users') }}">
<div class="p-2 border rounded-3 border-1 bg-white">
<input type="radio" class="btn-check" name="role" value="all" id="option_all" autocomplete="off"
@ -25,7 +23,9 @@
</button>
</div>
</form>
@if ($users->count() == 0)
<div class="text-center py-5">Нет данных для отображения</div>
@else
<div class="fs-5 bg-light p-0 m-0 border border-1 rounded-4 py-3">
<table class="table m-0">
<thead>
@ -62,7 +62,7 @@
<a class="dropdown-item"
href="{{ route('admin.users.edit', ['user' => $user]) }}">Редактировать</a>
<form method="post"
action="{{ route('admin.posts.delete', ['post' => $user]) }}">
action="{{ route('admin.users.delete', ['user' => $user]) }}">
@csrf
<button class="dropdown-item" type="submit">Удалить</button>
</form>
@ -75,6 +75,7 @@
</table>
</div>
@endif
@livewire('post.card')
</div>
@ -85,7 +86,7 @@
enctype="multipart/form-data">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="createUserModalLabel">Загрузка документа</h1>
<h1 class="modal-title fs-5" id="createUserModalLabel">Новый пользователь</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">

View File

@ -32,5 +32,15 @@ protected static function booted()
'role_id' => Role::CITY_MANAGER
]);
});
static::deleted(function (CityManager $cityManager)
{
if (CityManager::where('user_id', $cityManager->user->id)->count() == 0) {
UserRole::where([
'user_id' => $cityManager->user_id,
'role_id' => Role::CITY_MANAGER
])->delete();
}
});
}
}

View File

@ -0,0 +1,40 @@
<?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('company_admins', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropForeign(['company_id']);
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('company_id')
->references('id')->on('companies')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('company_admins', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropForeign(['company_id']);
$table->foreign('user_id')
->references('id')->on('users');
$table->foreign('company_id')
->references('id')->on('companies');
});
}
};

View File

@ -0,0 +1,39 @@
<?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('agents', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropForeign(['company_id']);
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
$table->foreign('company_id')
->references('id')->on('companies')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('agents', function (Blueprint $table) {
$table->dropForeign(['user_id']);
$table->dropForeign(['company_id']);
$table->foreign('user_id')
->references('id')->on('users');
$table->foreign('company_id')
->references('id')->on('companies');
});
}
};

View File

@ -60,6 +60,32 @@ function GetAvailableAgents($resultType = 'Collection')
}
}
if (!function_exists('GetAvailableCompanies')) {
function GetAvailableCompanies($resultType = 'Collection')
{
$companiesIds = [];
if ($adminCompany = AdminCompanyOfUser()) {
$companiesIds[] = $adminCompany->id;
}
if ($cityManager = CityManager::where('user_id', auth()->user()->id)) {
if ($cityManager->count()) {
$companies = Company::whereIn('city_id', $cityManager->pluck('city_id'));
if ($companies->count()) {
$companies = $companies->get()->pluck('id');
$companiesIds = array_merge($companiesIds, $companies->all());
}
}
}
$companiesIds = array_unique($companiesIds);
$companies = Company::whereIn('id', $companiesIds);
if ($resultType == 'Collection') {
return $companies->get();
} else {
return $companies;
};
}
}
if (!function_exists('GetAvailableComplexes')) {
function GetAvailableComplexes()
{

View File

@ -15,7 +15,8 @@ class CreateAgentLivewire extends Component
public function mount($containerId = 'createAgentModal')
{
$this->containerId = $containerId;
$availableCompaniesIds = GetAvailableAgents('Builder')->pluck('company_id');
$availableCompaniesIds = GetAvailableCompanies('Collection')->pluck('id');
$this->availableCompanies = Company::whereIn('id', $availableCompaniesIds)->get();
if ($this->availableCompanies->count() == 1) {
$this->companyId = $this->availableCompanies->first()->id;

View File

@ -42,6 +42,7 @@
"Company admin": "Администратор агентства",
"Agent": "Агент",
"Client": "Клиент",
"City manager": "Региональный менеджер",
"Status new": "Новый",
"Status moderation": "Модерация",
"Status accepted": "Одобрен",

View File

@ -27,7 +27,7 @@
<img src={{ url('/images/logo.png') }} alt="Logo" width="70">
</a>
</div>
<div class="col px-0 px-md-4 text-start" id="pageTitle">
<div class="col px-0 px-md-4 text-start align-middle" id="pageTitle">
<a class="icon-link icon-link-hover text-truncate fw-lighter fs-4 text-secondary text-uppercase text-decoration-none align-middle"
href="@isset($backUrl) {{ $backUrl }} @endisset"
style="--bs-icon-link-transform: translate3d(-.125rem, 0, 0);">
@ -93,6 +93,26 @@ class="bi bi-caret-left" viewBox="0 0 16 16">
@livewire('admin.menu')
</div>
<div class="col-10 px-0 px-md-4">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a class="icon-link"
href="{{ route('home') }}">
<i class="bi bi-house-door-fill"></i>
</a>
</li>
<li class="breadcrumb-item"><a href="{{ route('admin.index') }}">Админка</a></li>
@isset($title)
<li class="breadcrumb-item active" aria-current="page">
<a class=""
href="@isset($backUrl) {{ $backUrl }} @endisset"
style="">
{{ $title }}
</a>
</li>
@endisset
</ol>
</nav>
@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}