dbmsv4 init...2
This commit is contained in:
parent
e141e125f7
commit
fcfd9a9a05
@ -483,7 +483,8 @@ define("PAYMENT", [
|
|||||||
'BILLING' => [
|
'BILLING' => [
|
||||||
'BASE' => 'base',
|
'BASE' => 'base',
|
||||||
'MONTH' => 'month',
|
'MONTH' => 'month',
|
||||||
'ONETIME' => 'onetime'
|
'ONETIME' => 'onetime',
|
||||||
|
'PREPAYMENT' => 'prepayment'
|
||||||
],
|
],
|
||||||
'PAY' => [
|
'PAY' => [
|
||||||
'ACCOUNT' => 'account',
|
'ACCOUNT' => 'account',
|
||||||
|
|||||||
@ -13,7 +13,7 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}
|
|||||||
//1. app/Filters/AuthFilter.php
|
//1. app/Filters/AuthFilter.php
|
||||||
//2. Config/Filters.php -> $aliases = ['authFilter' => AuthFilter::class]
|
//2. Config/Filters.php -> $aliases = ['authFilter' => AuthFilter::class]
|
||||||
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
|
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
|
||||||
$routes->cli('collect', 'Collector::execute');
|
$routes->cli('invoice', 'Invoice::execute');
|
||||||
});
|
});
|
||||||
$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
|
$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
|
||||||
$routes->get('/', 'Home::index');
|
$routes->get('/', 'Home::index');
|
||||||
|
|||||||
@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controllers\CLI;
|
|
||||||
|
|
||||||
use App\Controllers\BaseController;
|
|
||||||
use App\DTOs\CollectorDTO;
|
|
||||||
use CodeIgniter\HTTP\RequestInterface;
|
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
|
||||||
use CodeIgniter\Validation\Exceptions\ValidationException;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
|
|
||||||
class Collector extends BaseController
|
|
||||||
{
|
|
||||||
private $service = null;
|
|
||||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
||||||
{
|
|
||||||
parent::initController($request, $response, $logger);
|
|
||||||
if ($this->service === null) {
|
|
||||||
$action = 'create';
|
|
||||||
$this->service = service('collectorservice');
|
|
||||||
$fields = ['trafficinfo_uid', 'in', 'out', 'raw_in', 'raw_out'];
|
|
||||||
$filters = ['trafficinfo_uid'];
|
|
||||||
$this->service->getFormService()->setFormFields($fields);
|
|
||||||
$this->service->getFormService()->setFormRules($action, $fields);
|
|
||||||
$this->service->getFormService()->setFormFilters($filters);
|
|
||||||
$this->service->getFormService()->setFormOptions($action, $filters);
|
|
||||||
$this->service->getFormService()->setBatchjobFilters($filters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public function execute(): void
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
log_message('info', "트래픽 수집 시작");
|
|
||||||
$trafficService = service('trafficservice');
|
|
||||||
$total = 1;
|
|
||||||
$success = 0;
|
|
||||||
$error = 0;
|
|
||||||
foreach ($trafficService->getEntities(['status' => STATUS['AVAILABLE']]) as $trafficEntity) {
|
|
||||||
try {
|
|
||||||
$entity = $this->service->create(new CollectorDTO($this->service->getCalculatedData($trafficEntity)));
|
|
||||||
$success++;
|
|
||||||
$message = "{$trafficEntity->getServerIP()} 트래픽 수집데이터 저장 완료 In: {$entity->getIn()} Kb/s / Out: {$entity->getOut()} Kb/s";
|
|
||||||
log_message('info', $message);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
$error++;
|
|
||||||
log_message('error', "{$trafficEntity->getServerIP()} 트래픽 수집데이터 저장 실패:{$e->getMessage()}");
|
|
||||||
}
|
|
||||||
$total++;
|
|
||||||
}
|
|
||||||
log_message('info', sprintf("성공:%s , 실패:%s , 총:%s 트래픽 수집 작업완료", $success, $error, $total));
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
log_message('error', "트래픽 수집 작업오류:{$e->getMessage()}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
43
app/Controllers/CLI/Invoice.php
Normal file
43
app/Controllers/CLI/Invoice.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controllers\CLI;
|
||||||
|
|
||||||
|
use App\Controllers\BaseController;
|
||||||
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
class Invoice extends BaseController
|
||||||
|
{
|
||||||
|
private $service = null;
|
||||||
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
parent::initController($request, $response, $logger);
|
||||||
|
if ($this->service === null) {
|
||||||
|
$this->service = service('customer_serviceservice');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
log_message('info', "청구서 발행 시작");
|
||||||
|
$success = 0;
|
||||||
|
$error = 0;
|
||||||
|
$total = 0;
|
||||||
|
foreach ($this->service->getEntities(['billing_at' => date("Y-m-d"), 'status' => STATUS['AVAILABLE']]) as $entity) {
|
||||||
|
try {
|
||||||
|
service('paymentservice')->createByService($entity);
|
||||||
|
$entity = $this->service->updateBillingAt($entity, $this->service->getNextMonthDate($entity));
|
||||||
|
log_message('info', "{$entity->getServerTitle()} 청구서 발행 완료: 다음달 청구일:{$entity->getBillingAt()} 입니다.");
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$error++;
|
||||||
|
log_message('error', "{$entity->getServerTitle()} 청구서 발행 실패:{$e->getMessage()}");
|
||||||
|
}
|
||||||
|
$total++;
|
||||||
|
}
|
||||||
|
log_message('info', sprintf("성공:%s , 실패:%s , 총:%s 청구서 발행 작업완료", $success, $error, $total));
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
log_message('error', "청구서 발행 작업오류:{$e->getMessage()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,7 +5,7 @@ return [
|
|||||||
'user_uid' => "관리자",
|
'user_uid' => "관리자",
|
||||||
'clientinfo_uid' => "고객",
|
'clientinfo_uid' => "고객",
|
||||||
'serviceinfo_uid' => "서비스",
|
'serviceinfo_uid' => "서비스",
|
||||||
'title' => "청구항목",
|
'title' => "청구제목",
|
||||||
'content' => "내용",
|
'content' => "내용",
|
||||||
'amount' => "청구금액",
|
'amount' => "청구금액",
|
||||||
'billing' => "청구방법",
|
'billing' => "청구방법",
|
||||||
@ -20,6 +20,7 @@ return [
|
|||||||
"BILLING" => [
|
"BILLING" => [
|
||||||
PAYMENT['BILLING']['MONTH'] => "매월",
|
PAYMENT['BILLING']['MONTH'] => "매월",
|
||||||
PAYMENT['BILLING']['ONETIME'] => "일회성",
|
PAYMENT['BILLING']['ONETIME'] => "일회성",
|
||||||
|
PAYMENT['BILLING']['PREPAYMENT'] => "선결제",
|
||||||
],
|
],
|
||||||
"PAY" => [
|
"PAY" => [
|
||||||
PAYMENT['PAY']['ACCOUNT'] => "예치금",
|
PAYMENT['PAY']['ACCOUNT'] => "예치금",
|
||||||
|
|||||||
@ -149,7 +149,7 @@ class ServiceService extends CustomerService
|
|||||||
}
|
}
|
||||||
return $amounts;
|
return $amounts;
|
||||||
}
|
}
|
||||||
//다음 달로 결제일 가져오기.
|
//다음 달로 결제일 가져오기.(CLI용)
|
||||||
final public function getNextMonthDate(ServiceEntity $entity): string
|
final public function getNextMonthDate(ServiceEntity $entity): string
|
||||||
{
|
{
|
||||||
// $sql = "UPDATE serviceinfo SET billing_at =
|
// $sql = "UPDATE serviceinfo SET billing_at =
|
||||||
@ -175,41 +175,44 @@ class ServiceService extends CustomerService
|
|||||||
// 최종 결과 리턴 (YYYY-MM-DD)
|
// 최종 결과 리턴 (YYYY-MM-DD)
|
||||||
return $date->format('Y-m-d');
|
return $date->format('Y-m-d');
|
||||||
}
|
}
|
||||||
// 서비스금액관련처리
|
//결제일 변경관련처리
|
||||||
private function getCacluatedAmount(ServiceEntity $entity): int
|
final public function updateBillingAt(int|ServiceEntity $uid, string $billing_at): ServiceEntity
|
||||||
{
|
{
|
||||||
|
$entity = is_int($uid) ? $this->getEntity($uid) : $uid;
|
||||||
|
if (!$entity instanceof ServiceEntity) {
|
||||||
|
throw new RuntimeException(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다.");
|
||||||
|
}
|
||||||
|
//총 서비스금액 설정
|
||||||
|
$formDatas = ['billing_at' => $billing_at];
|
||||||
|
$fields = array_keys($formDatas);
|
||||||
|
$this->getFormService()->setFormFields($fields);
|
||||||
|
$this->getFormService()->setFormRules('modify', $fields);
|
||||||
|
return parent::modify_process($entity, $formDatas);
|
||||||
|
}
|
||||||
|
// 서비스금액관련처리
|
||||||
|
final public function updateAmount(int|ServiceEntity $uid): ServiceEntity
|
||||||
|
{
|
||||||
|
$entity = is_int($uid) ? $this->getEntity($uid) : $uid;
|
||||||
|
if (!$entity instanceof ServiceEntity) {
|
||||||
|
throw new RuntimeException(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다.");
|
||||||
|
}
|
||||||
//총 서비스금액 구하기
|
//총 서비스금액 구하기
|
||||||
$server_amount = service('equipment_serverservice')->getCalculatedAmount($entity->getServerInfoUID());
|
$server_amount = service('equipment_serverservice')->getCalculatedAmount($entity->getServerInfoUID());
|
||||||
//기본:서버금액(서버비+서버파트(월비용))+상면비+회선비-할인액
|
//기본:서버금액(서버비+서버파트(월비용))+상면비+회선비-할인액
|
||||||
$caculatedAmount = (int)$server_amount + $entity->getRack() + $entity->getLine() - $entity->getSale();
|
$caculatedAmount = (int)$server_amount + $entity->getRack() + $entity->getLine() - $entity->getSale();
|
||||||
return $caculatedAmount;
|
|
||||||
}
|
//총 서비스금액 설정
|
||||||
final public function updateAmount(int $uid): ServiceEntity
|
$formDatas = ['amount' => $caculatedAmount];
|
||||||
{
|
$fields = array_keys($formDatas);
|
||||||
$entity = $this->getEntity($uid);
|
|
||||||
if (!$entity instanceof ServiceEntity) {
|
|
||||||
throw new \Exception(__METHOD__ . "에서 오류발생: {$uid} 서비스 정보를 찾을수 없습니다.");
|
|
||||||
}
|
|
||||||
$action = 'modify';
|
|
||||||
$fields = ['amount'];
|
|
||||||
$this->getFormService()->setFormFields($fields);
|
$this->getFormService()->setFormFields($fields);
|
||||||
$this->getFormService()->setFormRules($action, $fields);
|
$this->getFormService()->setFormRules('modify', $fields);
|
||||||
$formDatas['amount'] = $this->getCacluatedAmount($entity);
|
return parent::modify_process($entity, $formDatas);
|
||||||
$result = $this->model->update($entity->getPK(), $formDatas);
|
|
||||||
log_message('debug', $this->model->getLastQuery());
|
|
||||||
if ($result === false) {
|
|
||||||
$errors = $this->model->errors();
|
|
||||||
$errorMsg = is_array($errors) ? implode(", ", $errors) : "서비스 금액설정 실패했습니다.";
|
|
||||||
throw new RuntimeException(__METHOD__ . "에서 오류발생: " . $errorMsg);
|
|
||||||
}
|
|
||||||
return $this->getEntity($uid);
|
|
||||||
}
|
}
|
||||||
//기본 기능부분
|
//기본 기능부분
|
||||||
protected function getEntity_process(mixed $entity): ServiceEntity
|
protected function getEntity_process(mixed $entity): ServiceEntity
|
||||||
{
|
{
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function create_process(array $formDatas): ServiceEntity
|
protected function create_process(array $formDatas): ServiceEntity
|
||||||
{
|
{
|
||||||
//필수항목검사
|
//필수항목검사
|
||||||
@ -226,7 +229,7 @@ class ServiceService extends CustomerService
|
|||||||
//서버정보 연결
|
//서버정보 연결
|
||||||
service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID());
|
service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID());
|
||||||
//서비스비용 설정
|
//서비스비용 설정
|
||||||
$entity = $this->updateAmount($entity->getPK());
|
$entity = $this->updateAmount($entity);
|
||||||
//결제정보 생성
|
//결제정보 생성
|
||||||
service('paymentservice')->createByService($entity);
|
service('paymentservice')->createByService($entity);
|
||||||
return $entity;
|
return $entity;
|
||||||
@ -249,7 +252,7 @@ class ServiceService extends CustomerService
|
|||||||
service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID());
|
service('equipment_serverservice')->attachToService($entity, $entity->getServerInfoUID());
|
||||||
}
|
}
|
||||||
//서비스비용 설정
|
//서비스비용 설정
|
||||||
$entity = $this->updateAmount($entity->getPK());
|
$entity = $this->updateAmount($entity);
|
||||||
//결제정보 생성
|
//결제정보 생성
|
||||||
service('paymentservice')->modifyByService($entity);
|
service('paymentservice')->modifyByService($entity);
|
||||||
return $entity;
|
return $entity;
|
||||||
|
|||||||
@ -188,6 +188,10 @@ class PaymentService extends CommonService
|
|||||||
if (!$entity instanceof PaymentEntity) {
|
if (!$entity instanceof PaymentEntity) {
|
||||||
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
|
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
|
||||||
}
|
}
|
||||||
|
//선결제인경우 서비스정보에 결제일 변경용
|
||||||
|
if ($formDatas['billing'] === PAYMENT['BILLING']['PREPAYMENT'] && array_key_exists('billing_at', $formDatas)) {
|
||||||
|
service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt());
|
||||||
|
}
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +201,10 @@ class PaymentService extends CommonService
|
|||||||
if (!$entity instanceof PaymentEntity) {
|
if (!$entity instanceof PaymentEntity) {
|
||||||
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
|
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
|
||||||
}
|
}
|
||||||
|
//선결제인경우 서비스정보에 결제일 변경용
|
||||||
|
if ($formDatas['billing'] === PAYMENT['BILLING']['PREPAYMENT'] && array_key_exists('billing_at', $formDatas)) {
|
||||||
|
service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt());
|
||||||
|
}
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,6 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" class="text-center"><?= $serviceCellDatas['helper']->getListButton('onetime', '일회성추가', ['entity' => $serviceEntity], ['class' => 'btn btn-sm btn-primary']) ?></td>
|
<td colspan="2" class="text-center"><?= $serviceCellDatas['helper']->getListButton('onetime', '일회성/선결제 추가', ['entity' => $serviceEntity], ['class' => 'btn btn-sm btn-primary']) ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
Loading…
Reference in New Issue
Block a user