From fa700e56c86e67066cfa62d709c5f1267e885095 Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Mon, 29 Sep 2025 16:34:07 +0900 Subject: [PATCH] dbmsv2_init...1 --- app/Config/Routes.php | 1 + .../Admin/Customer/ServiceController.php | 52 ++-- app/Database/dbmsv2_test1.sql | 10 +- app/Interfaces/Customer/ServiceInterface.php | 6 +- app/Interfaces/Equipment/ServerInterface.php | 6 +- .../Equipment/ServerPartInterface.php | 6 +- .../Customer/Service/PaymentService.php | 56 ----- .../Customer/Service/ServerService.php | 54 ---- app/Services/Customer/ServiceService.php | 153 ++++++++--- .../Equipment/Server/ServerPartService.php | 35 --- .../Equipment/Server/ServiceService.php | 46 ---- .../Equipment/ServerPart/CPUService.php | 53 ---- .../Equipment/ServerPart/CSService.php | 55 ---- .../Equipment/ServerPart/DISKService.php | 53 ---- .../Equipment/ServerPart/IPService.php | 55 ---- .../Equipment/ServerPart/OSService.php | 53 ---- .../Equipment/ServerPart/PaymentService.php | 71 ------ .../Equipment/ServerPart/RAMService.php | 53 ---- .../Equipment/ServerPart/SOFTWAREService.php | 53 ---- .../Equipment/ServerPart/SWITCHService.php | 55 ---- .../Equipment/ServerPart/ServiceService.php | 42 ---- app/Services/Equipment/ServerPartService.php | 238 ++++++++++++++---- app/Services/Equipment/ServerService.php | 80 +++++- app/Services/Part/CPUService.php | 39 ++- app/Services/Part/CSService.php | 53 +++- app/Services/Part/DISKService.php | 39 ++- app/Services/Part/IPService.php | 56 ++++- app/Services/Part/OSService.php | 39 ++- app/Services/Part/PartService.php | 2 - app/Services/Part/RAMService.php | 39 ++- app/Services/Part/SOFTWAREService.php | 39 ++- app/Services/Part/SWITCHService.php | 54 +++- app/Services/PaymentService.php | 128 +++++++++- 33 files changed, 904 insertions(+), 870 deletions(-) delete mode 100644 app/Services/Customer/Service/PaymentService.php delete mode 100644 app/Services/Customer/Service/ServerService.php delete mode 100644 app/Services/Equipment/Server/ServerPartService.php delete mode 100644 app/Services/Equipment/Server/ServiceService.php delete mode 100644 app/Services/Equipment/ServerPart/CPUService.php delete mode 100644 app/Services/Equipment/ServerPart/CSService.php delete mode 100644 app/Services/Equipment/ServerPart/DISKService.php delete mode 100644 app/Services/Equipment/ServerPart/IPService.php delete mode 100644 app/Services/Equipment/ServerPart/OSService.php delete mode 100644 app/Services/Equipment/ServerPart/PaymentService.php delete mode 100644 app/Services/Equipment/ServerPart/RAMService.php delete mode 100644 app/Services/Equipment/ServerPart/SOFTWAREService.php delete mode 100644 app/Services/Equipment/ServerPart/SWITCHService.php delete mode 100644 app/Services/Equipment/ServerPart/ServiceService.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c84c111..baf352c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -126,6 +126,7 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->get('alternative/(:num)', 'ServiceController::alternative_form/$1'); $routes->post('alternative/(:num)', 'ServiceController::alternative/$1'); $routes->get('main/(:num)', 'ServiceController::main/$1'); + $routes->get('terminate/(:num)', 'ServiceController::terminate/$1'); $routes->post('history/(:num)', 'ServiceController::history/$1'); }); $routes->group('payment', ['namespace' => 'App\Controllers\Admin\Customer'], function ($routes) { diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index 56bcf61..f9bb090 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -142,18 +142,7 @@ class ServiceController extends CustomerController return $this->getResultFail($e->getMessage()); } } - protected function alternative_process(mixed $entity, array $formDatas): mixed - { - $serverEntity = $this->getService()->getServerService()->getEntity($formDatas['serverinfo_uid']); - if (!$serverEntity instanceof ServerEntity) { - throw new \Exception("{$formDatas['serverinfo_uid']}에 대한 서버정보를 찾을수 없습니다."); - } - $formDatas['clientinfo_uid'] = $entity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $entity->getPK(); - $formDatas['type'] = "alternative"; - $formDatas['status'] = STATUS['OCCUPIED']; - return $this->getServerService()->modify($serverEntity, $formDatas); - } + //대체서버 등록 public function alternative(int $uid): RedirectResponse|string { //Transaction Start @@ -172,7 +161,9 @@ class ServiceController extends CustomerController if (!$entity instanceof ServiceEntity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $this->entity = $this->alternative_process($entity, $this->getService()->getFormDatas()); + $formDatas = $this->getService()->getFormDatas(); + $formDatas['type'] = 'alternative'; //대체서버로 등록하기위해 필요 + $this->entity = $this->getService()->addAlternativeServer($entity, $formDatas); $db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { @@ -180,7 +171,7 @@ class ServiceController extends CustomerController return $this->getResultFail($e->getMessage()); } } - //MAIN서버선정 + //대체서버를 MAIN서버로 설정 public function main(mixed $uid): RedirectResponse|string { //Transaction Start @@ -199,17 +190,37 @@ class ServiceController extends CustomerController if (!$entity instanceof ServiceEntity) { throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); } - $formDatas = $this->getService()->getFormDatas(); if (!array_key_exists('serverinfo_uid', $formDatas)) { throw new \Exception("서비스의 메인서버로 설정할 서버정보가 없습니다."); } - $serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']); - if (!$serverEntity instanceof ServerEntity) { - throw new \Exception("{$formDatas['serverinfo_uid']}에 대한 서버정보를 찾을수 없습니다."); - } //서버정보설정 - $this->getService()->setMainServer($entity, $serverEntity); + $this->getService()->changeAlternativeServer($entity, $formDatas); + $db->transCommit(); + return $this->getResultSuccess(); + } catch (\Exception $e) { + $db->transRollback(); + return $this->getResultFail($e->getMessage()); + } + } + //서비스 서버해지 + public function terminate(mixed $uid): RedirectResponse|string + { + //Transaction Start + $db = \Config\Database::connect(); + $db->transStart(); + try { + $this->getService()->setAction(__FUNCTION__); + $this->getService()->setFormFields(['serverinfo_uid']); + //전달값정의 + $this->getService()->setFormDatas($this->request->getGet()); + //기존 Entity 가져오기 + $entity = $this->getService()->getEntity($uid); + if (!$entity instanceof ServiceEntity) { + throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다."); + } + $formDatas = $this->getService()->getFormDatas(); + $this->getService()->terminateAlternativeServer($entity, $formDatas); $db->transCommit(); return $this->getResultSuccess(); } catch (\Exception $e) { @@ -217,7 +228,6 @@ class ServiceController extends CustomerController return $this->getResultFail($e->getMessage()); } } - public function history(int $uid): RedirectResponse|string { //Transaction Start diff --git a/app/Database/dbmsv2_test1.sql b/app/Database/dbmsv2_test1.sql index 0ec5b21..955c310 100644 --- a/app/Database/dbmsv2_test1.sql +++ b/app/Database/dbmsv2_test1.sql @@ -380,7 +380,7 @@ CREATE TABLE `payment` ( LOCK TABLES `payment` WRITE; /*!40000 ALTER TABLE `payment` DISABLE KEYS */; -INSERT INTO `payment` VALUES (17,1,820,52,'HP DL360 Gen6',1000000,'month','2025-09-25',NULL,'unpaid','2025-09-26 10:00:39','2025-09-25 06:29:25',NULL),(18,1,1161,53,'HP DL360 Gen7',900000,'month','2025-09-25',NULL,'unpaid','2025-09-25 08:14:06','2025-09-25 06:31:18',NULL),(19,1,820,52,'2G',40000,'onetime','2025-09-25',NULL,'unpaid','2025-09-25 08:27:17','2025-09-25 08:15:08',NULL),(20,1,1087,54,'HP DL360 Gen8',900000,'month','2025-09-25',NULL,'unpaid',NULL,'2025-09-25 08:36:43',NULL),(21,1,820,52,'16G',300000,'onetime','2025-09-26',NULL,'unpaid',NULL,'2025-09-26 07:03:50',NULL); +INSERT INTO `payment` VALUES (17,1,820,52,'HP DL360 Gen6',1000000,'month','2025-09-25',NULL,'unpaid','2025-09-29 03:51:07','2025-09-25 06:29:25',NULL),(18,1,1161,53,'HP DL360 Gen7',900000,'month','2025-09-25',NULL,'unpaid','2025-09-25 08:14:06','2025-09-25 06:31:18',NULL),(19,1,820,52,'2G',40000,'onetime','2025-09-25',NULL,'unpaid','2025-09-25 08:27:17','2025-09-25 08:15:08',NULL),(20,1,1087,54,'HP DL360 Gen8',900000,'month','2025-09-25',NULL,'unpaid',NULL,'2025-09-25 08:36:43',NULL),(21,1,820,52,'16G',300000,'onetime','2025-09-26',NULL,'unpaid',NULL,'2025-09-26 07:03:50',NULL); /*!40000 ALTER TABLE `payment` ENABLE KEYS */; UNLOCK TABLES; @@ -485,7 +485,7 @@ CREATE TABLE `serverinfo` ( LOCK TABLES `serverinfo` WRITE; /*!40000 ALTER TABLE `serverinfo` DISABLE KEYS */; -INSERT INTO `serverinfo` VALUES (17,820,52,'250922-M1','normal','HP DL360 Gen6',500000,'2025-08-31 15:00:00','0000-00-00 00:00:00','occupied','2025-09-26 06:52:03','2025-09-22 02:19:25',NULL),(18,1161,53,'250922-M18','normal','HP DL360 Gen7',400000,'2025-09-01 15:00:00',NULL,'occupied','2025-09-26 01:28:35','2025-09-22 02:21:51',NULL),(19,1087,54,'250922-M19','normal','HP DL360 Gen8',500000,'2025-09-02 15:00:00',NULL,'occupied','2025-09-26 01:28:44','2025-09-22 02:22:14',NULL),(20,820,52,'250922-M20','alternative','HP DL360 Gen9',600000,'2025-09-03 15:00:00',NULL,'occupied','2025-09-26 04:02:28','2025-09-22 02:22:39',NULL),(21,820,52,'250922-M21','alternative','HP DL360 Gen10',700000,'2025-09-04 15:00:00',NULL,'occupied','2025-09-26 06:47:57','2025-09-22 02:23:08',NULL),(22,NULL,NULL,'250922-M22','normal','Hitach HA3000',800000,'2025-09-05 15:00:00','0000-00-00 00:00:00','available','2025-09-26 01:41:20','2025-09-22 02:23:36',NULL); +INSERT INTO `serverinfo` VALUES (17,820,52,'250922-M1','normal','HP DL360 Gen6',500000,'2025-08-31 15:00:00','0000-00-00 00:00:00','occupied','2025-09-26 06:52:03','2025-09-22 02:19:25',NULL),(18,1161,53,'250922-M18','normal','HP DL360 Gen7',400000,'2025-09-01 15:00:00',NULL,'occupied','2025-09-26 01:28:35','2025-09-22 02:21:51',NULL),(19,1087,54,'250922-M19','normal','HP DL360 Gen8',500000,'2025-09-02 15:00:00',NULL,'occupied','2025-09-26 01:28:44','2025-09-22 02:22:14',NULL),(20,820,52,'250922-M20','alternative','HP DL360 Gen9',600000,'2025-09-03 15:00:00',NULL,'occupied','2025-09-26 04:02:28','2025-09-22 02:22:39',NULL),(21,820,52,'250922-M21','alternative','HP DL360 Gen10',700000,'2025-09-04 15:00:00',NULL,'occupied','2025-09-26 06:47:57','2025-09-22 02:23:08',NULL),(22,820,52,'250922-M22','alternative','Hitach HA3000',800000,'2025-09-05 15:00:00','0000-00-00 00:00:00','occupied','2025-09-29 03:59:13','2025-09-22 02:23:36',NULL); /*!40000 ALTER TABLE `serverinfo` ENABLE KEYS */; UNLOCK TABLES; @@ -568,7 +568,7 @@ CREATE TABLE `serviceinfo` ( CONSTRAINT `FK_payment_TO_serviceinfo` FOREIGN KEY (`payment_uid`) REFERENCES `payment` (`uid`), CONSTRAINT `FK_serverinfo_TO_serviceinfo` FOREIGN KEY (`serverinfo_uid`) REFERENCES `serverinfo` (`uid`), CONSTRAINT `FK_user_TO_serviceinfo` FOREIGN KEY (`user_uid`) REFERENCES `user` (`uid`) -) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8 COMMENT='서비스정보'; +) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=utf8 COMMENT='서비스정보'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -577,7 +577,7 @@ CREATE TABLE `serviceinfo` ( LOCK TABLES `serviceinfo` WRITE; /*!40000 ALTER TABLE `serviceinfo` DISABLE KEYS */; -INSERT INTO `serviceinfo` VALUES (52,1,820,20,17,'prime_s68d4e145a474d','prime','chiba',100000,300000,'2025-09-25',1000000,'2025-09-25',NULL,NULL,'available','2025-09-26 10:00:39','2025-09-25 06:29:25',NULL),(53,1,1161,18,18,'itsolution_s68d4e1b6','itsolution','chiba',100000,300000,'2025-09-25',900000,'2025-09-25',NULL,NULL,'available','2025-09-25 08:14:06','2025-09-25 06:31:18',NULL),(54,1,1087,19,20,'gdidc_s68d4ff1b03fab','gdidc','chiba',100000,300000,'2025-09-25',900000,'2025-09-25',NULL,NULL,'available','2025-09-25 08:36:43','2025-09-25 08:36:43',NULL); +INSERT INTO `serviceinfo` VALUES (52,1,820,17,17,'prime_s68d4e145a474d','prime','chiba',100000,300000,'2025-09-25',1000000,'2025-09-25',NULL,NULL,'available','2025-09-29 03:51:07','2025-09-25 06:29:25',NULL),(53,1,1161,18,18,'itsolution_s68d4e1b6','itsolution','chiba',100000,300000,'2025-09-25',900000,'2025-09-25',NULL,NULL,'available','2025-09-25 08:14:06','2025-09-25 06:31:18',NULL),(54,1,1087,19,20,'gdidc_s68d4ff1b03fab','gdidc','chiba',100000,300000,'2025-09-25',900000,'2025-09-25',NULL,NULL,'available','2025-09-25 08:36:43','2025-09-25 08:36:43',NULL); /*!40000 ALTER TABLE `serviceinfo` ENABLE KEYS */; UNLOCK TABLES; @@ -726,4 +726,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2025-09-27 11:13:54 +-- Dump completed on 2025-09-29 12:59:51 diff --git a/app/Interfaces/Customer/ServiceInterface.php b/app/Interfaces/Customer/ServiceInterface.php index 8ba8d93..1e04f85 100644 --- a/app/Interfaces/Customer/ServiceInterface.php +++ b/app/Interfaces/Customer/ServiceInterface.php @@ -6,7 +6,7 @@ use App\Entities\Customer\ServiceEntity; interface ServiceInterface extends CustomerInterface { - public function createService(ServiceEntity $serviceEntity): ServiceEntity; - public function modifyService(ServiceEntity $serviceEntity): ServiceEntity; - public function deleteService(ServiceEntity $serviceEntity): ServiceEntity; + public function setService(ServiceEntity $serviceEntity, array $formDatas): ServiceEntity; + public function changeService(ServiceEntity $oldServiceEntity, ServiceEntity $serviceEntity, array $formDatas): ServiceEntity; + public function unsetService(ServiceEntity $serviceEntity, array $formDatas): ServiceEntity; } diff --git a/app/Interfaces/Equipment/ServerInterface.php b/app/Interfaces/Equipment/ServerInterface.php index c0d991e..7313728 100644 --- a/app/Interfaces/Equipment/ServerInterface.php +++ b/app/Interfaces/Equipment/ServerInterface.php @@ -6,7 +6,7 @@ use App\Entities\Equipment\ServerEntity; interface ServerInterface extends EquipmentInterface { - public function createServer(ServerEntity $serverEntity): ServerEntity; - public function modifyServer(ServerEntity $serverEntity): ServerEntity; - public function deleteServer(ServerEntity $serverEntity): ServerEntity; + public function setServer(ServerEntity $serverEntity, array $formDatas): ServerEntity; + public function changeServer(ServerEntity $oldServerEntity, ServerEntity $serverEntity, array $formDatas): ServerEntity; + public function unsetServer(ServerEntity $serverEntity, array $formDatas): ServerEntity; } diff --git a/app/Interfaces/Equipment/ServerPartInterface.php b/app/Interfaces/Equipment/ServerPartInterface.php index 84ab6d2..1070853 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): ServerPartEntity; - public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity; - public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity; + public function setServerPart(ServerPartEntity $serverPartEntity, array $formDatas): ServerPartEntity; + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $formDatas): ServerPartEntity; + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $formDatas): ServerPartEntity; } diff --git a/app/Services/Customer/Service/PaymentService.php b/app/Services/Customer/Service/PaymentService.php deleted file mode 100644 index ca7bd07..0000000 --- a/app/Services/Customer/Service/PaymentService.php +++ /dev/null @@ -1,56 +0,0 @@ -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(); - return $formDatas; - } - public function createService(ServiceEntity $serviceEntity): ServiceEntity - { - //필수정보처리 후 결제정보등록 - $entity = $this->getModel()->create($this->action_process($serviceEntity)); - //서비스정보 Entity에 결제정보 설정 - return $serviceEntity->setPaymentEntity($entity); - } - public function modifyService(ServiceEntity $serviceEntity): ServiceEntity - { - //결제정보 가져오기 - $entity = $serviceEntity->getPaymentEntity(); - if (!$entity instanceof PaymentEntity) { - throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보[{$serviceEntity->getPK()}]에 해당하는 결제정보를 찾을수 없습니다."); - } - //미납상태확인 - if ($entity->getStatus() !== STATUS['UNPAID']) { - throw new \Exception(__METHOD__ . "에서 오류발생: 완료된 결제는 수정이 불가합니다."); - } - //필수정보처리 후 결제정보수정 - $entity = $this->getModel()->modify($entity, $this->action_process($serviceEntity)); - //서비스정보 Entity에 결제정보 설정 - return $serviceEntity->setPaymentEntity($entity); - } - public function deleteService(ServiceEntity $serviceEntity): ServiceEntity - { - //삭제시에는 아무것도 하지 않는다. - return $serviceEntity; - } -} diff --git a/app/Services/Customer/Service/ServerService.php b/app/Services/Customer/Service/ServerService.php deleted file mode 100644 index 78b439b..0000000 --- a/app/Services/Customer/Service/ServerService.php +++ /dev/null @@ -1,54 +0,0 @@ -getServerEntity(); - if (!$entity instanceof ServerEntity) { - throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보[{$serviceEntity->getPK()}]에 해당하는 서버정보를 찾을수없습니다."); - } - //서버정보 수정 - return $this->getModel()->modify($entity, $formDatas); - } - public function createService(ServiceEntity $serviceEntity): ServiceEntity - { - $formDatas = []; - $formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID(); - $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); - $formDatas['status'] = STATUS['OCCUPIED']; - $entity = $this->action_process($serviceEntity, $formDatas); - //서비스정보 Entity에 서버정보 설정 - return $serviceEntity->setServerEntity($entity); - } - public function modifyService(ServiceEntity $serviceEntity): ServiceEntity - { - return $this->createService($serviceEntity); - } - public function deleteService(ServiceEntity $serviceEntity): ServiceEntity - { - $formDatas = []; - $formDatas['clientinfo_uid'] = null; - $formDatas['serviceinfo_uid'] = null; - $formDatas['format_at'] = date("Y-m-d"); - $formDatas['status'] = STATUS['TERMINATED']; - $entity = $this->action_process($serviceEntity, $formDatas); - //서비스정보 Entity에 서버정보 설정 - return $serviceEntity->setServerEntity($entity); - } -} diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 89f50d9..b0df867 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -4,14 +4,17 @@ namespace App\Services\Customer; use App\Entities\Customer\ServiceEntity; use App\Entities\Equipment\ServerEntity; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\PaymentEntity; use App\Helpers\Customer\ServiceHelper; +use App\Interfaces\Equipment\ServerInterface; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Customer\ServiceModel; -use App\Services\Customer\Service\PaymentService; -use App\Services\Customer\Service\ServerService; use App\Services\Equipment\ServerPartService; +use App\Services\Equipment\ServerService; +use App\Services\PaymentService; -class ServiceService extends CustomerService +class ServiceService extends CustomerService implements ServerInterface, ServerPartInterface { private ?ServerService $_serverService = null; private ?PaymentService $_paymentService = null; @@ -160,8 +163,10 @@ class ServiceService extends CustomerService ) WHERE billing_at = ? AND status = ?"; return $this->getModel()->query($sql, [$billing_at, $status]); } + //조정된 금액 설정 final public function getCaculatedAmount(ServiceEntity $entity): int { + //총서비스금액 계산 $caculatedAmount = $entity->getRack() + $entity->getLine() + $entity->getServerEntity()->getPrice(); //기본:상면비+회선비+서버금액(price)+서버파트연결(월비용) //해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 합산한다. foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getServerEntity()->getPK()]) as $serverPartEntity) { @@ -171,26 +176,49 @@ class ServiceService extends CustomerService } return $caculatedAmount; } - //조정된 금액 설정 final public function setAmount(ServiceEntity $entity): ServiceEntity { $caculatedAmount = $this->getCaculatedAmount($entity); + //계산된 금액이 현재 금액과 다른 경우 if ($entity->getAmount() !== $caculatedAmount) { $paymentEntity = $entity->getPaymentEntity(); if (!$paymentEntity instanceof PaymentEntity) { throw new \Exception(__METHOD__ . "에서 오류발생: 결제정보가 정의되지 않았습니다."); } //금액설정 - $entity = parent::modify($entity, ['amount' => $caculatedAmount]); - $this->getPaymentService()->setAmount($entity->getPaymentEntity(), $caculatedAmount); + parent::modify($entity, ['amount' => $caculatedAmount]); } return $entity; } - //서비스 메인서버 설정 - final public function setMainServer(ServiceEntity $entity, ServerEntity $serverEntity): ServiceEntity + //대체서버추가(가격변동은 없음) + final public function addAlternativeServer(ServiceEntity $entity, array $formDatas): ServiceEntity { + $this->getServerService()->setService($entity, $formDatas); + return $entity; + } + //대체 서버를 메인서버로 설정 + final public function changeAlternativeServer(ServiceEntity $entity, array $formDatas): ServiceEntity + { + $serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']); + if (!$serverEntity instanceof ServerEntity) { + throw new \Exception("{$formDatas['serverinfo_uid']}에 대한 서버정보를 찾을수 없습니다."); + } + //수정전 정보 + $oldEntity = $entity; + //메인서버 변경 $entity = parent::modify($entity, ['serverinfo_uid' => $serverEntity->getPK()]); - return $this->setAmount($entity); + //전체 서비스금액 설정 + $entity = $this->setAmount($entity); + //결제정보수정 + $entity = $this->getPaymentService()->changeService($oldEntity, $entity, $formDatas); + //결제정보 PK설정 + return parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); + } + //뎇[서버해지(대체서버는 해지는 가격변동은 없음) + final public function terminateAlternativeServer(ServiceEntity $entity, array $formDatas): ServiceEntity + { + $this->getServerService()->unsetService($entity, $formDatas); + return $entity; } //기본 기능부분 //FieldForm관련용 @@ -216,16 +244,6 @@ class ServiceService extends CustomerService } return $options; } - //Action 기능 - private function action_process(ServiceEntity $entity, string $action): ServiceEntity - { - //서버정보수정 - $entity = $this->getServerService()->$action($entity); - //결제정보수정 및 결제정보 PK값정의 - $entity = $this->getPaymentService()->$action($entity); - $entity = parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); - return $entity; - } //생성 public function create(array $formDatas): ServiceEntity { @@ -234,26 +252,101 @@ class ServiceService extends CustomerService } //신규등록(월청구액 전달값 그대로 사용) $entity = parent::create($formDatas); - //후처리작업 - return $this->action_process($entity, __FUNCTION__ . 'Service'); + //서버등록 + $entity = $this->getServerService()->setService($entity, $formDatas); + //전체 서비스금액 설정 + $entity = $this->setAmount($entity); + //결제정보수정 + $entity = $this->getPaymentService()->setService($entity, $formDatas); + //결제정보 PK설정 + return parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); } //수정 public function modify(mixed $entity, array $formDatas): ServiceEntity { - //기존 서버정보 해지 - if (array_key_exists('serverinfo_uid', $formDatas) && $entity->getServerEntity()->getPK() != $formDatas['serverinfo_uid']) { - $entity->getServerService()->deleteService($entity); + //수정전 정보 + $oldEntity = $entity; + //서비스정보 수정 + $entity = parent::modify($entity, $formDatas); + //기존 서버정보와 다르다면 서버변경 + if ($entity->getServerEntity()->getPK() != $formDatas['serverinfo_uid']) { + $entity = $this->getServerService()->changeService($oldEntity, $entity, $formDatas); } - //수정작업(월청구액계산 확인 후 서비스정보에 수정) - $entity = parent::modify($entity, ['amount' => $this->getCaculatedAmount($entity)]); - //후처리작업 - return $this->action_process($entity, __FUNCTION__ . 'Service'); + //전체 서비스금액 설정 + $entity = $this->setAmount($entity); + //결제정보수정 + $entity = $this->getPaymentService()->changeService($oldEntity, $entity, $formDatas); + //결제정보 PK설정 + return parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); } //삭제 public function delete(mixed $entity): ServiceEntity { - //선처리작업 - $this->action_process($entity, __FUNCTION__ . 'Service'); + //서버해지 + $this->getServerService()->unsetService($entity, ['serverinfo_uid' => $entity->getServerEntity()->getPK()]); return parent::delete($entity); } + + //서버관련 작업 + public function setServer(ServerEntity $serverEntity, array $serverDatas): ServerEntity + { + //아무것도 하지 않음 + return $serverEntity; + } + public function changeServer(ServerEntity $oldServerEntity, ServerEntity $serverEntity, array $serverDatas): ServerEntity + { + //서비스정보가 NULL이 아니고 형식이 대체(alternative)가 아닌경우만 적용 + if ($serverEntity->getServiceInfoUID() !== null && $serverEntity->getType() !== "alternative") { + //Service Entity 가져오기 + $entity = $this->getEntity($serverEntity->getServiceInfoUID()); + if (!$entity instanceof ServiceEntity) { + throw new \Exception("[{$serverEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); + } + //서비스금액변경 사항이 있는지 확인후 처리 + $entity = $this->setAmount($entity); + //결제정보수정 + $entity = $this->getPaymentService()->setService($entity, []); + //결제정보 PK설정 + parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); + } + return $serverEntity; + } + public function unsetServer(ServerEntity $serverEntity, array $serverDatas): ServerEntity + { + //서비스중인지 확인 + if ($serverEntity->getServiceInfoUID() !== null || $serverEntity->getStatus() === STATUS['OCCUPIED']) { + throw new \Exception("서비스중이 서버는 삭제하실수 없습니다."); + } + //아무것도 하지 않음 + return $serverEntity; + } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + if ($serverPartEntity->getBilling() !== PAYMENT['BILLING']['MONTH']) { + throw new \Exception("[{$serverPartEntity->getBilling()}],청구방식이 매월이 아닙니다."); + } + //Service Entity 가져오기 + $entity = $this->getEntity($serverPartEntity->getServiceInfoUID()); + if (!$entity instanceof ServiceEntity) { + throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); + } + //서비스금액변경 사항이 있는지 확인후 처리 + $entity = $this->setAmount($entity); + //결제정보수정 + $entity = $this->getPaymentService()->setService($entity, []); + //결제정보 PK설정 + return $serverPartEntity; + } + //setServerPart와 같은기능 + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + //setServerPart와 같은기능 + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } } diff --git a/app/Services/Equipment/Server/ServerPartService.php b/app/Services/Equipment/Server/ServerPartService.php deleted file mode 100644 index 4fef878..0000000 --- a/app/Services/Equipment/Server/ServerPartService.php +++ /dev/null @@ -1,35 +0,0 @@ -getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $serverPartEntity) { - $this->getModel()->delete($serverPartEntity); - } - return $serverEntity; - } -} diff --git a/app/Services/Equipment/Server/ServiceService.php b/app/Services/Equipment/Server/ServiceService.php deleted file mode 100644 index f1a21e2..0000000 --- a/app/Services/Equipment/Server/ServiceService.php +++ /dev/null @@ -1,46 +0,0 @@ -getServiceInfoUID() !== null && $serverEntity->getType() !== "alternative") { - //Service Entity 가져오기 - $entity = $this->getEntity($serverEntity->getServiceInfoUID()); - if (!$entity instanceof ServiceEntity) { - throw new \Exception("[{$serverEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); - } - //서비스금액변경 사항이 있는지 확인후 처리 - $entity = $this->setAmount($entity); - } - return $serverEntity; - } - public function deleteServer(ServerEntity $serverEntity): ServerEntity - { - //서비스중인지 확인 - if ($serverEntity->getServiceInfoUID() !== null || $serverEntity->getStatus() === STATUS['OCCUPIED']) { - throw new \Exception("서비스중이 서버는 삭제하실수 없습니다."); - } - //아무것도 하지 않음 - return $serverEntity; - } -} diff --git a/app/Services/Equipment/ServerPart/CPUService.php b/app/Services/Equipment/ServerPart/CPUService.php deleted file mode 100644 index 3640662..0000000 --- a/app/Services/Equipment/ServerPart/CPUService.php +++ /dev/null @@ -1,53 +0,0 @@ -getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof CPUEntity) { - 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->getModel()->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/ServerPart/CSService.php b/app/Services/Equipment/ServerPart/CSService.php deleted file mode 100644 index 646dee2..0000000 --- a/app/Services/Equipment/ServerPart/CSService.php +++ /dev/null @@ -1,55 +0,0 @@ -getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof CSEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다."); - } - //CS정보 수정 - return $this->getModel()->modify($entity, $formDatas); - } - public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - $formDatas = []; - $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/ServerPart/DISKService.php b/app/Services/Equipment/ServerPart/DISKService.php deleted file mode 100644 index 77d35a2..0000000 --- a/app/Services/Equipment/ServerPart/DISKService.php +++ /dev/null @@ -1,53 +0,0 @@ -getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof DISKEntity) { - 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->getModel()->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/ServerPart/IPService.php b/app/Services/Equipment/ServerPart/IPService.php deleted file mode 100644 index c9512c3..0000000 --- a/app/Services/Equipment/ServerPart/IPService.php +++ /dev/null @@ -1,55 +0,0 @@ -getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof IPEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다."); - } - //IP정보 수정 - return $this->getModel()->modify($entity, $formDatas); - } - public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - $formDatas = []; - $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/ServerPart/OSService.php b/app/Services/Equipment/ServerPart/OSService.php deleted file mode 100644 index 38edec1..0000000 --- a/app/Services/Equipment/ServerPart/OSService.php +++ /dev/null @@ -1,53 +0,0 @@ -getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof OSEntity) { - 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->getModel()->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/ServerPart/PaymentService.php b/app/Services/Equipment/ServerPart/PaymentService.php deleted file mode 100644 index 2c0e82d..0000000 --- a/app/Services/Equipment/ServerPart/PaymentService.php +++ /dev/null @@ -1,71 +0,0 @@ -getServiceInfoUID() === null) { - throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); - } - //일회인이 아닌경우 - if ($serverPartEntity->getBilling() !== PAYMENT['BILLING']['ONETIME']) { - throw new \Exception(__METHOD__ . "에서 오류발생: :" . lang("{$this->getClassName()}.BILLING." . PAYMENT['BILLING'][$serverPartEntity->getBilling()]) . "지급 상품은 처리가 불가, 일회성만 가능합니다."); - } - - $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 $formDatas; - } - public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - //필수정보처리 후 FormData 가져오기 - $formDatas = $this->action_process($serverPartEntity); - //당일결체일로 설정 - $formDatas['billing_at'] = date("Y-m-d"); - //결제정보등록 - $entity = $this->getModel()->create($formDatas); - //서버연결정보 Entity에 결제정보 설정 - return $serverPartEntity->setPaymentEntity($entity); - } - public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - //결제정보 가져오기 - $entity = $serverPartEntity->getPaymentEntity(); - if (!$entity instanceof PaymentEntity) { - throw new \Exception(__METHOD__ . "에서 오류발생: 서버파트연결정보{$serverPartEntity->getPK()}]에 해당하는 결제정보를 찾을수 없습니다."); - } - //미납상태확인 - if ($entity->getStatus() !== STATUS['UNPAID']) { - throw new \Exception(__METHOD__ . "에서 오류발생: 완료된 결제는 수정이 불가합니다."); - } - //필수정보처리 후 FormData 가져오기 - $formDatas = $this->action_process($serverPartEntity); - //결제정보수정 - $entity = $this->getModel()->modify($entity, $formDatas); - //서버연결정보 Entity에 결제정보 설정 - return $serverPartEntity->setPaymentEntity($entity); - } - - public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - //삭제시에는 아무것도 하지 않는다. - return $serverPartEntity; - } -} diff --git a/app/Services/Equipment/ServerPart/RAMService.php b/app/Services/Equipment/ServerPart/RAMService.php deleted file mode 100644 index f34347b..0000000 --- a/app/Services/Equipment/ServerPart/RAMService.php +++ /dev/null @@ -1,53 +0,0 @@ -getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof RAMEntity) { - 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->getModel()->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/ServerPart/SOFTWAREService.php b/app/Services/Equipment/ServerPart/SOFTWAREService.php deleted file mode 100644 index d028405..0000000 --- a/app/Services/Equipment/ServerPart/SOFTWAREService.php +++ /dev/null @@ -1,53 +0,0 @@ -getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof SOFTWAREEntity) { - 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->getModel()->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/ServerPart/SWITCHService.php b/app/Services/Equipment/ServerPart/SWITCHService.php deleted file mode 100644 index e9e4948..0000000 --- a/app/Services/Equipment/ServerPart/SWITCHService.php +++ /dev/null @@ -1,55 +0,0 @@ -getEntity($serverPartEntity->getPartUID()); - if (!$entity instanceof SWITCHEntity) { - throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 SWITCH정보를 찾을수없습니다."); - } - //SWITCH정보 수정 - return $this->getModel()->modify($entity, $formDatas); - } - public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - $formDatas = []; - $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/ServerPart/ServiceService.php b/app/Services/Equipment/ServerPart/ServiceService.php deleted file mode 100644 index 0022002..0000000 --- a/app/Services/Equipment/ServerPart/ServiceService.php +++ /dev/null @@ -1,42 +0,0 @@ -getEntity($serverPartEntity->getServiceInfoUID()); - if (!$entity instanceof ServiceEntity) { - throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); - } - //서비스금액변경 사항이 있는지 확인후 처리 - return $this->setAmount($entity); - } - public function createServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - $this->action_process($serverPartEntity); - return $serverPartEntity; - } - //create와 같은 작업임 - public function modifyServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - return $this->createServerPart($serverPartEntity); - } - //create와 같은 작업임 - public function deleteServerPart(ServerPartEntity $serverPartEntity): ServerPartEntity - { - return $this->createServerPart($serverPartEntity); - } -} diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index f181832..dcf2d27 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -6,17 +6,35 @@ use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerPartEntity; use App\Entities\PaymentEntity; use App\Helpers\Equipment\ServerPartHelper; +use App\Interfaces\Equipment\ServerInterface; use App\Models\Equipment\ServerPartModel; -use App\Services\Equipment\ServerService; +use App\Services\Customer\ServiceService; use App\Services\Equipment\EquipmentService; -use App\Services\Equipment\ServerPart\ServiceService; -use App\Services\Equipment\ServerPart\PaymentService; +use App\Services\Equipment\ServerService; +use App\Services\Part\CPUService; +use App\Services\Part\CSService; +use App\Services\Part\DISKService; +use App\Services\Part\IPService; +use App\Services\Part\OSService; +use App\Services\Part\RAMService; +use App\Services\Part\SOFTWAREService; +use App\Services\Part\SWITCHService; +use App\Services\PaymentService; -class ServerPartService extends EquipmentService +class ServerPartService extends EquipmentService implements ServerInterface { private ?ServiceService $_serviceService = null; private ?ServerService $_serverService = null; private ?PaymentService $_paymentService = null; + private ?CPUService $_cpuService = null; + private ?RAMService $_ramService = null; + private ?DISKService $_diskService = null; + private ?OSService $_osService = null; + private ?SOFTWAREService $_softwareService = null; + private ?SWITCHService $_switchService = null; + private ?IPService $_ipService = null; + private ?CSService $_csService = null; + private $_partServices = []; public function __construct() { @@ -92,17 +110,98 @@ class ServerPartService extends EquipmentService } return $this->_paymentService; } - final public function getPartService(string $type): object + final public function getCPUService(): CPUService { - if (!array_key_exists($type, $this->_partServices)) { - $class = "App\\Services\\Equipment\\ServerPart\\{$type}Service"; - if (!class_exists($class)) { - throw new \Exception("{$class} 클래스가 존재하지 않습니다."); - } - $this->_partServices[$type] = new $class(); + if (!$this->_cpuService) { + $this->_cpuService = new CPUService(); } - return $this->_partServices[$type]; + return $this->_cpuService; } + final public function getRAMService(): RAMService + { + if (!$this->_ramService) { + $this->_ramService = new RAMService(); + } + return $this->_ramService; + } + final public function getDISKService(): DISKService + { + if (!$this->_diskService) { + $this->_diskService = new DISKService(); + } + return $this->_diskService; + } + final public function getOSService(): OSService + { + if (!$this->_osService) { + $this->_osService = new OSService(); + } + return $this->_osService; + } + final public function getSOFTWAREService(): SOFTWAREService + { + if (!$this->_softwareService) { + $this->_softwareService = new SOFTWAREService(); + } + return $this->_softwareService; + } + final public function getCSService(): CSService + { + if (!$this->_csService) { + $this->_csService = new CSService(); + } + return $this->_csService; + } + + final public function getIPService(): IPService + { + if (!$this->_ipService) { + $this->_ipService = new IPService(); + } + return $this->_ipService; + } + + final public function getSWITCHService(): SWITCHService + { + if (!$this->_switchService) { + $this->_switchService = new SWITCHService(); + } + return $this->_switchService; + } + final public function getPartService(string $type) + { + switch ($type) { + case 'CPU': + $service = $this->getCPUService(); + break; + case 'RAM': + $service = $this->getRAMService(); + break; + case 'DISK': + $service = $this->getDISKService(); + break; + case 'OS': + $service = $this->getOSService(); + break; + case 'SOFTWARE': + $service = $this->getSOFTWAREService(); + break; + case 'IP': + $service = $this->getIPService(); + break; + case 'CS': + $service = $this->getCSService(); + break; + case 'SWITCH': + $service = $this->getSWITCHService(); + break; + default: + throw new \Exception(__METHOD__ . "에서 오류발생: {$type} 지정되지 않은 형식입니다."); + // break; + } + return $service; + } + //partEntity 정보 추가 protected function getEntity_process(mixed $entity): ServerPartEntity { @@ -145,30 +244,6 @@ class ServerPartService extends EquipmentService } return $options; } - //파트별정보 설정 - private function action_process(ServerPartEntity $entity, string $action): ServerPartEntity - { - //Type에 따른 부품서비스 정의 - $this->getPartService($entity->getType())->$action($entity); - //서비스 및 결제정보 처리 - switch ($entity->getBilling()) { - case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 - $entity = $this->getServiceService()->$action($entity); - break; - case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - $entity = $this->getPaymentService()->$action($entity); - //결제정보PK정의 - $entity = parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); - break; - case PAYMENT['BILLING']['BASE']: //기본처리 - //아무처리 않함 - break; - default: - throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); - // break; - } - return $entity; - } //부품연결정보생성 public function create(array $formDatas): ServerPartEntity { @@ -190,7 +265,26 @@ class ServerPartService extends EquipmentService $formDatas["serverinfo_uid"] = $serverEntity->getPK(); $entity = parent::create($formDatas); //후처리작업 - return $this->action_process($entity, __FUNCTION__ . 'ServerPart'); + //Type에 따른 부품서비스 정의 + $this->getPartService($entity->getType())->setServerPart($entity, $formDatas); + //서비스 및 결제정보 처리 + switch ($entity->getBilling()) { + case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 + $entity = $this->getServiceService()->setServerPart($entity, $formDatas); + break; + case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 + $entity = $this->getPaymentService()->setServerPart($entity, $formDatas); + //결제정보PK정의 + $entity = parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); + break; + case PAYMENT['BILLING']['BASE']: //기본처리 + //아무처리 않함 + break; + default: + throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); + // break; + } + return $entity; } //수정 public function modify(mixed $entity, array $formDatas): ServerPartEntity @@ -203,24 +297,78 @@ class ServerPartService extends EquipmentService if (!$serverEntity instanceof ServerEntity) { throw new \Exception("서버 정보가 지정되지 않았습니다."); } - //수정 전 부품연결정보관련 정보처리 - if ($entity->getCnt() != $formDatas['cnt'] || $entity->getPartUID() !== $formDatas['part_uid']) { - $entity = $this->action_process($entity, 'deleteServerPart'); - } - //수정작업 + //수정전 정보 + $oldEntity = $entity; + //서버연결정보 수정 $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); $formDatas["serverinfo_uid"] = $serverEntity->getPK(); $entity = parent::modify($entity, $formDatas); //후처리작업 - $entity = $this->action_process($entity, __FUNCTION__ . 'ServerPart'); + //Type에 따른 부품서비스 정의 + $this->getPartService($entity->getType())->changeServerPart($oldEntity, $entity, $formDatas); + //서비스 및 결제정보 처리 + switch ($entity->getBilling()) { + case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 + $entity = $this->getServiceService()->changeServerPart($oldEntity, $entity, $formDatas); + break; + case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 + $entity = $this->getPaymentService()->changeServerPart($oldEntity, $entity, $formDatas); + //결제정보PK정의 + $entity = parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); + break; + case PAYMENT['BILLING']['BASE']: //기본처리 + //아무처리 않함 + break; + default: + throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); + // break; + } return $entity; } //삭제 public function delete(mixed $entity): ServerPartEntity { $entity = parent::delete($entity); - //서비스금액 관련때문에 후처리작업 - return $this->action_process($entity, __FUNCTION__ . 'ServerPart'); + //Type에 따른 부품서비스 정의 + $this->getPartService($entity->getType())->unSetServerPart($entity, []); + //서비스 및 결제정보 처리 + switch ($entity->getBilling()) { + case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 + $entity = $this->getServiceService()->unSetServerPart($entity, []); + break; + case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 + $entity = $this->getPaymentService()->unSetServerPart($entity, []); + //결제정보PK정의 + $entity = parent::modify($entity, ['payment_uid' => $entity->getPaymentEntity()->getPK()]); + break; + case PAYMENT['BILLING']['BASE']: //기본처리 + //아무처리 않함 + break; + default: + throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); + // break; + } + return $entity; + } + + //서버관련 작업 + public function setServer(ServerEntity $serverEntity, array $serverDatas): ServerEntity + { + //아무것도 하지 않음 + return $serverEntity; + } + public function changeServer(ServerEntity $oldServerEntity, ServerEntity $serverEntity, array $serverDatas): ServerEntity + { + //아무것도 하지 않음 + return $serverEntity; + } + public function unsetServer(ServerEntity $serverEntity, array $serverDatas): ServerEntity + { + //기존 ServerPart정보 삭제 + foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $serverPartEntity) { + $this->getModel()->delete($serverPartEntity); + } + return $serverEntity; } } diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index b82434f..964f13e 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -2,14 +2,16 @@ namespace App\Services\Equipment; +use App\Entities\Customer\ServiceEntity; use App\Entities\Equipment\ServerEntity; use App\Helpers\Equipment\ServerHelper; +use App\Interfaces\Customer\ServiceInterface; use App\Models\Equipment\ServerModel; -use App\Services\Equipment\Server\ServiceService; -use App\Services\Equipment\Server\ServerPartService; +use App\Services\Customer\ServiceService; use App\Services\Equipment\EquipmentService; +use App\Services\Equipment\ServerPartService; -class ServerService extends EquipmentService +class ServerService extends EquipmentService implements ServiceInterface { private ?ServiceService $_serviceService = null; private ?ServerPartService $_serverPartService = null; @@ -160,13 +162,22 @@ class ServerService extends EquipmentService $entity = $this->getServerPartService()->$action($entity); return $entity; } + public function create(array $formDatas): ServerEntity + { + $entity = parent::create($formDatas); + return $entity; + } //수정 public function modify(mixed $entity, array $formDatas): ServerEntity { + //수정전 정보 + $oldEntity = $entity; //서버정보 수정 $entity = parent::modify($entity, $formDatas); - //후처리작업 - return $this->action_process($entity, __FUNCTION__ . 'Server'); + //서비스정보수정(청구액수정) + $entity = $this->getServiceService()->changeServer($oldEntity, $entity, []); + $entity = $this->getServerPartService()->changeServer($oldEntity, $entity, []); + return $entity; } //삭제 public function delete(mixed $entity): ServerEntity @@ -182,4 +193,63 @@ class ServerService extends EquipmentService $this->getModel()->orderBy("code ASC,title ASC"); parent::setOrderBy($field, $value); } + + //서비스관련 작업 + public function setService(ServiceEntity $serviceEntity, array $serviceDatas): ServiceEntity + { + if (!array_key_exists('serverinfo_uid', $serviceDatas)) { + throw new \Exception("서버정보가 없습니다."); + } + $entity = $this->getEntity($serviceDatas['serverinfo_uid']); + if (!$entity instanceof ServerEntity) { + throw new \Exception("{$serviceDatas['serverinfo_uid']}에 대한 서버정보를 찾을수 없습니다."); + } + $entity = $this->getEntity($serviceDatas['serverinfo_uid']); + if ($entity->getStatus() != STATUS['AVAILABLE']) { + throw new \Exception("{$entity->getCustomTitle()} 서버는 사용가능 서버가 아닙니다."); + } + $formDatas = []; + $formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); + $formDatas['status'] = STATUS['OCCUPIED']; + //대체서버용인지 확인 + if (array_key_exists('type', $serviceDatas) && $serviceDatas['type'] === 'alternative') { + $formDatas['type'] = $serviceDatas['type']; + } + //필수정보처리 후 서버정보등록 후 서비스정보 Entity에 서버정보 설정 + return $serviceEntity->setServerEntity($this->getModel()->modify($entity, $formDatas)); + } + public function changeService(ServiceEntity $oldServiceEntity, ServiceEntity $serviceEntity, array $serviceDatas): ServiceEntity + { + if (!array_key_exists('serverinfo_uid', $serviceDatas)) { + throw new \Exception("신규로 지정할 서버정보가 없습니다."); + } + //기존 서버 해지(uynsetService사용) + $this->unsetService($serviceEntity, ['serverinfo_uid' => $serviceEntity->getServerEntity()->getPK()]); + //신규서버 설정(setService사용) + return $this->setService($serviceEntity, $serviceDatas); + } + public function unsetService(ServiceEntity $serviceEntity, array $serviceDatas): ServiceEntity + { + if (!array_key_exists('serverinfo_uid', $serviceDatas)) { + throw new \Exception("서비스를 해지할 서버정보가 없습니다."); + } + if ($serviceEntity->getServerEntity()->getPK() === $serviceDatas['serverinfo_uid']) { + throw new \Exception("Main으로 설정된 서버는 해지하실 수 업습니다."); + } + $entity = $this->getEntity($serviceDatas['serverinfo_uid']); + if (!$entity instanceof ServerEntity) { + throw new \Exception("{$serviceDatas['serverinfo_uid']}에 대한 서버정보를 찾을수 없습니다."); + } + //서버정보설정 + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['format_at'] = date("Y-m-d"); + $formDatas['status'] = STATUS['AVAILABLE']; + $entity = $this->getModel()->modify($entity, $formDatas); + //서비스정보 Entity에 서버정보 설정 + return $serviceEntity; + } + //서버파트관련 작업 } diff --git a/app/Services/Part/CPUService.php b/app/Services/Part/CPUService.php index 92d21bc..b2d621b 100644 --- a/app/Services/Part/CPUService.php +++ b/app/Services/Part/CPUService.php @@ -2,12 +2,14 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\CPUEntity; use App\Helpers\Part\CPUHelper; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Part\CPUModel; -class CPUService extends PartService +class CPUService extends PartService implements ServerPartInterface { public function __construct() { @@ -50,4 +52,39 @@ class CPUService extends PartService $this->getModel()->orderBy('title ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof CPUEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + + //수정 전 부품연결정보관련 정보처리 갯수,파트가 달라졌을경우 (회수 -> 사용 처리) + //기존것 회수 처리 + if ($oldServerPartEntity->getCnt() != $serverPartEntity->getCnt() || $oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) { + $this->unsetServerPart($oldServerPartEntity, $serverPartDatas); + } + //신규것 사용처리 + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof CPUEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]); + } } diff --git a/app/Services/Part/CSService.php b/app/Services/Part/CSService.php index de0774f..f5385cc 100644 --- a/app/Services/Part/CSService.php +++ b/app/Services/Part/CSService.php @@ -2,13 +2,16 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; +use App\Entities\Part\CSEntity; use App\Helpers\Part\CSHelper; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Part\CSModel; use App\Services\Customer\ClientService; use App\Services\Customer\ServiceService; use App\Services\Equipment\ServerService; -class CSService extends PartService +class CSService extends PartService implements ServerPartInterface { private ?ClientService $_clientService = null; private ?ServiceService $_serviceService = null; @@ -101,4 +104,52 @@ class CSService extends PartService $this->getModel()->orderBy('INET_ATON(ip)', 'ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + $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정보 수정 + return $serverPartEntity->setPartEntity($this->getModel()->modify($entity, $formDatas)); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + + //수정 전 부품연결정보관련 정보처리 파트정보가 달라졌을경우 (회수 -> 사용 처리) + if ($oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) { + $this->unsetServerPart($oldServerPartEntity, $serverPartDatas); + } + //신규것 사용처리 + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): 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정보 수정 + return $serverPartEntity->setPartEntity($this->getModel()->modify($entity, $formDatas)); + } } diff --git a/app/Services/Part/DISKService.php b/app/Services/Part/DISKService.php index 621b9ff..84b922b 100644 --- a/app/Services/Part/DISKService.php +++ b/app/Services/Part/DISKService.php @@ -2,12 +2,14 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\DISKEntity; use App\Helpers\Part\DISKHelper; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Part\DISKModel; -class DISKService extends PartService +class DISKService extends PartService implements ServerPartInterface { public function __construct() { @@ -50,4 +52,39 @@ class DISKService extends PartService $this->getModel()->orderBy('title ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof DISKEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + + //수정 전 부품연결정보관련 정보처리 갯수,파트가 달라졌을경우 (회수 -> 사용 처리) + //기존것 회수 처리 + if ($oldServerPartEntity->getCnt() != $serverPartEntity->getCnt() || $oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) { + $this->unsetServerPart($oldServerPartEntity, $serverPartDatas); + } + //신규것 사용처리 + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof DISKEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]); + } } diff --git a/app/Services/Part/IPService.php b/app/Services/Part/IPService.php index 41b0392..df32d72 100644 --- a/app/Services/Part/IPService.php +++ b/app/Services/Part/IPService.php @@ -2,7 +2,10 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; +use App\Entities\Part\IPEntity; use App\Helpers\Part\IPHelper; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Part\IPModel; use App\Services\Customer\ClientService; use App\Services\Customer\ServiceService; @@ -10,7 +13,7 @@ use App\Services\Equipment\LineService; use App\Services\Equipment\ServerService; use App\Services\Part\PartService; -class IPService extends PartService +class IPService extends PartService implements ServerPartInterface { private ?LineService $_lineService = null; private ?ClientService $_clientService = null; @@ -116,4 +119,55 @@ class IPService extends PartService $this->getModel()->orderBy('INET_ATON(ip)', 'ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + $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상태가 설정되지 않았습니다."); + } + // IP정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof IPEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다."); + } + // IP정보 수정 + return $serverPartEntity->setPartEntity($this->getModel()->modify($entity, $formDatas)); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + + //수정 전 부품연결정보관련 정보처리 파트정보가 달라졌을경우 (회수 -> 사용 처리) + //기존것 회수 처리 + if ($oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) { + $this->unsetServerPart($oldServerPartEntity, $serverPartDatas); + } + //신규것 사용처리 + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + //기존 고객정보 기록용 + $formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $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정보 수정 + return $serverPartEntity->setPartEntity($this->getModel()->modify($entity, $formDatas)); + } } diff --git a/app/Services/Part/OSService.php b/app/Services/Part/OSService.php index 3ae8257..814472e 100644 --- a/app/Services/Part/OSService.php +++ b/app/Services/Part/OSService.php @@ -2,12 +2,14 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\OSEntity; use App\Helpers\Part\OSHelper; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Part\OSModel; -class OSService extends PartService +class OSService extends PartService implements ServerPartInterface { public function __construct() { @@ -50,4 +52,39 @@ class OSService extends PartService $this->getModel()->orderBy('title ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof OSEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + + //수정 전 부품연결정보관련 정보처리 갯수,파트가 달라졌을경우 (회수 -> 사용 처리) + //기존것 회수 처리 + if ($oldServerPartEntity->getCnt() != $serverPartEntity->getCnt() || $oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) { + $this->unsetServerPart($oldServerPartEntity, $serverPartDatas); + } + //신규것 사용처리 + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof OSEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]); + } } diff --git a/app/Services/Part/PartService.php b/app/Services/Part/PartService.php index 39a181f..afd0d6f 100644 --- a/app/Services/Part/PartService.php +++ b/app/Services/Part/PartService.php @@ -2,8 +2,6 @@ namespace App\Services\Part; -use App\Entities\Customer\ClientEntity; - use App\Helpers\CommonHelper; use App\Models\CommonModel; use App\Services\CommonService; diff --git a/app/Services/Part/RAMService.php b/app/Services/Part/RAMService.php index 0faef57..f4b6065 100644 --- a/app/Services/Part/RAMService.php +++ b/app/Services/Part/RAMService.php @@ -2,12 +2,14 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\RAMEntity; use App\Helpers\Part\RAMHelper; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Part\RAMModel; -class RAMService extends PartService +class RAMService extends PartService implements ServerPartInterface { public function __construct() { @@ -50,4 +52,39 @@ class RAMService extends PartService $this->getModel()->orderBy('title ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof RAMEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + + //수정 전 부품연결정보관련 정보처리 갯수,파트가 달라졌을경우 (회수 -> 사용 처리) + //기존것 회수 처리 + if ($oldServerPartEntity->getCnt() != $serverPartEntity->getCnt() || $oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) { + $this->unsetServerPart($oldServerPartEntity, $serverPartDatas); + } + //신규것 사용처리 + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof RAMEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]); + } } diff --git a/app/Services/Part/SOFTWAREService.php b/app/Services/Part/SOFTWAREService.php index a39a8b5..125af9b 100644 --- a/app/Services/Part/SOFTWAREService.php +++ b/app/Services/Part/SOFTWAREService.php @@ -2,12 +2,14 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\SOFTWAREEntity; use App\Helpers\Part\SOFTWAREHelper; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Part\SOFTWAREModel; -class SOFTWAREService extends PartService +class SOFTWAREService extends PartService implements ServerPartInterface { public function __construct() { @@ -50,4 +52,39 @@ class SOFTWAREService extends PartService $this->getModel()->orderBy('title ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof SOFTWAREEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + //부품정보에 서버정보 설정 및 서비스,고객정보 정의 + if ($entity->getStock() < $serverPartEntity->getCnt()) { + throw new \Exception("현재 재고수[{$entity->getStock()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() - $serverPartEntity->getCnt()]); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + + //수정 전 부품연결정보관련 정보처리 갯수,파트가 달라졌을경우 (회수 -> 사용 처리) + //기존것 회수 처리 + if ($oldServerPartEntity->getCnt() != $serverPartEntity->getCnt() || $oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) { + $this->unsetServerPart($oldServerPartEntity, $serverPartDatas); + } + //신규것 사용처리 + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //부품정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof SOFTWAREEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 부품정보를 찾을수없습니다."); + } + return $this->getModel()->modify($entity, ['stock' => $entity->getStock() + $serverPartEntity->getCnt()]); + } } diff --git a/app/Services/Part/SWITCHService.php b/app/Services/Part/SWITCHService.php index b9b27af..0ec976b 100644 --- a/app/Services/Part/SWITCHService.php +++ b/app/Services/Part/SWITCHService.php @@ -2,13 +2,16 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; +use App\Entities\Part\SWITCHEntity; use App\Helpers\Part\SWITCHHelper; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\Part\SWITCHModel; use App\Services\Customer\ServiceService; use App\Services\Equipment\ServerService; use App\Services\Part\PartService; -class SWITCHService extends PartService +class SWITCHService extends PartService implements ServerPartInterface { private ?ServiceService $_serviceService = null; private ?ServerService $_serverService = null; @@ -86,4 +89,53 @@ class SWITCHService extends PartService $this->getModel()->orderBy('code', 'ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + $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정보 수정 + return $serverPartEntity->setPartEntity($this->getModel()->modify($entity, $formDatas)); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + + //수정 전 부품연결정보관련 정보처리 파트정보가 달라졌을경우 (회수 -> 사용 처리) + //기존것 회수 처리 + if ($oldServerPartEntity->getPartUID() !== $serverPartEntity->getPartUID()) { + $this->unsetServerPart($oldServerPartEntity, $serverPartDatas); + } + //신규것 사용처리 + return $this->setServerPart($serverPartEntity, $serverPartDatas); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): 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__ . "에서 오류발생: SWITCH상태가 설정되지 않았습니다."); + } + //SWITCH정보가져오기 + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof SWITCHEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 SWITCH정보를 찾을수없습니다."); + } + //SWITCH정보 수정 + return $serverPartEntity->setPartEntity($this->getModel()->modify($entity, $formDatas)); + } } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index d6ddad1..7577845 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -2,8 +2,12 @@ namespace App\Services; +use App\Entities\Customer\ServiceEntity; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\PaymentEntity; use App\Helpers\PaymentHelper; +use App\Interfaces\Customer\ServiceInterface; +use App\Interfaces\Equipment\ServerPartInterface; use App\Models\PaymentModel; use App\Services\CommonService; use App\Services\Customer\ClientService; @@ -11,7 +15,7 @@ use App\Services\Customer\ServiceService; use App\Services\Equipment\ServerPartService; use App\Services\UserService; -class PaymentService extends CommonService +class PaymentService extends CommonService implements ServiceInterface, ServerPartInterface { private ?UserService $_userService = null; private ?ClientService $_clientService = null; @@ -116,16 +120,6 @@ class PaymentService extends CommonService } return $unPaids; } - final public function setAmount(PaymentEntity $entity, int $amount): PaymentEntity - { - if ($entity->getStatus() !== STATUS['UNPAID']) { - throw new \Exception(__METHOD__ . "에서 오류발생: 지급이 완료된 결제정보는 수정할 수 없습니다."); - } - if ($entity->getAmount() !== $amount) { - $this->getModel()->modify($entity, ['amount' => $amount]); - } - return $entity; - } //기본 기능부분 //FieldForm관련용 final public function getFormOption(string $field, array $options = []): array @@ -148,4 +142,116 @@ class PaymentService extends CommonService $this->getModel()->orderBy('billing_at ASC'); parent::setOrderBy($field, $value); } + + //서비스관련 작업 + public function setService(ServiceEntity $serviceEntity, array $serviceDatas): ServiceEntity + { + $formDatas = []; + $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(); + //필수정보처리 후 결제정보등록 후 서비스정보 Entity에 결제정보 설정 + return $serviceEntity->setPaymentEntity($this->getModel()->create($formDatas)); + } + public function changeService(ServiceEntity $oldServiceEntity, ServiceEntity $serviceEntity, array $serviceDatas): ServiceEntity + { + //결제정보 가져오기 + $entity = $serviceEntity->getPaymentEntity(); + if (!$entity instanceof PaymentEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보[{$serviceEntity->getPK()}]에 해당하는 결제정보를 찾을수 없습니다."); + } + //미납상태확인 + if ($entity->getStatus() !== STATUS['UNPAID']) { + throw new \Exception(__METHOD__ . "에서 오류발생: 완료된 결제는 수정이 불가합니다."); + } + $formDatas = []; + $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(); + //필수정보처리 후 결제정보수정 후 서비스정보 Entity에 결제정보 설정 + return $serviceEntity->setPaymentEntity($this->getModel()->modify($entity, $formDatas)); + } + public function unsetService(ServiceEntity $serviceEntity, array $serviceDatas): ServiceEntity + { + //아무것도 하지 않는다. + return $serviceEntity; + } + + //서버파트관련 작업(1회성만처리) + public function setServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + if ($serverPartEntity->getBilling() !== PAYMENT['BILLING']['ONETIME']) { + throw new \Exception("[{$serverPartEntity->getBilling()}],청구방식이 일회성이 아닙니다."); + } + if ($serverPartEntity->getServiceInfoUID() === null) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); + } + //일회인이 아닌경우 + 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(); //서버연결정보 수정시에 필요함 + //타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다. + $formDatas['title'] = $serverPartEntity->getPartEntity()->getTitle(); + $formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt + $formDatas['billing'] = $serverPartEntity->getBilling(); + //당일결체일로 설정 + $formDatas['billing_at'] = date("Y-m-d"); + //결제정보등록 + $entity = $this->getModel()->create($formDatas); + //서버연결정보 Entity에 결제정보 설정 + return $serverPartEntity->setPaymentEntity($entity); + } + public function changeServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + if ($serverPartEntity->getBilling() !== PAYMENT['BILLING']['ONETIME']) { + throw new \Exception("[{$serverPartEntity->getBilling()}],청구방식이 일회성이 아닙니다."); + } + //결제정보 가져오기 + $entity = $serverPartEntity->getPaymentEntity(); + if (!$entity instanceof PaymentEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서버파트연결정보{$serverPartEntity->getPK()}]에 해당하는 결제정보를 찾을수 없습니다."); + } + //미납상태확인 + if ($entity->getStatus() !== STATUS['UNPAID']) { + throw new \Exception(__METHOD__ . "에서 오류발생: 완료된 결제는 수정이 불가합니다."); + } + if ($serverPartEntity->getServiceInfoUID() === null) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); + } + //일회인이 아닌경우 + 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(); //서버연결정보 수정시에 필요함 + //타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다. + $formDatas['title'] = $serverPartEntity->getPartEntity()->getTitle(); + $formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt + $formDatas['billing'] = $serverPartEntity->getBilling(); + //당일결체일로 설정 + $formDatas['billing_at'] = date("Y-m-d"); + //결제정보수정 + $entity = $this->getModel()->modify($entity, $formDatas); + //서버연결정보 Entity에 결제정보 설정 + return $serverPartEntity->setPaymentEntity($entity); + } + public function unsetServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas): ServerPartEntity + { + //삭제시에는 아무것도 하지 않는다. + return $serverPartEntity; + } }