From 2bbf2a5704aac43d65f0bc67792be275e7ff9f59 Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Wed, 22 Oct 2025 17:53:07 +0900 Subject: [PATCH] dbmsv3 init...1 --- .../Equipment/ServerPartInterface.php | 3 +- app/Interfaces/PaymentInterface.php | 2 +- app/Services/Customer/AccountService.php | 32 ++--- app/Services/Equipment/ServerPartService.php | 24 ++-- app/Services/Part/CSService.php | 73 +++++------ app/Services/Part/DISKService.php | 28 ++--- app/Services/Part/IPService.php | 81 ++++++------- app/Services/Part/PartService.php | 53 ++++---- app/Services/Part/SWITCHService.php | 73 +++++------ app/Services/PaymentService.php | 114 +++++++++--------- 10 files changed, 216 insertions(+), 267 deletions(-) diff --git a/app/Interfaces/Equipment/ServerPartInterface.php b/app/Interfaces/Equipment/ServerPartInterface.php index 5423521..9a72589 100644 --- a/app/Interfaces/Equipment/ServerPartInterface.php +++ b/app/Interfaces/Equipment/ServerPartInterface.php @@ -6,5 +6,6 @@ use App\Entities\Equipment\ServerPartEntity; interface ServerPartInterface extends EquipmentInterface { - public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity; + public function setServerPart(ServerPartEntity $serverPartEntity): void; + public function unsetServerPart(ServerPartEntity $serverPartEntity): void; } diff --git a/app/Interfaces/PaymentInterface.php b/app/Interfaces/PaymentInterface.php index cc111b1..2b0007b 100644 --- a/app/Interfaces/PaymentInterface.php +++ b/app/Interfaces/PaymentInterface.php @@ -6,5 +6,5 @@ use App\Entities\PaymentEntity; interface PaymentInterface { - public function setPayment(string $action, PaymentEntity $paymentEntity, array $formDatas): PaymentEntity; + public function setPayment(PaymentEntity $paymentEntity): mixed; } diff --git a/app/Services/Customer/AccountService.php b/app/Services/Customer/AccountService.php index f0b05e0..60ce02e 100644 --- a/app/Services/Customer/AccountService.php +++ b/app/Services/Customer/AccountService.php @@ -53,28 +53,18 @@ class AccountService extends CustomerService implements PaymentInterface } return $this->getClientService()->setAccount($formDatas['status'], $entity, intval($formDatas['amount'])); } - public function setPayment(string $action, PaymentEntity $paymentEntity, array $paymentDatas): PaymentEntity + public function setPayment(PaymentEntity $paymentEntity): AccountEntity { - switch ($action) { - case 'create': - $formDatas = [ - 'clientinfo_uid' => $paymentEntity->getClientInfoUID(), - 'bank' => null, - 'title' => "[결제차감] {$paymentEntity->getTitle()}", - 'issue_at' => date('Y-m-d H:i:s'), - 'alias' => array_key_exists('alias', $paymentDatas) ? $paymentDatas['alias'] : null, - 'amount' => $paymentEntity->getAmount(), - 'status' => STATUS['WITHDRAWAL'], - ]; - $this->setBalance($formDatas); - parent::create($formDatas); - break; - // case 'modify': - // case 'delete': - default: - throw new \Exception(__METHOD__ . "에서 오류발생: {$action}는 지원하지 않는 기능입니다."); - } - return $paymentEntity; + $formDatas = [ + 'clientinfo_uid' => $paymentEntity->getClientInfoUID(), + 'bank' => null, + 'title' => "[결제차감] {$paymentEntity->getTitle()}", + 'issue_at' => date('Y-m-d H:i:s'), + 'amount' => $paymentEntity->getAmount(), + 'status' => STATUS['WITHDRAWAL'], + ]; + $this->setBalance($formDatas); + return parent::create($formDatas); } //기본 기능부분 //생성 diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 233b020..4e0f6f3 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -230,7 +230,7 @@ class ServerPartService extends EquipmentService implements ServerInterface //서버정보에 해당하는 ServerPart정보 모두 회수처리 후 서버정보에 기본 ServerPart를 다시 등록해준다. foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $entity) { //Type에 따른 부품서비스 정의 - $this->getPartService($entity->getType())->setServerPart('delete', $entity, []); + $this->getPartService($entity->getType())->unsetServerPart($entity); //서버연결정보 식제 parent::delete($entity); } @@ -301,7 +301,7 @@ class ServerPartService extends EquipmentService implements ServerInterface $entity = parent::create($formDatas); //후처리작업 //Type에 따른 부품서비스 정의 - $this->getPartService($entity->getType())->setServerPart('create', $entity, $formDatas); + $this->getPartService($entity->getType())->setServerPart($entity); //서비스 및 결제정보 처리 switch ($entity->getBilling()) { case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 @@ -312,9 +312,9 @@ class ServerPartService extends EquipmentService implements ServerInterface $this->getServiceService()->setAmount($this->getServiceService()->getEntity($entity->getServiceInfoUID())); break; case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - $entity = $this->getPaymentService()->setServerPart('create', $entity, $formDatas); + $paymentEntity = $this->getPaymentService()->createServerPart($entity); //결제정보PK정의 - $entity = parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); + $entity = parent::modify($entity, ['payment_uid' => $paymentEntity->getPK()]); break; case PAYMENT['BILLING']['BASE']: //기본처리 //아무처리 않함 @@ -339,7 +339,7 @@ class ServerPartService extends EquipmentService implements ServerInterface throw new \Exception("서버 정보가 지정되지 않았습니다."); } //수정전 정보 - $oldEntity = clone $entity; //반드시 clone 할것 + $this->getPartService($entity->getType())->unsetServerPart($entity); //서버연결정보 수정 $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); @@ -347,8 +347,7 @@ class ServerPartService extends EquipmentService implements ServerInterface $entity = parent::modify($entity, $formDatas); //후처리작업 //Type에 따른 부품서비스 정의 - $this->getPartService($entity->getType())->setServerPart('delete', $oldEntity, $formDatas); - $this->getPartService($entity->getType())->setServerPart('create', $entity, $formDatas); + $this->getPartService($entity->getType())->setServerPart($entity); //서비스 및 결제정보 처리 switch ($entity->getBilling()) { case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 @@ -358,11 +357,10 @@ class ServerPartService extends EquipmentService implements ServerInterface } break; case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - if ($oldEntity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면 - $oldEntity = $this->getPaymentService()->setServerPart('delete', $entity, []); - } if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면 - $entity = $this->getPaymentService()->setServerPart('create', $entity, $formDatas); + $paymentEntity = $this->getPaymentService()->modifyServerPart($entity); + //결제정보PK정의 + $entity = parent::modify($entity, ['payment_uid' => $paymentEntity->getPK()]); } break; case PAYMENT['BILLING']['BASE']: //기본처리 @@ -380,7 +378,7 @@ class ServerPartService extends EquipmentService implements ServerInterface public function delete(mixed $entity): ServerPartEntity { //Type에 따른 부품서비스 정의 - $this->getPartService($entity->getType())->setServerPart('delete', $entity, []); + $this->getPartService($entity->getType())->unsetServerPart($entity); //서버연결정보 식제 parent::delete($entity); //서비스 및 결제정보 후처리작업 @@ -393,7 +391,7 @@ class ServerPartService extends EquipmentService implements ServerInterface break; case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면 - $entity = $this->getPaymentService()->setServerPart('delete', $entity, []); + $this->getPaymentService()->deleteServerPart($entity); } break; case PAYMENT['BILLING']['BASE']: //기본처리 diff --git a/app/Services/Part/CSService.php b/app/Services/Part/CSService.php index f1c86a9..a29f8c3 100644 --- a/app/Services/Part/CSService.php +++ b/app/Services/Part/CSService.php @@ -96,47 +96,40 @@ class CSService extends PartService } //서버파트관련 작업 - public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + public function setServerPart(ServerPartEntity $serverPartEntity): void { - switch ($action) { - case 'create': - $formDatas = []; - $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); - $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); - $formDatas['status'] = STATUS['OCCUPIED']; - if (!array_key_exists('status', $formDatas)) { - throw new \Exception(__METHOD__ . "에서 오류발생: CS상태가 설정되지 않았습니다."); - } - //CS정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof CSEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다."); - } - //CS정보 수정 - $entity = parent::modify($entity, $formDatas); - break; - case 'delete': //반드시 serverPartEntity 사용해야함 - $formDatas = []; - $formDatas['clientinfo_uid'] = null; - $formDatas['serviceinfo_uid'] = null; - $formDatas['serverinfo_uid'] = null; - $formDatas['status'] = STATUS['AVAILABLE']; - if (!array_key_exists('status', $formDatas)) { - throw new \Exception(__METHOD__ . "에서 오류발생: CS상태가 설정되지 않았습니다."); - } - //CS정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof CSEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다."); - } - //CS정보 수정 - $entity = parent::modify($entity, $formDatas); - break; - default: - $entity = parent::setServerPart($action, $serverPartEntity, $serverPartDatas); - break; + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . "에서 오류발생: CS상태가 설정되지 않았습니다."); } - return $serverPartEntity; + //CS정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof CSEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다."); + } + //CS정보 수정 + parent::modify($entity, $formDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity): void + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['status'] = STATUS['AVAILABLE']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . "에서 오류발생: CS상태가 설정되지 않았습니다."); + } + //CS정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof CSEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다."); + } + //CS정보 수정 + parent::modify($entity, $formDatas); } } diff --git a/app/Services/Part/DISKService.php b/app/Services/Part/DISKService.php index bc2dcea..3bb35cd 100644 --- a/app/Services/Part/DISKService.php +++ b/app/Services/Part/DISKService.php @@ -54,25 +54,17 @@ class DISKService extends PartService } //서버파트관련 작업 - public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + public function unsetServerPart(ServerPartEntity $serverPartEntity): void { - switch ($action) { - case 'delete': //반드시 serverPartEntity 사용해야함 - //부품정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); - } - //부품정보에 서버정보 설정 및 서비스,고객정보 정의 - if ($entity->getStock() < $serverPartEntity->getCnt()) { - throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); - } - $entity = parent::modify($entity, ['format' => $entity->getFormat() + $serverPartEntity->getCnt()]); - break; - default: - $entity = parent::setServerPart($action, $serverPartEntity, $serverPartDatas); - break; + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); } - return $serverPartEntity; + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + parent::modify($entity, ['format' => $entity->getFormat() + $serverPartEntity->getCnt()]); } } diff --git a/app/Services/Part/IPService.php b/app/Services/Part/IPService.php index cfd0089..9c8e406 100644 --- a/app/Services/Part/IPService.php +++ b/app/Services/Part/IPService.php @@ -150,51 +150,44 @@ class IPService extends PartService implements ServerInterface } //서버파트관련 작업 - public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + public function setServerPart(ServerPartEntity $serverPartEntity): void { - switch ($action) { - case 'create': - $formDatas = []; - $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); - $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); - $formDatas['status'] = STATUS['OCCUPIED']; - if (!array_key_exists('status', $formDatas)) { - throw new \Exception(__METHOD__ . ":에서 {$action}오류발생: IP상태가 설정되지 않았습니다."); - } - //IP정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof IPEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다."); - } - if ($entity->getStatus() !== STATUS['AVAILABLE']) { - throw new \Exception(__METHOD__ . ":에서 {$action}오류발생: {$entity->getIP()}는 사용중인 IP입니다."); - } - //IP정보 수정 - $entity = parent::modify($entity, $formDatas); - break; - case 'delete': //반드시 serverPartEntity 사용해야함 - $formDatas = []; - $formDatas['clientinfo_uid'] = null; - $formDatas['serviceinfo_uid'] = null; - $formDatas['serverinfo_uid'] = null; - $formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null; - $formDatas['status'] = STATUS['AVAILABLE']; - if (!array_key_exists('status', $formDatas)) { - throw new \Exception(__METHOD__ . ":에서 {$action}오류발생: IP상태가 설정되지 않았습니다."); - } - //IP정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof IPEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다."); - } - //IP정보 수정 - $entity = parent::modify($entity, $formDatas); - break; - default: - $entity = parent::setServerPart($action, $serverPartEntity, $serverPartDatas); - break; + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . ":에서 오류발생: IP상태가 설정되지 않았습니다."); } - return $serverPartEntity; + //IP정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof IPEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다."); + } + if ($entity->getStatus() !== STATUS['AVAILABLE']) { + throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getIP()}는 사용중인 IP입니다."); + } + //IP정보 수정 + parent::modify($entity, $formDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity): void + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null; + $formDatas['status'] = STATUS['AVAILABLE']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . ":에서 오류발생: IP상태가 설정되지 않았습니다."); + } + //IP정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof IPEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다."); + } + //IP정보 수정 + parent::modify($entity, $formDatas); } } diff --git a/app/Services/Part/PartService.php b/app/Services/Part/PartService.php index 8595433..8a72eeb 100644 --- a/app/Services/Part/PartService.php +++ b/app/Services/Part/PartService.php @@ -17,37 +17,30 @@ abstract class PartService extends CommonService implements ServerPartInterface } //서버파트관련 작업 - public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + public function setServerPart(ServerPartEntity $serverPartEntity): void { - switch ($action) { - case 'create': - //부품정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); - } - //부품정보에 서버정보 설정 및 서비스,고객정보 정의 - if ($entity->getStock() < $serverPartEntity->getCnt()) { - throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); - } - $entity = parent::modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]); - break; - case 'delete': - //부품정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); - } - //부품정보에 서버정보 설정 및 서비스,고객정보 정의 - if ($entity->getStock() < $serverPartEntity->getCnt()) { - throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); - } - $entity = parent::modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]); - break; - default: - throw new \Exception("{$action}은 정의되지 않은 작업입니다."); - // break; + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); } - return $serverPartEntity; + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + parent::modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity): void + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + parent::modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]); } } diff --git a/app/Services/Part/SWITCHService.php b/app/Services/Part/SWITCHService.php index 5418741..f840454 100644 --- a/app/Services/Part/SWITCHService.php +++ b/app/Services/Part/SWITCHService.php @@ -128,47 +128,40 @@ class SWITCHService extends PartService implements ServerInterface } } //서버파트관련 작업 - public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + public function setServerPart(ServerPartEntity $serverPartEntity): void { - switch ($action) { - case 'create': - $formDatas = []; - $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); - $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); - $formDatas['status'] = STATUS['OCCUPIED']; - if (!array_key_exists('status', $formDatas)) { - throw new \Exception(__METHOD__ . "에서 오류발생: SWITCH상태가 설정되지 않았습니다."); - } - //SWITCH정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof SWITCHEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 SWITCH정보를 찾을수없습니다."); - } - //SWITCH정보 수정 - $entity = parent::modify($entity, $formDatas); - break; - case 'delete': //반드시 oldServerPartEntity 사용해야함 - $formDatas = []; - $formDatas['clientinfo_uid'] = null; - $formDatas['serviceinfo_uid'] = null; - $formDatas['serverinfo_uid'] = null; - $formDatas['status'] = STATUS['AVAILABLE']; - if (!array_key_exists('status', $formDatas)) { - throw new \Exception(__METHOD__ . "에서 오류발생: SWITCH상태가 설정되지 않았습니다."); - } - //SWITCH정보가져오기 - $entity = $this->getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof SWITCHEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 SWITCH정보를 찾을수없습니다."); - } - //SWITCH정보 수정 - $entity = parent::modify($entity, $formDatas); - break; - default: - $entity = parent::setServerPart($action, $serverPartEntity, $serverPartDatas); - break; + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . "에서 오류발생: SWITCH상태가 설정되지 않았습니다."); } - return $serverPartEntity; + //SWITCH정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof SWITCHEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 SWITCH정보를 찾을수없습니다."); + } + //SWITCH정보 수정 + parent::modify($entity, $formDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity): void + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['status'] = STATUS['AVAILABLE']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . "에서 오류발생: SWITCH상태가 설정되지 않았습니다."); + } + //SWITCH정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof SWITCHEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 SWITCH정보를 찾을수없습니다."); + } + //SWITCH정보 수정 + parent::modify($entity, $formDatas); } } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index ce8ae07..9ff639b 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -108,7 +108,7 @@ class PaymentService extends CommonService } return $unPaids; } - //서비스 생성 + //서비스 생성(월과금 결제) public function createService(ServiceEntity $serviceEntity): PaymentEntity { $formDatas = []; @@ -159,65 +159,60 @@ class PaymentService extends CommonService $this->delete($entity); } } - final public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $servicePartFormDatas): ServerPartEntity + //서버파트(일회성과금) + final public function createServerPart(ServerPartEntity $serverPartEntity): PaymentEntity { - switch ($action) { - case 'create': //일회성 서비스 생성용 - $formDatas = []; - $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); - $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); //서버연결정보 수정시에 필요함 - //타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다. - $formDatas['title'] = $serverPartEntity->getPartEntity()->getTitle(); - $formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt - $formDatas['billing'] = $serverPartEntity->getBilling(); - //당일결체일로 설정 - $formDatas['billing_at'] = date("Y-m-d"); - $entity = parent::create($formDatas); - break; - case 'modify': //일회성 서비스 수정용 - if ($serverPartEntity->getPaymentUID() === null) { - throw new \Exception(__METHOD__ . "에서 {$action}오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다."); - } - $entity = $this->getEntity($serverPartEntity->getPaymentUID()); - if (!$entity instanceof PaymentEntity) { - throw new \Exception(__METHOD__ . "에서 {$action}오류발생:결제정보를 찾을수 없습니다."); - } - if ($entity->getStatus() === STATUS['PAID']) { - throw new \Exception(__METHOD__ . "에서 {$action}오류발생:결제완료된 서비스는 수정할수 없습니다."); - } - $formDatas = []; - $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); - $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); //서버연결정보 수정시에 필요함 - //타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다. - $formDatas['title'] = $serverPartEntity->getPartEntity()->getTitle(); - $formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt - $formDatas['billing'] = $serverPartEntity->getBilling(); - $entity = parent::modify($entity, $formDatas); - break; - case 'delete': - if ($serverPartEntity->getPaymentUID() === null) { - throw new \Exception(__METHOD__ . "에서 {$action}오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다."); - } - $entity = $this->getEntity($serverPartEntity->getPaymentUID()); - if (!$entity instanceof PaymentEntity) { - throw new \Exception(__METHOD__ . "에서 {$action}오류발생:결제정보를 찾을수 없습니다."); - } - if ($entity->getStatus() === STATUS['PAID']) { - throw new \Exception(__METHOD__ . "에서 {$action}오류발생:결제완료된 서비스는 수정할수 없습니다."); - } - $entity = parent::delete($entity); - break; - default: - throw new \Exception(__METHOD__ . "에서 오류발생:{$action}은 정의되지 않은 작업입니다."); - // break; - } - if (!$entity instanceof PaymentEntity) { - throw new \Exception(__METHOD__ . "에서 {$action}->setPaymentEntity오류발생:결제정보를 찾을수 없습니다."); - } - return $serverPartEntity->setPaymentEntity($entity); + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + //서버연결정보 수정시에 필요함 + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + //타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다. + $formDatas['title'] = $serverPartEntity->getPartEntity()->getTitle(); + $formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt + $formDatas['billing'] = $serverPartEntity->getBilling(); + //당일결체일로 설정 + $formDatas['billing_at'] = date("Y-m-d"); + return parent::create($formDatas); } + final public function modifyServerPart(ServerPartEntity $serverPartEntity): PaymentEntity + { + if ($serverPartEntity->getPaymentUID() === null) { + throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다."); + } + $entity = $this->getEntity($serverPartEntity->getPaymentUID()); + if (!$entity instanceof PaymentEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생:결제정보를 찾을수 없습니다."); + } + if ($entity->getStatus() === STATUS['PAID']) { + throw new \Exception(__METHOD__ . "에서 오류발생:결제완료된 서비스는 수정할수 없습니다."); + } + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + //서버연결정보 수정시에 필요함 + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + //타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다. + $formDatas['title'] = $serverPartEntity->getPartEntity()->getTitle(); + $formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt + $formDatas['billing'] = $serverPartEntity->getBilling(); + return parent::modify($entity, $formDatas); + } + final public function deleteServerPart(ServerPartEntity $serverPartEntity): void + { + if ($serverPartEntity->getPaymentUID() === null) { + throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다."); + } + $entity = $this->getEntity($serverPartEntity->getPaymentUID()); + if (!$entity instanceof PaymentEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생:결제정보를 찾을수 없습니다."); + } + if ($entity->getStatus() === STATUS['PAID']) { + throw new \Exception(__METHOD__ . "에서 오류발생:결제완료된 서비스는 수정할수 없습니다."); + } + parent::delete($entity); + } + //Invoice 관련 public function getInvoiceData(ClientEntity $clientEntity, ServiceEntity $serviceEntity, PaymentEntity $entity, array $rows): array { @@ -291,7 +286,8 @@ class PaymentService extends CommonService 'status' => $entity->getStatus() ]); //예치금처리 - return $this->getAccountService()->setPayment('create', $entity, []); + $this->getAccountService()->setPayment($entity); + return $entity; } //결제정보 삭제 public function delete(mixed $entity): PaymentEntity