From e7c1da7ec1827c5b40c25ad91c8027c3f9f7624f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Fri, 12 Dec 2025 15:39:12 +0900 Subject: [PATCH] dbmsv4 init...3 --- app/Controllers/AbstractCRUDController.php | 18 ++++- .../Admin/Customer/ClientController.php | 10 +-- .../Admin/Customer/ServiceController.php | 57 +++++++++------ app/Controllers/Admin/PaymentController.php | 2 +- app/Controllers/CLI/Invoice.php | 2 +- app/Controllers/CommonController.php | 10 +-- app/Services/BoardService.php | 6 +- app/Services/CommonService.php | 72 ++++--------------- app/Services/Customer/ClientService.php | 2 +- app/Services/Customer/ServiceService.php | 31 +++----- .../Customer/Wallet/AccountService.php | 2 +- .../Customer/Wallet/CouponService.php | 2 +- app/Services/Customer/Wallet/PointService.php | 2 +- app/Services/Equipment/ServerPartService.php | 8 +-- app/Services/Equipment/ServerService.php | 4 +- app/Services/PaymentService.php | 18 ++--- 16 files changed, 99 insertions(+), 147 deletions(-) diff --git a/app/Controllers/AbstractCRUDController.php b/app/Controllers/AbstractCRUDController.php index 40f8508..bda1c59 100644 --- a/app/Controllers/AbstractCRUDController.php +++ b/app/Controllers/AbstractCRUDController.php @@ -41,8 +41,14 @@ abstract class AbstractCRUDController extends AbstractWebController } protected function create_process(array $formDatas): object { - // POST 데이터를 DTO 객체로 변환 (getPost()는 POST 요청 본문만 가져옵니다.) - return $this->service->create($this->service->createDTO($formDatas)); + // POST 데이터를 DTO 객체로 변환 + $dto = $this->service->createDTO($formDatas); + //DTO 타입 체크 로직을 일반화 + $dtoClass = $this->service->getDTOClass(); + if (!$dto instanceof $dtoClass) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)"); + } + return $this->service->create($dto->toArray()); } protected function create_result_process($entity, ?string $redirect_url = null): string|RedirectResponse @@ -102,7 +108,13 @@ abstract class AbstractCRUDController extends AbstractWebController protected function modify_process($uid, array $formDatas): object { // POST 데이터를 DTO 객체로 변환 - return $this->service->modify($uid, $this->service->createDTO($formDatas)); + $dto = $this->service->createDTO($formDatas); + //DTO 타입 체크 로직을 일반화 + $dtoClass = $this->service->getDTOClass(); + if (!$dto instanceof $dtoClass) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)"); + } + return $this->service->modify($uid, $dto->toArray()); } protected function modify_result_process($entity, ?string $redirect_url = null): string|RedirectResponse diff --git a/app/Controllers/Admin/Customer/ClientController.php b/app/Controllers/Admin/Customer/ClientController.php index 47ee985..8f06a27 100644 --- a/app/Controllers/Admin/Customer/ClientController.php +++ b/app/Controllers/Admin/Customer/ClientController.php @@ -55,11 +55,11 @@ class ClientController extends CustomerController public function history(int $uid): RedirectResponse|string { try { - $action = __FUNCTION__; - $fields = ['history']; - $this->service->getFormService()->setFormFields($fields); - $this->service->getFormService()->setFormRules($action, $fields); - $this->addViewDatas('entity', $this->service->modify($uid, $this->service->createDTO($this->request->getPost()))); + $history = $this->request->getPost('history'); + if (!$history) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 비고가 정의되지 않았습니다."); + } + $this->addViewDatas('entity', $this->service->modify($uid, $history)); 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/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index 9de67b9..3edd9b7 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -2,6 +2,7 @@ namespace App\Controllers\Admin\Customer; +use App\Entities\Customer\ServiceEntity; use App\Entities\Equipment\ServerEntity; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; @@ -45,6 +46,10 @@ class ServiceController extends CustomerController public function history(int $uid): RedirectResponse|string { try { + $history = $this->request->getPost('history'); + if (!$history) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 비고가 정의되지 않았습니다."); + } $this->addViewDatas('entity', parent::modify_process($uid, $this->request->getPost())); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 비고설정이 완료되었습니다."); } catch (\Throwable $e) { @@ -54,6 +59,10 @@ class ServiceController extends CustomerController public function billingat(int $uid): RedirectResponse|string { try { + $billing_at = $this->request->getPost('billing_at'); + if (!$billing_at) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 결제일이 정의되지 않았습니다."); + } $this->addViewDatas('entity', parent::modify_process($uid, $this->request->getPost())); return $this->action_redirect_process('info', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 결제일 변경이 완료되었습니다."); } catch (\Throwable $e) { @@ -65,9 +74,8 @@ class ServiceController extends CustomerController public function alternative_create_form(int $uid): string|RedirectResponse { try { - $action = __FUNCTION__; - $this->action_init_process($action, $this->request->getVar()); - return $this->action_render_process($action, $this->getViewDatas(), $this->request->getVar('ActionTemplate') ?? 'server'); + $this->action_init_process(__FUNCTION__, $this->request->getVar()); + 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()); } @@ -75,14 +83,15 @@ class ServiceController extends CustomerController public function alternative_create(int $uid): string|RedirectResponse { try { - $action = __FUNCTION__; - $fields = ['serverinfo_uid']; - $this->service->getFormService()->setFormFields($fields); - $this->service->getFormService()->setFormRules($action, $fields); + //추가할 대체서버 정의 + $serverinfo_uid = $this->request->getGet('serverinfo_uid'); + if (!$serverinfo_uid) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 변경할 대체서버가 정의되지 않았습니다."); + } //서비스정보 가져오기 $entity = $this->service->getEntity($uid); //대체서버 추가 - service('equipment_serverservice')->attachToService($entity, $this->request->getPost('serverinfo_uid')); + service('equipment_serverservice')->attachToService($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()); @@ -93,20 +102,22 @@ class ServiceController extends CustomerController public function alternative_modify(int $uid): string|RedirectResponse { try { - $action = __FUNCTION__; - $fields = ['serverinfo_uid']; - $this->service->getFormService()->setFormFields($fields); - $this->service->getFormService()->setFormRules($action, $fields); - //변경값 정의 - $formDatas = $this->request->getGet(); + //변경할 대체서버 정의 + $serverinfo_uid = $this->request->getGet('serverinfo_uid'); + if (!$serverinfo_uid) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 변경할 대체서버가 정의되지 않았습니다."); + } //서버 타이틀을 서비스 타이틀로 변경하기 위함 - $serverEntity = service('equipment_serverservice')->getEntity($formDatas['serverinfo_uid']); + $serverEntity = service('equipment_serverservice')->getEntity($serverinfo_uid); if (!$serverEntity instanceof ServerEntity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서버정보을 찾을수 없습니다."); } + //서버번호 와 서비스 제목 설정용 + $formDatas = []; + $formDatas['serverinfo_uid'] = $serverinfo_uid; $formDatas['title'] = $serverEntity->getCustomTitle(); //대체서버를 메인서버로 설정 - $this->service->modify($uid, $this->service->createDTO($formDatas)); + $this->service->modify($uid, $formDatas); 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()); @@ -115,14 +126,18 @@ class ServiceController extends CustomerController public function alternative_delete(int $uid): string|RedirectResponse { try { - $action = __FUNCTION__; - $fields = ['serverinfo_uid']; - $this->service->getFormService()->setFormFields($fields); - $this->service->getFormService()->setFormRules($action, $fields); + //해지할 대체서버 정의 + $serverinfo_uid = $this->request->getGet('serverinfo_uid'); + if (!$serverinfo_uid) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해지할 대체서버가 정의되지 않았습니다."); + } //서비스정보 가져오기 $entity = $this->service->getEntity($uid); + if (!$entity instanceof ServiceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 해당하는 서비스정보을 찾을수 없습니다."); + } //대체서버 해지 - service('equipment_serverservice')->detachFromService($entity, $this->request->getGet('serverinfo_uid')); + service('equipment_serverservice')->detachFromService($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()); diff --git a/app/Controllers/Admin/PaymentController.php b/app/Controllers/Admin/PaymentController.php index b23d069..c54a57b 100644 --- a/app/Controllers/Admin/PaymentController.php +++ b/app/Controllers/Admin/PaymentController.php @@ -133,7 +133,7 @@ class PaymentController extends AdminController final public function paid($uid): string|RedirectResponse { try { - $entity = $this->service->modify($uid, $this->service->createDTO(['status' => STATUS['PAID']])); + $entity = $this->service->modify($uid, ['status' => STATUS['PAID']]); return $this->action_redirect_process('info', "{$this->getTitle()}에서 {$entity->getTitle()} 결체처리가 완료되었습니다."); } catch (\Throwable $e) { return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 결제 오류:" . $e->getMessage()); diff --git a/app/Controllers/CLI/Invoice.php b/app/Controllers/CLI/Invoice.php index 21f9456..fb4e38b 100644 --- a/app/Controllers/CLI/Invoice.php +++ b/app/Controllers/CLI/Invoice.php @@ -27,7 +27,7 @@ class Invoice extends BaseController foreach ($this->service->getEntities(['billing_at' => date("Y-m-d"), 'status' => STATUS['AVAILABLE']]) as $entity) { try { service('paymentservice')->createByService($entity); - $entity = $this->service->updateBillingAt($entity, $this->service->getNextMonthDate($entity)); + $entity = $this->service->modify($entity, ['billing_at' => $this->service->getNextMonthDate($entity)]); log_message('info', "{$entity->getServerTitle()} 청구서 발행 완료: 다음달 청구일:{$entity->getBillingAt()} 입니다."); } catch (\Throwable $e) { $error++; diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 19ba749..82595a3 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -16,7 +16,6 @@ use RuntimeException; abstract class CommonController extends AbstractCRUDController { // --- 일괄 작업 (Batch Job) --- - protected function batchjob_pre_process(array $postDatas): array { // 1. postDatas에서 선택된 uids 정보 추출 @@ -31,8 +30,7 @@ abstract class CommonController extends AbstractCRUDController throw new RuntimeException("{$this->getTitle()}에서 일괄작업에 변경할 조건항목을 선택하셔야합니다."); } // 3. 데이터가 있는 필드 추출 - $selectedFields = array_keys($formDatas); - return array($uids, $selectedFields, $formDatas); + return array($uids, $formDatas); } protected function batchjob_process(array $uids, array $formDatas): array @@ -54,11 +52,7 @@ abstract class CommonController extends AbstractCRUDController try { $action = __FUNCTION__; // 사전작업 및 데이터 추출 초기화 - list($uids, $selectedFields, $formDatas) = $this->batchjob_pre_process($this->request->getPost()); - $this->service->getFormService()->setFormFields($selectedFields); - $this->service->getFormService()->setFormRules($action, $selectedFields); - $this->service->getFormService()->setFormFilters($selectedFields); - $this->service->getFormService()->setFormOptions($action, $selectedFields); + list($uids, $formDatas) = $this->batchjob_pre_process($this->request->getPost()); $entities = $this->batchjob_process($uids, $formDatas); return $this->batchjob_result_process($uids, $entities); } catch (\Throwable $e) { diff --git a/app/Services/BoardService.php b/app/Services/BoardService.php index 85351f8..04c6026 100644 --- a/app/Services/BoardService.php +++ b/app/Services/BoardService.php @@ -2,11 +2,9 @@ namespace App\Services; -use RuntimeException; use App\Models\BoardModel; use App\Helpers\BoardHelper; use App\Forms\BoardForm; -use App\Entities\CommonEntity; use App\Entities\BoardEntity; use App\DTOs\BoardDTO; @@ -19,9 +17,9 @@ class BoardService extends CommonService parent::__construct($model); $this->addClassPaths('Board'); } - protected function getDTOClass(): string + public function getDTOClass(): string { - return BOARDDTO::class; + return BoardDTO::class; } public function createDTO(array $formDatas): BoardDTO { diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 59c9d5b..23e5f1d 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -4,7 +4,6 @@ namespace App\Services; use App\DTOs\CommonDTO; use App\Entities\CommonEntity; -use App\Entities\PaymentEntity; use App\Libraries\AuthContext; use App\Models\CommonModel; use CodeIgniter\Database\Exceptions\DatabaseException; @@ -22,7 +21,7 @@ abstract class CommonService protected $title = null; protected function __construct(protected CommonModel $model) {} abstract public function action_init_process(string $action, array $formDatas = []): void; - abstract protected function getDTOClass(): string; + abstract public function getDTOClass(): string; abstract public function createDTO(array $formDatas): CommonDTO; abstract public function getEntityClass(): string; abstract public function getFormService(): mixed; @@ -187,18 +186,13 @@ abstract class CommonService log_message('debug', var_export($entity->toArray(), true)); return $entity; } - final public function create(object $dto): object + final public function create(array $formDatas): object { $db = \Config\Database::connect(); try { //트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정 $db->transException(true)->transStart(); - //DTO 타입 체크 로직을 일반화 - $dtoClass = $this->getDTOClass(); - if (!$dto instanceof $dtoClass) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)"); - } - $entity = $this->create_process($dto->toArray()); + $entity = $this->create_process($formDatas); $db->transComplete(); return $entity; } catch (DatabaseException $e) { @@ -247,16 +241,11 @@ abstract class CommonService return $entity; } - final public function modify(string|int $uid, object $dto): object + final public function modify(string|int $uid, array $formDatas): object { $db = \Config\Database::connect(); try { $db->transException(true)->transStart(); - //DTO 타입 체크 로직을 일반화 - $dtoClass = $this->getDTOClass(); - if (!$dto instanceof $dtoClass) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)"); - } $entity = $this->getEntity($uid); if (!$entity) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다."); @@ -266,7 +255,7 @@ abstract class CommonService if (!$entity instanceof $entityClass) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능"); } - $entity = $this->modify_process($entity, $dto->toArray()); + $entity = $this->modify_process($entity, $formDatas); // 트랜잭션 완료 및 커밋 $db->transComplete(); return $entity; @@ -280,47 +269,22 @@ abstract class CommonService ), $e->getCode(), $e); } catch (\Throwable $e) { $db->transRollback(); // 예외 발생 시 수동으로 롤백 - throw new RuntimeException($e->getMessage(), 0, $e); + throw new RuntimeException($e->getMessage()); } } //배치 작업용 수정 protected function batchjob_process($entity, array $formDatas): object { - $fields = array_keys($formDatas); - $this->getFormService()->setFormFields($fields); - $this->getFormService()->setFormRules('modify', $fields); - // 검증 - if (!$this->getFormService()->validate($formDatas)) { - throw new ValidationException( - implode("\n", service('validation')->getErrors()) - ); - } - //관리자 정보추가용 - $formDatas['user_uid'] = $this->getAuthContext()->getUID(); - //PK 추가 - $pkField = $this->model->getPKField(); - if (!isset($formDatas[$pkField]) && !empty($entity->getPK())) { - // original에 있는 PK 값을 attributes에 명시적으로 복사합니다. - $formDatas[$pkField] = $entity->getPK(); - } - foreach ($formDatas as $key => $value) { - if ($value !== null) { - $entity->$key = $value; - } - } - $entity = $this->save_process($entity); - //입력/출력데이터 확인용 - log_message('debug', var_export($formDatas, true)); - log_message('debug', var_export($entity->toArray(), true)); + $entity = $this->modify_process($entity, $formDatas); return $entity; } final public function batchjob(array $uids, array $formDatas): array { $db = \Config\Database::connect(); try { + //트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정 $db->transException(true)->transStart(); - //일괄작업처리 $entities = []; foreach ($uids as $uid) { $entity = $this->getEntity($uid); @@ -332,29 +296,18 @@ abstract class CommonService if (!$entity instanceof $entityClass) { throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능"); } - $entities[] = $this->batchjob_process($entity, $formDatas); + $entities[] = $this->modify_process($entity, $formDatas); } - // 트랜잭션 완료 및 커밋 - $db->transComplete(); return $entities; - } catch (DatabaseException $e) { - // DatabaseException을 포착하면 자동으로 롤백 처리됨 - throw new RuntimeException(sprintf( - "\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n", - __METHOD__, - $this->model->getLastQuery(), - $e->getMessage() - ), $e->getCode(), $e); } catch (\Throwable $e) { $db->transRollback(); // 예외 발생 시 수동으로 롤백 - throw new RuntimeException($e->getMessage(), 0, $e); + throw new RuntimeException($e->getMessage()); } } //삭제용 (일반) protected function delete_process($entity): object { - //삭제 $result = $this->model->delete($entity->getPK()); log_message('debug', $this->model->getLastQuery()); if ($result === false) { @@ -395,14 +348,13 @@ abstract class CommonService ), $e->getCode(), $e); } catch (\Throwable $e) { $db->transRollback(); // 예외 발생 시 수동으로 롤백 - throw new RuntimeException($e->getMessage(), 0, $e); + throw new RuntimeException($e->getMessage()); } } //삭제용 (배치 작업) protected function batchjob_delete_process($entity): object { - // delete_process를 호출하여 로직 재사용 (CommonEntity 로드 및 유효성 검사) $entity = $this->delete_process($entity); return $entity; } @@ -439,7 +391,7 @@ abstract class CommonService ), $e->getCode(), $e); } catch (\Throwable $e) { $db->transRollback(); // 예외 발생 시 수동으로 롤백 - throw new RuntimeException($e->getMessage(), 0, $e); + throw new RuntimeException($e->getMessage()); } } diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index 443203c..7390b9d 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -19,7 +19,7 @@ class ClientService extends CustomerService parent::__construct($model); $this->addClassPaths('Client'); } - protected function getDTOClass(): string + public function getDTOClass(): string { return ClientDTO::class; } diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index e82c1fe..31a0797 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -23,7 +23,7 @@ class ServiceService extends CustomerService parent::__construct($model); $this->addClassPaths('Service'); } - protected function getDTOClass(): string + public function getDTOClass(): string { return ServiceDTO::class; } @@ -175,32 +175,23 @@ class ServiceService extends CustomerService // 최종 결과 리턴 (YYYY-MM-DD) return $date->format('Y-m-d'); } - //결제일 변경관련처리 - final public function updateBillingAt(int|ServiceEntity $uid, string $billing_at): ServiceEntity - { - $entity = is_int($uid) ? $this->getEntity($uid) : $uid; - if (!$entity instanceof ServiceEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다."); - } - //총 서비스금액 설정 - $formDatas = ['billing_at' => $billing_at]; - return parent::modify_process($entity, $formDatas); - } // 서비스금액관련처리 - final public function updateAmount(int|ServiceEntity $uid): ServiceEntity + private function updateAmount(ServiceEntity $entity): ServiceEntity { - $entity = is_int($uid) ? $this->getEntity($uid) : $uid; - if (!$entity instanceof ServiceEntity) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다."); - } //총 서비스금액 구하기 $server_amount = service('equipment_serverservice')->getCalculatedAmount($entity->getServerInfoUID()); //기본:서버금액(서버비+서버파트(월비용))+상면비+회선비-할인액 $caculatedAmount = (int)$server_amount + $entity->getRack() + $entity->getLine() - $entity->getSale(); - //총 서비스금액 설정 - $formDatas = ['amount' => $caculatedAmount]; - return parent::modify_process($entity, $formDatas); + return parent::modify_process($entity, ['amount' => $caculatedAmount]); + } + final public function updateAmountByPK(int $uid): ServiceEntity + { + $entity = $this->getEntity($uid); + if (!$entity instanceof ServiceEntity) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServiceEntity만 가능"); + } + return $this->updateAmount($entity); } //기본 기능부분 protected function getEntity_process(mixed $entity): ServiceEntity diff --git a/app/Services/Customer/Wallet/AccountService.php b/app/Services/Customer/Wallet/AccountService.php index 44279c5..f1814d9 100644 --- a/app/Services/Customer/Wallet/AccountService.php +++ b/app/Services/Customer/Wallet/AccountService.php @@ -21,7 +21,7 @@ class AccountService extends WalletService parent::__construct($model); $this->addClassPaths('Account'); } - protected function getDTOClass(): string + public function getDTOClass(): string { return AccountDTO::class; } diff --git a/app/Services/Customer/Wallet/CouponService.php b/app/Services/Customer/Wallet/CouponService.php index 5903738..8763998 100644 --- a/app/Services/Customer/Wallet/CouponService.php +++ b/app/Services/Customer/Wallet/CouponService.php @@ -20,7 +20,7 @@ class CouponService extends WalletService parent::__construct($model); $this->addClassPaths('Coupon'); } - protected function getDTOClass(): string + public function getDTOClass(): string { return CouponDTO::class; } diff --git a/app/Services/Customer/Wallet/PointService.php b/app/Services/Customer/Wallet/PointService.php index d193221..0d81f8c 100644 --- a/app/Services/Customer/Wallet/PointService.php +++ b/app/Services/Customer/Wallet/PointService.php @@ -20,7 +20,7 @@ class PointService extends WalletService parent::__construct($model); $this->addClassPaths('Point'); } - protected function getDTOClass(): string + public function getDTOClass(): string { return PointDTO::class; } diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 4cddb0d..c0dc6f4 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -21,7 +21,7 @@ class ServerPartService extends EquipmentService parent::__construct($model); $this->addClassPaths('ServerPart'); } - protected function getDTOClass(): string + public function getDTOClass(): string { return ServerPartDTO::class; } @@ -135,7 +135,7 @@ class ServerPartService extends EquipmentService if ($entity->getServiceInfoUID() !== null) { //Billing형식이 Month이면 서비스 금액설정 호출 if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { - service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); + service('customer_serviceservice')->updateAmountByPK($entity->getServiceInfoUID()); } //Billing형식이 Onetime이면 일회성결제 추가 if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) { @@ -159,7 +159,7 @@ class ServerPartService extends EquipmentService if ($entity->getServiceInfoUID() !== null) { //월비용 서버파트 인경우 서비스 금액 재설정 if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { - service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); + service('customer_serviceservice')->updateAmountByPK($entity->getServiceInfoUID()); } //Billing형식이 Onetime이면 일회성결제 수정 (필요없는듯 하여 주석처리) // if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) { @@ -176,7 +176,7 @@ class ServerPartService extends EquipmentService if ($entity->getServiceInfoUID() !== null) { //월비용 서버파트 인경우 서비스 금액 재설정 if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) { - service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); + service('customer_serviceservice')->updateAmountByPK($entity->getServiceInfoUID()); } //Billing형식이 Onetime이면 일회성결제 수정 (필요없는듯 하여 주석처리) // if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) { diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index c11e666..2624de1 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -19,7 +19,7 @@ class ServerService extends EquipmentService parent::__construct($model); $this->addClassPaths('Server'); } - protected function getDTOClass(): string + public function getDTOClass(): string { return ServerDTO::class; } @@ -249,7 +249,7 @@ class ServerService extends EquipmentService service('equipment_chassisservice')->attachToServer($entity); } if ($entity->getServiceInfoUID() !== null) { //서비스가 정의 되어 있으면 - service('customer_serviceservice')->updateAmount($entity->getServiceInfoUID()); + service('customer_serviceservice')->updateAmountByPK($entity->getServiceInfoUID()); } return $entity; } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index c169d7c..4db21c3 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -24,7 +24,7 @@ class PaymentService extends CommonService parent::__construct($model); $this->addClassPaths('Payment'); } - protected function getDTOClass(): string + public function getDTOClass(): string { return PaymentDTO::class; } @@ -213,7 +213,7 @@ class PaymentService extends CommonService } //선결제인경우 서비스정보에 결제일 변경용 if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) { - service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt()); + service('customer_serviceservice')->modify($entity->getServiceInfoUID(), ['billing_at' => $entity->getBillingAt()]); } return $entity; } @@ -234,7 +234,7 @@ class PaymentService extends CommonService } //선결제인경우 서비스정보에 결제일 변경용 if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) { - service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt()); + service('customer_serviceservice')->modify($entity->getServiceInfoUID(), ['billing_at' => $entity->getBillingAt()]); } return $entity; } @@ -245,17 +245,7 @@ class PaymentService extends CommonService } return parent::delete_process($entity); } - //지불 관련 - //일괄 지불용 - protected function batchjob_process($entity, array $formDatas): object - { - // modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함) - $entity = parent::batchjob_process($entity, $formDatas); - if ($entity->getStatus() === STATUS['PAID']) { - $this->setWallet($entity); - } - return $entity; - } + //청구서 관련 public function getInvoices(ClientEntity $clientEntity, ServiceEntity $serviceEntity, PaymentEntity $entity, array $rows): array {