137 lines
5.5 KiB
PHP
137 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Customer;
|
|
|
|
use App\Entities\Customer\ServiceEntity;
|
|
use App\Helpers\Customer\ServiceHelper;
|
|
|
|
use App\Services\Customer\PaymentService;
|
|
use App\Services\Customer\ServiceService;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class ServiceController extends CustomerController
|
|
{
|
|
private ?PaymentService $_paymentService = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->content_title = lang("{$this->getService()->getClassName()}.title");
|
|
$this->class_path .= $this->getService()->getClassName();
|
|
$this->uri_path .= strtolower($this->getService()->getClassName('/')) . '/';
|
|
// $this->view_path .= strtolower($this->getService()->getClassName()) . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
|
public function getService(): ServiceService
|
|
{
|
|
if (!$this->_service) {
|
|
$this->_service = new ServiceService();
|
|
}
|
|
return $this->_service;
|
|
}
|
|
public function getHelper(): ServiceHelper
|
|
{
|
|
if (!$this->_helper) {
|
|
$this->_helper = new ServiceHelper();
|
|
}
|
|
return $this->_helper;
|
|
}
|
|
public function getPaymentService(): PaymentService
|
|
{
|
|
if (!$this->_paymentService) {
|
|
$this->_paymentService = new PaymentService();
|
|
}
|
|
return $this->_paymentService;
|
|
}
|
|
//Index,FieldForm관련
|
|
protected function getResultSuccess(string $message = MESSAGES["SUCCESS"], ?string $actionTemplate = null): RedirectResponse|string
|
|
{
|
|
switch ($this->getAction()) {
|
|
// case 'create_form':
|
|
// case 'modify_form':
|
|
case 'detail':
|
|
case 'view':
|
|
case 'index':
|
|
$this->control = $this->getControlDatas();
|
|
$this->getHelper()->setViewDatas($this->getViewDatas());
|
|
$actionTemplate = $this->request->getVar('ActionTemplate') ?? $actionTemplate ?? 'service';
|
|
if ($actionTemplate) {
|
|
$view_file = $this->view_path . $actionTemplate . DIRECTORY_SEPARATOR . $this->getAction();
|
|
} else {
|
|
$view_file = $this->view_path . $this->getAction();
|
|
}
|
|
$result = view($view_file, ['viewDatas' => $this->getViewDatas()]);
|
|
break;
|
|
default:
|
|
$result = parent::getResultSuccess($message, $actionTemplate);
|
|
break;
|
|
}
|
|
return $result;
|
|
}
|
|
//생성관련
|
|
protected function create_process(array $formDatas): ServiceEntity
|
|
{
|
|
// 관리자 UID는 현재 인증된 사용자로 설정
|
|
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
|
|
return parent::create_process($formDatas);
|
|
}
|
|
//수정관련
|
|
protected function modify_process(mixed $entity, array $formDatas): ServiceEntity
|
|
{
|
|
// 관리자 UID는 현재 인증된 사용자로 설정
|
|
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
|
|
return parent::modify_process($entity, $formDatas);
|
|
}
|
|
//List 관련
|
|
protected function index_process(array $entities = []): array
|
|
{
|
|
//서비스별 미납 Count
|
|
$this->unPaids = $this->getPaymentService()->getUnPaidCount();
|
|
//부모함수처리
|
|
return parent::index_process($entities);
|
|
}
|
|
|
|
public function detail(): RedirectResponse|string
|
|
{
|
|
try {
|
|
$this->setAction(__FUNCTION__);
|
|
$this->setFormFields();
|
|
$this->setFormFilters();
|
|
$this->setFormRules();
|
|
//기본값정의
|
|
$this->setFormDatas($this->request->getGet());
|
|
$this->setFormOptions();
|
|
//일괄작업용 Fields정의
|
|
$this->setControlDatas('batchjob_fields', $this->getService()->getBatchjobFields());
|
|
//일괄작업용 버튼정의
|
|
$this->setControlDatas('batchjob_buttions', $this->getService()->getBatchjobButtons());
|
|
helper(['form']);
|
|
//Return Url정의
|
|
$this->getMyAuth()->pushCurrentUrl($this->request->getUri()->getPath() . ($this->request->getUri()->getQuery() ? "?" . $this->request->getUri()->getQuery() : ""));
|
|
//조건절 처리
|
|
$this->index_condition_process();
|
|
//TotalCount (SoftDelete적용이 되려면 countAllResults를 사용해야함)
|
|
$this->total_count = $this->getService()->getTotalCount();
|
|
//Pagination 처리
|
|
$this->pagination = $this->index_pagenation_process();
|
|
//줄수 처리용
|
|
$this->page_options = $this->index_pageOptions_process();
|
|
//조건절 처리
|
|
//OrcerBy , Limit 처리
|
|
$this->order_field = $this->request->getVar('order_field');
|
|
$this->order_value = $this->request->getVar('order_value');
|
|
$this->getService()->setOrderBy($this->order_field, $this->order_value);
|
|
$this->getService()->setLimit($this->per_page);
|
|
$this->getService()->setOffset(($this->page - 1) * $this->per_page);
|
|
$this->index_condition_process();
|
|
$this->entities = $this->index_process();
|
|
return $this->getResultSuccess();
|
|
} catch (\Exception $e) {
|
|
return $e->getMessage();
|
|
// return $this->getResultFail($e->getMessage());
|
|
}
|
|
}
|
|
}
|