From 7fddfd54c7c12e3a85d1ff3f80ddd312457f1636 Mon Sep 17 00:00:00 2001 From: Thekindbull Date: Fri, 25 Apr 2025 10:26:13 +0800 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D0=B0=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BD=D0=B0=D0=B3=D1=80=D0=B0=D0=B6=D0=B4?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B2=20=D0=B0=D0=B4=D0=BC=D0=B8?= =?UTF-8?q?=D0=BD=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Livewire/CreateClientForm.php | 181 +++++------ .../Controllers/AdminCitiesController.php | 8 +- app/Modules/Admin/Http/Livewire/Payments.php | 27 +- app/Modules/Admin/Routes/web.php | 2 +- .../Admin/Views/cities/index.blade.php | 28 +- .../Admin/Views/payments/agents.blade.php | 307 +++++++++++------- .../Admin/Views/payments/companies.blade.php | 231 +++++++------ app/Modules/Payment/Traits/Paymentable.php | 7 +- resources/css/app.css | 4 + 9 files changed, 476 insertions(+), 319 deletions(-) diff --git a/app/Livewire/CreateClientForm.php b/app/Livewire/CreateClientForm.php index 6f7d2da..0ddf6a2 100644 --- a/app/Livewire/CreateClientForm.php +++ b/app/Livewire/CreateClientForm.php @@ -13,93 +13,90 @@ class CreateClientForm extends Component - { - const NEW = 1; - const ERROR = 2; +{ + const NEW = 1; + const ERROR = 2; const SUCCESS = 3; - const READY = 4; + const READY = 4; public $client; public $complexes; public $status; public $result; public $agent; protected $messages = [ - 'client.firstName.required' => 'Необходимо указать имя клиента', + 'client.firstName.required' => 'Необходимо указать имя клиента', 'client.secondName.required' => 'Необходимо указать фамилию клиента', - 'client.phone.required' => 'Необходимо указать телефон без кода страны "+7" или "8"', - 'client.phone.regex' => 'Телефон должен содержать 10 симвлов без указания кода страны "+7" или "8"', - 'client.phone.unique' => 'Клиент с таким телефоном уже существует', - 'agent.integer' => 'Необходимо указать агента, от которого добавляется контакт' + 'client.phone.required' => 'Необходимо указать телефон без кода страны "+7" или "8"', + 'client.phone.regex' => 'Телефон должен содержать 10 симвлов без указания кода страны "+7" или "8"', + 'client.phone.unique' => 'Клиент с таким телефоном уже существует', + 'agent.integer' => 'Необходимо указать агента, от которого добавляется контакт' ]; protected function rules() - { + { return [ - 'agent' => ['required', 'integer'], - 'client.firstName' => ['required', 'string', 'max:255'], + 'agent' => ['required', 'integer'], + 'client.firstName' => ['required', 'string', 'max:255'], 'client.secondName' => ['required', 'string', 'max:255'], - 'client.phone' => ['required', 'string', 'regex:/\(?([0-9]{3})\)([-]{1})([0-9]{3})([-]{1})([0-9]{4})/i'] + //'client.phone' => ['required', 'string', 'regex:/^(\+7)([0-9]{3})([-]{1})([0-9]{3})([-]{1})([0-9]{4})/i'] + 'client.phone' => ['required', 'string', 'regex:/^\+7 \d{3} \d{3}-\d{2}-\d{2}$/'] ]; - } + } public function mount() - { + { $userBroker = Agent::where('user_id', auth()->user()->id)->first(); $this->complexes = Complex::all(); $this->client = [ - 'firstName' => '', + 'firstName' => '', 'secondName' => '', - 'phone' => '', - 'complexId' => '' + 'phone' => '', + 'complexId' => '' ]; $this->status = self::NEW; if ($agent = Agent::where('user_id', auth()->user()->id)->first()) - { - $this->agent = $agent->id; - } - else - { - $this->agent = false; - } - } - public function update() { + $this->agent = $agent->id; } + else + { + $this->agent = false; + } + } + public function update() + { + } public function updated($propertyName) - { + { $this->status = self::NEW; if ($propertyName == 'client.phone') - { + { //$this->dispatch('phone-updated', ['newPhone' => 111]); //$this->js("checkPhoneFormat('123')"); - $phone = preg_replace('/[^0-9]/', "", $this->client['phone']); - if (strlen($phone) == 10) - { - $sArea = substr($phone, 0, 3); - $sPrefix = substr($phone, 3, 3); - $sNumber = substr($phone, 6, 4); - $phone = "(" . $sArea . ")-" . $sPrefix . "-" . $sNumber; - $this->client['phone'] = $phone; - } - elseif (strlen($this->client['phone']) == 1) - { - if ($this->client['phone'] == "8" || $this->client['phone'] == "7" || $this->client['phone'] == "+") - { - $this->client['phone'] = null; - } - else - { - $this->client['phone'] = $phone; - } - } - else - { - $this->client['phone'] = $phone; - } + $phone = preg_replace('/[^0-9\+]+/', "", $this->client['phone']); + if (strlen($this->client['phone']) <= 2) + { + $this->client['phone'] = "+7"; + } + elseif (strlen($phone) <= 12) + { + $code = substr($phone, 0, 2); + $sArea = substr($phone, 2, 3); + $sPrefix = substr($phone, 5, 3); + $sNumber1 = substr($phone, 8, 2); + $sNumber2 = substr($phone, 10, 2); + + $phone = $code . " " . $sArea . " " . $sPrefix . "-" . $sNumber1 . "-" . $sNumber2; + $this->client['phone'] = $phone; + } + else + { + $this->client['phone'] = $phone; } - $this->validateOnly($propertyName); } + $this->validateOnly($propertyName); + } public function render() - { + { if ( $this->client['firstName'] && $this->client['secondName'] @@ -107,95 +104,95 @@ public function render() && $this->client['complexId'] && $this->status == self::NEW ) - { + { $this->status = self::READY; - } + } $data = [ 'adminAccount' => false ]; if ($adminAccount = CompanyAdmin::where('user_id', auth()->user()->id)->first()) - { + { $data = [ 'adminAccount' => $adminAccount, - 'agents' => Agent::where('company_id', $adminAccount->company_id)->get() + 'agents' => Agent::where('company_id', $adminAccount->company_id)->get() ]; - } + } return view( 'livewire.create-client-form', $data ); - } + } public function resetData() - { + { $this->mount(); - } + } public function back() - { + { $this->status = self::NEW; - } + } public function save() - { + { $validated = $this->validate($this->rules()); $phone = '+7' . $this->client['phone']; $newUser = User::updateOrCreate( ['phone' => $phone], [ - 'name' => trim($this->client['firstName'] . ' ' . $this->client['secondName']), + 'name' => trim($this->client['firstName'] . ' ' . $this->client['secondName']), 'phone' => $phone ] ); $data = [ - 'agent_id' => $this->agent + 'agent_id' => $this->agent , - 'client_id' => $newUser->id + 'client_id' => $newUser->id , '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)) - { + { $newDeal->bitrix_id = $bitrixId; $newDeal->status = DealStatus::MODERATION; $newDeal->save(); $this->result = $bitrixId; return $this->status = self::SUCCESS; - } - else - { - $newDeal->delete(); - } } - return $this->status = self::ERROR; + else + { + $newDeal->delete(); + } } + return $this->status = self::ERROR; + } public function sendToBitrix(Deal $deal) - { + { //$user = auth()->user(); //$agent = Agent::where(column: 'user_id', $user->id)->first(); $agent = $deal->agent; $agentName = $agent->user->getPartialsName(); $data = [ - 'CLIENT_FIRST_NAME' => $this->client['firstName'], + 'CLIENT_FIRST_NAME' => $this->client['firstName'], 'CLIENT_SECOND_NAME' => $this->client['secondName'], - 'CLIENT_PHONE' => '+7' . $this->client['phone'], - 'BROKER_FIRST_NAME' => $agentName['firstName'], + 'CLIENT_PHONE' => '+7' . $this->client['phone'], + 'BROKER_FIRST_NAME' => $agentName['firstName'], 'BROKER_SECOND_NAME' => $agentName['secondName'], - 'BROKER_PHONE' => $agent->user->phone, - 'BROKER_INN' => $agent->company->inn, - 'OBJECT_NAME' => Complex::find($this->client['complexId'])->name, - 'CALLBACK_URL' => route('api.client', ['hash' => $this->client['confirmToken']]), + 'BROKER_PHONE' => $agent->user->phone, + 'BROKER_INN' => $agent->company->inn, + 'OBJECT_NAME' => Complex::find($this->client['complexId'])->name, + 'CALLBACK_URL' => route('api.client', ['hash' => $this->client['confirmToken']]), ]; $sender = new SendClient($deal->id, $data); $response = $sender->send(); if ($response) - { + { return $response; - } - else - { - return false; - } } - } \ No newline at end of file + else + { + return false; + } + } +} \ No newline at end of file diff --git a/app/Modules/Admin/Http/Controllers/AdminCitiesController.php b/app/Modules/Admin/Http/Controllers/AdminCitiesController.php index b10c0cb..9a6f600 100644 --- a/app/Modules/Admin/Http/Controllers/AdminCitiesController.php +++ b/app/Modules/Admin/Http/Controllers/AdminCitiesController.php @@ -31,17 +31,11 @@ public function index(Request $request) 'filter' => $request->filter ]); } - public function edit(City $city) - { - return view('admin::companies.edit', [ - 'city' => $city, - ]); - } public function update(Request $request, City $city) { $city->update($request->only('name')); - return to_route('admin.companies'); + return back(); } public function create(Request $request) diff --git a/app/Modules/Admin/Http/Livewire/Payments.php b/app/Modules/Admin/Http/Livewire/Payments.php index f015c87..79b84d8 100644 --- a/app/Modules/Admin/Http/Livewire/Payments.php +++ b/app/Modules/Admin/Http/Livewire/Payments.php @@ -8,7 +8,7 @@ use App\Models\Agent\Agent; class Payments extends Component { - public $value; + public $newValue; public $companyId; public function mount() { @@ -27,8 +27,8 @@ public function back() public function setPaymentValueForCompany(Company $company, Complex $complex) { - $company->setPayment($complex, $this->value); - $this->value = null; + $company->setPayment($complex, $this->newValue); + $this->newValue = null; } public function unsetPaymentForCompany(Company $company, Complex $complex) @@ -38,14 +38,14 @@ public function unsetPaymentForCompany(Company $company, Complex $complex) public function setPaymentValueForAgent(Agent $agent, Complex $complex) { - $agent->setPayment($complex, $this->value); - $this->value = null; + $agent->setPayment($complex, $this->newValue); + $this->newValue = null; } public function setPaymentAsParentForAgent(Agent $agent, Complex $complex) { $agent->setAsParentPayment($complex); - $this->value = null; + $this->newValue = null; } public function unsetPaymentForAgent(Agent $agent, Complex $complex) @@ -53,6 +53,21 @@ public function unsetPaymentForAgent(Agent $agent, Complex $complex) $agent->unsetPayment($complex); } + public function setPaymentForAllAgentOfCompany(Company $company, Complex $complex) + { + $compPayment = $company->getPaymentable($complex); + $compPayment = $compPayment->value; + if ($compPayment == null || $compPayment == -1) + { + return false; + } + $agents = Agent::where('company_id', $company->id)->get(); + foreach ($agents as $agent) + { + $agent->setPayment($complex, $compPayment); + } + } + public function render() { if ($this->companyId) diff --git a/app/Modules/Admin/Routes/web.php b/app/Modules/Admin/Routes/web.php index 9e33fa1..ecce70e 100644 --- a/app/Modules/Admin/Routes/web.php +++ b/app/Modules/Admin/Routes/web.php @@ -28,7 +28,7 @@ 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/{city}/edit', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'edit'])->name('admin.cities.edit'); + Route::post('/admin/cities/{city}/update', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'update'])->name('admin.cities.update'); Route::post('/admin/cities/create', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'create'])->name('admin.cities.create'); Route::post('/admin/cities/{city}/delete', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'delete'])->name('admin.cities.delete'); Route::post('/admin/cities/{city}/restore', [Modules\Admin\Http\Controllers\AdminCitiesController::class, 'restore'])->withTrashed()->name('admin.cities.restore'); diff --git a/app/Modules/Admin/Views/cities/index.blade.php b/app/Modules/Admin/Views/cities/index.blade.php index 13a6bf7..cab3f3a 100644 --- a/app/Modules/Admin/Views/cities/index.blade.php +++ b/app/Modules/Admin/Views/cities/index.blade.php @@ -1,6 +1,11 @@ @php($title = 'Города') @extends('layouts.admin') @section('content') +
- {{ $city->name }} +
+ {{ $city->name }} +
+
+ + @csrf + + + +
{{ $city->created_at ? $city->created_at->diffForHumans() : '' }} @@ -59,9 +76,12 @@ @else - Редактировать -
+ + @csrf
diff --git a/app/Modules/Admin/Views/payments/agents.blade.php b/app/Modules/Admin/Views/payments/agents.blade.php index a5616a5..2e5775a 100644 --- a/app/Modules/Admin/Views/payments/agents.blade.php +++ b/app/Modules/Admin/Views/payments/agents.blade.php @@ -1,124 +1,209 @@
- -
- - - - - @foreach ($complexes as $complex) - - @endforeach - - - - @foreach ($agents as $agent) - - +
+ +
+
Агент - {{ $complex->name }} -
- @php($compPayment = $company->getPaymentable($complex)) - - @if ($compPayment->value === null) - Не установлено - @elseif($compPayment->value == -1) - Наследовать - @else - {{ $compPayment->value }} % - @endif - -
-
- {{ $agent->user->name }} -
+ + + @foreach ($complexes as $complex) - @php($paymentable = $agent->getPaymentable($complex)) - @endforeach - @endforeach - -
Агент - @if ($paymentable->value == null) + + {{ $complex->name }} +
+ {{ $complex->city->name }} +
+
+ @php($compPayment = $company->getPaymentable($complex)) - @elseif($paymentable->value == -1) - - @else - - @endif - +
+
+ + + @foreach ($agents as $agent) + + + {{ $agent->user->name }} + + @foreach ($complexes as $complex) + @php($paymentable = $agent->getPaymentable($complex)) + + @if ($paymentable->value == null) + + @elseif($paymentable->value == -1) + + @else + + @endif + + @endforeach + + @endforeach + + +
diff --git a/app/Modules/Admin/Views/payments/companies.blade.php b/app/Modules/Admin/Views/payments/companies.blade.php index d7f45f7..99e73e9 100644 --- a/app/Modules/Admin/Views/payments/companies.blade.php +++ b/app/Modules/Admin/Views/payments/companies.blade.php @@ -1,97 +1,144 @@
- - - - - @foreach ($complexes as $complex) - - @endforeach - - - - - @foreach ($companies as $company) - - +
+
Компания{{ $complex->name }} -
- {{ $company->name }} -
+ + + @foreach ($complexes as $complex) - @php($paymentable = $company->getPaymentable($complex)) - + @endforeach - - @endforeach - -
Компания - @if ($paymentable->value == null) - - @elseif($paymentable->value == -1) - - @else - - @endif - {{ $complex->name }} +
+ {{ $complex->city->name }} +
+
- -
+ + + @foreach ($companies as $company) + + + + {{ $company->name }} + + + + + + @foreach ($complexes as $complex) + @php($paymentable = $company->getPaymentable($complex)) + + @if ($paymentable->value == null) + + @elseif($paymentable->value == -1) + + @else + + @endif + + @endforeach + + @endforeach + + + +
diff --git a/app/Modules/Payment/Traits/Paymentable.php b/app/Modules/Payment/Traits/Paymentable.php index c0aee12..bfe7318 100644 --- a/app/Modules/Payment/Traits/Paymentable.php +++ b/app/Modules/Payment/Traits/Paymentable.php @@ -6,7 +6,7 @@ use App\Models\Complex; trait Paymentable { - private $defaultValue = null; // -1 || null + private $defaultValue = -1; // -1 || null protected static function boot() { parent::boot(); @@ -15,11 +15,6 @@ protected static function boot() { }); - - static::deleted(function ($item) - { - - }); } private function getClassName() diff --git a/resources/css/app.css b/resources/css/app.css index bb7b2a6..e488499 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -5,6 +5,10 @@ .bg-primary { border-color: #ce4711 !important; } +label { + color: rgba(var(--bs-body-color-rgb), .65); +} + .btn-secondary, .btn-secondary:disabled { color: white;