From bec3fe8ec40518e608ea3e461722ffcc92f2fe74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Mon, 15 Dec 2025 10:50:30 +0900 Subject: [PATCH] dbmsv4 init...3 --- .../Admin/Customer/ServiceController.php | 13 ++++++---- app/Forms/CommonForm.php | 1 - app/Services/CommonService.php | 1 - app/Services/Customer/ServiceService.php | 22 ++++++++++------ app/Services/Equipment/ServerService.php | 22 ++++++++++++---- app/Services/PaymentService.php | 26 +++++++++---------- 6 files changed, 52 insertions(+), 33 deletions(-) diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index 18a5e05..ce06750 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -79,7 +79,7 @@ class ServiceController extends CustomerController public function alternative_create_form(int $uid): string|RedirectResponse { try { - $this->action_init_process(__FUNCTION__, $this->request->getVar()); + $this->action_init_process(__FUNCTION__, ['uid' => $uid]); return $this->action_render_process(__FUNCTION__, $this->getViewDatas(), $this->request->getVar('ActionTemplate') ?? 'server'); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가폼 오류:" . $e->getMessage()); @@ -96,8 +96,11 @@ class ServiceController extends CustomerController } //서비스정보 가져오기 $entity = $this->service->getEntity($uid); + if (!$entity instanceof ServiceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보을 찾을수 없습니다."); + } //대체서버 추가 - service('equipment_serverservice')->attachToService($entity, $serverinfo_uid); + service('equipment_serverservice')->attatchToService($entity, $serverinfo_uid); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가가 완료되었습니다."); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 추가 오류:" . $e->getMessage()); @@ -120,7 +123,7 @@ class ServiceController extends CustomerController } //서버번호 와 서비스 제목 설정용 $formDatas = []; - $formDatas['serverinfo_uid'] = $serverinfo_uid; + $formDatas['serverinfo_uid'] = $serverEntity->getPK(); $formDatas['title'] = $serverEntity->getCustomTitle(); //대체서버를 메인서버로 설정 $this->service->modify($uid, $formDatas); @@ -142,10 +145,10 @@ class ServiceController extends CustomerController //서비스정보 가져오기 $entity = $this->service->getEntity($uid); if (!$entity instanceof ServiceEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서비스정보을 찾을수 없습니다."); + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보을 찾을수 없습니다."); } //대체서버 해지 - service('equipment_serverservice')->detachFromService($entity, $serverinfo_uid); + service('equipment_serverservice')->deatchFromService($serverinfo_uid); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 해지가 완료되었습니다."); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 대체서버 해지 오류:" . $e->getMessage()); diff --git a/app/Forms/CommonForm.php b/app/Forms/CommonForm.php index 6c23063..68d8664 100644 --- a/app/Forms/CommonForm.php +++ b/app/Forms/CommonForm.php @@ -118,7 +118,6 @@ abstract class CommonForm //Validation용 final public function validate(array $formDatas): bool { - dd($this); if ($this->_validation === null) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: Validation 서비스가 초기화되지 않았습니다."); } diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index ddfcf6f..23e5f1d 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -218,7 +218,6 @@ abstract class CommonService //관리자 정보추가용 $formDatas['user_uid'] = $this->getAuthContext()->getUID(); // 데이터 검증 - // dd($this->getFormService()); if (!$this->getFormService()->validate($formDatas)) { throw new ValidationException( implode("\n", service('validation')->getErrors()) diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 4d2ab02..3530594 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -4,6 +4,7 @@ namespace App\Services\Customer; use App\DTOs\Customer\ServiceDTO; use App\Entities\Customer\ServiceEntity; +use App\Entities\Equipment\ServerEntity; use App\Forms\Customer\ServiceForm; use App\Helpers\Customer\ServiceHelper; use App\Models\Customer\ServiceModel; @@ -210,7 +211,7 @@ class ServiceService extends CustomerService throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServiceEntity만 가능"); } //서버정보 연결 - service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID()); + service('equipment_serverservice')->attatchToService($entity, $entity->getServerInfoUID()); //서비스비용 설정 $entity = $this->saveAmount($entity); //결제정보 생성 @@ -226,14 +227,19 @@ class ServiceService extends CustomerService if (!$entity instanceof ServiceEntity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServiceEntity만 가능"); } - //서버정보 연결 신규서버로 변경되었으면 신규서버 추가 - if ($oldEntity->getServerInfoUID() !== $entity->getServerInfoUID()) { - service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID()); - } - //서비스비용 설정 + //신규 서비스 서버의 비용으로 재계산 서비스 금액 설정 $entity = $this->saveAmount($entity); - //결제정보 생성 - service('paymentservice')->modifyByService($entity); + //기존 서비스용 결제비용 과 신규 서버스용으로 결제비용이 다르면 수정 + if ($oldEntity->getAmount() !== $entity->getAmount()) { + service('paymentservice')->modifyByService($oldEntity, $entity); + } + //서버정보 연결 신규서버로 변경 + if ($oldEntity->getServerInfoUID() !== $entity->getServerInfoUID()) { + //기존서버는 대체서버로 변경 + service('equipment_serverservice')->modifyByService($oldEntity->getServerInfoUID()); + //신규서버는 메인서버로 추가 + service('equipment_serverservice')->attatchToService($entity, $entity->getServerInfoUID()); + } return $entity; } //List 검색용 diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 26a9aaf..779ff33 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -264,24 +264,36 @@ class ServerService extends EquipmentService //OrderBy 처리 //서비스관련 - //Service 결제데이터 가져오기 - public function attachToService(ServiceEntity $serviceEntity, int $uid): void + public function attatchToService(ServiceEntity $serviceEntity, $uid): void { $entity = $this->getEntity($uid); if (!$entity instanceof ServerEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서버정보을 찾을수 없습니다."); + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서버정보을 찾을수 없습니다."); } + $formDatas = []; $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID(); $formDatas['status'] = $formDatas['status'] ?? STATUS['OCCUPIED']; parent::modify_process($entity, $formDatas); } - public function detachFromService(int|ServerEntity $uid): void + public function modifyByService($uid): void { $entity = $this->getEntity($uid); if (!$entity instanceof ServerEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서버정보을 찾을수 없습니다."); + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서버정보을 찾을수 없습니다."); } + $formDatas = []; + $formDatas['type'] = 'alternative'; + parent::modify_process($entity, $formDatas); + } + //해지처리 + public function deatchFromService($uid): void + { + $entity = $this->getEntity($uid); + if (!$entity instanceof ServerEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서버정보을 찾을수 없습니다."); + } + $formDatas = []; $formDatas['serviceinfo_uid'] = NULL; $formDatas["clientinfo_uid"] = NULL; $formDatas["switchinfo_uid"] = NULL; diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 4db21c3..3a9644a 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -279,7 +279,7 @@ class PaymentService extends CommonService } //서비스관련 - private function getFormDatasByService(ServiceEntity $serviceEntity, array $formDatas = []): array + private function getFormDatasFromService(ServiceEntity $serviceEntity, array $formDatas = []): array { $formDatas['serviceinfo_uid'] = $serviceEntity->getPK(); $formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUID(); @@ -297,28 +297,28 @@ class PaymentService extends CommonService } public function createByService(ServiceEntity $serviceEntity): PaymentEntity { - $formDatas = $this->getFormDatasByService($serviceEntity); + $formDatas = $this->getFormDatasFromService($serviceEntity); return parent::create_process($formDatas); } - public function modifyByService(ServiceEntity $serviceEntity): PaymentEntity + public function modifyByService(ServiceEntity $oldServiceEntity, ServiceEntity $serviceEntity): PaymentEntity { - //서비스정보의 청구방식이 Month이고 지급기한일과 같고,상태가 UNPAID인 결제정보 가져와서 결제정보 수정 + //기존 서비스정보의 청구방식이 Month이고 지급기한일과 같고,상태가 UNPAID인 결제정보 가져와서 결제정보 수정 $entity = $this->getEntity([ - 'serviceinfo_uid' => $serviceEntity->getPK(), + 'serviceinfo_uid' => $oldServiceEntity->getPK(), 'billing' => PAYMENT['BILLING']['MONTH'], - 'billing_at' => $serviceEntity->getBillingAt(), + 'billing_at' => $oldServiceEntity->getBillingAt(), 'status' => STATUS['UNPAID'] ]); if (!$entity instanceof PaymentEntity) { //해당조건에 맞는게 없으면 생성 - $entity = $this->createByService($serviceEntity); - } else { - $formDatas = $this->getFormDatasByService($serviceEntity); - $entity = parent::modify_process($entity, $formDatas); + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 기존 서비스정보의 {$oldServiceEntity->getPK()}에 해당하는 결제정보가 존재하지 않습니다."); } + //신규 서비스정보에 맞게 수정 + $formDatas = $this->getFormDatasFromService($serviceEntity); + $entity = parent::modify_process($entity, $formDatas); return $entity; } //서버파트별 일회성 관련 - private function getFormDatasByServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): array + private function getFormDatasFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): array { if ($serverPartEntity->getServiceInfoUID() === null) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보가 정의되지 않아 일회성 상품을 설정하실수 없습니다."); @@ -338,7 +338,7 @@ class PaymentService extends CommonService if ($serverPartEntity->getServiceInfoUID() === null) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보가 정의되지 않아 일회성 상품을 설정하실수 없습니다."); } - $formDatas = $this->getFormDatasByServerPart($serverPartEntity); + $formDatas = $this->getFormDatasFromServerPart($serverPartEntity); return parent::create_process($formDatas); } public function modifyByServerPart(ServerPartEntity $serverPartEntity): PaymentEntity @@ -356,7 +356,7 @@ class PaymentService extends CommonService if (!$entity instanceof PaymentEntity) { $entity = $this->createByServerPart($serverPartEntity); } else { - $formDatas = $this->getFormDatasByServerPart($serverPartEntity); + $formDatas = $this->getFormDatasFromServerPart($serverPartEntity); $entity = parent::modify_process($entity, $formDatas); } return $entity;