добавлена возможность создавать пользователей из
админки, фикс формы создания клиентов для пользователей - не агентов
This commit is contained in:
parent
8393a29876
commit
fc2e050ac6
@ -7,106 +7,89 @@
|
|||||||
use Modules\Main\Models\Agent\Agent;
|
use Modules\Main\Models\Agent\Agent;
|
||||||
use Modules\Main\Models\Complex;
|
use Modules\Main\Models\Complex;
|
||||||
|
|
||||||
if (!function_exists('AdminCompanyOfUser'))
|
if (!function_exists('AdminCompanyOfUser')) {
|
||||||
{
|
|
||||||
function 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;
|
return $adminAccount->company;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists(function: 'AgentCompanyOfUser'))
|
if (!function_exists(function: 'AgentCompanyOfUser')) {
|
||||||
{
|
|
||||||
function AgentCompanyOfUser()
|
function AgentCompanyOfUser()
|
||||||
{
|
{
|
||||||
$city = false;
|
$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;
|
return $adminAccount->company;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('GetAvailableAgents'))
|
if (!function_exists('GetAvailableAgents')) {
|
||||||
{
|
|
||||||
function GetAvailableAgents()
|
function GetAvailableAgents()
|
||||||
{
|
{
|
||||||
$agents = [];
|
$agents = false;
|
||||||
if ($adminCompany = AdminCompanyOfUser())
|
if ($adminCompany = AdminCompanyOfUser()) {
|
||||||
{
|
|
||||||
$agents = Agent::where('company_id', $adminCompany->id);
|
$agents = Agent::where('company_id', $adminCompany->id);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$cityManager = CityManager::where('user_id', auth()->user()->id);
|
$cityManager = CityManager::where('user_id', auth()->user()->id);
|
||||||
if ($cityManager->count())
|
if ($cityManager->count()) {
|
||||||
{
|
$companies = Company::where('city_id', $cityManager->first()->city_id);
|
||||||
$agents = Agent::whereIn('company_id', Company::where('city_id', $cityManager->city_id)->get()->pluck('company_id'));
|
if ($companies->count()) {
|
||||||
}
|
$agents = Agent::whereIn('company_id', $companies->get()->pluck('id'));
|
||||||
else
|
}
|
||||||
{
|
} else {
|
||||||
$agents = Agent::where('user_id', auth()->user()->id);
|
$agents = Agent::where('user_id', auth()->user()->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($agents === false) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
$agents->with('company:id,name');
|
$agents->with('company:id,name');
|
||||||
$agents->with('user:id,name');
|
$agents->with('user:id,name');
|
||||||
return $agents->get()->toArray();
|
return $agents->get()->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('GetAvailableComplexes'))
|
if (!function_exists('GetAvailableComplexes')) {
|
||||||
{
|
|
||||||
function GetAvailableComplexes()
|
function GetAvailableComplexes()
|
||||||
{
|
{
|
||||||
$complexes = false;
|
$complexes = false;
|
||||||
if ($adminCompany = AdminCompanyOfUser())
|
if ($adminCompany = AdminCompanyOfUser()) {
|
||||||
{
|
|
||||||
$complexes = Complex::where('city_id', $adminCompany->city_id);
|
$complexes = Complex::where('city_id', $adminCompany->city_id);
|
||||||
}
|
} else {
|
||||||
else
|
$cityManager = CityManager::where('user_id', auth()->user()->id);
|
||||||
{
|
if ($cityManager->count()) {
|
||||||
if ($agent = Agent::where('user_id', auth()->user()->id)->first())
|
$complexes = Complex::where('city_id', $cityManager->first()->city_id);
|
||||||
{
|
} else {
|
||||||
$complexes = Complex::where('city_id', $agent->company->city_id);
|
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 $complexes->get()->toArray();
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('GetAvailableCities'))
|
if (!function_exists('GetAvailableCities')) {
|
||||||
{
|
|
||||||
function GetAvailableCities()
|
function GetAvailableCities()
|
||||||
{
|
{
|
||||||
$agents = [];
|
$agents = [];
|
||||||
if ($adminCompany = AdminCompanyOfUser())
|
if ($adminCompany = AdminCompanyOfUser()) {
|
||||||
{
|
|
||||||
$agents = Agent::where('company_id', $adminCompany->id);
|
$agents = Agent::where('company_id', $adminCompany->id);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$cityManager = CityManager::where('user_id', auth()->user()->id);
|
$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'));
|
$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);
|
$agents = Agent::where('user_id', auth()->user()->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user