diff --git a/app/Http/Controllers/Bitrix/ClientsApiController.php b/app/Http/Controllers/Bitrix/ClientsApiController.php new file mode 100644 index 0000000..cf50a02 --- /dev/null +++ b/app/Http/Controllers/Bitrix/ClientsApiController.php @@ -0,0 +1,68 @@ +hash)->first()) + { + switch ( $request->action ) + { + case $this::ACTION_CONFIRM: + $this->confirm($deal, $request); + break; + case $this::ACTION_UPDATE_CONTRACT: + $this->updateContract($deal, $request); + break; + } + return true; + } + return false; + } + + public function confirm(Deal $deal, Request $request) + { + if ((bool) $request->is_unique) + { + $deal->status = DealStatus::UNIQUE; + } + else + { + $deal->status = DealStatus::NOT_UNIQUE; + } + + Log::build([ + 'driver' => 'single', + 'path' => storage_path('logs/bitrix.log'), + ])->error( + json_encode( + [ + 'is_unique' => $request->is_unique, + 'deal' => $deal->id, + 'status' => $deal->status + ] + ) + ); + $deal->save(); + return $deal->id; + } + + public function update_contract(Deal $deal, Request $request) + { + $contract = new ContractApiController; + $contract($deal, $request); + } + } diff --git a/app/Http/Controllers/Bitrix/ContractApiController.php b/app/Http/Controllers/Bitrix/ContractApiController.php new file mode 100644 index 0000000..6d2b788 --- /dev/null +++ b/app/Http/Controllers/Bitrix/ContractApiController.php @@ -0,0 +1,29 @@ + $deal->id], + [ + 'status' => ContractStatus::NEW , + 'comment' => $request->comment, + 'price' => $request->price, + 'reward' => $request->reward, + 'square' => $request->square, + 'floor' => $request->floor + ] + ); + return true; + } + } \ No newline at end of file diff --git a/app/Http/Controllers/Company/ConfirmCompanyController.php b/app/Http/Controllers/Company/ConfirmCompanyController.php index d51e5cd..4a987df 100644 --- a/app/Http/Controllers/Company/ConfirmCompanyController.php +++ b/app/Http/Controllers/Company/ConfirmCompanyController.php @@ -34,6 +34,7 @@ public function __invoke(Request $request) ]); $user->setForcedPassword(); } + CompanyAdmin::where('user_id', $user->id)->delete();//удаляю, если уже была админская учетка CompanyAdmin::create([ 'user_id' => $user->id, 'company_id' => $company->id diff --git a/app/Http/Controllers/ConfirmClientFromBitrix.php b/app/Http/Controllers/ConfirmClientFromBitrix.php index 3cd2000..4ea31cf 100644 --- a/app/Http/Controllers/ConfirmClientFromBitrix.php +++ b/app/Http/Controllers/ConfirmClientFromBitrix.php @@ -1,5 +1,5 @@ $contract + ] + ); + + } + + public function getAllDealsInCompany(Request $request) + { + $user = auth()->user(); + } + } diff --git a/app/Livewire/CreateClientForm.php b/app/Livewire/CreateClientForm.php index ebea135..2007c7e 100644 --- a/app/Livewire/CreateClientForm.php +++ b/app/Livewire/CreateClientForm.php @@ -177,7 +177,7 @@ public function sendToBitrix(Deal $deal) 'BROKER_PHONE' => $agent->user->phone, 'BROKER_INN' => $agent->company->inn, 'OBJECT_NAME' => Complex::find($this->client['complexId'])->name, - 'CALLBACK_URL' => route('deal.confirm', ['hash' => $this->client['confirmToken']]), + 'CALLBACK_URL' => route('api.client', ['hash' => $this->client['confirmToken']]), ]; $sender = new SendClient($deal->id, $data); $response = $sender->send(); diff --git a/app/Livewire/MainMenu.php b/app/Livewire/MainMenu.php new file mode 100644 index 0000000..90fbafc --- /dev/null +++ b/app/Livewire/MainMenu.php @@ -0,0 +1,27 @@ +userId = auth()->user()->id; + } + public function render() + { + return view('livewire.main-menu', [ + 'userRoles' => UserRole::where('user_id', $this->userId)->pluck('role_id')->toArray(), + 'roles' => Role::class + ]); + } + } diff --git a/app/Models/Agent/Agent.php b/app/Models/Agent/Agent.php index 0b0ac64..2a7c7a5 100644 --- a/app/Models/Agent/Agent.php +++ b/app/Models/Agent/Agent.php @@ -9,6 +9,8 @@ use App\Models\Company\Company; use App\Models\User; +use App\Models\User\UserRole; +use App\Models\User\Role; use App\Models\Deal\Deal; class Agent extends Model @@ -34,4 +36,32 @@ public function deals() { return $this->hasMany(Deal::class); } + + protected static function booted(): void + { + static::created(function (Agent $agent) + { + UserRole::create([ + 'user_id' => $agent->user_id, + 'role_id' => Role::AGENT + ]); + }); + static::updated(function (Agent $agent) + { + if ($agent->trashed()) + { + UserRole::where([ + 'user_id' => $agent->user_id, + 'role_id' => Role::AGENT + ])->delete(); + } + else + { + UserRole::create([ + 'user_id' => $agent->user_id, + 'role_id' => Role::AGENT + ]); + } + }); + } } diff --git a/app/Models/Bitrix/SendClient.php b/app/Models/Bitrix/SendClient.php index 92af2e3..3421dd4 100644 --- a/app/Models/Bitrix/SendClient.php +++ b/app/Models/Bitrix/SendClient.php @@ -26,7 +26,7 @@ class SendClient public function __construct($id, $data) { - $this->ID = $id; + $this->ID = env('BITRIX_CODE_PREFIX', '') . $id; $data = array_change_key_case($data, CASE_UPPER); $finalData = []; $refl = new \ReflectionClass(__CLASS__); diff --git a/app/Models/Company/CompanyAdmin.php b/app/Models/Company/CompanyAdmin.php index 8a27f00..380d5a9 100644 --- a/app/Models/Company/CompanyAdmin.php +++ b/app/Models/Company/CompanyAdmin.php @@ -5,6 +5,9 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use App\Models\User\UserRole; +use App\Models\User\Role; + class CompanyAdmin extends Model { use HasFactory; @@ -13,4 +16,22 @@ class CompanyAdmin extends Model 'company_id' ]; + protected static function booted(): void + { + static::created(function (CompanyAdmin $admin) + { + UserRole::create([ + 'user_id' => $admin->user_id, + 'role_id' => Role::COMPANY_ADMIN + ]); + }); + static::deleted(function (CompanyAdmin $admin) + { + UserRole::where([ + 'user_id' => $admin->user_id, + 'role_id' => Role::COMPANY_ADMIN + ])->delete(); + }); + + } } diff --git a/app/Models/Deal/Contract.php b/app/Models/Deal/Contract.php new file mode 100644 index 0000000..6d23d59 --- /dev/null +++ b/app/Models/Deal/Contract.php @@ -0,0 +1,28 @@ +belongsTo(Deal::class, 'deal_id'); + } + } diff --git a/app/Models/Deal/ContractStatus.php b/app/Models/Deal/ContractStatus.php new file mode 100644 index 0000000..f294dd8 --- /dev/null +++ b/app/Models/Deal/ContractStatus.php @@ -0,0 +1,11 @@ +belongsTo(\App\Models\Agent\Agent::class, 'agent_id'); } + + public function contract() + { + return $this->hasOne(Contract::class, 'deal_id'); + } + + protected static function booted(): void + { + static::created(function (Deal $deal) + { + UserRole::create([ + 'user_id' => $deal->client_id, + 'role_id' => Role::CLIENT + ]); + }); + static::deleted(function (Deal $deal) + { + UserRole::where([ + 'user_id' => $deal->client_id, + 'role_id' => Role::CLIENT + ])->delete(); + }); + + } } diff --git a/app/Models/User/Role.php b/app/Models/User/Role.php new file mode 100644 index 0000000..67a5ace --- /dev/null +++ b/app/Models/User/Role.php @@ -0,0 +1,17 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + + DB::table('roles')->insert([ + ['id' => 1, 'name' => 'Super admin'], + ['id' => 2, 'name' => 'Company admin'], + ['id' => 3, 'name' => 'Agent'], + ['id' => 4, 'name' => 'Client'], + ]); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('roles'); + } + }; diff --git a/database/migrations/2025_03_12_024023_create_user_roles_table.php b/database/migrations/2025_03_12_024023_create_user_roles_table.php new file mode 100644 index 0000000..8b28d8d --- /dev/null +++ b/database/migrations/2025_03_12_024023_create_user_roles_table.php @@ -0,0 +1,30 @@ +id(); + $table->foreignId('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreignId(column: 'role_id')->references('id')->on('roles')->onDelete('cascade'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('user_roles'); + } + }; diff --git a/database/migrations/2025_03_12_145038_create_client_contract_table.php b/database/migrations/2025_03_12_145038_create_client_contract_table.php new file mode 100644 index 0000000..d967f4f --- /dev/null +++ b/database/migrations/2025_03_12_145038_create_client_contract_table.php @@ -0,0 +1,35 @@ +id(); + $table->foreignId('deal_id')->references('id')->on('deals')->onDelete('cascade'); + $table->enum('status', ['NEW', 'DECLINE', 'TREATY', 'SUCCESS', 'RESERVATION'])->default('NEW'); + $table->string('comment')->nullable(); + $table->float('price')->nullable(); + $table->float('reward')->nullable(); + $table->float('square')->nullable(); + $table->integer('floor')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('client_contract'); + } + }; diff --git a/lang/ru.json b/lang/ru.json index 1a87168..f6a9108 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -29,5 +29,6 @@ "Phone": "Номер телефона", "Email": "Электронная почта", "SelfEmployer name": "ФИО полностью", - "SoleProperty name": "ФИО полностью" + "SoleProperty name": "ФИО полностью", + "contract status new": "Новый" } \ No newline at end of file diff --git a/resources/views/clients/contract/index.blade.php b/resources/views/clients/contract/index.blade.php new file mode 100644 index 0000000..4e22527 --- /dev/null +++ b/resources/views/clients/contract/index.blade.php @@ -0,0 +1,110 @@ +@extends('layouts.app') + +@section('content') +
@@ -66,7 +66,7 @@ class="badge bg-light text-dark border-secondary bg-opacity-75 fs-6 rounded-pill
10 августа 2024 г.
@@ -83,7 +83,7 @@ class="badge bg-light text-dark border-secondary bg-opacity-75 fs-6 rounded-pill
10 августа 2024 г.
diff --git a/resources/views/makets/projects.blade.php b/resources/views/makets/projects.blade.php
index d8dc3d3..11c7f1e 100644
--- a/resources/views/makets/projects.blade.php
+++ b/resources/views/makets/projects.blade.php
@@ -14,8 +14,8 @@
-
+ Иркутск, ул. 4-я Совесткая, 11
Иркутск, ул. 4-я Совесткая, 11
-
-
+ Иркутск, ул. 4-я Совесткая, 11
Иркутск, ул. 4-я Совесткая, 11
-
-
+ Иркутск, ул. 4-я Совесткая, 11
Иркутск, ул. 4-я Совесткая, 11
-
- Иркутск, ул. 4-я Совесткая, 11
-
- Иркутск, ул. 4-я Совесткая, 11
-
- Иркутск, ул. 4-я Совесткая, 11
-
- Иркутск, ул. 4-я Совесткая, 11
-
- Иркутск, ул. 4-я Совесткая, 11
-
- Иркутск, ул. 4-я Совесткая, 11
-
@@ -130,7 +130,7 @@ class="" alt="...">
Иркутск, ул. 4-я Совесткая, 11
@@ -149,7 +149,7 @@ class="" alt="...">
Иркутск, ул. 4-я Совесткая, 11
diff --git a/routes/api.php b/routes/api.php
index da06763..94321dc 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -5,6 +5,7 @@
use App\Http\Controllers\ConfirmClientFromBitrix;
use App\Http\Controllers\Company\ConfirmCompanyController;
+use App\Http\Controllers\Bitrix\ClientsApiController;
/*
|--------------------------------------------------------------------------
@@ -17,9 +18,13 @@
|
*/
-Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
+Route::middleware('auth:sanctum')->get('/user', function (Request $request)
+ {
return $request->user();
-});
+ });
-Route::post('/client/confirm', [ConfirmClientFromBitrix::class, 'confirm'])->name('deal.confirm');
-Route::post('/company/status/update', ConfirmCompanyController::class)->name('company.status.update');
\ No newline at end of file
+Route::post('/client', [ClientsApiController::class, 'index'])->name('api.client');
+
+//Route::post('/client/confirm', [ConfirmClientFromBitrix::class, 'confirm'])->name('deal.confirm');
+//Route::post('/client/{$deal}/contract', CoController::class)->name('company.status.update');
+Route::post('/company/status/update', ConfirmCompanyController::class)->name('company.status.update');
diff --git a/routes/web.php b/routes/web.php
index d592d74..37109c4 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -39,6 +39,7 @@
{
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/clients/table', [App\Http\Controllers\ClientsTableController::class, 'index'])->name('clients.table');
+ Route::get('/contract/{contract}', [App\Http\Controllers\Deal\ContractController::class, 'index'])->name('contract');
Route::get('/company/details/', [App\Http\Controllers\Company\DetailsController::class, 'index'])->name('company.details');
Route::post('/company/{company}/details/', [App\Http\Controllers\Company\DetailsController::class, 'store'])->name('company.details.store');
Route::get('/agents/table', [App\Http\Controllers\Company\AgentsTableController::class, 'index'])->name('company.agents.table');