From f05590d9b03a3768181167ef8c3771c4e8531bd9 Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Thu, 30 Oct 2025 13:51:10 +0900 Subject: [PATCH] dbmsv3 init...1 --- app/Interfaces/Customer/ServiceInterface.php | 10 +++ app/Interfaces/Equipment/ServerInterface.php | 1 + .../Equipment/ServerPartInterface.php | 2 + .../Customer/ServiceV1Processor.php | 27 ++++--- .../Equipment/ServerPartV1Processor.php | 72 +++---------------- .../Equipment/ServerV1Processor.php | 4 +- app/Services/Customer/ServiceService.php | 34 +++------ app/Services/Equipment/ServerPartService.php | 25 ++++++- app/Services/Equipment/ServerService.php | 20 ++++-- app/Services/PaymentService.php | 1 - 10 files changed, 91 insertions(+), 105 deletions(-) create mode 100644 app/Interfaces/Customer/ServiceInterface.php diff --git a/app/Interfaces/Customer/ServiceInterface.php b/app/Interfaces/Customer/ServiceInterface.php new file mode 100644 index 0000000..4ac00a7 --- /dev/null +++ b/app/Interfaces/Customer/ServiceInterface.php @@ -0,0 +1,10 @@ +getServerInfoUID() ); - // 3) 금액 계산 + 결제정보반영 - $amount = $this->service->getCalculatedAmount($entity, $serverEntity); - $this->service->getModel()->modify($entity, ['amount' => $amount]); - $paymentEntity = $this->paymentService->createForService($entity); + // 3) 결제정보반영 + $this->service->setAmount( + $entity, + $this->serverService->getCalculatedAmount($serverEntity), + 'createForService' + ); // 4) 서비스 FK 동기화 $entity = $this->service->getModel()->modify($entity, [ 'title' => $entity->getTitle(), 'serverinfo_id' => $serverEntity->getPK(), - 'payment_uid' => $paymentEntity->getPK(), ]); // 6) 로그 $this->logService->create([ @@ -67,8 +68,11 @@ class ServiceV1Processor $entity, $entity->getServerInfoUID() ); - // 3) 금액 재계산 + 결제정보반영 - $entity = $this->service->setAmount($entity->getPK()); + // 3) 결제정보반영 + $this->service->setAmount( + $entity, + $this->serverService->getCalculatedAmount($serverEntity) + ); // 5) 서비스 FK 동기화 $entity = $this->service->getModel()->modify($entity, [ 'title' => $entity->getTitle(), @@ -99,6 +103,8 @@ class ServiceV1Processor } // 3) 서비스 삭제 $this->service->getModel()->delete($entity); + // 4) 결제정보 반영(서비스번호,서버번호 Null처리) + $this->paymentService->unlinkFromService($entity); // 4) 로그 $this->logService->create([ 'title' => "[{$entity->getTitle()}] 서비스 해지", @@ -156,8 +162,11 @@ class ServiceV1Processor 'title' => $serverEntity->getCustomTitle(), 'serverinfo_uid' => $serverEntity->getPK() ]); - // 3) 금액 재계산 + 결제정보반영 - $entity = $this->service->setAmount($entity->getPK()); + // 4) 결제정보반영 + $this->service->setAmount( + $entity, + $this->serverService->getCalculatedAmount($serverEntity) + ); // 5) 로그 $this->logService->create([ 'title' => "{$oldServerEntity->getCustomTitle()}=>{$serverEntity->getCustomTitle()} 메인서버변경", diff --git a/app/Processors/Equipment/ServerPartV1Processor.php b/app/Processors/Equipment/ServerPartV1Processor.php index 0ba0cee..0119840 100644 --- a/app/Processors/Equipment/ServerPartV1Processor.php +++ b/app/Processors/Equipment/ServerPartV1Processor.php @@ -4,7 +4,6 @@ namespace App\Processors\Equipment; use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerPartEntity; -use App\Services\Customer\ServiceService; use App\Services\Equipment\ServerPartService; use App\Services\Equipment\ServerService; use App\Services\MyLogService; @@ -19,7 +18,6 @@ class ServerPartV1Processor public function __construct( private BaseConnection $db, private ServerPartService $service, - private ServiceService $serviceService, private ServerService $serverService, private PaymentService $paymentService, private IPService $ipService, @@ -29,7 +27,6 @@ class ServerPartV1Processor public function create(array $formDatas): ServerPartEntity { - $this->db->transStart(); //서버정보가져오기 if (!array_key_exists('serverinfo_uid', $formDatas)) { throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다."); @@ -42,6 +39,7 @@ class ServerPartV1Processor if ($formDatas['billing'] !== PAYMENT['BILLING']['BASE'] && $serverEntity->getServiceInfoUID() === null) { throw new \Exception(__METHOD__ . "에서 오류발생:서비스가 지정되어야 작업이 가능합니다."); } + $this->db->transStart(); // 1) 생성작업 $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); @@ -50,26 +48,7 @@ class ServerPartV1Processor // 2) Type에 따른 각 파트 정의 $this->service->getPartService($entity->getType())->attachToServerPart($entity); // 3) 과금정의 - switch ($entity->getBilling()) { - case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 - if ($entity->getServiceInfoUID() === null) { - throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); - } - //서비스 금액만 재계산변경 - $this->serviceService->setAmount($entity->getServiceInfoUID()); - break; - case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - $paymentEntity = $this->paymentService->createForServerPart($entity); - //결제정보PK정의 - $entity = $this->service->getModel()->modify($entity, ['payment_uid' => $paymentEntity->getPK()]); - break; - case PAYMENT['BILLING']['BASE']: //기본처리 - //아무처리 않함 - break; - default: - throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); - // break; - } + $this->service->setAmount($entity, "createForServerPart"); // 4) 로그 $this->logService->create(formDatas: [ 'title' => "{$entity->getTitle()} 서버파트 추가", @@ -83,11 +62,11 @@ class ServerPartV1Processor } public function modify(ServerPartEntity $entity, array $formDatas): ServerPartEntity { - $this->db->transStart(); //서버정보가져오기 if (!array_key_exists('serverinfo_uid', $formDatas)) { throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다."); } + $this->db->transStart(); // 1) 수정전 정보 //파트값이 정의되어 있으면 $isChangedPart = false; @@ -113,24 +92,7 @@ class ServerPartV1Processor $this->service->getPartService($entity->getType())->attachToServerPart($entity); } // 3) 과금정의 - switch ($entity->getBilling()) { - case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 - if ($entity->getServiceInfoUID() === null) { - throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); - } - //서비스 금액만 재계산변경 - $this->serviceService->setAmount($entity->getServiceInfoUID()); - break; - case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - $this->paymentService->updateForServerPart($entity); - break; - case PAYMENT['BILLING']['BASE']: //기본처리 - //아무처리 않함 - break; - default: - throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); - // break; - } + $this->service->setAmount($entity, "updateForServerPart"); // 4) 로그 $this->logService->create(formDatas: [ 'title' => "{$entity->getTitle()} 서버파트 수정", @@ -151,27 +113,13 @@ class ServerPartV1Processor $this->service->getPartService($entity->getType())->detachFromServerPart($entity); } // 2) 서버파트정보 삭제 - $this->service->getModel()->delete($entity); - // 3) 과금처리 - switch ($entity->getBilling()) { - case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 - if ($entity->getServiceInfoUID() !== null) { //서비스가 정의되어 있으면 - //서비스 금액만 재계산변경 - $this->serviceService->setAmount($entity->getServiceInfoUID()); - } - break; - case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면 - $this->paymentService->unlinkFromServerPart($entity); - } - break; - case PAYMENT['BILLING']['BASE']: //기본처리 - //아무처리 않함 - break; - default: - throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); - // break; + $serverEntity = $this->serverService->getEntity($entity->getServerInfoUID()); + if (!$serverEntity instanceof ServerEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServerInfoUID()} 서버 정보를 찾을수 없습니다."); } + $this->service->getModel()->delete($entity); + // 3) 과금정의 + $this->service->setAmount($entity, "unlinkFromServerPart"); // 4) 로그 $this->logService->create(formDatas: [ 'title' => "{$entity->getTitle()} 서버파트 삭제", diff --git a/app/Processors/Equipment/ServerV1Processor.php b/app/Processors/Equipment/ServerV1Processor.php index 221dc1e..66f69fa 100644 --- a/app/Processors/Equipment/ServerV1Processor.php +++ b/app/Processors/Equipment/ServerV1Processor.php @@ -91,9 +91,9 @@ class ServerV1Processor if ($entity->getIP() && $isChangedIP) { $this->ipService->attachToServer($entity); } - //5) 서비스금액 설정:서비스가 연결되어 있고 대체서버가 아니면, 서비스정보수정(청구액수정) + //4) 서비스금액 설정:서비스가 연결되어 있고 대체서버가 아니면, 과금정의 if ($entity->getServiceInfoUID() !== null && $entity->getType() !== SERVER['TYPES']['ALTERNATIVE']) { - $this->serviceService->setAmount($entity->getServiceInfoUID()); + $this->service->setAmount($entity); } //5) Log처리 $this->logService->create([ diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 5fd29ac..a7b49d0 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -3,16 +3,16 @@ namespace App\Services\Customer; use App\Entities\Customer\ServiceEntity; -use App\Entities\Equipment\ServerEntity; use App\Helpers\Customer\ServiceHelper; +use App\Interfaces\Customer\ServiceInterface; use App\Models\Customer\ServiceModel; +use App\Processors\Customer\ServiceV1Processor as Proceessor; use App\Services\Equipment\ServerService; use App\Services\PaymentService; use DateTimeImmutable; use DateTimeZone; -use App\Processors\Customer\ServiceV1Processor as Proceessor; -class ServiceService extends CustomerService +class ServiceService extends CustomerService implements ServiceInterface { private ?ServerService $_serverService = null; private ?PaymentService $_paymentService = null; @@ -159,28 +159,14 @@ class ServiceService extends CustomerService // 최종 결과 리턴 (YYYY-MM-DD) return $date->format('Y-m-d'); } - //총서비스금액 계산 - //기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액 - public function getCalculatedAmount(ServiceEntity $entity, ServerEntity $serverEntity): int + //서비스금액관련처리 + public function setAmount(ServiceEntity $entity, int $calculatedServerAmount, string $callBack = "updateForService"): ServiceEntity { - return $entity->getRack() + $entity->getLine() + $this->getServerService()->getCalculatedAmount($serverEntity) - $entity->getSale(); - } - //서비스금액변경 - public function setAmount(string $uid): ServiceEntity - { - $entity = $this->getEntity($uid); - if (!$entity instanceof ServiceEntity) { - throw new \Exception(__METHOD__ . "에서 오류발생: [{$uid}]에 대한 서비스정보를 찾을수 없습니다."); - } - $serverEntity = $this->getServerService()->getEntity($entity->getServerInfoUID()); - if (!$serverEntity instanceof ServerEntity) { - throw new \Exception(__METHOD__ . "에서 오류발생: [{$entity->getServerInfoUID()}]에 대한 서버정보를 찾을수 없습니다."); - } - $amount = $this->getCalculatedAmount($entity, $serverEntity); - $entity = parent::modify($entity, ['amount' => $amount]); - //결제정보 수정 - $this->getPaymentService()->updateForService($entity); - return $entity; + //기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액 + $amount = $entity->getRack() + $entity->getLine() + $calculatedServerAmount - $entity->getSale(); + //결제정보 반영 + $this->getPaymentService()->$callBack($entity, $amount); + return $this->getModel()->modify($entity, ['amount' => $amount,]); } //기본 기능부분 //FieldForm관련용 diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 9d93f26..ca8babc 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -189,6 +189,28 @@ class ServerPartService extends EquipmentService implements ServerPartInterface } return $service; } + //결제관련처리 + public function setAmount(ServerPartEntity $entity, string $callBack): ServerPartEntity + { + //기본처리 + if ($entity->getBilling() === PAYMENT['BILLING']['BASE']) { + return $entity; + } + //월별과금용(서버->서비스정보 반영) + if ($entity->getBilling() === PAYMENT['BILLING']['MONTH']) { + $serverEntity = $this->getServerService()->getEntity($entity->getServerInfoUID()); + if (!$serverEntity instanceof ServerEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServerInfoUID()} 서버 정보를 찾을수 없습니다."); + } + $this->getServerService()->setAmount($serverEntity); + } + //일회성용 + if ($entity->getBilling() === PAYMENT['BILLING']['ONETIME']) { + $paymentEntity = $this->getPaymentService()->$callBack($entity); + $entity = $this->getModel()->modify($entity, ['payment_uid' => $paymentEntity->getPK()]); + } + return $entity; + } //서버관련 작업 public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void { @@ -253,7 +275,6 @@ class ServerPartService extends EquipmentService implements ServerPartInterface $processor = new Proceessor( \Config\Database::connect(), $this, - $this->getServiceService(), $this->getServerService(), $this->getPaymentService(), $this->getIPService(), @@ -268,7 +289,6 @@ class ServerPartService extends EquipmentService implements ServerPartInterface $processor = new Proceessor( \Config\Database::connect(), $this, - $this->getServiceService(), $this->getServerService(), $this->getPaymentService(), $this->getIPService(), @@ -283,7 +303,6 @@ class ServerPartService extends EquipmentService implements ServerPartInterface $processor = new Proceessor( \Config\Database::connect(), $this, - $this->getServiceService(), $this->getServerService(), $this->getPaymentService(), $this->getIPService(), diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 756ba6e..516e2a9 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -173,11 +173,9 @@ class ServerService extends EquipmentService implements ServerInterface } return $rows; } - //총 서버금액 설정() - //기본:서버금액(price)+서버파트연결(월비용) - final public function getCalculatedAmount(ServerEntity $entity): int + public function getCalculatedAmount(ServerEntity $entity): int { - $caculatedAmount = $entity->getPrice(); + $caculatedAmount = $entity->getPrice(); //해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 합산한다. foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $serverPartEntity) { if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { //월비용일때만 적용 @@ -186,6 +184,20 @@ class ServerService extends EquipmentService implements ServerInterface } return $caculatedAmount; } + //서비스금액관련처리 + public function setAmount(ServerEntity $entity): ServerEntity + { + if ($entity->getServiceInfoUID() === null) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); + } + //서비스정보 반영 + $serviceEntity = $this->getServiceService()->getEntity($entity->getServiceInfoUID()); + if (!$serviceEntity instanceof ServiceEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServiceInfoUID()} 서비스 정보를 찾을수 없습니다."); + } + $this->getServiceService()->setAmount($serviceEntity, $this->getCalculatedAmount($entity)); + return $entity; + } //Service관련 public function attachToService(ServiceEntity $serviceEntity, string $serverinfo_uid, array $formDatas = []): ServerEntity { diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index dd697a3..7bdbd2c 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -121,7 +121,6 @@ class PaymentService extends CommonService implements PaymentInterface } return $unPaids; } - //Service관련(월과금) //서비스생성 public function createForService(ServiceEntity $serviceEntity): PaymentEntity {