diff --git a/app/Entities/Equipment/ServerPartEntity.php b/app/Entities/Equipment/ServerPartEntity.php index 27d60a1..dd36332 100644 --- a/app/Entities/Equipment/ServerPartEntity.php +++ b/app/Entities/Equipment/ServerPartEntity.php @@ -29,7 +29,7 @@ class ServerPartEntity extends EquipmentEntity return $this->attributes['payment_uid'] ?? null; } //기본기능용 - public function getTotalAmount(): int + public function getCalulatedAmount(): int { return $this->getAmount() * $this->getCnt(); } diff --git a/app/Interfaces/PaymentInterface.php b/app/Interfaces/PaymentInterface.php index f300046..f1105de 100644 --- a/app/Interfaces/PaymentInterface.php +++ b/app/Interfaces/PaymentInterface.php @@ -3,19 +3,18 @@ namespace App\Interfaces; use App\Entities\Customer\ServiceEntity; -use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerPartEntity; use App\Entities\PaymentEntity; interface PaymentInterface { //서비스 결제(월과금 서비스 사용) - public function createForService(ServiceEntity $service, int $amount): PaymentEntity; - public function updateForService(ServiceEntity $service, string $payment_uid, int $amount): PaymentEntity; - public function unlinkFromService(string $payment_uid): PaymentEntity; + public function createForService(ServiceEntity $serviceEntity): PaymentEntity; + public function updateForService(ServiceEntity $serviceEntity): PaymentEntity; + public function unlinkFromService(ServiceEntity $serviceEntity): PaymentEntity; //서버 파트 결제(파트/기타 일회성 서비스 사용) - public function createForServerPart(ServerPartEntity $serverPart, int $amount): PaymentEntity; - public function updateForServerPart(ServerPartEntity $serverPart, string $payment_uid, int $amount): PaymentEntity; - public function unlinkFromServerPart(string $payment_uid): PaymentEntity; + public function createForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity; + public function updateForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity; + public function unlinkFromServerPart(ServerPartEntity $serverPartEntity): PaymentEntity; } diff --git a/app/Models/Equipment/ServerPartModel.php b/app/Models/Equipment/ServerPartModel.php index 3e082c4..656ca21 100644 --- a/app/Models/Equipment/ServerPartModel.php +++ b/app/Models/Equipment/ServerPartModel.php @@ -38,11 +38,11 @@ class ServerPartModel extends EquipmentModel } switch ($field) { case "serverinfo_uid": + case "part_uid": case "cnt": case "amount": $rule = "required|numeric"; break; - case "part_uid": case "clientinfo_uid": case "serviceinfo_uid": case "payment_uid": diff --git a/app/Processors/CommonProcessor.php b/app/Processors/CommonProcessor.php index 48c1728..e416771 100644 --- a/app/Processors/CommonProcessor.php +++ b/app/Processors/CommonProcessor.php @@ -17,7 +17,7 @@ abstract class CommonProcessor final protected function setLog(string $title, string $status, ?string $context = null): void { - $this->logService->create([ + $this->logService->getModel()->create([ 'title' => $title, 'status' => $status, 'context' => $context diff --git a/app/Processors/Customer/ServiceV1Processor.php b/app/Processors/Customer/ServiceV1Processor.php index 49840f5..486a8a2 100644 --- a/app/Processors/Customer/ServiceV1Processor.php +++ b/app/Processors/Customer/ServiceV1Processor.php @@ -31,19 +31,18 @@ class ServiceV1Processor $entity, $entity->getServerInfoUID() ); - // 3) 금액 계산 + 반영 + // 3) 금액 계산 + 결제정보반영 $amount = $this->service->getCalculatedAmount($entity, $serverEntity); $this->service->getModel()->modify($entity, ['amount' => $amount]); - // 4) 결제 생성 - $paymentEntity = $this->paymentService->createForService($entity, $amount); - // 5) 서비스 FK 동기화 + $paymentEntity = $this->paymentService->createForService($entity); + // 4) 서비스 FK 동기화 $entity = $this->service->getModel()->modify($entity, [ 'title' => $entity->getTitle(), 'serverinfo_id' => $serverEntity->getPK(), 'payment_uid' => $paymentEntity->getPK(), ]); // 6) 로그 - $this->logService->create([ + $this->logService->getModel()->create([ 'title' => "{$entity->getTitle()} 서비스 추가", 'status' => $entity->getStatus(), ]); @@ -68,19 +67,15 @@ class ServiceV1Processor $entity, $entity->getServerInfoUID() ); - // 3) 금액 재계산 + 반영 - $amount = $this->service->getCalculatedAmount($entity, $serverEntity); - $this->service->getModel()->modify($entity, ['amount' => $amount]); - // 4) 결제 수정 - $payment = $this->paymentService->updateForService($entity, $entity->getPaymentUID(), $amount); + // 3) 금액 재계산 + 결제정보반영 + $entity = $this->service->setAmount($entity->getPK()); // 5) 서비스 FK 동기화 $entity = $this->service->getModel()->modify($entity, [ 'title' => $entity->getTitle(), - 'serverinfo_id' => $serverEntity->getPK(), - 'payment_uid' => $payment->getPK(), + 'serverinfo_id' => $serverEntity->getPK() ]); // 6) 로그 - $this->logService->create(formDatas: [ + $this->logService->getModel()->create(formDatas: [ 'title' => "{$entity->getTitle()} 서비스 수정", 'status' => $entity->getStatus(), ]); @@ -96,7 +91,7 @@ class ServiceV1Processor $this->db->transStart(); // 1) 결제 분리 if ($entity->getPaymentUID()) { - $this->paymentService->unlinkFromService($entity->getPaymentUID()); + $this->paymentService->unlinkFromService($entity); } // 2) 연결된 모든 서버 해지 foreach ($this->serverService->getEntities($entity->getPK()) as $serverEntity) { @@ -105,7 +100,7 @@ class ServiceV1Processor // 3) 서비스 삭제 $this->service->getModel()->delete($entity); // 4) 로그 - $this->logService->create([ + $this->logService->getModel()->create([ 'title' => "[{$entity->getTitle()}] 서비스 해지", 'status' => $entity->getStatus(), ]); @@ -132,7 +127,7 @@ class ServiceV1Processor ] ); // 2) 로그 - $this->logService->create([ + $this->logService->getModel()->create([ 'title' => "[{$entity->getTitle()}] 대체서버 추가", 'status' => $entity->getStatus(), ]); @@ -156,19 +151,15 @@ class ServiceV1Processor $serverinfo_uid, ['type' => $serverEntity->getType()] ); - // 3) 금액 재계산 + 반영 - $amount = $this->service->getCalculatedAmount($entity, $serverEntity); - $this->service->getModel()->modify($entity, ['amount' => $amount]); - // 4) 결제 수정 - $payment = $this->paymentService->updateForService($entity, $entity->getPaymentUID(), $amount); + // 3) 금액 재계산 + 결제정보반영 + $entity = $this->service->setAmount($entity->getPK()); // 4) 서비스 FK 동기화 $entity = $this->service->getModel()->modify($entity, [ 'title' => $entity->getTitle(), - 'serverinfo_id' => $serverEntity->getPK(), - 'payment_uid' => $payment->getPK(), + 'serverinfo_id' => $serverEntity->getPK() ]); // 5) 로그 - $this->logService->create([ + $this->logService->getModel()->create([ 'title' => "[{$entity->getTitle()}] 메인서버변경", 'status' => $entity->getStatus(), ]); @@ -187,7 +178,7 @@ class ServiceV1Processor $this->db->transStart(); $this->serverService->detachFromService($serverinfo_uid); // 4) 로그 - $this->logService->create([ + $this->logService->getModel()->create([ 'title' => "[{$entity->getTitle()}] 대체서버 해지", 'status' => $entity->getStatus(), ]); diff --git a/app/Processors/Equipment/ServerPartV1Processor.php b/app/Processors/Equipment/ServerPartV1Processor.php index a661065..843d82a 100644 --- a/app/Processors/Equipment/ServerPartV1Processor.php +++ b/app/Processors/Equipment/ServerPartV1Processor.php @@ -3,12 +3,14 @@ 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; use App\Services\Part\IPService; use App\Services\Part\SWITCHService; +use App\Services\PaymentService; use CodeIgniter\Database\BaseConnection; use RuntimeException; @@ -16,41 +18,62 @@ class ServerPartV1Processor { public function __construct( private BaseConnection $db, - private ServerService $service, + private ServerPartService $service, private ServiceService $serviceService, - private ServerPartService $serverPartService, + private ServerService $serverService, + private PaymentService $paymentService, private IPService $ipService, private SWITCHService $switchService, private MyLogService $logService, ) {} - public function create(array $formDatas): ServerEntity + public function create(array $formDatas): ServerPartEntity { $this->db->transStart(); - //1) 서버정보 생성 - //switch값이 없으면 null처리 - if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) { - $formDatas['switch'] = null; + //서버정보가져오기 + if (!array_key_exists('serverinfo_uid', $formDatas)) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다."); } - //ip값이 없으면 null처리 - if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) { - $formDatas['ip'] = null; + $serverEntity = $this->serverService->getEntity($formDatas['serverinfo_uid']); + if (!$serverEntity instanceof ServerEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: {$formDatas['serverinfo_uid']} 서버 정보를 찾을수 없습니다."); } + //서비스정의확인(기본은 제외) + if ($formDatas['billing'] !== PAYMENT['BILLING']['BASE'] && $serverEntity->getServiceInfoUID() === null) { + throw new \Exception(__METHOD__ . "에서 오류발생:서비스가 지정되어야 작업이 가능합니다."); + } + // 1) 생성작업 + $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); + $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); + $formDatas["serverinfo_uid"] = $serverEntity->getPK(); $entity = $this->service->getModel()->create($formDatas); - //2) 서버의 Type별 서버파트정보등록(서버파트연결 자동등록용) - $this->serverPartService->attachToServer($entity); - //3) Switch가 정의되어 있으면 - if ($entity->getSwitch() !== null) { // - $this->switchService->attachToServer($entity); + // 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; } - //4) //IP가 정의되어 있으면 - if ($entity->getIP() !== null) { - $this->ipService->attachToServer($entity); - } - //5) Log처리 - $this->logService->create([ - 'title' => "[{$entity->getTitle()}] 서버 추가", - 'status' => $entity->getStatus() + // 4) 로그 + $this->logService->getModel()->create(formDatas: [ + 'title' => "{$entity->getTitle()} 서버파트 추가", + 'status' => $entity->getStatus(), ]); $this->db->transComplete(); if ($this->db->transStatus() === false) { @@ -58,54 +81,63 @@ class ServerPartV1Processor } return $entity; } - public function modify(ServerEntity $entity, array $formDatas): ServerEntity + public function modify(ServerPartEntity $entity, array $formDatas): ServerPartEntity { $this->db->transStart(); - //1) 사전처리 작업 - //Switch값이 정의되어 있으면 - $formDatas['switch'] = null; //기본Switch 정보 유지 - $isChangedSwitch = false; - if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) { - //기존 Switch값과 다르면 - if ($entity->getSwitch() != $formDatas['switch']) { - //기존 Switch값이 있으면 해지 - if ($entity->getSwitch() != null) { - $this->switchService->detachFromServer($entity); + //서버정보가져오기 + if (!array_key_exists('serverinfo_uid', $formDatas)) { + throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다."); + } + // 1) 수정전 정보 + //파트값이 정의되어 있으면 + $formDatas['part_uid'] = null; //null이면 기존정보 유지 + $isPartChanged = false; + if (array_key_exists('part_uid', $formDatas) && !$formDatas['part_uid']) { + //기존파트값과 다르면 + if ($entity->getPartUID() != $formDatas['part_uid']) { + //기존파트값이 있으면 해지 + if ($entity->getPartUID() != null) { + $this->service->getPartService($entity->getType())->detachFromServerPart($entity); } - $isChangedSwitch = true; + $isPartChanged = true; } } - //IP값이 정의되어 있으면 - $formDatas['ip'] = null; //기본IPh 정보 유지 - $isChangedIP = false; - if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) { - //기존 IP값과 다르면 - if ($entity->getSwitch() != $formDatas['ip']) { - //기존 IP값이 있으면 해지 - if ($entity->getIP() != null) { - $this->ipService->detachFromServer($entity); - } - $isChangedIP = true; - } + // 2) 서버연결정보 수정 + $serverEntity = $this->serverService->getEntity($formDatas['serverinfo_uid']); + if (!$serverEntity instanceof ServerEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: {$formDatas['serverinfo_uid']} 서버 정보를 찾을수 없습니다."); } - //2) 서버정보 수정 + $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); + $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); + $formDatas["serverinfo_uid"] = $serverEntity->getPK(); $entity = $this->service->getModel()->modify($entity, $formDatas); - //3) Switch값이 있고 신규값인경우 - if ($entity->getSwitch() && $isChangedSwitch) { - $this->switchService->attachToServer($entity); + // 3) Type에 따른 각 파트 정의 + if ($isPartChanged) { //파트가 바뀐경우 추가작업 + $this->service->getPartService($entity->getType())->attachToServerPart($entity); } - //3) IP값이 있고 신규값인경우 - if ($entity->getIP() && $isChangedIP) { - $this->ipService->attachToServer($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; } - //5) 서비스금액 설정:서비스가 연결되어 있고 대체서버가 아니면, 서비스정보수정(청구액수정) - if ($entity->getServiceInfoUID() !== null && $entity->getType() !== SERVER['TYPES']['ALTERNATIVE']) { - $this->serviceService->setAmount($entity->getServiceInfoUID()); - } - //5) Log처리 - $this->logService->create([ - 'title' => "[{$entity->getTitle()}] 서버 정보변경", - 'status' => $entity->getStatus() + // 4) 로그 + $this->logService->getModel()->create(formDatas: [ + 'title' => "{$entity->getTitle()} 서버파트 수정", + 'status' => $entity->getStatus(), ]); $this->db->transComplete(); if ($this->db->transStatus() === false) { @@ -114,23 +146,40 @@ class ServerPartV1Processor return $entity; } - public function delete(ServerEntity $entity): ServerEntity + public function delete(ServerPartEntity $entity): ServerPartEntity { - //서비스가 연결되어있거나 , 사용가능 상태가 아니면 삭제불가 - if ($entity->getServiceInfoUID() !== null || $entity->getStatus() !== STATUS['AVAILABLE']) { - throw new \Exception("서비스중인 서버는 삭제하실수 없습니다."); - } $this->db->transStart(); - //기존 Switch값이 있으면 해지 - if ($entity->getSwitch() != null) { - $this->switchService->detachFromServer($entity); + // 1) 서버파트정보 삭제 + $this->service->getModel()->delete($entity); + // 2) 기존파트값이 있으면 해지 + if ($entity->getPartUID() != null) { + $this->service->getPartService($entity->getType())->detachFromServerPart($entity); } - //기존 IP값이 있으면 해지 - if ($entity->getIP() != null) { - $this->ipService->detachFromServer($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; } - //기존 서버파트 해지 - $this->serverPartService->detachFromServer($entity); + // 4) 로그 + $this->logService->getModel()->create(formDatas: [ + 'title' => "{$entity->getTitle()} 서버파트 삭제", + 'status' => $entity->getStatus(), + ]); $this->db->transComplete(); if ($this->db->transStatus() === false) { throw new RuntimeException('트랜잭션 실패'); diff --git a/app/Processors/Equipment/ServerV1Processor.php b/app/Processors/Equipment/ServerV1Processor.php index b70173b..58f1f37 100644 --- a/app/Processors/Equipment/ServerV1Processor.php +++ b/app/Processors/Equipment/ServerV1Processor.php @@ -48,7 +48,7 @@ class ServerV1Processor $this->ipService->attachToServer($entity); } //5) Log처리 - $this->logService->create([ + $this->logService->getModel()->create([ 'title' => "[{$entity->getTitle()}] 서버 추가", 'status' => $entity->getStatus() ]); @@ -63,7 +63,7 @@ class ServerV1Processor $this->db->transStart(); //1) 사전처리 작업 //Switch값이 정의되어 있으면 - $formDatas['switch'] = null; //기본Switch 정보 유지 + $formDatas['switch'] = null; //null이면 기존정보 유지 $isChangedSwitch = false; if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) { //기존 Switch값과 다르면 @@ -76,7 +76,7 @@ class ServerV1Processor } } //IP값이 정의되어 있으면 - $formDatas['ip'] = null; //기본IPh 정보 유지 + $formDatas['ip'] = null; //null이면 기존정보 유지 $isChangedIP = false; if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) { //기존 IP값과 다르면 @@ -103,7 +103,7 @@ class ServerV1Processor $this->serviceService->setAmount($entity->getServiceInfoUID()); } //5) Log처리 - $this->logService->create([ + $this->logService->getModel()->create([ 'title' => "[{$entity->getTitle()}] 서버 정보변경", 'status' => $entity->getStatus() ]); diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index f865196..a56de3d 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -167,7 +167,7 @@ class ServiceService extends CustomerService return $entity->getRack() + $entity->getLine() + $this->getServerService()->getCalculatedAmount($serverEntity) - $entity->getSale(); } //서비스금액변경 - public function setAmount(string $uid): PaymentEntity + public function setAmount(string $uid): ServiceEntity { $entity = $this->getEntity($uid); if (!$entity instanceof ServiceEntity) { @@ -178,9 +178,9 @@ class ServiceService extends CustomerService throw new \Exception(__METHOD__ . "에서 오류발생: [{$entity->getServerInfoUID()}]에 대한 서버정보를 찾을수 없습니다."); } $amount = $this->getCalculatedAmount($entity, $serverEntity); - $entity = parent::modify($entity, ['amount' => $amount]); //결제정보 수정 - return $this->getPaymentService()->updateForService($entity, $entity->getPaymentUID(), $amount); + $this->getPaymentService()->updateForService($entity); + return parent::modify($entity, ['amount' => $amount]); } //기본 기능부분 //FieldForm관련용 diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 94c08b0..3751a67 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -18,6 +18,7 @@ use App\Services\Part\RAMService; use App\Services\Part\SOFTWAREService; use App\Services\Part\SWITCHService; use App\Services\PaymentService; +use App\Processors\Equipment\ServerPartV1Processor as Proceessor; class ServerPartService extends EquipmentService implements ServerPartInterface { @@ -255,127 +256,46 @@ class ServerPartService extends EquipmentService implements ServerPartInterface //부품연결정보생성 public function create(array $formDatas): ServerPartEntity { - //서버정보가져오기 - if (!array_key_exists('serverinfo_uid', $formDatas)) { - throw new \Exception("서버 정보가 지정되지 않았습니다."); - } - $serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']); - if (!$serverEntity instanceof ServerEntity) { - throw new \Exception("서버 정보가 지정되지 않았습니다."); - } - //서비스정의확인(기본은 제외) - if ($formDatas['billing'] !== PAYMENT['BILLING']['BASE'] && $serverEntity->getServiceInfoUID() === null) { - throw new \Exception(__METHOD__ . "에서 오류발생:{월,일회성 과금용은 서비스가 지정되어야 작업이 가능합니다."); - } - //생성작업 - $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); - $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); - $formDatas["serverinfo_uid"] = $serverEntity->getPK(); - $entity = parent::create($formDatas); - //후처리작업 - //Type에 따른 부품서비스 정의 - $this->getPartService($entity->getType())->setServerPart($entity); - //서비스 및 결제정보 처리 - switch ($entity->getBilling()) { - case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 - if ($entity->getServiceInfoUID() === null) { - throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다."); - } - //서비스 금액만 재계산변경 - $this->getServiceService()->setAmount($entity->getServiceInfoUID()); - break; - case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - $paymentEntity = $this->getPaymentService()->createServerPart($entity); - //결제정보PK정의 - $entity = parent::modify($entity, ['payment_uid' => $paymentEntity->getPK()]); - break; - case PAYMENT['BILLING']['BASE']: //기본처리 - //아무처리 않함 - break; - default: - throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); - // break; - } - //Log처리 - $this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 서버파트정보 추가"]); - return $entity; + $processor = new Proceessor( + \Config\Database::connect(), + $this, + $this->getServiceService(), + $this->getServerService(), + $this->getPaymentService(), + $this->getIPService(), + $this->getSwitchService(), + $this->getMylogService() + ); + return $processor->create($formDatas); } //수정 public function modify(mixed $entity, array $formDatas): ServerPartEntity { - //서버정보가져오기 - if (!array_key_exists('serverinfo_uid', $formDatas)) { - throw new \Exception("서버 정보가 지정되지 않았습니다."); - } - $serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']); - if (!$serverEntity instanceof ServerEntity) { - throw new \Exception("서버 정보가 지정되지 않았습니다."); - } - //수정전 정보 - $this->getPartService($entity->getType())->unsetServerPart($entity); - //서버연결정보 수정 - $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); - $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); - $formDatas["serverinfo_uid"] = $serverEntity->getPK(); - $entity = parent::modify($entity, $formDatas); - //후처리작업 - //Type에 따른 부품서비스 정의 - $this->getPartService($entity->getType())->setServerPart($entity); - //서비스 및 결제정보 처리 - switch ($entity->getBilling()) { - case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 - if ($entity->getServiceInfoUID() !== null) { //서비스가 정의되어 있으면 - //서비스 금액만 재계산변경 - $this->getServiceService()->setAmount($entity->getServiceInfoUID()); - } - break; - case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면 - $paymentEntity = $this->getPaymentService()->modifyServerPart($entity); - //결제정보PK정의 - $entity = parent::modify($entity, ['payment_uid' => $paymentEntity->getPK()]); - } - break; - case PAYMENT['BILLING']['BASE']: //기본처리 - //아무처리 않함 - break; - default: - throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); - // break; - } - //Log처리 - $this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 서버파트정보 수정"]); - return $entity; + $processor = new Proceessor( + \Config\Database::connect(), + $this, + $this->getServiceService(), + $this->getServerService(), + $this->getPaymentService(), + $this->getIPService(), + $this->getSwitchService(), + $this->getMylogService() + ); + return $processor->modify($entity, $formDatas); } //삭제 public function delete(mixed $entity): ServerPartEntity { - //Type에 따른 부품서비스 정의 - $this->getPartService($entity->getType())->unsetServerPart($entity); - //서버연결정보 식제 - parent::delete($entity); - //서비스 및 결제정보 후처리작업 - switch ($entity->getBilling()) { - case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 - if ($entity->getServiceInfoUID() !== null) { //서비스가 정의되어 있으면 - //서비스 금액만 재계산변경 - $this->getServiceService()->setAmount($entity->getServiceInfoUID()); - } - break; - case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리 - if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면 - $this->getPaymentService()->deleteServerPart($entity); - } - break; - case PAYMENT['BILLING']['BASE']: //기본처리 - //아무처리 않함 - break; - default: - throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다."); - // break; - } - //Log처리 - $this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 서버파트정보 삭제"]); - return $entity; + $processor = new Proceessor( + \Config\Database::connect(), + $this, + $this->getServiceService(), + $this->getServerService(), + $this->getPaymentService(), + $this->getIPService(), + $this->getSwitchService(), + $this->getMylogService() + ); + return $processor->delete($entity); } } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index c5d7002..636a702 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -123,7 +123,7 @@ class PaymentService extends CommonService implements PaymentInterface } //Service관련(월과금) //서비스생성 - public function createForService(ServiceEntity $serviceEntity, int $amount): PaymentEntity + public function createForService(ServiceEntity $serviceEntity): PaymentEntity { $billingAt = new DateTimeImmutable($serviceEntity->getBillingAt(), new DateTimeZone('Asia/Tokyo')); return $this->getModel()->create([ @@ -131,17 +131,20 @@ class PaymentService extends CommonService implements PaymentInterface 'serviceinfo_uid' => $serviceEntity->getPK(), 'serverinfo_uid' => $serviceEntity->getServerInfoUID(), //서버정보 번호 'title' => sprintf('[%s] %s 서비스비용', $serviceEntity->getTitle(), $billingAt->format('Y년 n월')), - 'amount' => $amount, + 'amount' => $serviceEntity->getAmount(), 'billing' => PAYMENT['BILLING']['MONTH'], 'billing_at' => $billingAt->format('Y-m-d'), ]); } //서비스수정 - public function updateForService(ServiceEntity $serviceEntity, string $payment_uid, int $amount): PaymentEntity + public function updateForService(ServiceEntity $serviceEntity): PaymentEntity { - $paymentEntity = $this->getEntity($payment_uid); + if ($serviceEntity->getPaymentUID() === null) { + throw new \Exception(__METHOD__ . "에서 오류발생:서비스정보에 결제정보가 정의되지 않았습니다."); + } + $paymentEntity = $this->getEntity($serviceEntity->getPaymentUID()); if (!$paymentEntity instanceof PaymentEntity) { - throw new \Exception("[{$payment_uid}]에 대한 결제정보를 찾을 수 없습니다."); + throw new \Exception("[{$serviceEntity->getPaymentUID()}]에 대한 결제정보를 찾을 수 없습니다."); } $billingAt = new DateTimeImmutable($serviceEntity->getBillingAt(), new DateTimeZone('Asia/Tokyo')); return $this->getModel()->modify($paymentEntity, [ @@ -149,41 +152,40 @@ class PaymentService extends CommonService implements PaymentInterface 'serviceinfo_uid' => $serviceEntity->getPK(), 'serverinfo_uid' => $serviceEntity->getServerInfoUID(), 'title' => sprintf('[%s] %s 서비스비용', $serviceEntity->getTitle(), $billingAt->format('Y년 n월')), - 'amount' => $amount, + 'amount' => $serviceEntity->getAmount(), 'billing' => PAYMENT['BILLING']['MONTH'], 'billing_at' => $billingAt->format('Y-m-d'), ]); } //서비스해지 - public function unlinkFromService(string $payment_uid): PaymentEntity + public function unlinkFromService(ServiceEntity $erviceEntity): PaymentEntity { - $paymentEntity = $this->getEntity($payment_uid); + $paymentEntity = $this->getEntity($erviceEntity->getPaymentUID()); if (!$paymentEntity instanceof PaymentEntity) { - throw new \Exception("[{$payment_uid}]에 대한 결제정보를 찾을 수 없습니다."); + throw new \Exception("[{$erviceEntity->getPaymentUID()}]에 대한 결제정보를 찾을 수 없습니다."); } + //서비스해지시에는 고객정보로 서비스금액을 전환 서비스정보 NULL처리 return $this->getModel()->modify($paymentEntity, [ 'serviceinfo_uid' => null, - 'serverinfo_uid' => null, ]); } //서버파트(일회성과금) - final public function createForServerPart(ServerPartEntity $serverPartEntity, int $amount): PaymentEntity + public function createForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity { $formDatas = []; $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); //서버연결정보 수정시에 필요함 $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); - //타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다. $formDatas['title'] = $serverPartEntity->getTitle(); - $formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt + $formDatas['amount'] = $serverPartEntity->getCalulatedAmount(); //단가*cnt $formDatas['billing'] = $serverPartEntity->getBilling(); //당일결체일로 설정 $formDatas['billing_at'] = date("Y-m-d"); return parent::create($formDatas); } - final public function updateForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity + public function updateForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity { if ($serverPartEntity->getPaymentUID() === null) { throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다."); @@ -200,13 +202,12 @@ class PaymentService extends CommonService implements PaymentInterface $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); //서버연결정보 수정시에 필요함 $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); - //타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다. $formDatas['title'] = $serverPartEntity->getTitle(); - $formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt + $formDatas['amount'] = $serverPartEntity->getCalulatedAmount(); //단가*cnt $formDatas['billing'] = $serverPartEntity->getBilling(); return parent::modify($entity, $formDatas); } - final public function deleteServerPart(ServerPartEntity $serverPartEntity): void + public function unlinkFromServerPart(ServerPartEntity $serverPartEntity): PaymentEntity { if ($serverPartEntity->getPaymentUID() === null) { throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다."); @@ -218,7 +219,10 @@ class PaymentService extends CommonService implements PaymentInterface if ($entity->getStatus() === STATUS['PAID']) { throw new \Exception(__METHOD__ . "에서 오류발생:결제완료된 서비스는 수정할수 없습니다."); } - parent::delete($entity); + //서비스해지시에는 고객정보로 서비스금액을 전환 서비스정보 NULL처리 + return $this->getModel()->modify($entity, [ + 'serviceinfo_uid' => null, + ]); } //Invoice 관련