- 파트너 명함신청 (/sales/business-cards): 모든 사용자 (신청폼+이력) - 명함신청 처리 (/sales/business-cards/manage): 관리자 전용 (2분할) - 뱃지를 manage 라우트에 연동
80 lines
2.8 KiB
PHP
80 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Tenants\Tenant;
|
|
use App\Services\Sales\BusinessCardRequestService;
|
|
use App\Services\Sales\SalesManagerService;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class ViewServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// 모든 뷰에 테넌트 목록 공유 (전역용)
|
|
View::composer('*', function ($view) {
|
|
if (auth()->check()) {
|
|
// 테넌트가 선택되지 않은 경우 자동으로 HQ 테넌트 설정
|
|
if (! session('selected_tenant_id')) {
|
|
$hqTenant = auth()->user()->getHQTenant();
|
|
if ($hqTenant) {
|
|
session(['selected_tenant_id' => $hqTenant->id]);
|
|
}
|
|
}
|
|
|
|
$globalTenants = Tenant::active()
|
|
->orderBy('company_name')
|
|
->get(['id', 'company_name', 'code']);
|
|
|
|
$view->with('globalTenants', $globalTenants);
|
|
}
|
|
});
|
|
|
|
// 사이드바 메뉴 뱃지 데이터 (전역 공유 - 컴포넌트에서도 접근 가능)
|
|
View::composer('partials.sidebar', function ($view) {
|
|
$menuBadges = [
|
|
'byRoute' => [], // 라우트명 기준
|
|
'byUrl' => [], // URL 기준
|
|
];
|
|
|
|
if (auth()->check()) {
|
|
try {
|
|
$salesManagerService = app(SalesManagerService::class);
|
|
$approvalStats = $salesManagerService->getApprovalStats();
|
|
|
|
// 영업파트너 승인 대기 건수
|
|
if ($approvalStats['pending'] > 0) {
|
|
$menuBadges['byRoute']['sales.managers.approvals'] = $approvalStats['pending'];
|
|
$menuBadges['byUrl']['/sales/managers/approvals'] = $approvalStats['pending'];
|
|
}
|
|
|
|
// 명함신청 대기 건수 (관리자용 처리 메뉴에 표시)
|
|
$businessCardService = app(BusinessCardRequestService::class);
|
|
$businessCardPending = $businessCardService->getPendingCount();
|
|
if ($businessCardPending > 0) {
|
|
$menuBadges['byRoute']['sales.business-cards.manage'] = $businessCardPending;
|
|
$menuBadges['byUrl']['/sales/business-cards/manage'] = $businessCardPending;
|
|
}
|
|
} catch (\Exception $e) {
|
|
// 서비스 오류 시 무시
|
|
}
|
|
}
|
|
|
|
// View::share로 전역 공유 (Blade 컴포넌트에서도 접근 가능)
|
|
View::share('menuBadges', $menuBadges);
|
|
});
|
|
}
|
|
}
|