From ead109480b201b68d305ff31e9c825256d214d6e Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Mon, 13 Oct 2025 10:41:05 +0900 Subject: [PATCH] dbmsv3 init...1 --- app/Helpers/CommonHelper.php | 1 + app/Interfaces/Customer/CustomerInterface.php | 2 +- app/Language/en/Payment.php | 5 +- .../DBMigration/Process/SwitchCodeProcess.php | 2 +- app/Services/Customer/AccountService.php | 3 + app/Services/Customer/ClientService.php | 8 +- app/Services/PaymentService.php | 37 ++++++++- app/Views/admin/server/index.php | 2 +- public/js/admin/form.js | 76 ++++++++++--------- 9 files changed, 89 insertions(+), 47 deletions(-) diff --git a/app/Helpers/CommonHelper.php b/app/Helpers/CommonHelper.php index 0cffd79..8c8852f 100644 --- a/app/Helpers/CommonHelper.php +++ b/app/Helpers/CommonHelper.php @@ -291,6 +291,7 @@ class CommonHelper case 'end_at': case 'updated_at': case 'created_at': + case 'deleted_at': $extras['class'] = array_key_exists('class', $extras) ? $extras['class'] . ' calender' : 'calender'; $form = form_input($field, $value ?? "", $extras); break; diff --git a/app/Interfaces/Customer/CustomerInterface.php b/app/Interfaces/Customer/CustomerInterface.php index 3e017cf..10c68e6 100644 --- a/app/Interfaces/Customer/CustomerInterface.php +++ b/app/Interfaces/Customer/CustomerInterface.php @@ -2,4 +2,4 @@ namespace App\Interfaces\Customer; -interface CustomerInterFace {} +interface CustomerInterface {} diff --git a/app/Language/en/Payment.php b/app/Language/en/Payment.php index a50d386..26e7345 100644 --- a/app/Language/en/Payment.php +++ b/app/Language/en/Payment.php @@ -22,8 +22,9 @@ return [ PAYMENT['BILLING']['ONETIME'] => "일회성", ], "PAY" => [ - "account" => "예치금", - "coupon" => "쿠폰", + PAYMENT['PAY']['ACCOUNT'] => "예치금", + PAYMENT['PAY']['COUPON'] => "쿠폰", + PAYMENT['PAY']['POINT'] => "포인트", ], "STATUS" => [ STATUS['UNPAID'] => "미지급", diff --git a/app/Libraries/DBMigration/Process/SwitchCodeProcess.php b/app/Libraries/DBMigration/Process/SwitchCodeProcess.php index c24bbc2..80fc239 100644 --- a/app/Libraries/DBMigration/Process/SwitchCodeProcess.php +++ b/app/Libraries/DBMigration/Process/SwitchCodeProcess.php @@ -5,7 +5,7 @@ namespace App\Libraries\DBMigration\Process; use App\Entities\Part\SWITCHEntity; use CodeIgniter\Database\BaseConnection; -class SWITCHCodeProcess implements MigrationProcessInterface +class SwitchCodeProcess implements MigrationProcessInterface { private $db; public function __construct(BaseConnection $db) diff --git a/app/Services/Customer/AccountService.php b/app/Services/Customer/AccountService.php index 4344f12..7ff98b8 100644 --- a/app/Services/Customer/AccountService.php +++ b/app/Services/Customer/AccountService.php @@ -56,6 +56,9 @@ class AccountService extends CustomerService if (!$entity instanceof ClientEntity) { throw new \Exception("{$formDatas['clientinfo_uid']}에 대한 고객정보를 찾을수 없습니다."); } + if (!array_key_exists('amount', $formDatas) || !array_key_exists('status', $formDatas)) { + throw new \Exception("입출금처리를 위한 금액과 상태값이 필요합니다."); + } $amount = intval($formDatas['amount']); if ($formDatas['status'] === AccountEntity::DEFAULT_STATUS) { //입금, 쿠폰추가 $entity = $this->getClientService()->deposit($entity, 'account_balance', $amount); diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index fb629f7..c5101fc 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -110,10 +110,9 @@ class ClientService extends CustomerService break; default: throw new \Exception("{$field}는 알수없는 Field가 정의되었습니다."); + // break; } - $formDatas = [$field => $amount]; - // dd($formDatas); - return parent::modify($entity, $formDatas); + return parent::modify($entity, [$field => $amount]); } //출금(쿠폰:사용)처리 final public function withdrawal(ClientEntity $entity, string $field, int $amount): ClientEntity @@ -141,8 +140,7 @@ class ClientService extends CustomerService throw new \Exception("{$field}는 알수없는 Field가 정의되었습니다."); // break; } - $formDatas = [$field => $amount]; - return parent::modify($entity, $formDatas); + return parent::modify($entity, [$field => $amount]); } //기본 기능부분 //생성 diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 29b52a1..5c18f53 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -2,6 +2,7 @@ namespace App\Services; +use App\Entities\Customer\ClientEntity; use App\Entities\Customer\ServiceEntity; use App\Entities\Equipment\ServerPartEntity; use App\Entities\PaymentEntity; @@ -10,6 +11,7 @@ use App\Interfaces\Customer\ServiceInterface; use App\Interfaces\Equipment\ServerPartInterface; use App\Models\PaymentModel; use App\Services\CommonService; +use App\Services\Customer\AccountService; use App\Services\Customer\ClientService; use App\Services\Customer\ServiceService; use App\Services\Equipment\ServerPartService; @@ -103,7 +105,6 @@ class PaymentService extends CommonService implements ServiceInterface, ServerPa } return $this->_serverPartService; } - //총 미납건수, 금액 final public function getUnPaids(string $group, array $where = []): array { @@ -219,6 +220,40 @@ class PaymentService extends CommonService implements ServiceInterface, ServerPa $formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID(); return parent::create($formDatas); } + //일괄처리작업(결제작업) + public function batchjob(mixed $entity, array $formDatas): mixed + { + //고객정보 + $userEntity = $this->getClientService()->getEntity($entity->getClientInfoUID()); + if (!$userEntity instanceof ClientEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: 고객정보[{$entity->getClientInfoUID()}]를 찾을수 없습니다."); + } + if (!array_key_exists('pay', $formDatas)) { + throw new \Exception(__METHOD__ . "에서 오류발생: 결제상태(pay) 정보가 없습니다."); + } + switch ($formDatas['pay']) { + case PAYMENT['PAY']['ACCOUNT']: + //예치금 출금처리 + if ($userEntity->getAccountBalance() < $entity->getAmount()) { + throw new \Exception(__METHOD__ . "에서 오류발생: 고객[{$userEntity->getName()}]의 예치금이 부족합니다.({$userEntity->getAccountBalance()} < {$entity->getAmount()})"); + } + break; + case PAYMENT['PAY']['COUPON']: + //쿠폰 출금처리 + if ($userEntity->getCouponBalance() < 1) { + throw new \Exception(__METHOD__ . "에서 오류발생: 고객[{$userEntity->getName()}]의 쿠폰이 부족합니다.({$userEntity->getCouponBalance()} < 1)"); + } + break; + case PAYMENT['PAY']['POINT']: + break; + default: + throw new \Exception(__METHOD__ . "에서 오류발생: 알수없는 결제방법(pay)입니다."); + // break; + } + //결제처리완료 + $entity = parent::batchjob($entity, $formDatas); + return $entity; + } //List 검색용 //OrderBy 처리 final public function setOrderBy(mixed $field = null, mixed $value = null): void diff --git a/app/Views/admin/server/index.php b/app/Views/admin/server/index.php index fcf5c40..8052b94 100644 --- a/app/Views/admin/server/index.php +++ b/app/Views/admin/server/index.php @@ -80,7 +80,7 @@ getHelper()->getFieldView('ip', $entity->ip, $viewDatas) ?> - + $entity->getPK(), 'types' => SERVERPART['SERVER_PARTTYPES'], diff --git a/public/js/admin/form.js b/public/js/admin/form.js index f0481be..444b011 100644 --- a/public/js/admin/form.js +++ b/public/js/admin/form.js @@ -1,49 +1,53 @@ -/** - * 공용 폼 초기화 함수 - * @param {HTMLElement} context - 초기화 대상 (없으면 document 전체) - */ -function initFormJS(context) { - const root = context || document; +// /public/js/admin/form.js +window.initFormModal = function (context) { + const $context = context ? $(context) : $(document); - // Datepicker - if (root.querySelector(".calender")) { - $(root).find(".calender").datepicker({ - changeYear: true, - changeMonth: true, - yearRange: "-10:+0", - dateFormat: "yy-mm-dd" - }); - } + // ✅ 캘린더 + $context.find(".calender").datepicker({ + changeYear: true, + changeMonth: true, + yearRange: "-10:+0", + dateFormat: "yy-mm-dd" + }); - // TinyMCE - if (root.querySelector(".tinymce")) { - if (document.compatMode !== "CSS1Compat") { - console.error("문서가 표준 모드가 아닙니다."); - return; + // ✅ TinyMCE + if ($context.find(".tinymce").length) { + if (typeof tinymce !== "undefined") { + tinymce.remove(); // 기존 인스턴스 제거 + tinymce.init({ + selector: ".tinymce", + license_key: "gpl", + height: 250, + plugins: "advlist autolink lists link image charmap preview anchor", + toolbar: "undo redo | bold italic underline | align | link image | code fullscreen preview", + menubar: "file edit view insert format tools table help" + }); } - tinymce.init({ - selector: 'textarea.tinymce', - license_key: 'gpl', - height: 250, - plugins: 'advlist autolink lists link image charmap preview anchor', - toolbar: 'undo redo blocks fontfamily fontsize forecolor backcolor | ' + - 'bold italic underline strikethrough | align numlist bullist | ' + - 'link image | table media | code fullscreen preview', - menubar: 'file edit view insert format tools table help' - }); } - // Select2 - if (root.querySelector(".select-field")) { - $(root).find(".select-field").select2({ + // ✅ Select2 (입력 허용) + if ($context.find(".select-field").length) { + $context.find(".select-field").select2({ theme: "bootstrap-5", - tags: true, // 없는 값 입력 가능 + tags: true, allowClear: true, language: { noResults: function () { - return "직접 입력 후 Enter"; + return "직접 입력 후 Enter"; // 사용자 안내 } } }); } -} \ No newline at end of file + + console.log("✅ Form initialized inside modal:", context); +}; + +// ✅ DOM 전체 로드 후 (페이지 최초 로드시 실행) +document.addEventListener("DOMContentLoaded", function () { + window.initFormModal(document); +}); + +// ✅ Modal 로드 시점에 재초기화 +$(document).on("shown.bs.modal", ".modal", function (e) { + window.initFormModal(this); +}); \ No newline at end of file