From fc2e050ac68a9d240c5cc1bdd9026abcfaee531f Mon Sep 17 00:00:00 2001 From: developer Date: Fri, 5 Dec 2025 07:08:15 +0800 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D0=B5=D0=B9=20=D0=B8=D0=B7=20=D0=B0=D0=B4?= =?UTF-8?q?=D0=BC=D0=B8=D0=BD=D0=BA=D0=B8,=20=D1=84=D0=B8=D0=BA=D1=81=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D0=B5=D0=B9=20-=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=B0=D0=B3=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Modules/Main/Helpers/helper.php | 87 ++++++++++++----------------- 1 file changed, 35 insertions(+), 52 deletions(-) diff --git a/app/Modules/Main/Helpers/helper.php b/app/Modules/Main/Helpers/helper.php index 5df408e..8b7f1d4 100644 --- a/app/Modules/Main/Helpers/helper.php +++ b/app/Modules/Main/Helpers/helper.php @@ -7,106 +7,89 @@ use Modules\Main\Models\Agent\Agent; use Modules\Main\Models\Complex; -if (!function_exists('AdminCompanyOfUser')) -{ +if (!function_exists('AdminCompanyOfUser')) { function AdminCompanyOfUser() { - if ($adminAccount = CompanyAdmin::where('user_id', auth()->user()->id)->first()) - { + if ($adminAccount = CompanyAdmin::where('user_id', auth()->user()->id)->first()) { return $adminAccount->company; - } - else - { + } else { return false; } } } -if (!function_exists(function: 'AgentCompanyOfUser')) -{ +if (!function_exists(function: 'AgentCompanyOfUser')) { function AgentCompanyOfUser() { $city = false; - if ($adminAccount = Agent::where('user_id', auth()->user()->id)->first()) - { + if ($adminAccount = Agent::where('user_id', auth()->user()->id)->first()) { return $adminAccount->company; - } - else - { + } else { return false; } } } -if (!function_exists('GetAvailableAgents')) -{ +if (!function_exists('GetAvailableAgents')) { function GetAvailableAgents() { - $agents = []; - if ($adminCompany = AdminCompanyOfUser()) - { + $agents = false; + if ($adminCompany = AdminCompanyOfUser()) { $agents = Agent::where('company_id', $adminCompany->id); - } - else - { + } else { $cityManager = CityManager::where('user_id', auth()->user()->id); - if ($cityManager->count()) - { - $agents = Agent::whereIn('company_id', Company::where('city_id', $cityManager->city_id)->get()->pluck('company_id')); - } - else - { + if ($cityManager->count()) { + $companies = Company::where('city_id', $cityManager->first()->city_id); + if ($companies->count()) { + $agents = Agent::whereIn('company_id', $companies->get()->pluck('id')); + } + } else { $agents = Agent::where('user_id', auth()->user()->id); } } + if ($agents === false) { + return []; + } $agents->with('company:id,name'); $agents->with('user:id,name'); return $agents->get()->toArray(); } } -if (!function_exists('GetAvailableComplexes')) -{ +if (!function_exists('GetAvailableComplexes')) { function GetAvailableComplexes() { $complexes = false; - if ($adminCompany = AdminCompanyOfUser()) - { + if ($adminCompany = AdminCompanyOfUser()) { $complexes = Complex::where('city_id', $adminCompany->city_id); - } - else - { - if ($agent = Agent::where('user_id', auth()->user()->id)->first()) - { - $complexes = Complex::where('city_id', $agent->company->city_id); + } else { + $cityManager = CityManager::where('user_id', auth()->user()->id); + if ($cityManager->count()) { + $complexes = Complex::where('city_id', $cityManager->first()->city_id); + } else { + if ($agent = Agent::where('user_id', auth()->user()->id)->first()) { + $complexes = Complex::where('city_id', $agent->company->city_id); + } } } - if ($complexes) - { + if ($complexes) { return $complexes->get()->toArray(); } return []; } } -if (!function_exists('GetAvailableCities')) -{ +if (!function_exists('GetAvailableCities')) { function GetAvailableCities() { $agents = []; - if ($adminCompany = AdminCompanyOfUser()) - { + if ($adminCompany = AdminCompanyOfUser()) { $agents = Agent::where('company_id', $adminCompany->id); - } - else - { + } else { $cityManager = CityManager::where('user_id', auth()->user()->id); - if ($cityManager->count()) - { + if ($cityManager->count()) { $agents = Agent::whereIn('company_id', Company::where('city_id', $cityManager->city_id)->get()->pluck('company_id')); - } - else - { + } else { $agents = Agent::where('user_id', auth()->user()->id); } }