From be378d99ef50eee8f57a6e6f0d72e59b2d8de105 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 16:19:26 +0900 Subject: [PATCH] dbmsv4 init...3 --- app/Forms/CommonForm.php | 14 ++++----- app/Services/CommonService.php | 22 +++++++------- .../Customer/Wallet/AccountService.php | 2 +- .../Customer/Wallet/CouponService.php | 26 ++++++++++------- app/Services/Customer/Wallet/PointService.php | 29 +++++++++++-------- .../Customer/Wallet/WalletService.php | 5 ++-- 6 files changed, 53 insertions(+), 45 deletions(-) diff --git a/app/Forms/CommonForm.php b/app/Forms/CommonForm.php index 9080386..cad7fe9 100644 --- a/app/Forms/CommonForm.php +++ b/app/Forms/CommonForm.php @@ -123,21 +123,19 @@ abstract class CommonForm } $dynamicRules = []; $dynamicLabels = []; // 레이블 배열 추가 - if (!count($this->getFormRules())) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 지정된 Form RULE이 없습니다."); - } foreach ($this->getFormRules() as $field => $rule) { list($field, $rule) = $this->getValidationRule($field, $rule); $dynamicRules[$field] = $rule; // 규칙만 저장 $dynamicLabels[$field] = $this->getFormFields()[$field]; } - log_message('debug', 'Validate Fields: ' . var_export($this->getFormFields(), true)); - log_message('debug', 'Validate Rules: ' . var_export($dynamicRules, true)); - log_message('debug', 'Validate Data: ' . var_export($formDatas, true)); + if (!count($dynamicRules)) { + log_message('debug', 'Validate Rules: ' . var_export($this->getFormRules(), true)); + log_message('debug', 'Validate Dynamic Rules: ' . var_export($dynamicRules, true)); + log_message('debug', 'Validate Data: ' . var_export($formDatas, true)); + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 지정된 Form RULE이 없습니다."); + } // setRules의 세 번째 인자로 레이블 전달 $this->_validation->setRules($dynamicRules, [], $dynamicLabels); - - // run()에는 데이터만 전달 (setRules에서 이미 설정됨) $result = $this->_validation->run($formDatas); if ($result === false) { $message = static::class . '->' . __FUNCTION__ . "에서 데이터 검증 오류발생: " . var_export($this->_validation->getErrors(), true); diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 0cd0798..b1d37d9 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -190,8 +190,8 @@ abstract class CommonService } $entity = $this->save_process($entity); //입력/출력데이터 확인용 - log_message('debug', var_export($formDatas, true)); - log_message('debug', var_export($entity->toArray(), true)); + // log_message('debug', var_export($formDatas, true)); + // log_message('debug', var_export($entity->toArray(), true)); return $entity; } final public function create(array $formDatas): object @@ -225,13 +225,13 @@ abstract class CommonService $fields = array_keys($formDatas); $this->getFormService()->setFormFields($fields); $this->getFormService()->setFormRules('modify', $fields); - if (static::class === PaymentService::class) { - var_dump($this->getFormService()->getFormRules()); - echo "
"; - var_dump($formDatas); - dd($entity->toArray()); - echo "
"; - } + // if (static::class === PaymentService::class) { + // var_dump($this->getFormService()->getFormRules()); + // echo "
"; + // var_dump($formDatas); + // dd($entity->toArray()); + // echo "
"; + // } // 데이터 검증 if (!$this->getFormService()->validate($formDatas)) { throw new ValidationException( @@ -251,8 +251,8 @@ abstract class CommonService } $entity = $this->save_process($entity); //입력/출력데이터 확인용 - log_message('debug', var_export($formDatas, true)); - log_message('debug', var_export($entity->toArray(), true)); + // log_message('debug', var_export($formDatas, true)); + // log_message('debug', var_export($entity->toArray(), true)); return $entity; } diff --git a/app/Services/Customer/Wallet/AccountService.php b/app/Services/Customer/Wallet/AccountService.php index 2bd9ecb..7fc3dff 100644 --- a/app/Services/Customer/Wallet/AccountService.php +++ b/app/Services/Customer/Wallet/AccountService.php @@ -170,7 +170,7 @@ class AccountService extends WalletService $formDatas['alias'] = array_key_exists('alias', $formDatas) ? $formDatas['alias'] : $clientEntity->getTitle(); $formDatas['balance'] = $clientEntity->getAccountBalance() - $formDatas['amount']; if ($formDatas['balance'] < 0) { - throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔액이 0보다 값이 정의 되었습니다."); + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔액({$formDatas['balance']})이 0보다 작은 값이 정의되었습니다."); } //고객 잔액 갱신 service('customer_clientservice')->modify_process($clientEntity, [self::CLIENTINFO_BALANCE_FIELD => $formDatas['balance']]); diff --git a/app/Services/Customer/Wallet/CouponService.php b/app/Services/Customer/Wallet/CouponService.php index b386739..33fbaec 100644 --- a/app/Services/Customer/Wallet/CouponService.php +++ b/app/Services/Customer/Wallet/CouponService.php @@ -5,7 +5,6 @@ namespace App\Services\Customer\Wallet; use App\DTOs\Customer\Wallet\CouponDTO; use App\Entities\Customer\ClientEntity; use App\Entities\Customer\Wallet\CouponEntity; -use App\Entities\PaymentEntity; use App\Forms\Customer\Wallet\CouponForm; use App\Helpers\Customer\Wallet\CouponHelper; use App\Models\Customer\Wallet\CouponModel; @@ -139,22 +138,27 @@ class CouponService extends WalletService return parent::deposit_process($clientEntity, $formDatas); } //결제 관련 쿠폰 사용 처리 - protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array + protected function withdrawal_process(ClientEntity $clientEntity, array $formDatas): array { - $amount = $paymentEntity->getAmount(); - $balance = $clientEntity->getCouponBalance(); - if ($balance < $amount) { + if (!array_key_exists('amount', $formDatas)) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 출금액이 정의되지 않았습니다."); + } + if ($clientEntity->getCouponBalance() < $formDatas['amount']) { throw new RuntimeException(sprintf( - "%s 에서 오류발생: 사용쿠폰 수량(%s) , %s 고객의 잔여쿠폰 수량(%s)이 부족합니다.", + "%s 에서 오류발생: 사용쿠폰 수량(%s) , %s 잔여쿠폰 수량(%s)이 부족합니다.", static::class . '->' . __FUNCTION__, - number_format($amount), + number_format($formDatas['amount']), $clientEntity->getTitle(), - number_format($balance) + number_format($clientEntity->getCouponBalance()) )); } //최종처리 - $formDatas['cnt'] = $amount; - $formDatas['balance'] = $balance - $amount; - return $formDatas; + $formDatas['balance'] = $clientEntity->getCouponBalance() - $formDatas['amount']; + if ($formDatas['balance'] < 0) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔여쿠폰수량({$formDatas['balance']})이 0보다 작은 값이 정의되었습니다."); + } + //고객 잔여쿠폰 갱신 + service('customer_clientservice')->modify_process($clientEntity, [self::CLIENTINFO_BALANCE_FIELD => $formDatas['balance']]); + return parent::withdrawal_process($clientEntity, $formDatas); } } diff --git a/app/Services/Customer/Wallet/PointService.php b/app/Services/Customer/Wallet/PointService.php index a01da2c..b316434 100644 --- a/app/Services/Customer/Wallet/PointService.php +++ b/app/Services/Customer/Wallet/PointService.php @@ -5,7 +5,6 @@ namespace App\Services\Customer\Wallet; use App\DTOs\Customer\Wallet\PointDTO; use App\Entities\Customer\ClientEntity; use App\Entities\Customer\Wallet\PointEntity; -use App\Entities\PaymentEntity; use App\Forms\Customer\Wallet\PointForm; use App\Helpers\Customer\Wallet\PointHelper; use App\Models\Customer\Wallet\PointModel; @@ -13,6 +12,7 @@ use RuntimeException; class PointService extends WalletService { + const CLIENTINFO_BALANCE_FIELD = 'point_balance'; private $_form = null; private $_helper = null; public function __construct(PointModel $model) @@ -122,23 +122,28 @@ class PointService extends WalletService //FormFilter 조건절 처리 //검색어조건절처리 - //결제 관련 출금 처리 - protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array + //결제 관련 포인트 사용 처리 + protected function withdrawal_process(ClientEntity $clientEntity, array $formDatas): array { - $amount = $paymentEntity->getAmount(); - $balance = $clientEntity->getPointBalance(); - if ($balance < $amount) { + if (!array_key_exists('amount', $formDatas)) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 사용포인트가 정의되지 않았습니다."); + } + if ($clientEntity->getPointBalance() < $formDatas['amount']) { throw new RuntimeException(sprintf( - "%s 에서 오류발생: 사용포인트(%s) , %s 고객의 포인트(%s)가 부족합니다.", + "%s 에서 오류발생: 사용포인트(%s) , %s 잔여포인트(%s)가 부족합니다.", static::class . '->' . __FUNCTION__, - number_format($amount), + number_format($formDatas['amount']), $clientEntity->getTitle(), - number_format($balance) + number_format($clientEntity->getPointBalance()) )); } //최종처리 - $formDatas['amount'] = $amount; - $formDatas['balance'] = $balance - $amount; - return $formDatas; + $formDatas['balance'] = $clientEntity->getPointBalance() - $formDatas['amount']; + if ($formDatas['balance'] < 0) { + throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔여포인트({$formDatas['balance']})가 0보다 작은 값이 정의되었습니다."); + } + //고객 잔여포인트 갱신 + service('customer_clientservice')->modify_process($clientEntity, [self::CLIENTINFO_BALANCE_FIELD => $formDatas['balance']]); + return parent::withdrawal_process($clientEntity, $formDatas); } } diff --git a/app/Services/Customer/Wallet/WalletService.php b/app/Services/Customer/Wallet/WalletService.php index 56d2dec..759c120 100644 --- a/app/Services/Customer/Wallet/WalletService.php +++ b/app/Services/Customer/Wallet/WalletService.php @@ -58,7 +58,7 @@ abstract class WalletService extends CustomerService $formDatas['issue_at'] = array_key_exists('issue_at', $formDatas) ? $formDatas['issue_at'] : date('Y-m-d'); return $formDatas; } - //결제관련 출금 처리 + //결제관련 출금 처리(결제를 통해서만 호출되므로 action_init_process로 fields,rules 초기화 필요) final public function withdrawalByPayment(PaymentEntity $paymentEntity): void { //고객 정보 @@ -72,7 +72,8 @@ abstract class WalletService extends CustomerService 'amount' => $paymentEntity->getAmount(), 'status' => STATUS['WITHDRAWAL'], ]; - $this->withdrawal_process($clientEntity, $formDatas); + //초기화 + $this->action_init_process('create'); $this->create_process($formDatas); } }