From 58f59312710f3f90145db99587cfbdf16a415838 Mon Sep 17 00:00:00 2001 From: hskwon Date: Tue, 9 Dec 2025 21:49:59 +0900 Subject: [PATCH] =?UTF-8?q?AdminPmIssue=20=EB=AA=A8=EB=8D=B8=EC=97=90=20?= =?UTF-8?q?=EB=A7=88=EA=B0=90=EC=9D=BC=20=EA=B4=80=EB=A0=A8=20=EC=8A=A4?= =?UTF-8?q?=EC=BD=94=ED=94=84/=EC=86=8D=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scopeOverdue: 마감일 지난 미해결 이슈 필터 - scopeDueSoon: 마감일 임박 이슈 필터 (N일 이내) - scopeNeedsAttention: 주의 필요 이슈 통합 스코프 - getDdayAttribute: D-day 계산 접근자 - getDueStatusAttribute: 마감 상태 접근자 (overdue/due_soon/normal) --- app/Models/Admin/AdminPmIssue.php | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/app/Models/Admin/AdminPmIssue.php b/app/Models/Admin/AdminPmIssue.php index 696c0c1b..e1feb560 100644 --- a/app/Models/Admin/AdminPmIssue.php +++ b/app/Models/Admin/AdminPmIssue.php @@ -136,6 +136,74 @@ public function scopeOpen($query) return $query->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]); } + /** + * 마감일 지난 이슈 (미해결) + */ + public function scopeOverdue($query) + { + return $query->whereNotNull('due_date') + ->where('due_date', '<', now()->startOfDay()) + ->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]); + } + + /** + * 마감일 임박 (N일 이내, 미해결) + */ + public function scopeDueSoon($query, int $days = 3) + { + return $query->whereNotNull('due_date') + ->whereBetween('due_date', [now()->startOfDay(), now()->addDays($days)->endOfDay()]) + ->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]); + } + + /** + * 주의 필요 이슈 (마감 초과 + 마감 임박 + 긴급) + */ + public function scopeNeedsAttention($query) + { + return $query->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]) + ->where(function ($q) { + $q->where('is_urgent', true) + ->orWhere(function ($q2) { + $q2->whereNotNull('due_date') + ->where('due_date', '<=', now()->addDays(3)->endOfDay()); + }); + }); + } + + /** + * D-day 계산 + */ + public function getDdayAttribute(): ?int + { + if (! $this->due_date) { + return null; + } + + return now()->startOfDay()->diffInDays($this->due_date, false); + } + + /** + * 마감 상태 (overdue, due_soon, normal, null) + */ + public function getDueStatusAttribute(): ?string + { + if (! $this->due_date || in_array($this->status, [self::STATUS_RESOLVED, self::STATUS_CLOSED])) { + return null; + } + + $dday = $this->dday; + + if ($dday < 0) { + return 'overdue'; + } + if ($dday <= 3) { + return 'due_soon'; + } + + return 'normal'; + } + /** * 관계: 프로젝트 */