From e437c1e3cd84bbcada909ad942706d76c754b0cf Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Wed, 18 Jun 2025 09:57:13 +0900 Subject: [PATCH] dbms_init...1 --- app/Models/Customer/ServiceModel.php | 25 ------------------------ app/Services/CommonService.php | 2 +- app/Services/Customer/ServiceService.php | 19 +++++++++++------- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/app/Models/Customer/ServiceModel.php b/app/Models/Customer/ServiceModel.php index 8f7da73..943b493 100644 --- a/app/Models/Customer/ServiceModel.php +++ b/app/Models/Customer/ServiceModel.php @@ -59,29 +59,4 @@ class ServiceModel extends CustomerModel } return $rule; } - //다음 달로 결제일을 연장합니다. - public function extendPaymentDate(int $uid): mixed - { - $sql = "UPDATE ? SET billing_at = IF( - DAY(billing_at) = DAY(LAST_DAY(billing_at)), - LAST_DAY(DATE_ADD(billing_at, INTERVAL 1 MONTH)), - DATE_ADD(billing_at, INTERVAL 1 MONTH)) - WHERE uid = ? AND status = ?"; - $sql = $this->setQuery($sql) - ->setParameter(1, $this->getTableName()) - ->setParameter(2, $uid) - ->setParameter(3, DEFAULTS['STATUS']) - ->getSQL(); - if (!$sql) { - throw new \Exception("SQL문이 생성되지 않았습니다."); - } - if (!$this->isValidQuery($sql)) { - throw new \Exception("SQL문이 유효하지 않습니다: " . $sql); - } - // 쿼리 실행 - if (!$this->execute($sql)) { - throw new \Exception("SQL문 실행에 실패했습니다: " . $sql); - } - return $this->query($sql); - } } diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 929240f..7643c7a 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -71,7 +71,7 @@ abstract class CommonService } return $this->setRelatedEntity($entity); } - public function findAllDatas(array $columns = ['*']): mixed + protected function findAllDatas(array $columns = ['*']): mixed { return $this->getModel()->select(implode(',', $columns))->findAll(); } diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 2ff8132..03bc81b 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -78,24 +78,29 @@ class ServiceService extends CustomerService { return $this->_searchIP; } - public function findAllDatas(array $columns = ['*']): mixed + protected function findAllDatas(array $columns = ['*']): mixed { $ip = $this->getSearchIp(); if ($ip) { - $sql = "SELECT serviceinfo.* FROM serviceinfo + $sql = "SELECT serviceinfo.* FROM serviceinfo LEFT JOIN serviceinfo_items ON serviceinfo.uid = serviceinfo_items.serviceinfo_uid - WHERE serviceinfo_items.item_type='IP' - AND serviceinfo_items.item_uid IN (SELECT uid FROM ipinfo WHERE ip='{$ip}')"; - return $this->getModel()->query($sql)->getResult(ServiceEntity::class); + WHERE serviceinfo_items.item_type = ? + AND serviceinfo_items.item_uid IN (SELECT uid FROM ipinfo WHERE ip = ?)"; + return $this->getModel()->query($sql, ['IP', $ip])->getResult(ServiceEntity::class); } return parent::findAllDatas($columns); } //기본 기능부분 //다음 달로 결제일을 연장합니다. - public function extendPaymentDate(ServiceEntity $entity): void + public function extendBillingAt(ServiceEntity $entity): bool { - $this->getModel()->extendPaymentDate($entity->getPK()); + $sql = "UPDATE serviceinfo SET billing_at = + IF(DAY(billing_at) > DAY(LAST_DAY(billing_at)), + LAST_DAY(DATE_ADD(billing_at, INTERVAL 1 MONTH)), + DATE_ADD(billing_at, INTERVAL 1 MONTH) + ) WHERE uid = ?"; + return $this->getModel()->query($sql, [$entity->getPK()]); } public function create(array $formDatas, mixed $entity = null): ServiceEntity {