diff --git a/app/Controllers/Admin/Customer/PaymentController.php b/app/Controllers/Admin/Customer/PaymentController.php index 56b85d9..7f67032 100644 --- a/app/Controllers/Admin/Customer/PaymentController.php +++ b/app/Controllers/Admin/Customer/PaymentController.php @@ -5,10 +5,8 @@ namespace App\Controllers\Admin\Customer; use App\Entities\Customer\ClientEntity; use App\Entities\PaymentEntity; use App\Entities\Customer\ServiceEntity; -use App\Libraries\LogCollector; - use App\Services\Customer\ClientService; -use App\Services\PaymentService; +use App\Services\Payment\PaymentService; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index 80ed89a..fecb849 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -3,7 +3,7 @@ namespace App\Controllers\Admin\Customer; use App\Entities\Customer\ServiceEntity; -use App\Services\PaymentService; +use App\Services\Payment\PaymentService; use App\Services\Customer\ServiceService; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; diff --git a/app/Controllers/Admin/Home.php b/app/Controllers/Admin/Home.php index da52440..8f830e4 100644 --- a/app/Controllers/Admin/Home.php +++ b/app/Controllers/Admin/Home.php @@ -3,7 +3,7 @@ namespace App\Controllers\Admin; use App\Services\Customer\ServiceService; -use App\Services\PaymentService; +use App\Services\Payment\PaymentService; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index 618f86d..f1932dc 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -5,7 +5,7 @@ namespace App\Services\Customer; use App\Entities\Customer\ClientEntity; use App\Helpers\Customer\ClientHelper; use App\Models\Customer\ClientModel; -use App\Services\PaymentService; +use App\Services\Payment\PaymentService; class ClientService extends CustomerService { diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 2e28503..a0c9d84 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -11,7 +11,7 @@ use App\Helpers\Customer\ServiceHelper; use App\Models\Customer\ServiceModel; use App\Services\Equipment\ServerService; use App\Traits\IPTrait; -use App\Services\PaymentService; +use App\Services\Payment\PaymentService; class ServiceService extends CustomerService { diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 049f6fb..8175cc6 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -7,7 +7,8 @@ use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerPartEntity; use App\Helpers\Equipment\ServerPartHelper; use App\Models\Equipment\ServerPartModel; -use App\Services\PaymentService; +use App\Services\Payment\CreatePayment; +use App\Services\Payment\ModifyPayment; class ServerPartService extends EquipmentService { @@ -15,7 +16,8 @@ class ServerPartService extends EquipmentService private ?PartService $_partService = null; private ?IPService $_ipService = null; private ?CSService $_csService = null; - private ?PaymentService $_paymentService = null; + private ?CreatePayment $_creatPayment = null; + private ?ModifyPayment $_modifyPayment = null; public function __construct() { parent::__construct(new ServerPartModel(), new ServerPartHelper()); @@ -98,12 +100,22 @@ class ServerPartService extends EquipmentService return $this->_csService; } - final public function getPaymentService(): PaymentService + final public function getPaymentService(string $action): CreatePayment|ModifyPayment { - if (!$this->_paymentService) { - $this->_paymentService = new PaymentService(); + switch ($action) { + case 'modify': + if (!$this->_modifyPayment) { + $this->_modifyPayment = new ModifyPayment(); + } + $paymentService = $this->_modifyPayment; + break; + default: + if (!$this->_creatPayment) { + $this->_creatPayment = new CreatePayment(); + } + return $this->_creatPayment; } - return $this->_paymentService; + return $paymentService; } //partEntity 정보 추가 protected function getEntity_process(mixed $entity): ServerPartEntity @@ -228,7 +240,7 @@ class ServerPartService extends EquipmentService //부품정보 설정 $entity = $this->setServerPart($entity, ['part_uid' => $formDatas['part_uid'], 'status' => STATUS['OCCUPIED']]); //결제관련정보 설정 - $entity = $this->getPaymentService()->setServerPart($entity); + $entity = $this->getPaymentService(__FUNCTION__)->setServerPart($entity); return $entity; } //수정 @@ -256,7 +268,7 @@ class ServerPartService extends EquipmentService $entity = $this->setServerPart($entity, ['part_uid' => $formDatas['part_uid'], 'status' => STATUS['OCCUPIED']]); } //결제관련정보 정의 - $entity = $this->getPaymentService()->setServerPart($entity, ['action' => __FUNCTION__]); + $entity = $this->getPaymentService(__FUNCTION__)->setServerPart($entity, ['action' => __FUNCTION__]); return $entity; } //삭제 diff --git a/app/Services/Payment/CreatePayment.php b/app/Services/Payment/CreatePayment.php new file mode 100644 index 0000000..6ee7b1d --- /dev/null +++ b/app/Services/Payment/CreatePayment.php @@ -0,0 +1,24 @@ +getBilling() === PAYMENT['BILLING']['ONETIME'] ? date("Y-m-d") : $serviceEntity->getBillingAT(); + $entity = $this->create($formDatas); + return $serverPartEntity; + } +} diff --git a/app/Services/Payment/ModifyPayment.php b/app/Services/Payment/ModifyPayment.php new file mode 100644 index 0000000..2ae22fb --- /dev/null +++ b/app/Services/Payment/ModifyPayment.php @@ -0,0 +1,30 @@ +getEntity(['serverpartinfo_uid' => $serverPartEntity->getPK(), 'status' => STATUS['UNPAID']]); + if (!$entity instanceof PaymentEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: {$serverPartEntity->getPK()}에 해당하는 결제정보를 찾을수 없습니다."); + } + $entity = $this->modify($entity, $formDatas); + return $serverPartEntity; + } +} diff --git a/app/Services/PaymentService.php b/app/Services/Payment/PaymentService.php similarity index 85% rename from app/Services/PaymentService.php rename to app/Services/Payment/PaymentService.php index 11dccc4..d0a5089 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/Payment/PaymentService.php @@ -1,6 +1,6 @@ getModel()->orderBy('billing_at ASC'); parent::setOrderBy($field, $value); @@ -132,20 +133,23 @@ class PaymentService extends CommonService implements ServerPartInterface ->get()->getResult(); } //생성 - public function create(array $formDatas): PaymentEntity + final public function create(array $formDatas): PaymentEntity { // 관리자 UID는 현재 인증된 사용자로 설정 $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); return parent::create($formDatas); } //수정 - public function modify(mixed $entity, array $formDatas): PaymentEntity + final public function modify(mixed $entity, array $formDatas): PaymentEntity { // 관리자 UID는 현재 인증된 사용자로 설정 $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); return parent::modify($entity, $formDatas); } - //서버연결정보용 등록 + protected function setServerPart_process(ServerPartEntity $serverPartEntity, ServiceEntity $serviceEntity, array $formDatas): serverPartEntity + { + return $serverPartEntity; + } public function setServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): ServerPartEntity { if ($serverPartEntity->getServiceInfoUID() === null) { @@ -156,13 +160,6 @@ class PaymentService extends CommonService implements ServerPartInterface if (!$serviceEntity) { throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다."); } - //수정인경우 기존 결제정보 가져오기 - if (array_key_exists('action', $formDatas) && $formDatas['action'] === 'modify') { - $entity = $this->getEntity(['serverpartinfo_uid' => $serverPartEntity->getPK()]); - if (!$entity instanceof PaymentEntity) { - throw new \Exception("{$serverPartEntity->getPK()}에 해당하는 결제정보를 찾을수 없습니다."); - } - } //월비용인경우 서비스 제공가에 서버연결정보 제공가 합산금액으로 설정 if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { $formDatas['serverinfo_uid'] = $serviceEntity->getServerInfoUID(); @@ -179,17 +176,11 @@ class PaymentService extends CommonService implements ServerPartInterface $formDatas['title'] = $serverPartEntity->getType() === 'ETC' ? $serverPartEntity->getTitle() : $serverPartEntity->getPartEntity()->getTitle(); $formDatas['amount'] = $serverPartEntity->getAmount(); $formDatas['billing'] = $serverPartEntity->getBilling(); - if (array_key_exists('action', $formDatas) && $formDatas['action'] === 'modify') { - $this->modify($entity, $formDatas); - } else { - //생성일때만 지급기한일 설정 - $formDatas['billing_at'] = $serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME'] ? date("Y-m-d") : $serviceEntity->getBillingAT(); - $this->create($formDatas); - } + $formDatas['billing_at'] = $serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME'] ? date("Y-m-d") : $serviceEntity->getBillingAT(); + $serverPartEntity = $this->setServerPart_process($serverPartEntity, $serviceEntity, $formDatas); } return $serverPartEntity; } - //서비스정보용 등록 public function service(ServiceEntity $serviceEntity, array $formDatas = []): ServiceEntity {