refactor:영업관리 데이터를 DB 테이블로 변경
- 모델 추가: SalesPartner, SalesTenantManagement, SalesScenarioChecklist, SalesConsultation - 모델 위치 이동: app/Models/ → app/Models/Sales/ - 컨트롤러 수정: 캐시 대신 DB 모델 사용 - 뷰 수정: Eloquent 모델 속성 사용 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Sales;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Sales\SalesTenantManagement;
|
||||
use App\Models\Tenants\Tenant;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -103,12 +104,20 @@ private function getDashboardData(Request $request): array
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
// 각 테넌트의 영업 관리 정보 로드
|
||||
$tenantIds = $tenants->pluck('id')->toArray();
|
||||
$managements = SalesTenantManagement::whereIn('tenant_id', $tenantIds)
|
||||
->with('manager')
|
||||
->get()
|
||||
->keyBy('tenant_id');
|
||||
|
||||
return compact(
|
||||
'stats',
|
||||
'commissionByRole',
|
||||
'totalCommissionRatio',
|
||||
'tenantStats',
|
||||
'tenants',
|
||||
'managements',
|
||||
'period',
|
||||
'year',
|
||||
'month',
|
||||
@@ -129,17 +138,15 @@ public function assignManager(int $tenantId, Request $request): JsonResponse
|
||||
$tenant = Tenant::findOrFail($tenantId);
|
||||
$managerId = $request->input('manager_id');
|
||||
|
||||
// 캐시 키
|
||||
$cacheKey = "tenant_manager:{$tenantId}";
|
||||
// 테넌트 영업 관리 정보 조회 또는 생성
|
||||
$management = SalesTenantManagement::findOrCreateByTenant($tenantId);
|
||||
|
||||
if ($managerId === 0) {
|
||||
// 본인으로 설정 (현재 로그인 사용자)
|
||||
$manager = auth()->user();
|
||||
cache()->put($cacheKey, [
|
||||
'id' => $manager->id,
|
||||
'name' => $manager->name,
|
||||
'is_self' => true,
|
||||
], now()->addDays(365));
|
||||
$management->update([
|
||||
'manager_user_id' => $manager->id,
|
||||
]);
|
||||
} else {
|
||||
// 특정 매니저 지정
|
||||
$manager = User::find($managerId);
|
||||
@@ -150,11 +157,9 @@ public function assignManager(int $tenantId, Request $request): JsonResponse
|
||||
], 404);
|
||||
}
|
||||
|
||||
cache()->put($cacheKey, [
|
||||
'id' => $manager->id,
|
||||
'name' => $manager->name,
|
||||
'is_self' => $manager->id === auth()->id(),
|
||||
], now()->addDays(365));
|
||||
$management->update([
|
||||
'manager_user_id' => $manager->id,
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
|
||||
Reference in New Issue
Block a user