dbms/app/Controllers/CLI/Payment.php
2025-06-20 12:16:51 +09:00

66 lines
2.4 KiB
PHP

<?php
namespace App\Controllers\CLI;
use App\Controllers\BaseController;
use App\Services\Customer\ServiceService;
use App\Services\Customer\ServiceItemService;
use App\Services\Customer\ServicePaymentService;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class Payment extends BaseController
{
private $_db = null;
private ?ServiceService $_serviceService = null;
private ?ServiceItemService $_servicItemeService = null;
private ?ServicePaymentService $_servicePaymentService = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
// $this->_db = \Config\Database::connect();
}
public function getServiceService(): ServiceService
{
if (!$this->_serviceService) {
$this->_serviceService = new ServiceService($this->request);
}
return $this->_serviceService;
}
public function getServiceItemService(): ServiceItemService
{
if (!$this->_servicItemeService) {
$this->_servicItemeService = new ServiceItemService($this->request);
}
return $this->_servicItemeService;
}
public function getServicePaymentService(): ServicePaymentService
{
if (!$this->_servicePaymentService) {
$this->_servicePaymentService = new ServicePaymentService($this->request);
}
return $this->_servicePaymentService;
}
public function billing(): void
{
//Transaction Start
$this->getServiceService()->getModel()->transStart();
try {
//서비스중인 서버중 결제일이 오늘인 서비스 확인후 연장처리
$this->getServiceService()->extendBillingAt(date('Y-m-d'), DEFAULTS['STATUS']);
log_message("notice", "Billing 작업을 완료하였습니다.");
$this->getServiceService()->getModel()->transCommit();
} catch (\Exception $e) {
//Transaction Rollback
$this->getServiceService()->getModel()->transRollback();
log_message(
"error",
"Billing 작업을 실패하였습니다.\n--------------\n" .
$e->getMessage() .
"\n--------------\n"
);
}
}
}