From 1d33896294c2600e199ede86c9aba2f9beea779d Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Fri, 20 Jun 2025 11:10:39 +0900 Subject: [PATCH] dbms_init...1 --- app/Controllers/CommonController.php | 11 ++++- app/Helpers/Customer/AccountHelper.php | 33 +++++++++++++++ app/Helpers/Customer/CouponHelper.php | 33 +++++++++++++++ app/Helpers/Customer/PointHelper.php | 34 +++++++++++++++ app/Services/Customer/AccountService.php | 4 +- app/Services/Customer/ClientService.php | 54 +++++++++++++++++++++--- app/Services/Customer/CouponService.php | 3 +- app/Services/Customer/PointService.php | 3 +- app/Views/admin/create_form.php | 2 +- app/Views/admin/popup/create_form.php | 2 +- app/Views/admin/popup/modify_form.php | 31 ++++++++++++++ 11 files changed, 194 insertions(+), 16 deletions(-) create mode 100644 app/Views/admin/popup/modify_form.php diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 92c5b87..466cdbf 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -225,7 +225,12 @@ abstract class CommonController extends BaseController { LogCollector::debug($message); $this->getMyLogService()->save($this->getService(), __FUNCTION__, $this->getMyAuth(), $message); - return redirect()->back()->withInput()->with('error', $message); + // echo $this->request->getMethod(); + // exit; + if ($this->request->getMethod() === 'POST') { + return redirect()->back()->withInput()->with('error', $message); + } + return redirect()->to($this->getMyAuth()->popPreviousUrl())->with('error', $message); } protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { @@ -265,6 +270,7 @@ abstract class CommonController extends BaseController { try { //각 Field 초기화 + // $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); $this->initAction(__FUNCTION__); //FieldRule정의 foreach ($this->getFormFields() as $field) { @@ -324,6 +330,7 @@ abstract class CommonController extends BaseController { try { //각 Field 초기화 + // $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); $this->initAction(__FUNCTION__); //FieldRule정의 foreach ($this->getFormFields() as $field) { @@ -670,13 +677,13 @@ abstract class CommonController extends BaseController { try { //각 Field 초기화 + $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); $this->initAction(__FUNCTION__); //FieldRule정의 foreach ($this->getIndexFields() as $field) { $this->setFieldRule($field, $this->getFormFieldRule($this->getAction(), $field)); } // 현재 URL을 스택에 저장 - $this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : "")); helper(['form']); $this->entities = $this->index_process(); return $this->getResultSuccess(); diff --git a/app/Helpers/Customer/AccountHelper.php b/app/Helpers/Customer/AccountHelper.php index aa5d47f..0408764 100644 --- a/app/Helpers/Customer/AccountHelper.php +++ b/app/Helpers/Customer/AccountHelper.php @@ -13,4 +13,37 @@ class AccountHelper extends CustomerHelper parent::__construct($request); $this->setTitleField(AccountModel::TITLE); } + public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null + { + switch ($field) { + case 'amount': + $value = number_format($value) . "원"; + break; + default: + if (in_array($field, $viewDatas['control']['filter_fields'])) { + $value = $viewDatas['control']['filter_optons'][$field][$value]->getTitle(); + } + break; + } + if (is_array($value)) { + echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다"; + exit; + } + return $value; + } + public function getListButton(string $action, array $viewDatas, array $extras = []): string + { + switch ($action) { + case 'modify': + $action = $viewDatas['entity']->getPK(); + break; + case 'delete': + $action = ""; + break; + default: + $action = parent::getListButton($action, $viewDatas, $extras); + break; + } + return $action; + } } diff --git a/app/Helpers/Customer/CouponHelper.php b/app/Helpers/Customer/CouponHelper.php index ec87cd0..8b47dea 100644 --- a/app/Helpers/Customer/CouponHelper.php +++ b/app/Helpers/Customer/CouponHelper.php @@ -13,4 +13,37 @@ class CouponHelper extends CustomerHelper parent::__construct($request); $this->setTitleField(CouponModel::TITLE); } + public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null + { + switch ($field) { + case 'amount': + $value = number_format($value) . "개"; + break; + default: + if (in_array($field, $viewDatas['control']['filter_fields'])) { + $value = $viewDatas['control']['filter_optons'][$field][$value]->getTitle(); + } + break; + } + if (is_array($value)) { + echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다"; + exit; + } + return $value; + } + public function getListButton(string $action, array $viewDatas, array $extras = []): string + { + switch ($action) { + case 'modify': + $action = $viewDatas['entity']->getPK(); + break; + case 'delete': + $action = ""; + break; + default: + $action = parent::getListButton($action, $viewDatas, $extras); + break; + } + return $action; + } } diff --git a/app/Helpers/Customer/PointHelper.php b/app/Helpers/Customer/PointHelper.php index e297f66..8e735bc 100644 --- a/app/Helpers/Customer/PointHelper.php +++ b/app/Helpers/Customer/PointHelper.php @@ -13,4 +13,38 @@ class PointHelper extends CustomerHelper parent::__construct($request); $this->setTitleField(field: PointModel::TITLE); } + + public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null + { + switch ($field) { + case 'amount': + $value = number_format($value) . "원"; + break; + default: + if (in_array($field, $viewDatas['control']['filter_fields'])) { + $value = $viewDatas['control']['filter_optons'][$field][$value]->getTitle(); + } + break; + } + if (is_array($value)) { + echo __METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다"; + exit; + } + return $value; + } + public function getListButton(string $action, array $viewDatas, array $extras = []): string + { + switch ($action) { + case 'modify': + $action = $viewDatas['entity']->getPK(); + break; + case 'delete': + $action = ""; + break; + default: + $action = parent::getListButton($action, $viewDatas, $extras); + break; + } + return $action; + } } diff --git a/app/Services/Customer/AccountService.php b/app/Services/Customer/AccountService.php index e49b94f..159353e 100644 --- a/app/Services/Customer/AccountService.php +++ b/app/Services/Customer/AccountService.php @@ -42,7 +42,7 @@ class AccountService extends CustomerService //기본 기능부분 //고객예치금처리 - private function setBalance(array $formDatas): ClientEntity + private function setBalance(array $formDatas): void { //account_balance 체크 $entity = $this->getClientService()->getEntity($formDatas['clientinfo_uid']); @@ -50,12 +50,12 @@ class AccountService extends CustomerService throw new \Exception("{$formDatas['clientinfo_uid']}에 대한 고객정보를 찾을수 없습니다."); } $amount = intval($formDatas['amount']); + // dd($formDatas); if ($formDatas['status'] === DEFAULTS['STATUS']) { //입금, 쿠폰추가 $entity = $this->getClientService()->deposit($entity, 'account_balance', $amount); } else { // 출금, 쿠폰사용 $entity = $this->getClientService()->withdrawal($entity, 'account_balance', $amount); } - return $entity; } public function create(array $formDatas, mixed $entity = null): AccountEntity { diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index cd2335a..ddb7534 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -41,18 +41,60 @@ class ClientService extends CustomerService //압금(쿠폰:추가)처리 public function deposit(ClientEntity $entity, string $field, int $amount): ClientEntity { - if ($amount < 0) { - throw new \Exception("입금액 , 쿠폰 추가갯수가 0보다 작습니다."); + switch ($field) { + case 'account_balance': + if ($amount < 0) { + throw new \Exception("입금액이 0보다 작습니다."); + } + $amount += $entity->getAccountBalance(); + break; + case 'coupon_balance': + if ($amount < 0) { + throw new \Exception("쿠폰 추가갯수가 0보다 작습니다."); + } + $amount += $entity->getCouponBalance(); + break; + case 'point_balance': + if ($amount < 0) { + throw new \Exception("포인트 입금액 0보다 작습니다."); + } + $amount += $entity->getPointBalance(); + break; + default: + throw new \Exception("{$field}는 알수없는 Field가 정의되었습니다."); } - return $this->getClientService()->modify($entity, [$field => $entity->getAccountBalance() + $amount]); + $formDatas = [$field => $amount]; + // dd($formDatas); + return $this->getClientService()->modify($entity, $formDatas); } //출금(쿠폰:사용)처리 public function withdrawal(ClientEntity $entity, string $field, int $amount): ClientEntity { - if ($entity->getAccountBalance() < $amount) { - throw new \Exception("잔여액,잔여 쿠폰갯수:{$entity->getAccountBalance()} < 출금액 , 사용쿠폰갯수: {$amount}보다 작습니다."); + switch ($field) { + case 'account_balance': + if ($entity->getAccountBalance() < $amount) { + throw new \Exception("예치금[{$entity->getAccountBalance()}]이 출금액:{$amount}보다 부족합니다."); + } + $amount = $entity->getAccountBalance() - $amount; + break; + case 'coupon_balance': + if ($entity->getCouponBalance() < $amount) { + throw new \Exception("쿠폰[{$entity->getCouponBalance()}]이 사용수:{$amount}보다 부족합니다."); + } + $amount = $entity->getCouponBalance() - $amount; + break; + case 'point_balance': + if ($entity->getPointBalance() < $amount) { + throw new \Exception("포인트금액[{$entity->getPointBalance()}]이 출금액:{$amount}보다 부족합니다."); + } + $amount = $entity->getPointBalance() - $amount; + break; + default: + throw new \Exception("{$field}는 알수없는 Field가 정의되었습니다."); + // break; } - return $this->getClientService()->modify($entity, [$field => $entity->getAccountBalance() - $amount]); + $formDatas = [$field => $amount]; + return $this->getClientService()->modify($entity, $formDatas); } public function create(array $formDatas, mixed $entity = new ClientEntity()): ClientEntity diff --git a/app/Services/Customer/CouponService.php b/app/Services/Customer/CouponService.php index a21af02..60e486e 100644 --- a/app/Services/Customer/CouponService.php +++ b/app/Services/Customer/CouponService.php @@ -41,7 +41,7 @@ class CouponService extends CustomerService //기본 기능부분 //고객예치금처리 - private function setBalance(array $formDatas): ClientEntity + private function setBalance(array $formDatas): void { //coupon_balance 체크 $entity = $this->getClientService()->getEntity($formDatas['clientinfo_uid']); @@ -54,7 +54,6 @@ class CouponService extends CustomerService } else { // 출금, 쿠폰사용 $entity = $this->getClientService()->withdrawal($entity, 'coupon_balance', $amount); } - return $entity; } public function create(array $formDatas, mixed $entity = null): CouponEntity { diff --git a/app/Services/Customer/PointService.php b/app/Services/Customer/PointService.php index e0e6678..bb5912c 100644 --- a/app/Services/Customer/PointService.php +++ b/app/Services/Customer/PointService.php @@ -40,7 +40,7 @@ class PointService extends CustomerService } //기본 기능부분 - private function setBalance(array $formDatas): ClientEntity + private function setBalance(array $formDatas): void { //point_balance 체크 $entity = $this->getClientService()->getEntity($formDatas['clientinfo_uid']); @@ -53,7 +53,6 @@ class PointService extends CustomerService } else { // 출금, 쿠폰사용 $entity = $this->getClientService()->withdrawal($entity, 'point_balance', $amount); } - return $entity; } public function create(array $formDatas, mixed $entity = null): PointEntity { diff --git a/app/Views/admin/create_form.php b/app/Views/admin/create_form.php index a2c9e3a..3eb92d1 100644 --- a/app/Views/admin/create_form.php +++ b/app/Views/admin/create_form.php @@ -18,7 +18,7 @@ getFieldLabel($field, $viewDatas) ?> - getFieldForm($field, old($field) ?? isset($viewDatas[$field]) ? $viewDatas[$field] : null, $viewDatas) ?> + getFieldForm($field, old($field) ?? array_key_exists($field, $viewDatas) ? $viewDatas[$field] : null, $viewDatas) ?> diff --git a/app/Views/admin/popup/create_form.php b/app/Views/admin/popup/create_form.php index a2c9e3a..3eb92d1 100644 --- a/app/Views/admin/popup/create_form.php +++ b/app/Views/admin/popup/create_form.php @@ -18,7 +18,7 @@ getFieldLabel($field, $viewDatas) ?> - getFieldForm($field, old($field) ?? isset($viewDatas[$field]) ? $viewDatas[$field] : null, $viewDatas) ?> + getFieldForm($field, old($field) ?? array_key_exists($field, $viewDatas) ? $viewDatas[$field] : null, $viewDatas) ?> diff --git a/app/Views/admin/popup/modify_form.php b/app/Views/admin/popup/modify_form.php new file mode 100644 index 0000000..1cda426 --- /dev/null +++ b/app/Views/admin/popup/modify_form.php @@ -0,0 +1,31 @@ +extend(LAYOUTS[$viewDatas['layout']]['path']) ?> +section('content') ?> +alert($error) ?> +
+ + + + + + + + + + 'action_form', ...$viewDatas['forms']['attributes']], $viewDatas['forms']['hiddens']) ?> +
+ + + + + + + +
getFieldLabel($field, $viewDatas) ?> + getFieldForm($field, old($field) ?? $viewDatas['entity']->$field, $viewDatas) ?> +
+
+
"btn btn-outline btn-primary"]) ?>
+ +
+
+endSection() ?> \ No newline at end of file