diff --git a/app/Controllers/Admin/Home.php b/app/Controllers/Admin/Home.php index 6323f90..d031dbf 100644 --- a/app/Controllers/Admin/Home.php +++ b/app/Controllers/Admin/Home.php @@ -64,23 +64,22 @@ class Home extends AdminController } return $result; } + + //Index,FieldForm관련 public function index(): RedirectResponse|string { $this->initAction(__FUNCTION__); - //최근 inverval(default : 7일)일간 신규서버 정보 + //Total 서버 현황 + $this->totalCounts = $this->getService()->getTotalCountsByType(); //LINE,IP,SERVER등 추가 FilterOption 셋팅용 foreach (SERVICE_ITEM_TYPES as $item_type => $label) { $this->setFilterFieldOption($item_type, $this->getService()->getFilterOptionsByItemType($item_type)); } + //interval을 기준으로 최근 신규 서비스정보 가져오기 $this->interval = intval($this->request->getVar('interval') ?? SERVICE_NEW_INTERVAL); - $entities = []; - foreach ($this->getService()->getEntitiesByNewService($this->interval) as $entity) { - $entities[$entity->getPK()] = $this->getService()->setItemEntitiesByService($entity); - } - $this->newServiceEntities = $entities; - $this->newServiceCount = count($this->newServiceEntities); - + $this->newServiceEntities = $this->getService()->getEntitiesByNewService($this->interval); + $this->newServiceCount = count($this->newServiceEntities); //미납 서버 정보 $this->unPaidEntities = $this->getServicePaymentService()->getEntitiesByUnPaid(); $this->unPaidCount = count($this->unPaidEntities); diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index e03677d..76e8cb7 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -138,16 +138,45 @@ class ServiceService extends CustomerService foreach (SERVICE_ITEM_TYPES as $item_type => $label) { $entity->setItemEntities( $item_type, - $this->getServiceItemService()->getEntities(['serviceinfo_uid' => $entity->getPK(), 'item_type' => $item_type]) + $this->getServiceItemService()->getEntities([ + 'serviceinfo_uid' => $entity->getPK(), + 'item_type' => $item_type + ]) ); } return $entity; } - //interval을 기준으로 신규서비스 가져오기 - final public function getEntitiesByNewService(int $interval, string $status = DEFAULTS['STATUS']) + //interval을 기준으로 최근 신규 서비스정보 가져오기 + final public function getEntitiesByNewService(int $interval, string $status = DEFAULTS['STATUS']): array { - $where = sprintf("start_at >= NOW()-INTERVAL {$interval} DAY AND status = '%s'", DEFAULTS['STATUS']); - return $this->getEntities($where); + $where = sprintf("start_at >= NOW()-INTERVAL {$interval} DAY AND status = '%s'", $status); + $entities = []; + foreach ($this->getEntities($where) as $entity) { + $entities[$entity->getPK()] = $this->setItemEntitiesByService($entity); + }; + return $entities; + } + //서비스 방식에 따른 서비스별 Count + final public function getTotalCountsByType(): array + { + $sql = "SELECT type, + COUNT(CASE WHEN location = 'default' THEN 1 END) AS chiba, + COUNT(CASE WHEN location = 'tokyo' THEN 1 END) AS tokyo, + COUNT(CASE WHEN location IN ('default', 'tokyo') THEN 1 END) AS total + FROM serviceinfo GROUP BY type;"; + + $totalCounts = ['chiba_total' => 0, 'tokyo_total' => 0, 'all_total' => 0]; + foreach ($this->getModel()->query($sql)->getResult() as $row) { + $totalCounts[$row->type] = [ + 'chiba' => $row->chiba, + 'tokyo' => $row->tokyo, + 'total' => $row->total, + ]; + $totalCounts['chiba_total'] += $row->chiba; + $totalCounts['tokyo_total'] += $row->tokyo; + } + $totalCounts['all_total'] = $totalCounts['chiba_total'] + $totalCounts['tokyo_total']; + return $totalCounts; } //다음 달로 결제일을 연장합니다. final public function extendBillingAt(string $billing_at, string $status): bool diff --git a/app/Views/admin/welcome_message.php b/app/Views/admin/welcome_message.php index 62f5ab3..ce96ed0 100644 --- a/app/Views/admin/welcome_message.php +++ b/app/Views/admin/welcome_message.php @@ -14,10 +14,10 @@ = $this->include("templates/{$viewDatas['layout']}/welcome_banner"); ?>