From 2eccd6d67ceac7c8116feeaf81b3040d980d42aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Sat, 20 Sep 2025 15:33:47 +0900 Subject: [PATCH] dbmsv2 init...1 --- app/Interfaces/Customer/ServiceInterface.php | 6 +- .../Equipment/ServerPartInterface.php | 6 +- app/Services/Customer/Service/ServerPart.php | 43 ++++++++ app/Services/Customer/ServiceService.php | 98 ++++++++++--------- app/Services/Equipment/CS/ServerPart.php | 53 ++++++++++ app/Services/Equipment/CS/ServicePart.php | 44 --------- app/Services/Equipment/IP/ServerPart.php | 53 ++++++++++ app/Services/Equipment/IP/ServicePart.php | 44 --------- app/Services/Equipment/Part/ServerPart.php | 52 ++++++++++ app/Services/Equipment/Part/ServicePart.php | 43 -------- app/Services/Equipment/Server/Service.php | 43 +++++--- app/Services/Equipment/ServerPartService.php | 90 ++++++++--------- app/Services/Equipment/Switch/ServerPart.php | 53 ++++++++++ app/Services/Equipment/Switch/ServicePart.php | 45 --------- app/Services/Payment/ServerPart.php | 70 +++++-------- app/Services/Payment/Service.php | 46 ++++++--- app/Services/Service/ServicePart.php | 32 ------ 17 files changed, 442 insertions(+), 379 deletions(-) create mode 100644 app/Services/Customer/Service/ServerPart.php create mode 100644 app/Services/Equipment/CS/ServerPart.php delete mode 100644 app/Services/Equipment/CS/ServicePart.php create mode 100644 app/Services/Equipment/IP/ServerPart.php delete mode 100644 app/Services/Equipment/IP/ServicePart.php create mode 100644 app/Services/Equipment/Part/ServerPart.php delete mode 100644 app/Services/Equipment/Part/ServicePart.php create mode 100644 app/Services/Equipment/Switch/ServerPart.php delete mode 100644 app/Services/Equipment/Switch/ServicePart.php delete mode 100644 app/Services/Service/ServicePart.php diff --git a/app/Interfaces/Customer/ServiceInterface.php b/app/Interfaces/Customer/ServiceInterface.php index 91da46f..f62a0d3 100644 --- a/app/Interfaces/Customer/ServiceInterface.php +++ b/app/Interfaces/Customer/ServiceInterface.php @@ -3,11 +3,11 @@ namespace App\Interfaces\Customer; use App\Entities\Customer\ServiceEntity; -use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerPartEntity; interface ServiceInterface extends CustomerInterface { - public function setService(string $action, ServiceEntity $serviceEntity, array $serviceDatas): ServiceENtity; - public function setServiceAmount(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity; + public function createService(ServiceEntity $serviceEntity): ServiceEntity; + public function modifyService(ServiceEntity $serviceEntity): ServiceEntity; + public function deleteService(ServiceEntity $serviceEntity): ServiceEntity; } diff --git a/app/Interfaces/Equipment/ServerPartInterface.php b/app/Interfaces/Equipment/ServerPartInterface.php index ae42351..84ab6d2 100644 --- a/app/Interfaces/Equipment/ServerPartInterface.php +++ b/app/Interfaces/Equipment/ServerPartInterface.php @@ -6,7 +6,7 @@ use App\Entities\Equipment\ServerPartEntity; interface ServerPartInterface extends EquipmentInterface { - public function createServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity; - public function modifyServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity; - public function deleteServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity; + public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity; + public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity; + public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity; } diff --git a/app/Services/Customer/Service/ServerPart.php b/app/Services/Customer/Service/ServerPart.php new file mode 100644 index 0000000..f368e57 --- /dev/null +++ b/app/Services/Customer/Service/ServerPart.php @@ -0,0 +1,43 @@ +getEntity($serverPartEntity->getServiceInfoUID()); + if (!$entity instanceof ServiceEntity) { + throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); + } + //서비스금액은 modify 함수내에서 재계산을 하므로 여기서는 modify만 호출함 + return parent::modify($entity, []); + } + public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + //필수정보처리 후 FormData 가져오기 + $this->action_process($serverPartEntity); + return $serverPartEntity; + } + public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + return $this->createServerPart($serverPartEntity); + } + public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + return $this->createServerPart($serverPartEntity); + } +} diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index cf3ee16..ea4ff7c 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -2,22 +2,24 @@ namespace App\Services\Customer; -use App\Entities\Customer\ClientEntity; -use App\Entities\Customer\ServiceEntity; -use App\Entities\Equipment\ServerEntity; -use App\Entities\PaymentEntity; -use App\Entities\UserEntity; -use App\Helpers\Customer\ServiceHelper; -use App\Models\Customer\ServiceModel; -use App\Services\Equipment\Server\Service as ServerService; -use App\Services\Payment\Service as PaymentService; use App\Traits\IPTrait; +use App\Services\Payment\Service as PaymentService; +use App\Services\Equipment\Server\Service as ServerService; +use App\Services\Equipment\ServerPartService; +use App\Models\Customer\ServiceModel; +use App\Helpers\Customer\ServiceHelper; +use App\Entities\UserEntity; +use App\Entities\PaymentEntity; +use App\Entities\Equipment\ServerEntity; +use App\Entities\Customer\ServiceEntity; +use App\Entities\Customer\ClientEntity; class ServiceService extends CustomerService { use IPTrait; private ?ServerService $_serverService = null; private ?PaymentService $_paymentService = null; + private ?ServerPartService $_serverPartService = null; public function __construct() { parent::__construct(new ServiceModel(), new ServiceHelper()); @@ -35,8 +37,8 @@ class ServiceService extends CustomerService "line", "start_at", "billing_at", - "amount", "status", + 'amount', "history", ]; } @@ -137,6 +139,13 @@ class ServiceService extends CustomerService } return $this->_serverService; } + public function getServerPartService(): ServerPartService + { + if (!$this->_serverPartService) { + $this->_serverPartService = new ServerPartService(); + } + return $this->_serverPartService; + } //기본 기능부분 public function getFormOption(string $field, array $options = []): array { @@ -219,18 +228,41 @@ class ServiceService extends CustomerService ) WHERE billing_at = ? AND status = ?"; return $this->getModel()->query($sql, [$billing_at, $status]); } - + //월청구액 계산값 + final public function getCalculatedAmount(ServiceEntity $entity): int + { + $serverEntity = $this->getServerService()->getEntity($entity->getServerInfoUID()); + if (!$serverEntity instanceof ServerEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생:[{$entity->getServerInfoUID()}]에 대한 서버정보를 찾을수 없습니다."); + } + $total_amount = $serverEntity->getPrice(); //서버금액(price) + //해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 합산한다. + foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $serverPartEntity) { + if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { + $total_amount += $serverPartEntity->getAmount(); + } + } + return $total_amount; + } //기본기능 + private function action_process(ServiceEntity $entity, string $action): ServiceEntity + { + //서버정보에 서비스정보 등록 + $entity = $this->getServerService()->$action($entity); + $entity = $this->getPaymentService()->$action($entity); + return $entity; + } //생성 public function create(array $formDatas): ServiceEntity { if (!array_key_exists('serverinfo_uid', $formDatas)) { throw new \Exception("서버가 지정되지 않았습니다."); } - $entity = parent::create(formDatas: $formDatas); - $entity = $this->getServerService()->setService(__FUNCTION__, $entity, ['serverinfo_uid' => $formDatas['serverinfo_uid'], 'status' => STATUS['OCCUPIED']]); - // 결제정보에 추가한다. - $this->getPaymentService()->setService(__FUNCTION__, $entity); + //신규등록 + $entity = parent::create($formDatas); + //월청구액계산 후 서비스정보에 수정 + $entity = parent::modify($entity, ['amount' => $this->getCalculatedAmount($entity)]); + $this->action_process($entity, __FUNCTION__ . 'Service'); return $entity; } //수정 @@ -239,43 +271,21 @@ class ServiceService extends CustomerService if (!array_key_exists('serverinfo_uid', $formDatas)) { throw new \Exception("서버가 지정되지 않았습니다."); } - //기존서버정보 사용가능으로 설정 + //기존 각서버파트정보 if ($entity->getServerInfoUID() && $entity->getServerInfoUID() !== $formDatas['serverinfo_uid']) { - $this->getServerService()->setService($entity, $entity->getServerEntity()->getPK(), STATUS['AVAILABLE']); + $this->action_process($entity, 'deleteService'); } - //서비스 정보수정 + //수정작업 + //월청구액계산 후 서비스정보에 수정 + $formDatas['amount'] = $this->getCalculatedAmount($entity->getPK()); $entity = parent::modify($entity, $formDatas); - //신규서버정보 사용중으로 설정 - if ($entity->getServerInfoUID() !== $formDatas['serverinfo_uid']) { - $entity->setServerEntity($this->getServerService()->setService($entity, $formDatas['serverinfo_uid'], STATUS['OCCUPIED'])); - } - //수정된 정보중 서버,결제일,청구액이 바뀐경우 결제정보에서 미납인경우 수정해준다. - if ( - $entity->getServerInfoUID() !== $formDatas['serverinfo_uid'] || - $entity->getBillingAt() !== $formDatas['billing_at'] || - $entity->getAmount() !== $formDatas['amount'] - ) { - $paymentEntity = $this->getPaymentService()->getEntity(['serviceinfo_uid' => $entity->getPK(), 'status' => STATUS['UNPAID']]); - if (!($paymentEntity instanceof PaymentEntity)) { - throw new \Exception("{$entity->getPK()}에 해당하는 미결제정보를 찾을수 없습니다."); - } - $paymentDatas = []; - $paymentDatas['clientinfo_uid'] = $entity->getClientInfoUID(); - $paymentDatas['serviceinfo_uid'] = $entity->getPK(); - $paymentDatas['serverinfo_uid'] = $entity->getServerInfoUID(); - $paymentDatas['title'] = $entity->getServerEntity()->getTitle(); - $paymentDatas['amount'] = $entity->getAmount(); - $paymentDatas['billing'] = PAYMENT['BILLING']['MONTH']; - $paymentDatas['billing_at'] = $entity->getBillingAt(); - $this->getPaymentService()->modify($paymentEntity, $paymentDatas); - } + $this->action_process($entity, __FUNCTION__ . 'Service'); return $entity; } //삭제 public function delete(mixed $entity): ServiceEntity { - //기존서버정보 사용가능으로 설정 - $this->getServerService()->setService($entity, $entity->getServerEntity()->getPK(), STATUS['AVAILABLE']); + $this->action_process($entity, __FUNCTION__ . 'Service'); return parent::delete($entity); } //History diff --git a/app/Services/Equipment/CS/ServerPart.php b/app/Services/Equipment/CS/ServerPart.php new file mode 100644 index 0000000..9295121 --- /dev/null +++ b/app/Services/Equipment/CS/ServerPart.php @@ -0,0 +1,53 @@ +getEntity($serverPartEntity->getPartUID()); + if (!($entity instanceof CSEntity)) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다."); + } + //CS정보 수정 + return $this->modify($entity, $formDatas); + } + public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + $entity = $this->action_process($serverPartEntity, $formDatas); + return $serverPartEntity->setPartEntity($entity); + } + public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + return $this->createServerPart($serverPartEntity); + } + public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['status'] = STATUS['AVAILABLE']; + $entity = $this->action_process($serverPartEntity, $formDatas); + return $serverPartEntity->setPartEntity($entity); + } +} diff --git a/app/Services/Equipment/CS/ServicePart.php b/app/Services/Equipment/CS/ServicePart.php deleted file mode 100644 index 3bea5da..0000000 --- a/app/Services/Equipment/CS/ServicePart.php +++ /dev/null @@ -1,44 +0,0 @@ -getEntity($serverPartDatas['part_uid']); - if (!($entity instanceof CSEntity)) { - throw new \Exception("{$serverPartDatas['part_uid']}에 해당하는 CS정보를를 찾을수없습니다."); - } - //부품정보에 서버정보 설정 및 서비스,고객정보 정의 - $formDatas = []; - if ($serverPartDatas['status'] === STATUS['AVAILABLE']) { - //사용가능 - $formDatas['clientinfo_uid'] = null; - $formDatas['serviceinfo_uid'] = null; - $formDatas['serverinfo_uid'] = null; - } else { - $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); - $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); - } - $formDatas['status'] = $serverPartDatas['status']; - return $serverPartEntity->setPartEntity($this->modify($entity, $formDatas)); - } -} diff --git a/app/Services/Equipment/IP/ServerPart.php b/app/Services/Equipment/IP/ServerPart.php new file mode 100644 index 0000000..5e4c43a --- /dev/null +++ b/app/Services/Equipment/IP/ServerPart.php @@ -0,0 +1,53 @@ +getEntity($serverPartEntity->getPartUID()); + if (!($entity instanceof IPEntity)) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다."); + } + //IP정보 수정 + return $this->modify($entity, $formDatas); + } + public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + $entity = $this->action_process($serverPartEntity, $formDatas); + return $serverPartEntity->setPartEntity($entity); + } + public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + return $this->createServerPart($serverPartEntity); + } + public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['status'] = STATUS['AVAILABLE']; + $entity = $this->action_process($serverPartEntity, $formDatas); + return $serverPartEntity->setPartEntity($entity); + } +} diff --git a/app/Services/Equipment/IP/ServicePart.php b/app/Services/Equipment/IP/ServicePart.php deleted file mode 100644 index b95a26b..0000000 --- a/app/Services/Equipment/IP/ServicePart.php +++ /dev/null @@ -1,44 +0,0 @@ -getEntity($serverPartDatas['part_uid']); - if (!($entity instanceof IPEntity)) { - throw new \Exception("{$serverPartDatas['part_uid']}에 해당하는 IP정보를를 찾을수없습니다."); - } - //부품정보에 서버정보 설정 및 서비스,고객정보 정의 - $formDatas = []; - if ($serverPartDatas['status'] === STATUS['AVAILABLE']) { - //사용가능 - $formDatas['clientinfo_uid'] = null; - $formDatas['serviceinfo_uid'] = null; - $formDatas['serverinfo_uid'] = null; - } else { - $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); - $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); - } - $formDatas['status'] = $serverPartDatas['status']; - return $serverPartEntity->setPartEntity($this->modify($entity, $formDatas)); - } -} diff --git a/app/Services/Equipment/Part/ServerPart.php b/app/Services/Equipment/Part/ServerPart.php new file mode 100644 index 0000000..416dca9 --- /dev/null +++ b/app/Services/Equipment/Part/ServerPart.php @@ -0,0 +1,52 @@ +getEntity($serverPartEntity->getPartUID()); + if (!($entity instanceof PartEntity)) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + $formDatas = []; + if ($action === "return") { //해지된 부품 재고 반납 처리 + $formDatas['stock'] = $entity->getStock() + $serverPartEntity->getCnt(); + } + if ($action === "use") { //사용된 부품 재고 사용처리 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + $formDatas['stock'] = $entity->getStock() - $serverPartEntity->getCnt(); + } + return $this->modify($entity, $formDatas); + } + + public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + $entity = $this->action_process($serverPartEntity, "use"); + return $serverPartEntity->setPartEntity($entity); + } + public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + return $this->createServerPart($serverPartEntity); + } + public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + $entity = $this->action_process($serverPartEntity, "return"); + return $serverPartEntity->setPartEntity($entity); + } +} diff --git a/app/Services/Equipment/Part/ServicePart.php b/app/Services/Equipment/Part/ServicePart.php deleted file mode 100644 index b697f1f..0000000 --- a/app/Services/Equipment/Part/ServicePart.php +++ /dev/null @@ -1,43 +0,0 @@ -getEntity($serverPartDatas['part_uid']); - if (!($entity instanceof PartEntity)) { - throw new \Exception("{$serverPartDatas['part_uid']}에 해당하는 부품정보를 찾을수없습니다."); - } - //부품정보에 서버정보 설정 및 서비스,고객정보 정의 - $formDatas = []; - if ($serverPartDatas['status'] === STATUS['AVAILABLE']) { //해지된 부품 재고수를 처리 - $formDatas['stock'] = $entity->getStock() + $serverPartEntity->getCnt(); - } - if ($serverPartDatas['status'] === STATUS['OCCUPIED']) { //추가된 부품 재고수를 처리 - if ($entity->getStock() < $serverPartEntity->getCnt()) { - throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); - } - $formDatas['stock'] = $entity->getStock() - $serverPartEntity->getCnt(); - } - return $serverPartEntity->setPartEntity($this->modify($entity, $formDatas)); - } -} diff --git a/app/Services/Equipment/Server/Service.php b/app/Services/Equipment/Server/Service.php index 34e89d2..49e1e16 100644 --- a/app/Services/Equipment/Server/Service.php +++ b/app/Services/Equipment/Server/Service.php @@ -4,7 +4,6 @@ namespace App\Services\Equipment\Server; use App\Entities\Customer\ServiceEntity; use App\Entities\Equipment\ServerEntity; -use App\Entities\Equipment\ServerPartEntity; use App\Interfaces\Customer\ServiceInterface; use App\Services\Equipment\ServerService; @@ -14,23 +13,41 @@ class Service extends ServerService implements ServiceInterface { parent::__construct(); } - //서버연결정보용 등록 - //서비스정보용 등록 - public function setService(string $action, ServiceEntity $serviceEntity, array $serviceDatas = []): ServiceENtity + private function action_process(ServiceEntity $serviceEntity, array $formDatas = []): ServerEntity { - $entity = $this->getEntity($serviceDatas['serverinfo_uid']); - if (!($entity instanceof ServerEntity)) { - throw new \Exception("{$serviceDatas['serverinfo_uid']}에 해당하는 서버정보를 찾을수없습니다."); + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서버상태가 설정되지 않았습니다."); } - $formDatas = []; + //서버정보 가져오기 + $entity = $this->getEntity($serviceEntity->getServerInfoUID()); + if (!($entity instanceof ServerEntity)) { + throw new \Exception("{$serviceEntity->getServerInfoUID()}에 해당하는 서버정보를 찾을수없습니다."); + } + //서버정보 수정 + return $this->modify($entity, $formDatas); + } + public function createService(ServiceEntity $serviceEntity): ServiceEntity + { + $formDatas = []; $formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID(); $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); - $formDatas['status'] = $serviceDatas['status']; - $entity = $this->modify($entity, $formDatas); - return $serviceEntity->setServerENtity($entity); + $formDatas['status'] = STATUS['OCCUPIED']; + $entity = $this->action_process($serviceEntity, $formDatas); + //서비스정보 Entity에 서버정보 설정 + return $serviceEntity->setServerEntity($entity); } - public function setServiceAmount(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + public function modifyService(ServiceEntity $serviceEntity): ServiceEntity { - return $serverPartEntity; + return $this->createService($serviceEntity); + } + public function deleteService(ServiceEntity $serviceEntity): ServiceEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['status'] = STATUS['AVAILABLE']; + $entity = $this->action_process($serviceEntity, $formDatas); + //서비스정보 Entity에 서버정보 설정 + return $serviceEntity->setServerEntity($entity); } } diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 18ce661..9b93b99 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -2,16 +2,16 @@ namespace App\Services\Equipment; -use App\Entities\Equipment\ServerEntity; -use App\Entities\Equipment\ServerPartEntity; -use App\Helpers\Equipment\ServerPartHelper; -use App\Models\Equipment\ServerPartModel; -use App\Services\Equipment\EquipmentService; -use App\Services\Equipment\CS\ServerePart as CSService; -use App\Services\Equipment\IP\ServerePart as IPService; -use App\Services\Equipment\Part\ServerPart as PartService; +use App\Services\Payment\ServerPart as PaymentService; use App\Services\Equipment\Switch\ServerPart as SwitchService; -use App\Services\Payment\ServicePart as PaymentService; +use App\Services\Equipment\Part\ServerPart as PartService; +use App\Services\Equipment\IP\ServerPart as IPService; +use App\Services\Equipment\CS\ServerPart as CSService; +use App\Services\Equipment\EquipmentService; +use App\Models\Equipment\ServerPartModel; +use App\Helpers\Equipment\ServerPartHelper; +use App\Entities\Equipment\ServerPartEntity; +use App\Entities\Equipment\ServerEntity; class ServerPartService extends EquipmentService { @@ -73,13 +73,6 @@ class ServerPartService extends EquipmentService { return ['billing', 'type']; } - final public function getSwitchService(): SwitchService - { - if (!$this->_switchService) { - $this->_switchService = new SwitchService(); - } - return $this->_switchService; - } final public function getPartService(): PartService { if (!$this->_partService) { @@ -87,6 +80,13 @@ class ServerPartService extends EquipmentService } return $this->_partService; } + final public function getSwitchService(): SwitchService + { + if (!$this->_switchService) { + $this->_switchService = new SwitchService(); + } + return $this->_switchService; + } final public function getIPService(): IPService { if (!$this->_ipService) { @@ -184,7 +184,7 @@ class ServerPartService extends EquipmentService return $options; } //파트별정보 설정 - private function setServerPart(string $action, ServerPartEntity $entity, array $formDatas): ServerPartEntity + private function action_process(ServerPartEntity $entity, string $action): ServerPartEntity { //Type에 따른 부품서비스 정의 switch ($entity->getType()) { @@ -194,18 +194,33 @@ class ServerPartService extends EquipmentService case 'OS': case 'DB': case 'SOFTWARE': - $entity = $this->getPartService()->$action($entity, $formDatas); + $entity = $this->getPartService()->$action($entity); break; case 'SWITCH': - $entity = $this->getSwitchService()->$action($entity, $formDatas); + $entity = $this->getSwitchService()->$action($entity); break; case 'IP': - $entity = $this->getIPService()->$action($entity, $formDatas); + $entity = $this->getIPService()->$action($entity); break; case 'CS': - $entity = $this->getCSService()->$action($entity, $formDatas); + $entity = $this->getCSService()->$action($entity); break; } + //서비스 및 결제정보 처리 + switch ($entity->getBilling()) { + case PAYMENT['BILLING']['MONTH']: //월별 + $entity = $this->getServiceService()->$action($entity); + break; + case PAYMENT['BILLING']['ONETIME']: //일회성 + $entity = $this->getPaymentService()->$action($entity); + break; + case PAYMENT['BILLING']['BASE']: //기본 + //아무처리 않함 + break; + default: + throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); + // break; + } return $entity; } //부품연결정보생성 @@ -229,13 +244,8 @@ class ServerPartService extends EquipmentService $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); $formDatas["serverinfo_uid"] = $serverEntity->getPK(); $entity = parent::create($formDatas); - //부품정보 설정 - $entity = $this->setServerPart("createServerPart", $entity, ['part_uid' => $formDatas['part_uid'], 'status' => STATUS['OCCUPIED']]); - //결제방식이 기본이 아니면 결제관련정보 설정 - if ($entity->getBilling() !== PAYMENT['BILLING']['BASE']) { - $entity = $this->getPaymentService()->createServerPart($entity); - } - return $entity; + //부품연결정보관련 정보처리 + return $this->action_process($entity, __FUNCTION__ . 'ServerPart'); } //수정 public function modify(mixed $entity, array $formDatas): ServerPartEntity @@ -248,34 +258,24 @@ class ServerPartService extends EquipmentService if (!($serverEntity instanceof ServerEntity)) { throw new \Exception("서버 정보가 지정되지 않았습니다."); } - //부품연결정보에 부품정보가 변경된 경우(기존것은 AVAILABLE로 변경) - if ($entity->getPartUID() != $formDatas['part_uid']) { - $entity = $this->setServerPart("modifyServerPart", $entity, ['part_uid' => $entity->getPartUID(), 'status' => STATUS['AVAILABLE']]); + //수정 전 부품연결정보관련 정보처리 + if ($entity->getCnt() != $formDatas['cnt'] || $entity->getPartUID() !== $formDatas['part_uid']) { + $entity = $this->action_process($entity, 'deleteServerPart'); } //수정작업 $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); $formDatas["serverinfo_uid"] = $serverEntity->getPK(); $entity = parent::modify($entity, $formDatas); - //부품연결정보에 부품정보가 변경된 경우 OCCUPIED로 변경 - if ($entity->getPartUID() != $formDatas['part_uid']) { - $entity = $this->setServerPart("modifyServerPart", $entity, ['part_uid' => $formDatas['part_uid'], 'status' => STATUS['OCCUPIED']]); - } - //결제방식이 기본이 아니면 결제관련정보 설정 - if ($entity->getBilling() !== PAYMENT['BILLING']['BASE']) { - $entity = $this->getPaymentService()->modifyeServerPart($entity); - } + //수정 후 부품연결정보관련 정보처리 + $entity = $this->action_process($entity, __FUNCTION__ . 'ServerPart'); return $entity; } //삭제 public function delete(mixed $entity): ServerPartEntity { - //부품연결정보에 부품정보 정의 - $entity = $this->setServerPart("deleteServerPart", $entity, ['part_uid' => $entity->getPartUID(), 'status' => STATUS['AVAILABLE']]); - //결제방식이 기본이 아니면 결제관련정보 설정 - if ($entity->getBilling() !== PAYMENT['BILLING']['BASE']) { - $entity = $this->getPaymentService()->deleteServerPart($entity); - } + //부품연결정보관련 정보처리 + $entity = $this->action_process($entity, __FUNCTION__ . 'ServerPart'); return parent::delete($entity); } } diff --git a/app/Services/Equipment/Switch/ServerPart.php b/app/Services/Equipment/Switch/ServerPart.php new file mode 100644 index 0000000..8e39a34 --- /dev/null +++ b/app/Services/Equipment/Switch/ServerPart.php @@ -0,0 +1,53 @@ +getEntity($serverPartEntity->getPartUID()); + if (!($entity instanceof SwitchEntity)) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 스위치정보를 찾을수없습니다."); + } + //스위치정보 수정 + return $this->modify($entity, $formDatas); + } + public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + $entity = $this->action_process($serverPartEntity, $formDatas); + return $serverPartEntity->setPartEntity($entity); + } + public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + return $this->createServerPart($serverPartEntity); + } + public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['status'] = STATUS['AVAILABLE']; + $entity = $this->action_process($serverPartEntity, $formDatas); + return $serverPartEntity->setPartEntity($entity); + } +} diff --git a/app/Services/Equipment/Switch/ServicePart.php b/app/Services/Equipment/Switch/ServicePart.php deleted file mode 100644 index ac3f4de..0000000 --- a/app/Services/Equipment/Switch/ServicePart.php +++ /dev/null @@ -1,45 +0,0 @@ -getEntity($serverPartDatas['part_uid']); - if (!($entity instanceof SwitchEntity)) { - throw new \Exception("{$serverPartDatas['part_uid']}에 해당하는 스위치정보를 찾을수없습니다."); - } - - //부품정보에 서버정보 설정 및 서비스,고객정보 정의 - $formDatas = []; - if ($serverPartDatas['status'] === STATUS['AVAILABLE']) { - //사용가능 - $formDatas['clientinfo_uid'] = null; - $formDatas['serviceinfo_uid'] = null; - $formDatas['serverinfo_uid'] = null; - } else { - $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); - $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); - } - $formDatas['status'] = $serverPartDatas['status']; - return $serverPartEntity->setPartEntity($this->modify($entity, $formDatas)); - } -} diff --git a/app/Services/Payment/ServerPart.php b/app/Services/Payment/ServerPart.php index 4ef03a1..aadca84 100644 --- a/app/Services/Payment/ServerPart.php +++ b/app/Services/Payment/ServerPart.php @@ -2,7 +2,6 @@ namespace App\Services\Payment; -use App\Entities\Customer\ServiceEntity; use App\Entities\Equipment\ServerPartEntity; use App\Entities\PaymentEntity; use App\Interfaces\Equipment\ServerPartInterface; @@ -25,29 +24,17 @@ class ServerPart extends PaymentService implements ServerPartInterface return $this->_serverPartService; } - //월과금은 해당 서비스의 항목별 금액을 총 합산후 청구금액을 설정후 결제정보에 신규등록/수정한다 - private function serverPart_process_month(ServiceEntity $serviceEntity, ServerPartEntity $serverPartEntity): ServiceEntity + private function action_process(ServerPartEntity $serverPartEntity): array { - //월비용인경우 서비스 제공가에 서버연결정보 제공가 합산금액으로 설정 - $serviceFormDatas = []; - $serviceFormDatas['serverinfo_uid'] = $serviceEntity->getServerInfoUID(); - $serviceFormDatas['billing_at'] = $serviceEntity->getBillingAt(); - //해당 서비스(서버) 관련 경제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 수정한다. - $serviceFormDatas['amount'] = $serviceEntity->getServerEntity()->getPrice(); //서버금액(price) - //월과금용 ServerPartEntity의 금액을 모두 총합산한 금액을 설정한다. - foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $serviceEntity->getServerInfoUID()]) as $serverPartEntity) { - $serviceFormDatas['amount'] += $serverPartEntity->getAmount(); + if ($serverPartEntity->getServiceInfoUID() === null) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); } - return $this->getServiceService()->modify($serviceEntity, $serviceFormDatas); - } - private function serverPart_process(ServerPartEntity $serverPartEntity, array $formDatas = []): array - { - //Service Entity 가져오기 - $serviceEntity = $this->getServiceService()->getEntity($serverPartEntity->getServiceInfoUID()); - if (!$serviceEntity) { - throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); + //일회인이 아닌경우 + if ($serverPartEntity->getBilling() !== PAYMENT['BILLING']['ONETIME']) { + throw new \Exception(__METHOD__ . "에서 오류발생: :" . lang("{$this->getClassName()}.BILLING." . PAYMENT['BILLING'][$serverPartEntity->getBilling()]) . "지급 상품은 처리가 불가, 일회성만 가능합니다."); } + $formDatas = []; $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); //서버연결정보 수정시에 필요함 @@ -56,46 +43,35 @@ class ServerPart extends PaymentService implements ServerPartInterface $formDatas['title'] = $serverPartEntity->getType() === 'ETC' ? $serverPartEntity->getTitle() : $serverPartEntity->getPartEntity()->getTitle(); $formDatas['amount'] = $serverPartEntity->getAmount(); $formDatas['billing'] = $serverPartEntity->getBilling(); - //월과금인경우 - if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { - //결제일설정 - $formDatas['billing_at'] = $serviceEntity->getBillingAt(); - $this->serverPart_process_month($serviceEntity, $serverPartEntity); - } - //일회성인경우 - if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME']) { - //당일결체일로 설정 - $formDatas['billing_at'] = date("Y-m-d"); - } return $formDatas; } - public function createServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas = []): ServerPartEntity + public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity { - if ($serverPartEntity->getServiceInfoUID() === null) { - throw new \Exception(lang("{$this->getClassName()}.BILLING." . PAYMENT['BILLING']['MONTH']) . "지급 상품은 서비스정보가 정의된 후에만 가능합니다."); - } - //Service Entity 가져오기 - $serviceEntity = $this->getServiceService()->getEntity($serverPartEntity->getServiceInfoUID()); - if (!$serviceEntity) { - throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); - } - //기본 처리 후 FormData 가져오기 - $formDatas = $this->serverPart_process($serverPartEntity); + //필수정보처리 후 FormData 가져오기 + $formDatas = $this->action_process($serverPartEntity); + //당일결체일로 설정 + $formDatas['billing_at'] = date("Y-m-d"); //결제정보등록 $this->create($formDatas); return $serverPartEntity; } - public function modifyServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas = []): ServerPartEntity + public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity { - //serverpartinfo_uid에 해당하는 결제정보 가져오기 + //미납상태의 결제정보 가져오기 $entity = $this->getEntity(['serverpartinfo_uid' => $serverPartEntity->getPK(), 'status' => STATUS['UNPAID']]); if (!$entity instanceof PaymentEntity) { throw new \Exception(__METHOD__ . "에서 오류발생: {$serverPartEntity->getPK()}에 해당하는 결제정보를 찾을수 없습니다."); } - //기본 처리 후 FormData 가져오기 - $formDatas = $this->serverPart_process($serverPartEntity); - //결제수정등록 + //필수정보처리 후 FormData 가져오기 + $formDatas = $this->action_process($serverPartEntity); + //결제정보수정 $this->modify($entity, $formDatas); return $serverPartEntity; } + + public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity + { + //삭제시에는 아무것도 하지 않는다. + return $serverPartEntity; + } } diff --git a/app/Services/Payment/Service.php b/app/Services/Payment/Service.php index 5106d05..bb6ce11 100644 --- a/app/Services/Payment/Service.php +++ b/app/Services/Payment/Service.php @@ -2,10 +2,10 @@ namespace App\Services\Payment; -use App\Entities\Customer\ServiceEntity; -use App\Entities\Equipment\ServerPartEntity; -use App\Interfaces\Customer\ServiceInterface; use App\Services\Customer\ServiceService; +use App\Interfaces\Customer\ServiceInterface; +use App\Entities\PaymentEntity; +use App\Entities\Customer\ServiceEntity; class Service extends ServiceService implements ServiceInterface { @@ -13,23 +13,37 @@ class Service extends ServiceService implements ServiceInterface { parent::__construct(); } - //서버연결정보용 등록 - //서비스정보용 등록 - public function setService(string $action, ServiceEntity $serviceEntity, array $serviceDatas = []): ServiceENtity + private function action_process(ServiceEntity $serviceEntity, array $formDatas = []): array { - $formDatas = []; - $formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID(); + $formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID(); $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); - $formDatas['serverinfo_uid'] = $serviceEntity->getServerInfoUID(); - $formDatas['title'] = $serviceEntity->getServerEntity()->getTitle(); - $formDatas['amount'] = $serviceEntity->getAmount(); - $formDatas['billing'] = PAYMENT['BILLING']['MONTH']; - $formDatas['billing_at'] = $serviceEntity->getBillingAt(); - $this->create($formDatas); + $formDatas['serverinfo_uid'] = $serviceEntity->getServerInfoUID(); + $formDatas['title'] = $serviceEntity->getServerEntity()->getTitle(); + $formDatas['amount'] = $serviceEntity->getAmount(); + $formDatas['billing'] = PAYMENT['BILLING']['MONTH']; + $formDatas['billing_at'] = $serviceEntity->getBillingAt(); + return $formDatas; + } + public function createService(ServiceEntity $serviceEntity): ServiceEntity + { + //필수정보처리 후 결제정보등록 + $this->create($this->action_process($serviceEntity)); return $serviceEntity; } - public function setServiceAmount(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + public function modifyService(ServiceEntity $serviceEntity): ServiceEntity { - return $serverPartEntity; + //미납상태의 결제정보 가져오기 + $entity = $this->getEntity(['serviceinfo_uid' => $serviceEntity->getPK(), 'status' => STATUS['UNPAID']]); + if (!$entity instanceof PaymentEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: {$serviceEntity->getPK()}에 해당하는 결제정보를 찾을수 없습니다."); + } + //필수정보처리 후 결제정보수정 + $this->modify($entity, $this->action_process($serviceEntity)); + return $serviceEntity; + } + public function deleteService(ServiceEntity $serviceEntity): ServiceEntity + { + //삭제시에는 아무것도 하지 않는다. + return $serviceEntity; } } diff --git a/app/Services/Service/ServicePart.php b/app/Services/Service/ServicePart.php deleted file mode 100644 index e203461..0000000 --- a/app/Services/Service/ServicePart.php +++ /dev/null @@ -1,32 +0,0 @@ -