diff --git a/app/Http/Controllers/ClientsTableController.php b/app/Http/Controllers/ClientsTableController.php index 1b67922..164ea4a 100644 --- a/app/Http/Controllers/ClientsTableController.php +++ b/app/Http/Controllers/ClientsTableController.php @@ -4,7 +4,7 @@ use Illuminate\Http\Request; -use App\Models\Deal; +use App\Models\Deal\Deal; use App\Models\Agent\Agent; use App\Models\City; diff --git a/app/Http/Controllers/ConfirmClientFromBitrix.php b/app/Http/Controllers/ConfirmClientFromBitrix.php index d0a23f3..7f81456 100644 --- a/app/Http/Controllers/ConfirmClientFromBitrix.php +++ b/app/Http/Controllers/ConfirmClientFromBitrix.php @@ -3,8 +3,8 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; - -use App\Models\Deal; +use App\Models\Deal\Deal; +use App\Models\Deal\DealStatus; class ConfirmClientFromBitrix extends Controller { @@ -13,11 +13,11 @@ public function confirm(Request $request) $deal = Deal::where('confirm_token', $request->hash)->first(); if ($request->is_unique == true) { - $deal->is_unique = true; + $deal->status = DealStatus::UNIQUE; } else { - $deal->is_unique = false; + $deal->is_unique = DealStatus::NOT_UNIQUE; } $deal->save(); return $deal->id; diff --git a/app/Livewire/AgentsTable.php b/app/Livewire/AgentsTable.php index 6f0c230..7bf416c 100644 --- a/app/Livewire/AgentsTable.php +++ b/app/Livewire/AgentsTable.php @@ -8,7 +8,7 @@ use App\Models\Company\CompanyAdmin; use App\Models\Agent\Agent; use App\Models\Agent\AgentStatus; -use App\Models\Deal; +use App\Models\Deal\Deal; class AgentsTable extends Component { diff --git a/app/Livewire/ClientsTable.php b/app/Livewire/ClientsTable.php index 93a33db..abed761 100644 --- a/app/Livewire/ClientsTable.php +++ b/app/Livewire/ClientsTable.php @@ -7,7 +7,7 @@ use Livewire\WithoutUrlPagination; use App\Models\Agent\Agent; -use App\Models\Deal; +use App\Models\Deal\Deal; class ClientsTable extends Component { diff --git a/app/Livewire/CreateClientForm.php b/app/Livewire/CreateClientForm.php index 6454300..0fda970 100644 --- a/app/Livewire/CreateClientForm.php +++ b/app/Livewire/CreateClientForm.php @@ -4,9 +4,9 @@ use Livewire\Component; use App\Models\User; -use App\Models\Deal; +use App\Models\Deal\Deal; +use App\Models\Deal\DealStatus; use App\Models\Complex; -use App\Models\Status; use App\Models\Agent\Agent; use App\Models\Bitrix\SendClient; @@ -126,12 +126,13 @@ public function save() 'complex_id' => $this->client['complexId'] ]; $data['confirm_token'] = $this->client['confirmToken'] = hash('sha256', json_encode($data)); + if ($newDeal = Deal::create($data)) { if ($bitrixId = $this->sendToBitrix($newDeal->id)) { $newDeal->bitrix_id = $bitrixId; - $newDeal->status = 'MODERATION'; + $newDeal->status = DealStatus::MODERATION; $newDeal->save(); $this->result = $bitrixId; return $this->status = self::SUCCESS; diff --git a/app/Models/Agent/Agent.php b/app/Models/Agent/Agent.php index 1af8364..0b0ac64 100644 --- a/app/Models/Agent/Agent.php +++ b/app/Models/Agent/Agent.php @@ -9,7 +9,7 @@ use App\Models\Company\Company; use App\Models\User; -use App\Models\Deal; +use App\Models\Deal\Deal; class Agent extends Model { diff --git a/app/Models/Company/Details.php b/app/Models/Company/Details.php index 038bf2e..76c6cd9 100644 --- a/app/Models/Company/Details.php +++ b/app/Models/Company/Details.php @@ -7,27 +7,31 @@ use App\Models\Company\Company; class Details -{ + { use HasFactory; public $details; - public function __construct(Company $company) { + public function __construct(Company $company) + { $company; - if (!$company->details) { - if ($company->type == 'SELFEMP') + if (!$company->details) { + if ($company->type == 'SELFEMP') + { $company->details = $this->emptyForSelfEmp(); $company->save(); - }; + } + ; if ($company->type == 'AGENCY') - { + { $company->details = $this->emptyForAgency(); $company->save(); + } } - } $this->details = $company->details; - } + } - private function emptyForSelfEmp() { + private function emptyForSelfEmp() + { $data = [ 'user' => [ 'firstName' => '', @@ -49,9 +53,10 @@ private function emptyForSelfEmp() { ] ]; return $data; - } + } - private function emptyForAgency() { + private function emptyForAgency() + { $data = [ 'name' => '', 'fullName' => '', @@ -72,5 +77,5 @@ private function emptyForAgency() { ] ]; return $data; + } } -} diff --git a/app/Models/Deal.php b/app/Models/Deal/Deal.php similarity index 74% rename from app/Models/Deal.php rename to app/Models/Deal/Deal.php index 4de96ea..bf94172 100644 --- a/app/Models/Deal.php +++ b/app/Models/Deal/Deal.php @@ -1,15 +1,15 @@ belongsTo(\App\Models\Complex::class); - } + } - public function user() { + public function user() + { return $this->belongsTo(\App\Models\User::class, 'client_id'); + } } -} diff --git a/app/Models/Deal/DealStatus.php b/app/Models/Deal/DealStatus.php new file mode 100644 index 0000000..9a805e3 --- /dev/null +++ b/app/Models/Deal/DealStatus.php @@ -0,0 +1,11 @@ +id(); $table->foreignId('client_id')->references('id')->on('users'); $table->foreignId('complex_id')->references('id')->on('complexes')->onDelete('cascade'); $table->foreignId('agent_id')->references('id')->on('agents')->onDelete('cascade'); $table->string('bitrix_id')->nullable(); $table->string('confirm_token')->nullable(); - $table->enum('status',['NEW','MODERATION','UNIQUE','NOT UNIQUE'])->default('NEW'); + $table->enum('status', ['NEW', 'MODERATION', 'UNIQUE', 'NOT UNIQUE'])->default('NEW'); $table->timestamps(); - }); - } + }); + } /** * Reverse the migrations. */ public function down(): void - { + { Schema::dropIfExists('clients'); - } -}; + } + };