dbmsv3 init...1

This commit is contained in:
choi.jh 2025-10-30 13:51:10 +09:00
parent a17fade55d
commit f05590d9b0
10 changed files with 91 additions and 105 deletions

View File

@ -0,0 +1,10 @@
<?php
namespace App\Interfaces\Customer;
use App\Entities\Customer\ServiceEntity;
interface ServiceInterface
{
public function setAmount(ServiceEntity $entity, int $calculatedServerAmount): ServiceEntity;
}

View File

@ -9,4 +9,5 @@ interface ServerInterface
{ {
public function attachToService(ServiceEntity $serviceEntity, string $serverinfo_uid, array $formDatas = []): ServerEntity; public function attachToService(ServiceEntity $serviceEntity, string $serverinfo_uid, array $formDatas = []): ServerEntity;
public function detachFromService(string $serverinfo_uid): ServerEntity; public function detachFromService(string $serverinfo_uid): ServerEntity;
public function setAmount(ServerEntity $entity): ServerEntity;
} }

View File

@ -3,9 +3,11 @@
namespace App\Interfaces\Equipment; namespace App\Interfaces\Equipment;
use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
interface ServerPartInterface interface ServerPartInterface
{ {
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void; public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void;
public function detachFromServer(ServerEntity $serverEntity): void; public function detachFromServer(ServerEntity $serverEntity): void;
public function setAmount(ServerPartEntity $entity, string $callBack): ServerPartEntity;
} }

View File

@ -31,15 +31,16 @@ class ServiceV1Processor
$entity, $entity,
$entity->getServerInfoUID() $entity->getServerInfoUID()
); );
// 3) 금액 계산 + 결제정보반영 // 3) 결제정보반영
$amount = $this->service->getCalculatedAmount($entity, $serverEntity); $this->service->setAmount(
$this->service->getModel()->modify($entity, ['amount' => $amount]); $entity,
$paymentEntity = $this->paymentService->createForService($entity); $this->serverService->getCalculatedAmount($serverEntity),
'createForService'
);
// 4) 서비스 FK 동기화 // 4) 서비스 FK 동기화
$entity = $this->service->getModel()->modify($entity, [ $entity = $this->service->getModel()->modify($entity, [
'title' => $entity->getTitle(), 'title' => $entity->getTitle(),
'serverinfo_id' => $serverEntity->getPK(), 'serverinfo_id' => $serverEntity->getPK(),
'payment_uid' => $paymentEntity->getPK(),
]); ]);
// 6) 로그 // 6) 로그
$this->logService->create([ $this->logService->create([
@ -67,8 +68,11 @@ class ServiceV1Processor
$entity, $entity,
$entity->getServerInfoUID() $entity->getServerInfoUID()
); );
// 3) 금액 재계산 + 결제정보반영 // 3) 결제정보반영
$entity = $this->service->setAmount($entity->getPK()); $this->service->setAmount(
$entity,
$this->serverService->getCalculatedAmount($serverEntity)
);
// 5) 서비스 FK 동기화 // 5) 서비스 FK 동기화
$entity = $this->service->getModel()->modify($entity, [ $entity = $this->service->getModel()->modify($entity, [
'title' => $entity->getTitle(), 'title' => $entity->getTitle(),
@ -99,6 +103,8 @@ class ServiceV1Processor
} }
// 3) 서비스 삭제 // 3) 서비스 삭제
$this->service->getModel()->delete($entity); $this->service->getModel()->delete($entity);
// 4) 결제정보 반영(서비스번호,서버번호 Null처리)
$this->paymentService->unlinkFromService($entity);
// 4) 로그 // 4) 로그
$this->logService->create([ $this->logService->create([
'title' => "[{$entity->getTitle()}] 서비스 해지", 'title' => "[{$entity->getTitle()}] 서비스 해지",
@ -156,8 +162,11 @@ class ServiceV1Processor
'title' => $serverEntity->getCustomTitle(), 'title' => $serverEntity->getCustomTitle(),
'serverinfo_uid' => $serverEntity->getPK() 'serverinfo_uid' => $serverEntity->getPK()
]); ]);
// 3) 금액 재계산 + 결제정보반영 // 4) 결제정보반영
$entity = $this->service->setAmount($entity->getPK()); $this->service->setAmount(
$entity,
$this->serverService->getCalculatedAmount($serverEntity)
);
// 5) 로그 // 5) 로그
$this->logService->create([ $this->logService->create([
'title' => "{$oldServerEntity->getCustomTitle()}=>{$serverEntity->getCustomTitle()} 메인서버변경", 'title' => "{$oldServerEntity->getCustomTitle()}=>{$serverEntity->getCustomTitle()} 메인서버변경",

View File

@ -4,7 +4,6 @@ namespace App\Processors\Equipment;
use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity; use App\Entities\Equipment\ServerPartEntity;
use App\Services\Customer\ServiceService;
use App\Services\Equipment\ServerPartService; use App\Services\Equipment\ServerPartService;
use App\Services\Equipment\ServerService; use App\Services\Equipment\ServerService;
use App\Services\MyLogService; use App\Services\MyLogService;
@ -19,7 +18,6 @@ class ServerPartV1Processor
public function __construct( public function __construct(
private BaseConnection $db, private BaseConnection $db,
private ServerPartService $service, private ServerPartService $service,
private ServiceService $serviceService,
private ServerService $serverService, private ServerService $serverService,
private PaymentService $paymentService, private PaymentService $paymentService,
private IPService $ipService, private IPService $ipService,
@ -29,7 +27,6 @@ class ServerPartV1Processor
public function create(array $formDatas): ServerPartEntity public function create(array $formDatas): ServerPartEntity
{ {
$this->db->transStart();
//서버정보가져오기 //서버정보가져오기
if (!array_key_exists('serverinfo_uid', $formDatas)) { if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다."); throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다.");
@ -42,6 +39,7 @@ class ServerPartV1Processor
if ($formDatas['billing'] !== PAYMENT['BILLING']['BASE'] && $serverEntity->getServiceInfoUID() === null) { if ($formDatas['billing'] !== PAYMENT['BILLING']['BASE'] && $serverEntity->getServiceInfoUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생:서비스가 지정되어야 작업이 가능합니다."); throw new \Exception(__METHOD__ . "에서 오류발생:서비스가 지정되어야 작업이 가능합니다.");
} }
$this->db->transStart();
// 1) 생성작업 // 1) 생성작업
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID(); $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID(); $formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
@ -50,26 +48,7 @@ class ServerPartV1Processor
// 2) Type에 따른 각 파트 정의 // 2) Type에 따른 각 파트 정의
$this->service->getPartService($entity->getType())->attachToServerPart($entity); $this->service->getPartService($entity->getType())->attachToServerPart($entity);
// 3) 과금정의 // 3) 과금정의
switch ($entity->getBilling()) { $this->service->setAmount($entity, "createForServerPart");
case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리
if ($entity->getServiceInfoUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다.");
}
//서비스 금액만 재계산변경
$this->serviceService->setAmount($entity->getServiceInfoUID());
break;
case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리
$paymentEntity = $this->paymentService->createForServerPart($entity);
//결제정보PK정의
$entity = $this->service->getModel()->modify($entity, ['payment_uid' => $paymentEntity->getPK()]);
break;
case PAYMENT['BILLING']['BASE']: //기본처리
//아무처리 않함
break;
default:
throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다.");
// break;
}
// 4) 로그 // 4) 로그
$this->logService->create(formDatas: [ $this->logService->create(formDatas: [
'title' => "{$entity->getTitle()} 서버파트 추가", 'title' => "{$entity->getTitle()} 서버파트 추가",
@ -83,11 +62,11 @@ class ServerPartV1Processor
} }
public function modify(ServerPartEntity $entity, array $formDatas): ServerPartEntity public function modify(ServerPartEntity $entity, array $formDatas): ServerPartEntity
{ {
$this->db->transStart();
//서버정보가져오기 //서버정보가져오기
if (!array_key_exists('serverinfo_uid', $formDatas)) { if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다."); throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다.");
} }
$this->db->transStart();
// 1) 수정전 정보 // 1) 수정전 정보
//파트값이 정의되어 있으면 //파트값이 정의되어 있으면
$isChangedPart = false; $isChangedPart = false;
@ -113,24 +92,7 @@ class ServerPartV1Processor
$this->service->getPartService($entity->getType())->attachToServerPart($entity); $this->service->getPartService($entity->getType())->attachToServerPart($entity);
} }
// 3) 과금정의 // 3) 과금정의
switch ($entity->getBilling()) { $this->service->setAmount($entity, "updateForServerPart");
case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리
if ($entity->getServiceInfoUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다.");
}
//서비스 금액만 재계산변경
$this->serviceService->setAmount($entity->getServiceInfoUID());
break;
case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리
$this->paymentService->updateForServerPart($entity);
break;
case PAYMENT['BILLING']['BASE']: //기본처리
//아무처리 않함
break;
default:
throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다.");
// break;
}
// 4) 로그 // 4) 로그
$this->logService->create(formDatas: [ $this->logService->create(formDatas: [
'title' => "{$entity->getTitle()} 서버파트 수정", 'title' => "{$entity->getTitle()} 서버파트 수정",
@ -151,27 +113,13 @@ class ServerPartV1Processor
$this->service->getPartService($entity->getType())->detachFromServerPart($entity); $this->service->getPartService($entity->getType())->detachFromServerPart($entity);
} }
// 2) 서버파트정보 삭제 // 2) 서버파트정보 삭제
$this->service->getModel()->delete($entity); $serverEntity = $this->serverService->getEntity($entity->getServerInfoUID());
// 3) 과금처리 if (!$serverEntity instanceof ServerEntity) {
switch ($entity->getBilling()) { throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServerInfoUID()} 서버 정보를 찾을수 없습니다.");
case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리
if ($entity->getServiceInfoUID() !== null) { //서비스가 정의되어 있으면
//서비스 금액만 재계산변경
$this->serviceService->setAmount($entity->getServiceInfoUID());
}
break;
case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리
if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면
$this->paymentService->unlinkFromServerPart($entity);
}
break;
case PAYMENT['BILLING']['BASE']: //기본처리
//아무처리 않함
break;
default:
throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다.");
// break;
} }
$this->service->getModel()->delete($entity);
// 3) 과금정의
$this->service->setAmount($entity, "unlinkFromServerPart");
// 4) 로그 // 4) 로그
$this->logService->create(formDatas: [ $this->logService->create(formDatas: [
'title' => "{$entity->getTitle()} 서버파트 삭제", 'title' => "{$entity->getTitle()} 서버파트 삭제",

View File

@ -91,9 +91,9 @@ class ServerV1Processor
if ($entity->getIP() && $isChangedIP) { if ($entity->getIP() && $isChangedIP) {
$this->ipService->attachToServer($entity); $this->ipService->attachToServer($entity);
} }
//5) 서비스금액 설정:서비스가 연결되어 있고 대체서버가 아니면, 서비스정보수정(청구액수정) //4) 서비스금액 설정:서비스가 연결되어 있고 대체서버가 아니면, 과금정의
if ($entity->getServiceInfoUID() !== null && $entity->getType() !== SERVER['TYPES']['ALTERNATIVE']) { if ($entity->getServiceInfoUID() !== null && $entity->getType() !== SERVER['TYPES']['ALTERNATIVE']) {
$this->serviceService->setAmount($entity->getServiceInfoUID()); $this->service->setAmount($entity);
} }
//5) Log처리 //5) Log처리
$this->logService->create([ $this->logService->create([

View File

@ -3,16 +3,16 @@
namespace App\Services\Customer; namespace App\Services\Customer;
use App\Entities\Customer\ServiceEntity; use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Helpers\Customer\ServiceHelper; use App\Helpers\Customer\ServiceHelper;
use App\Interfaces\Customer\ServiceInterface;
use App\Models\Customer\ServiceModel; use App\Models\Customer\ServiceModel;
use App\Processors\Customer\ServiceV1Processor as Proceessor;
use App\Services\Equipment\ServerService; use App\Services\Equipment\ServerService;
use App\Services\PaymentService; use App\Services\PaymentService;
use DateTimeImmutable; use DateTimeImmutable;
use DateTimeZone; use DateTimeZone;
use App\Processors\Customer\ServiceV1Processor as Proceessor;
class ServiceService extends CustomerService class ServiceService extends CustomerService implements ServiceInterface
{ {
private ?ServerService $_serverService = null; private ?ServerService $_serverService = null;
private ?PaymentService $_paymentService = null; private ?PaymentService $_paymentService = null;
@ -159,28 +159,14 @@ class ServiceService extends CustomerService
// 최종 결과 리턴 (YYYY-MM-DD) // 최종 결과 리턴 (YYYY-MM-DD)
return $date->format('Y-m-d'); return $date->format('Y-m-d');
} }
//총서비스금액 계산 //서비스금액관련처리
//기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액 public function setAmount(ServiceEntity $entity, int $calculatedServerAmount, string $callBack = "updateForService"): ServiceEntity
public function getCalculatedAmount(ServiceEntity $entity, ServerEntity $serverEntity): int
{ {
return $entity->getRack() + $entity->getLine() + $this->getServerService()->getCalculatedAmount($serverEntity) - $entity->getSale(); //기본:상면비+회선비+서버금액(price)+서버파트연결(월비용)-할인액
} $amount = $entity->getRack() + $entity->getLine() + $calculatedServerAmount - $entity->getSale();
//서비스금액변경 //결제정보 반영
public function setAmount(string $uid): ServiceEntity $this->getPaymentService()->$callBack($entity, $amount);
{ return $this->getModel()->modify($entity, ['amount' => $amount,]);
$entity = $this->getEntity($uid);
if (!$entity instanceof ServiceEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: [{$uid}]에 대한 서비스정보를 찾을수 없습니다.");
}
$serverEntity = $this->getServerService()->getEntity($entity->getServerInfoUID());
if (!$serverEntity instanceof ServerEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: [{$entity->getServerInfoUID()}]에 대한 서버정보를 찾을수 없습니다.");
}
$amount = $this->getCalculatedAmount($entity, $serverEntity);
$entity = parent::modify($entity, ['amount' => $amount]);
//결제정보 수정
$this->getPaymentService()->updateForService($entity);
return $entity;
} }
//기본 기능부분 //기본 기능부분
//FieldForm관련용 //FieldForm관련용

View File

@ -189,6 +189,28 @@ class ServerPartService extends EquipmentService implements ServerPartInterface
} }
return $service; return $service;
} }
//결제관련처리
public function setAmount(ServerPartEntity $entity, string $callBack): ServerPartEntity
{
//기본처리
if ($entity->getBilling() === PAYMENT['BILLING']['BASE']) {
return $entity;
}
//월별과금용(서버->서비스정보 반영)
if ($entity->getBilling() === PAYMENT['BILLING']['MONTH']) {
$serverEntity = $this->getServerService()->getEntity($entity->getServerInfoUID());
if (!$serverEntity instanceof ServerEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServerInfoUID()} 서버 정보를 찾을수 없습니다.");
}
$this->getServerService()->setAmount($serverEntity);
}
//일회성용
if ($entity->getBilling() === PAYMENT['BILLING']['ONETIME']) {
$paymentEntity = $this->getPaymentService()->$callBack($entity);
$entity = $this->getModel()->modify($entity, ['payment_uid' => $paymentEntity->getPK()]);
}
return $entity;
}
//서버관련 작업 //서버관련 작업
public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): void
{ {
@ -253,7 +275,6 @@ class ServerPartService extends EquipmentService implements ServerPartInterface
$processor = new Proceessor( $processor = new Proceessor(
\Config\Database::connect(), \Config\Database::connect(),
$this, $this,
$this->getServiceService(),
$this->getServerService(), $this->getServerService(),
$this->getPaymentService(), $this->getPaymentService(),
$this->getIPService(), $this->getIPService(),
@ -268,7 +289,6 @@ class ServerPartService extends EquipmentService implements ServerPartInterface
$processor = new Proceessor( $processor = new Proceessor(
\Config\Database::connect(), \Config\Database::connect(),
$this, $this,
$this->getServiceService(),
$this->getServerService(), $this->getServerService(),
$this->getPaymentService(), $this->getPaymentService(),
$this->getIPService(), $this->getIPService(),
@ -283,7 +303,6 @@ class ServerPartService extends EquipmentService implements ServerPartInterface
$processor = new Proceessor( $processor = new Proceessor(
\Config\Database::connect(), \Config\Database::connect(),
$this, $this,
$this->getServiceService(),
$this->getServerService(), $this->getServerService(),
$this->getPaymentService(), $this->getPaymentService(),
$this->getIPService(), $this->getIPService(),

View File

@ -173,11 +173,9 @@ class ServerService extends EquipmentService implements ServerInterface
} }
return $rows; return $rows;
} }
//총 서버금액 설정() public function getCalculatedAmount(ServerEntity $entity): int
//기본:서버금액(price)+서버파트연결(월비용)
final public function getCalculatedAmount(ServerEntity $entity): int
{ {
$caculatedAmount = $entity->getPrice(); $caculatedAmount = $entity->getPrice();
//해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 합산한다. //해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 합산한다.
foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $serverPartEntity) { foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $serverPartEntity) {
if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { //월비용일때만 적용 if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { //월비용일때만 적용
@ -186,6 +184,20 @@ class ServerService extends EquipmentService implements ServerInterface
} }
return $caculatedAmount; return $caculatedAmount;
} }
//서비스금액관련처리
public function setAmount(ServerEntity $entity): ServerEntity
{
if ($entity->getServiceInfoUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다.");
}
//서비스정보 반영
$serviceEntity = $this->getServiceService()->getEntity($entity->getServiceInfoUID());
if (!$serviceEntity instanceof ServiceEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생: {$entity->getServiceInfoUID()} 서비스 정보를 찾을수 없습니다.");
}
$this->getServiceService()->setAmount($serviceEntity, $this->getCalculatedAmount($entity));
return $entity;
}
//Service관련 //Service관련
public function attachToService(ServiceEntity $serviceEntity, string $serverinfo_uid, array $formDatas = []): ServerEntity public function attachToService(ServiceEntity $serviceEntity, string $serverinfo_uid, array $formDatas = []): ServerEntity
{ {

View File

@ -121,7 +121,6 @@ class PaymentService extends CommonService implements PaymentInterface
} }
return $unPaids; return $unPaids;
} }
//Service관련(월과금)
//서비스생성 //서비스생성
public function createForService(ServiceEntity $serviceEntity): PaymentEntity public function createForService(ServiceEntity $serviceEntity): PaymentEntity
{ {