diff --git a/app/Controllers/Admin/Customer/ClientController.php b/app/Controllers/Admin/Customer/ClientController.php index ac89200..63d8812 100644 --- a/app/Controllers/Admin/Customer/ClientController.php +++ b/app/Controllers/Admin/Customer/ClientController.php @@ -37,6 +37,20 @@ class ClientController extends CustomerController return $this->_helper; } //Index,FieldForm관련 + //생성관련 + protected function create_process(array $formDatas): void + { + // 관리자 UID는 현재 인증된 사용자로 설정 + $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); + parent::create_process($formDatas); + } + //수정관련 + protected function modify_process(mixed $entity, array $formDatas): void + { + // 관리자 UID는 현재 인증된 사용자로 설정 + $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); + parent::modify_process($entity, $formDatas); + } protected function setValidation(Validation $validation, string $field, string $rule): Validation { switch ($field) { diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index db489df..76f1eca 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -67,6 +67,20 @@ class ServiceController extends CustomerController return $result; } //Index,FieldForm관련 + //생성관련 + protected function create_process(array $formDatas): void + { + // 관리자 UID는 현재 인증된 사용자로 설정 + $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); + parent::create_process($formDatas); + } + //수정관련 + protected function modify_process(mixed $entity, array $formDatas): void + { + // 관리자 UID는 현재 인증된 사용자로 설정 + $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); + parent::modify_process($entity, $formDatas); + } //View 관련 protected function view_process(mixed $entity): void { diff --git a/app/Controllers/Admin/Customer/ServiceItemController.php b/app/Controllers/Admin/Customer/ServiceItemController.php index 31539ca..32052ed 100644 --- a/app/Controllers/Admin/Customer/ServiceItemController.php +++ b/app/Controllers/Admin/Customer/ServiceItemController.php @@ -2,9 +2,11 @@ namespace App\Controllers\Admin\Customer; +use App\Entities\Customer\ServicePaymentEntity; use App\Helpers\Customer\ServiceItemHelper; -use App\Services\Customer\ServiceItemService; +use App\Services\Customer\ServiceItemService; +use App\Services\Customer\ServicePaymentService; use App\Services\Customer\ServiceService; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\RequestInterface; @@ -14,6 +16,7 @@ use Psr\Log\LoggerInterface; class ServiceItemController extends CustomerController { private ?ServiceService $_serviceService = null; + private ?ServicePaymentService $_servicePaymentService = null; public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { parent::initController($request, $response, $logger); @@ -50,6 +53,13 @@ class ServiceItemController extends CustomerController } return $this->_serviceService; } + public function getServicePaymentService(): ServicePaymentService + { + if (!$this->_servicePaymentService) { + $this->_servicePaymentService = new ServicePaymentService(); + } + return $this->_servicePaymentService; + } protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string { switch ($this->getAction()) { @@ -86,7 +96,16 @@ class ServiceItemController extends CustomerController if (!$serviceEntity) { throw new \Exception("{$formDatas['serviceinfo_uid']}에 대한 서비스정보를 찾을수 없습니다."); } - //부모처리 parent::create_process($formDatas); + //결제 처리 + $paymentFormDatas = []; + //금액(amount)가 0원일경우는 바로 결제완료 처리함. + if ($this->entity->getAmount() === 0) { + // 관리자 UID는 현재 인증된 사용자로 설정 + $paymentFormDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); + $paymentFormDatas['status'] = ServicePaymentEntity::STATUS_PAID; + } + // dd($paymentFormDatas); + $this->getServicePaymentService()->createByServiceItemService($paymentFormDatas, $this->entity); } } diff --git a/app/Controllers/Admin/Customer/ServicePaymentController.php b/app/Controllers/Admin/Customer/ServicePaymentController.php index 629f41c..d2cf14b 100644 --- a/app/Controllers/Admin/Customer/ServicePaymentController.php +++ b/app/Controllers/Admin/Customer/ServicePaymentController.php @@ -78,6 +78,20 @@ class ServicePaymentController extends CustomerController return $result; } //Index,FieldForm관련 + //생성관련 + protected function create_process(array $formDatas): void + { + // 관리자 UID는 현재 인증된 사용자로 설정 + $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); + parent::create_process($formDatas); + } + //수정관련 + protected function modify_process(mixed $entity, array $formDatas): void + { + // 관리자 UID는 현재 인증된 사용자로 설정 + $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); + parent::modify_process($entity, $formDatas); + } //View 관련 protected function view_process(mixed $entity): void { diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index b4d46dd..ded751f 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -44,7 +44,7 @@ class UserController extends AdminController { switch ($this->getAction()) { case 'profile_modify': - $this->getMyLogService()->save($this->getService()->getClassName(), __FUNCTION__, $message); + $this->getMyLogService()->save($this->getService()->getClassName(), __FUNCTION__, $message, $this->getMyAuth()->getUIDByAuthInfo()); $result = $this->view($this->entity->getPK()); break; case 'profile_modify_form': diff --git a/app/Controllers/CLI/Payment.php b/app/Controllers/CLI/Payment.php index d2f01c0..af4de16 100644 --- a/app/Controllers/CLI/Payment.php +++ b/app/Controllers/CLI/Payment.php @@ -3,9 +3,10 @@ namespace App\Controllers\CLI; use App\Controllers\BaseController; -use App\Services\Customer\ServiceService; +use App\Entities\Customer\ServicePaymentEntity; use App\Services\Customer\ServiceItemService; use App\Services\Customer\ServicePaymentService; +use App\Services\Customer\ServiceService; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; @@ -54,8 +55,8 @@ class Payment extends BaseController //결제정보 ServicePaymentService에 월별 결제만 신규등록 if ($itemEntity->getBillingCycle() == "month") { //결제정보 ServicePaymentService에 등록 - $this->getServicePaymentService()->setServiceItemEntity($itemEntity); - $this->getServicePaymentService()->create([]); + $paymentFormDatas = ['status' => ServicePaymentEntity::STATUS_UNPAID]; + $this->getServicePaymentService()->createByServiceItemService($paymentFormDatas, $itemEntity); } } } diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index c2684ca..772faa1 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -240,7 +240,7 @@ abstract class CommonController extends BaseController protected function getResultFail(string $message = MESSAGES["FAILED"]): RedirectResponse { LogCollector::debug($message); - $this->getMyLogService()->save($this->getService()->getClassName(), __FUNCTION__, $message); + $this->getMyLogService()->save($this->getService()->getClassName(), __FUNCTION__, $message, $this->getMyAuth()->getUIDByAuthInfo()); if ($this->request->getMethod() === 'POST') { return redirect()->back()->withInput()->with('error', $message); } @@ -252,7 +252,7 @@ abstract class CommonController extends BaseController switch ($this->getAction()) { case 'create': case 'modify': - $this->getMyLogService()->save($this->getService()->getClassName(), __FUNCTION__, $message); + $this->getMyLogService()->save($this->getService()->getClassName(), __FUNCTION__, $message, $this->getMyAuth()->getUIDByAuthInfo()); $result = $this->view($this->entity->getPK()); break; case 'create_form': @@ -297,6 +297,7 @@ abstract class CommonController extends BaseController return $this->getResultFail($e->getMessage()); } } + //생성관련 protected function create_process(array $formDatas): void { //데이터 검증 diff --git a/app/Entities/Customer/ServicePaymentEntity.php b/app/Entities/Customer/ServicePaymentEntity.php index 5c3f7cc..d39ab73 100644 --- a/app/Entities/Customer/ServicePaymentEntity.php +++ b/app/Entities/Customer/ServicePaymentEntity.php @@ -9,6 +9,8 @@ class ServicePaymentEntity extends CustomerEntity { const PK = ServicePaymentModel::PK; const TITLE = ServicePaymentModel::TITLE; + const STATUS_UNPAID = "default"; + const STATUS_PAID = "paid"; //관리자정보객체 final public function getServiceUid(): int { diff --git a/app/Models/CommonModel.php b/app/Models/CommonModel.php index 058f89a..a7b5f1c 100644 --- a/app/Models/CommonModel.php +++ b/app/Models/CommonModel.php @@ -148,9 +148,10 @@ abstract class CommonModel extends Model // 최종 저장 시 오류 발생하면 if (!$this->save($formDatas)) { $message = sprintf( - "\n------%s 오류-----\n%s\n------------------------------\n", + "\n------%s 오류-----\n%s\n%s\n------------------------------\n", __METHOD__, - var_export($this->errors(), true) + var_export($this->errors(), true), + $this->getLastQuery() ); LogCollector::debug($message); throw new \Exception($message); diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 831ced2..10517f4 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -10,20 +10,12 @@ abstract class CommonService private $_serviceDatas = []; private $_model = null; private $_classNames = []; - private $_myAuth = null; protected function __construct() {} abstract public function getModelClass(): mixed; abstract public function getEntityClass(): mixed; abstract public function getFormFields(): array; abstract public function getFilterFields(): array; abstract public function getBatchJobFields(): array; - final protected function getMyAuth(): mixed - { - if (!$this->_myAuth) { - $this->_myAuth = service('myauth'); - } - return $this->_myAuth; - } public function getIndexFields(): array { return $this->getFormFields(); diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index 3b33d06..6b8e1ae 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -99,8 +99,6 @@ class ClientService extends CustomerService public function create(array $formDatas): ClientEntity { - //수정자 정보 자동추가용 - $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); $formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']); return parent::create($formDatas); } @@ -110,8 +108,6 @@ class ClientService extends CustomerService if (isset($formDatas['role'])) { $formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']); } - //수정자 정보 자동추가용 - $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); return parent::modify($entity, $formDatas); } } diff --git a/app/Services/Customer/ServiceItemService.php b/app/Services/Customer/ServiceItemService.php index e1e6de0..552e45a 100644 --- a/app/Services/Customer/ServiceItemService.php +++ b/app/Services/Customer/ServiceItemService.php @@ -6,12 +6,10 @@ use App\Entities\Customer\ServiceItemEntity; use App\Entities\Equipment\Part\IpEntity; use App\Models\Customer\ServiceItemModel; use App\Services\Customer\CustomerService; -use App\Services\Customer\ServicePaymentService; use App\Services\Equipment\Part\IpService; class ServiceItemService extends CustomerService { - private ?ServicePaymentService $_servicePaymentService = null; private ?IpService $_ipService = null; public function __construct() { @@ -33,13 +31,6 @@ class ServiceItemService extends CustomerService } return $this->_ipService; } - public function getServicePaymentService(): ServicePaymentService - { - if (!$this->_servicePaymentService) { - $this->_servicePaymentService = new ServicePaymentService(); - } - return $this->_servicePaymentService; - } public function getFormFields(): array { return [ @@ -67,16 +58,6 @@ class ServiceItemService extends CustomerService } //Entity의 관련객체정의용 //FieldForm관련용 - public function create(array $formDatas): ServiceItemEntity - { - $entity = parent::create($formDatas); - //결제정보 ServicePaymentService에 등록 - $this->getServicePaymentService()->setServiceItemEntity($entity); - //관리자 정보 자동추가용 - $paymentFormDatas = ['user_uid' => $this->getMyAuth()->getUIDByAuthInfo()]; - $this->getServicePaymentService()->create($paymentFormDatas); - return $entity; - } public function modify(mixed $entity, array $formDatas): ServiceItemEntity { //IP가 기존과 다를경우 //toggle,batchjob의 경우 $formDatas에 code가 없을수도 있음 diff --git a/app/Services/Customer/ServicePaymentService.php b/app/Services/Customer/ServicePaymentService.php index 9ecaff8..883cccb 100644 --- a/app/Services/Customer/ServicePaymentService.php +++ b/app/Services/Customer/ServicePaymentService.php @@ -6,14 +6,9 @@ use App\Entities\Customer\ServiceEntity; use App\Entities\Customer\ServiceItemEntity; use App\Entities\Customer\ServicePaymentEntity; use App\Models\Customer\ServicePaymentModel; -use App\Services\Customer\ServiceService; -use App\Services\UserService; class ServicePaymentService extends CustomerService { - private ?ServiceItemEntity $_serviceItemEntity = null; - private ?UserService $_userService = null; - private ?ServiceService $_serviceService = null; public function __construct() { parent::__construct(); @@ -53,18 +48,6 @@ class ServicePaymentService extends CustomerService { return ['serviceinfo_uid', "ownerinfo_uid", 'item_type', 'item_uid', 'billing_cycle', 'amount', 'billing_at', 'issue_at', 'countdown', 'status', 'user_uid']; } - public function setServiceItemEntity(ServiceItemEntity $entity): void - { - $this->_serviceItemEntity = $entity; - } - public function getServiceItemEntity(): ServiceItemEntity - { - if ($this->_serviceItemEntity === null) { - throw new \Exception("ServiceItem이 지정되지 않았습니다."); - } - return $this->_serviceItemEntity; - } - //Entity의 관련객체정의용 //기본 기능부분 //FieldForm관련용 public function getFormFieldOption(string $field, array $options = []): array @@ -93,30 +76,23 @@ class ServicePaymentService extends CustomerService return $unpaids; } //결체처리정보 등록 : ServiceItemService에서 사용 - public function create(array $formDatas): ServicePaymentEntity + public function createByServiceItemService(array $formDatas, ServiceItemEntity $serviceItemEntity): ServicePaymentEntity { - $serviceItemEntity = $this->getServiceItemEntity(); $serviceEntity = $this->getServiceService()->getEntity($serviceItemEntity->getServiceUid()); if (!$serviceEntity) { throw new \Exception("{$serviceItemEntity->getServiceUid()}에 대한 서비스정보를 찾을수 없습니다."); } - $formDatas = [ - 'serviceinfo_uid' => $serviceItemEntity->getServiceUid(), - 'ownerinfo_uid' => $serviceEntity->getOwnerUid(), - 'item_type' => $serviceItemEntity->getItemType(), - 'item_uid' => $serviceItemEntity->getItemUid(), - 'billing_cycle' => $serviceItemEntity->getBillingCycle(), - 'amount' => $serviceItemEntity->getAmount(), - 'billing_at' => $serviceEntity->getBillingAt(), - 'issue_at' => date('Y-m-d'), - ]; - //금액(amount)가 0원일경우는 바로 결제완료 및 결제자 등록 처리함. - if ($serviceItemEntity->getAmount() === 0) { - $formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo(); - $formDatas['status'] = 'paid'; - } + $formDatas['serviceinfo_uid'] = $serviceItemEntity->getServiceUid(); + $formDatas['ownerinfo_uid'] = $serviceEntity->getOwnerUid(); + $formDatas['item_type'] = $serviceItemEntity->getItemType(); + $formDatas['item_uid'] = $serviceItemEntity->getItemUid(); + $formDatas['billing_cycle'] = $serviceItemEntity->getBillingCycle(); + $formDatas['amount'] = $serviceItemEntity->getAmount(); + $formDatas['billing_at'] = $serviceEntity->getBillingAt(); + $formDatas['issue_at'] = date('Y-m-d'); return $this->create($formDatas); } + //Service정보 와 관리자가 기존 정보과 같고, 결제가 아직 완료되지 않은 결제정보의 관리자 변경 public function modifyOwnerByService(ServiceEntity $serviceEntity, int $ownerinfo_uid) { diff --git a/app/Services/MyLogService.php b/app/Services/MyLogService.php index f66b3b3..b2ef938 100644 --- a/app/Services/MyLogService.php +++ b/app/Services/MyLogService.php @@ -69,10 +69,10 @@ class MyLogService extends CommonService } return $options; } - public function save(string $class, string $method, string $title): MyLogEntity + public function save(string $class, string $method, string $title, int $user_uid): MyLogEntity { $formDatas = [ - 'user_uid' => $this->getMyAuth()->getUIDByAuthInfo(), + 'user_uid' => $user_uid, 'class_name' => $class, 'method_name' => $method, 'title' => $title,