From aabbe2f5e6417010c9cf2915dbe4bda22a226239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Tue, 9 Dec 2025 14:30:07 +0900 Subject: [PATCH] dbmsv4 init...2 --- app/Controllers/CommonController.php | 1 - app/Services/CommonService.php | 37 ++++++++++++++++++++----- app/Services/Customer/ClientService.php | 4 +-- app/Services/PaymentService.php | 2 +- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 825a165..0acfa91 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -38,7 +38,6 @@ abstract class CommonController extends AbstractCRUDController protected function batchjob_process(array $uids, array $formDatas): array { - // Service 로직 호출 (오버라이드 포인트) return $this->service->batchjob($uids, $formDatas); } diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index ee09259..f53517f 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -62,7 +62,7 @@ abstract class CommonService // 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사 $entityClass = $this->getEntityClass(); if (!$entity instanceof $entityClass) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능:\n" . var_export($entity, true)); + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 {$entityClass}만 가능:" . get_class($entity)); } return $this->getEntity_process($entity); } catch (DatabaseException $e) { @@ -169,9 +169,9 @@ abstract class CommonService //생성용 protected function create_process(array $formDatas): object { - $fields = array_keys($formDatas); - $this->getFormService()->setFormFields($fields); - $this->getFormService()->setFormRules('create', $fields); + // $fields = array_keys($formDatas); + // $this->getFormService()->setFormFields($fields); + // $this->getFormService()->setFormRules('create', $fields); //FormData 검증 if (!$this->getFormService()->validate($formDatas)) { throw new ValidationException(implode("\n", service('validation')->getErrors())); @@ -238,7 +238,6 @@ abstract class CommonService // original에 있는 PK 값을 attributes에 명시적으로 복사합니다. $formDatas[$pkField] = $entity->getPK(); } - // dd($formDatas); foreach ($formDatas as $key => $value) { if ($value !== null) { $entity->$key = $value; @@ -291,8 +290,32 @@ abstract class CommonService //배치 작업용 수정 protected function batchjob_process($entity, array $formDatas): object { - // modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함) - $entity = $this->modify_process($entity, $formDatas); + $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)); return $entity; } final public function batchjob(array $uids, array $formDatas): array diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index ad29460..e966d92 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -146,8 +146,8 @@ class ClientService extends CustomerService if ($status === STATUS['WITHDRAWAL']) { if ($balance < $value) { throw new RuntimeException(sprintf( - "%s 에서 오류발생: %s 고객의 %s[%s]이/가 사용한 %s 금액/수[%s] 보다 작습니다.", - __METHOD__, + "%s 에서 오류발생: %s 고객의 %s[ %s ]이/가 사용한 %s 금액/수[ %s ]이/가 부족합니다.", + static::class . '->' . __FUNCTION__, $entity->getTitle(), $title, number_format($balance), diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 1f28b47..29eda9c 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -213,7 +213,7 @@ class PaymentService extends CommonService protected function batchjob_process($entity, array $formDatas): object { // modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함) - $entity = $this->modify_process($entity, $formDatas); + $entity = parent::batchjob_process($entity, $formDatas); //지불방식에 따른 고객 예치금,쿠폰,포인트 처리 service('customer_clientservice')->updateWalletByPayment($entity); return $entity;