dbmsv3 init...1

This commit is contained in:
choi.jh 2025-10-28 11:11:12 +09:00
parent 48538d8ffb
commit 9793e1e1b9
10 changed files with 212 additions and 249 deletions

View File

@ -29,7 +29,7 @@ class ServerPartEntity extends EquipmentEntity
return $this->attributes['payment_uid'] ?? null; return $this->attributes['payment_uid'] ?? null;
} }
//기본기능용 //기본기능용
public function getTotalAmount(): int public function getCalulatedAmount(): int
{ {
return $this->getAmount() * $this->getCnt(); return $this->getAmount() * $this->getCnt();
} }

View File

@ -3,19 +3,18 @@
namespace App\Interfaces; namespace App\Interfaces;
use App\Entities\Customer\ServiceEntity; use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity; use App\Entities\Equipment\ServerPartEntity;
use App\Entities\PaymentEntity; use App\Entities\PaymentEntity;
interface PaymentInterface interface PaymentInterface
{ {
//서비스 결제(월과금 서비스 사용) //서비스 결제(월과금 서비스 사용)
public function createForService(ServiceEntity $service, int $amount): PaymentEntity; public function createForService(ServiceEntity $serviceEntity): PaymentEntity;
public function updateForService(ServiceEntity $service, string $payment_uid, int $amount): PaymentEntity; public function updateForService(ServiceEntity $serviceEntity): PaymentEntity;
public function unlinkFromService(string $payment_uid): PaymentEntity; public function unlinkFromService(ServiceEntity $serviceEntity): PaymentEntity;
//서버 파트 결제(파트/기타 일회성 서비스 사용) //서버 파트 결제(파트/기타 일회성 서비스 사용)
public function createForServerPart(ServerPartEntity $serverPart, int $amount): PaymentEntity; public function createForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity;
public function updateForServerPart(ServerPartEntity $serverPart, string $payment_uid, int $amount): PaymentEntity; public function updateForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity;
public function unlinkFromServerPart(string $payment_uid): PaymentEntity; public function unlinkFromServerPart(ServerPartEntity $serverPartEntity): PaymentEntity;
} }

View File

@ -38,11 +38,11 @@ class ServerPartModel extends EquipmentModel
} }
switch ($field) { switch ($field) {
case "serverinfo_uid": case "serverinfo_uid":
case "part_uid":
case "cnt": case "cnt":
case "amount": case "amount":
$rule = "required|numeric"; $rule = "required|numeric";
break; break;
case "part_uid":
case "clientinfo_uid": case "clientinfo_uid":
case "serviceinfo_uid": case "serviceinfo_uid":
case "payment_uid": case "payment_uid":

View File

@ -17,7 +17,7 @@ abstract class CommonProcessor
final protected function setLog(string $title, string $status, ?string $context = null): void final protected function setLog(string $title, string $status, ?string $context = null): void
{ {
$this->logService->create([ $this->logService->getModel()->create([
'title' => $title, 'title' => $title,
'status' => $status, 'status' => $status,
'context' => $context 'context' => $context

View File

@ -31,19 +31,18 @@ class ServiceV1Processor
$entity, $entity,
$entity->getServerInfoUID() $entity->getServerInfoUID()
); );
// 3) 금액 계산 + 반영 // 3) 금액 계산 + 결제정보반영
$amount = $this->service->getCalculatedAmount($entity, $serverEntity); $amount = $this->service->getCalculatedAmount($entity, $serverEntity);
$this->service->getModel()->modify($entity, ['amount' => $amount]); $this->service->getModel()->modify($entity, ['amount' => $amount]);
// 4) 결제 생성 $paymentEntity = $this->paymentService->createForService($entity);
$paymentEntity = $this->paymentService->createForService($entity, $amount); // 4) 서비스 FK 동기화
// 5) 서비스 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(), 'payment_uid' => $paymentEntity->getPK(),
]); ]);
// 6) 로그 // 6) 로그
$this->logService->create([ $this->logService->getModel()->create([
'title' => "{$entity->getTitle()} 서비스 추가", 'title' => "{$entity->getTitle()} 서비스 추가",
'status' => $entity->getStatus(), 'status' => $entity->getStatus(),
]); ]);
@ -68,19 +67,15 @@ class ServiceV1Processor
$entity, $entity,
$entity->getServerInfoUID() $entity->getServerInfoUID()
); );
// 3) 금액 재계산 + 반영 // 3) 금액 재계산 + 결제정보반영
$amount = $this->service->getCalculatedAmount($entity, $serverEntity); $entity = $this->service->setAmount($entity->getPK());
$this->service->getModel()->modify($entity, ['amount' => $amount]);
// 4) 결제 수정
$payment = $this->paymentService->updateForService($entity, $entity->getPaymentUID(), $amount);
// 5) 서비스 FK 동기화 // 5) 서비스 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' => $payment->getPK(),
]); ]);
// 6) 로그 // 6) 로그
$this->logService->create(formDatas: [ $this->logService->getModel()->create(formDatas: [
'title' => "{$entity->getTitle()} 서비스 수정", 'title' => "{$entity->getTitle()} 서비스 수정",
'status' => $entity->getStatus(), 'status' => $entity->getStatus(),
]); ]);
@ -96,7 +91,7 @@ class ServiceV1Processor
$this->db->transStart(); $this->db->transStart();
// 1) 결제 분리 // 1) 결제 분리
if ($entity->getPaymentUID()) { if ($entity->getPaymentUID()) {
$this->paymentService->unlinkFromService($entity->getPaymentUID()); $this->paymentService->unlinkFromService($entity);
} }
// 2) 연결된 모든 서버 해지 // 2) 연결된 모든 서버 해지
foreach ($this->serverService->getEntities($entity->getPK()) as $serverEntity) { foreach ($this->serverService->getEntities($entity->getPK()) as $serverEntity) {
@ -105,7 +100,7 @@ class ServiceV1Processor
// 3) 서비스 삭제 // 3) 서비스 삭제
$this->service->getModel()->delete($entity); $this->service->getModel()->delete($entity);
// 4) 로그 // 4) 로그
$this->logService->create([ $this->logService->getModel()->create([
'title' => "[{$entity->getTitle()}] 서비스 해지", 'title' => "[{$entity->getTitle()}] 서비스 해지",
'status' => $entity->getStatus(), 'status' => $entity->getStatus(),
]); ]);
@ -132,7 +127,7 @@ class ServiceV1Processor
] ]
); );
// 2) 로그 // 2) 로그
$this->logService->create([ $this->logService->getModel()->create([
'title' => "[{$entity->getTitle()}] 대체서버 추가", 'title' => "[{$entity->getTitle()}] 대체서버 추가",
'status' => $entity->getStatus(), 'status' => $entity->getStatus(),
]); ]);
@ -156,19 +151,15 @@ class ServiceV1Processor
$serverinfo_uid, $serverinfo_uid,
['type' => $serverEntity->getType()] ['type' => $serverEntity->getType()]
); );
// 3) 금액 재계산 + 반영 // 3) 금액 재계산 + 결제정보반영
$amount = $this->service->getCalculatedAmount($entity, $serverEntity); $entity = $this->service->setAmount($entity->getPK());
$this->service->getModel()->modify($entity, ['amount' => $amount]);
// 4) 결제 수정
$payment = $this->paymentService->updateForService($entity, $entity->getPaymentUID(), $amount);
// 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' => $payment->getPK(),
]); ]);
// 5) 로그 // 5) 로그
$this->logService->create([ $this->logService->getModel()->create([
'title' => "[{$entity->getTitle()}] 메인서버변경", 'title' => "[{$entity->getTitle()}] 메인서버변경",
'status' => $entity->getStatus(), 'status' => $entity->getStatus(),
]); ]);
@ -187,7 +178,7 @@ class ServiceV1Processor
$this->db->transStart(); $this->db->transStart();
$this->serverService->detachFromService($serverinfo_uid); $this->serverService->detachFromService($serverinfo_uid);
// 4) 로그 // 4) 로그
$this->logService->create([ $this->logService->getModel()->create([
'title' => "[{$entity->getTitle()}] 대체서버 해지", 'title' => "[{$entity->getTitle()}] 대체서버 해지",
'status' => $entity->getStatus(), 'status' => $entity->getStatus(),
]); ]);

View File

@ -3,12 +3,14 @@
namespace App\Processors\Equipment; namespace App\Processors\Equipment;
use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Services\Customer\ServiceService; 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;
use App\Services\Part\IPService; use App\Services\Part\IPService;
use App\Services\Part\SWITCHService; use App\Services\Part\SWITCHService;
use App\Services\PaymentService;
use CodeIgniter\Database\BaseConnection; use CodeIgniter\Database\BaseConnection;
use RuntimeException; use RuntimeException;
@ -16,41 +18,62 @@ class ServerPartV1Processor
{ {
public function __construct( public function __construct(
private BaseConnection $db, private BaseConnection $db,
private ServerService $service, private ServerPartService $service,
private ServiceService $serviceService, private ServiceService $serviceService,
private ServerPartService $serverPartService, private ServerService $serverService,
private PaymentService $paymentService,
private IPService $ipService, private IPService $ipService,
private SWITCHService $switchService, private SWITCHService $switchService,
private MyLogService $logService, private MyLogService $logService,
) {} ) {}
public function create(array $formDatas): ServerEntity public function create(array $formDatas): ServerPartEntity
{ {
$this->db->transStart(); $this->db->transStart();
//1) 서버정보 생성 //서버정보가져오기
//switch값이 없으면 null처리 if (!array_key_exists('serverinfo_uid', $formDatas)) {
if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) { throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다.");
$formDatas['switch'] = null;
} }
//ip값이 없으면 null처리 $serverEntity = $this->serverService->getEntity($formDatas['serverinfo_uid']);
if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) { if (!$serverEntity instanceof ServerEntity) {
$formDatas['ip'] = null; throw new \Exception(__METHOD__ . "에서 오류발생: {$formDatas['serverinfo_uid']} 서버 정보를 찾을수 없습니다.");
} }
//서비스정의확인(기본은 제외)
if ($formDatas['billing'] !== PAYMENT['BILLING']['BASE'] && $serverEntity->getServiceInfoUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생:서비스가 지정되어야 작업이 가능합니다.");
}
// 1) 생성작업
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
$entity = $this->service->getModel()->create($formDatas); $entity = $this->service->getModel()->create($formDatas);
//2) 서버의 Type별 서버파트정보등록(서버파트연결 자동등록용) // 2) Type에 따른 각 파트 정의
$this->serverPartService->attachToServer($entity); $this->service->getPartService($entity->getType())->attachToServerPart($entity);
//3) Switch가 정의되어 있으면 // 3) 과금정의
if ($entity->getSwitch() !== null) { // switch ($entity->getBilling()) {
$this->switchService->attachToServer($entity); 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) //IP가 정의되어 있으면 // 4) 로그
if ($entity->getIP() !== null) { $this->logService->getModel()->create(formDatas: [
$this->ipService->attachToServer($entity); 'title' => "{$entity->getTitle()} 서버파트 추가",
} 'status' => $entity->getStatus(),
//5) Log처리
$this->logService->create([
'title' => "[{$entity->getTitle()}] 서버 추가",
'status' => $entity->getStatus()
]); ]);
$this->db->transComplete(); $this->db->transComplete();
if ($this->db->transStatus() === false) { if ($this->db->transStatus() === false) {
@ -58,54 +81,63 @@ class ServerPartV1Processor
} }
return $entity; return $entity;
} }
public function modify(ServerEntity $entity, array $formDatas): ServerEntity public function modify(ServerPartEntity $entity, array $formDatas): ServerPartEntity
{ {
$this->db->transStart(); $this->db->transStart();
//1) 사전처리 작업 //서버정보가져오기
//Switch값이 정의되어 있으면 if (!array_key_exists('serverinfo_uid', $formDatas)) {
$formDatas['switch'] = null; //기본Switch 정보 유지 throw new \Exception(__METHOD__ . "에서 오류발생: 서버 정보가 지정되지 않았습니다.");
$isChangedSwitch = false; }
if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) { // 1) 수정전 정보
//기존 Switch값과 다르면 //파트값이 정의되어 있으면
if ($entity->getSwitch() != $formDatas['switch']) { $formDatas['part_uid'] = null; //null이면 기존정보 유지
//기존 Switch값이 있으면 해지 $isPartChanged = false;
if ($entity->getSwitch() != null) { if (array_key_exists('part_uid', $formDatas) && !$formDatas['part_uid']) {
$this->switchService->detachFromServer($entity); //기존파트값과 다르면
if ($entity->getPartUID() != $formDatas['part_uid']) {
//기존파트값이 있으면 해지
if ($entity->getPartUID() != null) {
$this->service->getPartService($entity->getType())->detachFromServerPart($entity);
} }
$isChangedSwitch = true; $isPartChanged = true;
} }
} }
//IP값이 정의되어 있으면 // 2) 서버연결정보 수정
$formDatas['ip'] = null; //기본IPh 정보 유지 $serverEntity = $this->serverService->getEntity($formDatas['serverinfo_uid']);
$isChangedIP = false; if (!$serverEntity instanceof ServerEntity) {
if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) { throw new \Exception(__METHOD__ . "에서 오류발생: {$formDatas['serverinfo_uid']} 서버 정보를 찾을수 없습니다.");
//기존 IP값과 다르면
if ($entity->getSwitch() != $formDatas['ip']) {
//기존 IP값이 있으면 해지
if ($entity->getIP() != null) {
$this->ipService->detachFromServer($entity);
}
$isChangedIP = true;
}
} }
//2) 서버정보 수정 $formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
$entity = $this->service->getModel()->modify($entity, $formDatas); $entity = $this->service->getModel()->modify($entity, $formDatas);
//3) Switch값이 있고 신규값인경우 // 3) Type에 따른 각 파트 정의
if ($entity->getSwitch() && $isChangedSwitch) { if ($isPartChanged) { //파트가 바뀐경우 추가작업
$this->switchService->attachToServer($entity); $this->service->getPartService($entity->getType())->attachToServerPart($entity);
} }
//3) IP값이 있고 신규값인경우 // 3) 과금정의
if ($entity->getIP() && $isChangedIP) { switch ($entity->getBilling()) {
$this->ipService->attachToServer($entity); 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;
} }
//5) 서비스금액 설정:서비스가 연결되어 있고 대체서버가 아니면, 서비스정보수정(청구액수정) // 4) 로그
if ($entity->getServiceInfoUID() !== null && $entity->getType() !== SERVER['TYPES']['ALTERNATIVE']) { $this->logService->getModel()->create(formDatas: [
$this->serviceService->setAmount($entity->getServiceInfoUID()); 'title' => "{$entity->getTitle()} 서버파트 수정",
} 'status' => $entity->getStatus(),
//5) Log처리
$this->logService->create([
'title' => "[{$entity->getTitle()}] 서버 정보변경",
'status' => $entity->getStatus()
]); ]);
$this->db->transComplete(); $this->db->transComplete();
if ($this->db->transStatus() === false) { if ($this->db->transStatus() === false) {
@ -114,23 +146,40 @@ class ServerPartV1Processor
return $entity; return $entity;
} }
public function delete(ServerEntity $entity): ServerEntity public function delete(ServerPartEntity $entity): ServerPartEntity
{ {
//서비스가 연결되어있거나 , 사용가능 상태가 아니면 삭제불가
if ($entity->getServiceInfoUID() !== null || $entity->getStatus() !== STATUS['AVAILABLE']) {
throw new \Exception("서비스중인 서버는 삭제하실수 없습니다.");
}
$this->db->transStart(); $this->db->transStart();
//기존 Switch값이 있으면 해지 // 1) 서버파트정보 삭제
if ($entity->getSwitch() != null) { $this->service->getModel()->delete($entity);
$this->switchService->detachFromServer($entity); // 2) 기존파트값이 있으면 해지
if ($entity->getPartUID() != null) {
$this->service->getPartService($entity->getType())->detachFromServerPart($entity);
} }
//기존 IP값이 있으면 해지 // 3) 과금처리
if ($entity->getIP() != null) { switch ($entity->getBilling()) {
$this->ipService->detachFromServer($entity); 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;
} }
//기존 서버파트 해지 // 4) 로그
$this->serverPartService->detachFromServer($entity); $this->logService->getModel()->create(formDatas: [
'title' => "{$entity->getTitle()} 서버파트 삭제",
'status' => $entity->getStatus(),
]);
$this->db->transComplete(); $this->db->transComplete();
if ($this->db->transStatus() === false) { if ($this->db->transStatus() === false) {
throw new RuntimeException('트랜잭션 실패'); throw new RuntimeException('트랜잭션 실패');

View File

@ -48,7 +48,7 @@ class ServerV1Processor
$this->ipService->attachToServer($entity); $this->ipService->attachToServer($entity);
} }
//5) Log처리 //5) Log처리
$this->logService->create([ $this->logService->getModel()->create([
'title' => "[{$entity->getTitle()}] 서버 추가", 'title' => "[{$entity->getTitle()}] 서버 추가",
'status' => $entity->getStatus() 'status' => $entity->getStatus()
]); ]);
@ -63,7 +63,7 @@ class ServerV1Processor
$this->db->transStart(); $this->db->transStart();
//1) 사전처리 작업 //1) 사전처리 작업
//Switch값이 정의되어 있으면 //Switch값이 정의되어 있으면
$formDatas['switch'] = null; //기본Switch 정보 유지 $formDatas['switch'] = null; //null이면 기존정보 유지
$isChangedSwitch = false; $isChangedSwitch = false;
if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) { if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) {
//기존 Switch값과 다르면 //기존 Switch값과 다르면
@ -76,7 +76,7 @@ class ServerV1Processor
} }
} }
//IP값이 정의되어 있으면 //IP값이 정의되어 있으면
$formDatas['ip'] = null; //기본IPh 정보 유지 $formDatas['ip'] = null; //null이면 기존정보 유지
$isChangedIP = false; $isChangedIP = false;
if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) { if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) {
//기존 IP값과 다르면 //기존 IP값과 다르면
@ -103,7 +103,7 @@ class ServerV1Processor
$this->serviceService->setAmount($entity->getServiceInfoUID()); $this->serviceService->setAmount($entity->getServiceInfoUID());
} }
//5) Log처리 //5) Log처리
$this->logService->create([ $this->logService->getModel()->create([
'title' => "[{$entity->getTitle()}] 서버 정보변경", 'title' => "[{$entity->getTitle()}] 서버 정보변경",
'status' => $entity->getStatus() 'status' => $entity->getStatus()
]); ]);

View File

@ -167,7 +167,7 @@ class ServiceService extends CustomerService
return $entity->getRack() + $entity->getLine() + $this->getServerService()->getCalculatedAmount($serverEntity) - $entity->getSale(); return $entity->getRack() + $entity->getLine() + $this->getServerService()->getCalculatedAmount($serverEntity) - $entity->getSale();
} }
//서비스금액변경 //서비스금액변경
public function setAmount(string $uid): PaymentEntity public function setAmount(string $uid): ServiceEntity
{ {
$entity = $this->getEntity($uid); $entity = $this->getEntity($uid);
if (!$entity instanceof ServiceEntity) { if (!$entity instanceof ServiceEntity) {
@ -178,9 +178,9 @@ class ServiceService extends CustomerService
throw new \Exception(__METHOD__ . "에서 오류발생: [{$entity->getServerInfoUID()}]에 대한 서버정보를 찾을수 없습니다."); throw new \Exception(__METHOD__ . "에서 오류발생: [{$entity->getServerInfoUID()}]에 대한 서버정보를 찾을수 없습니다.");
} }
$amount = $this->getCalculatedAmount($entity, $serverEntity); $amount = $this->getCalculatedAmount($entity, $serverEntity);
$entity = parent::modify($entity, ['amount' => $amount]);
//결제정보 수정 //결제정보 수정
return $this->getPaymentService()->updateForService($entity, $entity->getPaymentUID(), $amount); $this->getPaymentService()->updateForService($entity);
return parent::modify($entity, ['amount' => $amount]);
} }
//기본 기능부분 //기본 기능부분
//FieldForm관련용 //FieldForm관련용

View File

@ -18,6 +18,7 @@ use App\Services\Part\RAMService;
use App\Services\Part\SOFTWAREService; use App\Services\Part\SOFTWAREService;
use App\Services\Part\SWITCHService; use App\Services\Part\SWITCHService;
use App\Services\PaymentService; use App\Services\PaymentService;
use App\Processors\Equipment\ServerPartV1Processor as Proceessor;
class ServerPartService extends EquipmentService implements ServerPartInterface class ServerPartService extends EquipmentService implements ServerPartInterface
{ {
@ -255,127 +256,46 @@ class ServerPartService extends EquipmentService implements ServerPartInterface
//부품연결정보생성 //부품연결정보생성
public function create(array $formDatas): ServerPartEntity public function create(array $formDatas): ServerPartEntity
{ {
//서버정보가져오기 $processor = new Proceessor(
if (!array_key_exists('serverinfo_uid', $formDatas)) { \Config\Database::connect(),
throw new \Exception("서버 정보가 지정되지 않았습니다."); $this,
} $this->getServiceService(),
$serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']); $this->getServerService(),
if (!$serverEntity instanceof ServerEntity) { $this->getPaymentService(),
throw new \Exception("서버 정보가 지정되지 않았습니다."); $this->getIPService(),
} $this->getSwitchService(),
//서비스정의확인(기본은 제외) $this->getMylogService()
if ($formDatas['billing'] !== PAYMENT['BILLING']['BASE'] && $serverEntity->getServiceInfoUID() === null) { );
throw new \Exception(__METHOD__ . "에서 오류발생:{월,일회성 과금용은 서비스가 지정되어야 작업이 가능합니다."); return $processor->create($formDatas);
}
//생성작업
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
$entity = parent::create($formDatas);
//후처리작업
//Type에 따른 부품서비스 정의
$this->getPartService($entity->getType())->setServerPart($entity);
//서비스 및 결제정보 처리
switch ($entity->getBilling()) {
case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리
if ($entity->getServiceInfoUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생: 서비스정보가 정의된 후에만 가능합니다.");
}
//서비스 금액만 재계산변경
$this->getServiceService()->setAmount($entity->getServiceInfoUID());
break;
case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리
$paymentEntity = $this->getPaymentService()->createServerPart($entity);
//결제정보PK정의
$entity = parent::modify($entity, ['payment_uid' => $paymentEntity->getPK()]);
break;
case PAYMENT['BILLING']['BASE']: //기본처리
//아무처리 않함
break;
default:
throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다.");
// break;
}
//Log처리
$this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 서버파트정보 추가"]);
return $entity;
} }
//수정 //수정
public function modify(mixed $entity, array $formDatas): ServerPartEntity public function modify(mixed $entity, array $formDatas): ServerPartEntity
{ {
//서버정보가져오기 $processor = new Proceessor(
if (!array_key_exists('serverinfo_uid', $formDatas)) { \Config\Database::connect(),
throw new \Exception("서버 정보가 지정되지 않았습니다."); $this,
} $this->getServiceService(),
$serverEntity = $this->getServerService()->getEntity($formDatas['serverinfo_uid']); $this->getServerService(),
if (!$serverEntity instanceof ServerEntity) { $this->getPaymentService(),
throw new \Exception("서버 정보가 지정되지 않았습니다."); $this->getIPService(),
} $this->getSwitchService(),
//수정전 정보 $this->getMylogService()
$this->getPartService($entity->getType())->unsetServerPart($entity); );
//서버연결정보 수정 return $processor->modify($entity, $formDatas);
$formDatas["clientinfo_uid"] = $serverEntity->getClientInfoUID();
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
$entity = parent::modify($entity, $formDatas);
//후처리작업
//Type에 따른 부품서비스 정의
$this->getPartService($entity->getType())->setServerPart($entity);
//서비스 및 결제정보 처리
switch ($entity->getBilling()) {
case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리
if ($entity->getServiceInfoUID() !== null) { //서비스가 정의되어 있으면
//서비스 금액만 재계산변경
$this->getServiceService()->setAmount($entity->getServiceInfoUID());
}
break;
case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리
if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면
$paymentEntity = $this->getPaymentService()->modifyServerPart($entity);
//결제정보PK정의
$entity = parent::modify($entity, ['payment_uid' => $paymentEntity->getPK()]);
}
break;
case PAYMENT['BILLING']['BASE']: //기본처리
//아무처리 않함
break;
default:
throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다.");
// break;
}
//Log처리
$this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 서버파트정보 수정"]);
return $entity;
} }
//삭제 //삭제
public function delete(mixed $entity): ServerPartEntity public function delete(mixed $entity): ServerPartEntity
{ {
//Type에 따른 부품서비스 정의 $processor = new Proceessor(
$this->getPartService($entity->getType())->unsetServerPart($entity); \Config\Database::connect(),
//서버연결정보 식제 $this,
parent::delete($entity); $this->getServiceService(),
//서비스 및 결제정보 후처리작업 $this->getServerService(),
switch ($entity->getBilling()) { $this->getPaymentService(),
case PAYMENT['BILLING']['MONTH']: //월별과금일때만 처리 $this->getIPService(),
if ($entity->getServiceInfoUID() !== null) { //서비스가 정의되어 있으면 $this->getSwitchService(),
//서비스 금액만 재계산변경 $this->getMylogService()
$this->getServiceService()->setAmount($entity->getServiceInfoUID()); );
} return $processor->delete($entity);
break;
case PAYMENT['BILLING']['ONETIME']: //일회성일때만 처리
if ($entity->getPaymentUID() !== null) { //결제정보가 정의되어 있으면
$this->getPaymentService()->deleteServerPart($entity);
}
break;
case PAYMENT['BILLING']['BASE']: //기본처리
//아무처리 않함
break;
default:
throw new \Exception(__METHOD__ . "에서 오류발생:{$entity->getBilling()}은 지정되지 않은 결제방식입니다.");
// break;
}
//Log처리
$this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 서버파트정보 삭제"]);
return $entity;
} }
} }

View File

@ -123,7 +123,7 @@ class PaymentService extends CommonService implements PaymentInterface
} }
//Service관련(월과금) //Service관련(월과금)
//서비스생성 //서비스생성
public function createForService(ServiceEntity $serviceEntity, int $amount): PaymentEntity public function createForService(ServiceEntity $serviceEntity): PaymentEntity
{ {
$billingAt = new DateTimeImmutable($serviceEntity->getBillingAt(), new DateTimeZone('Asia/Tokyo')); $billingAt = new DateTimeImmutable($serviceEntity->getBillingAt(), new DateTimeZone('Asia/Tokyo'));
return $this->getModel()->create([ return $this->getModel()->create([
@ -131,17 +131,20 @@ class PaymentService extends CommonService implements PaymentInterface
'serviceinfo_uid' => $serviceEntity->getPK(), 'serviceinfo_uid' => $serviceEntity->getPK(),
'serverinfo_uid' => $serviceEntity->getServerInfoUID(), //서버정보 번호 'serverinfo_uid' => $serviceEntity->getServerInfoUID(), //서버정보 번호
'title' => sprintf('[%s] %s 서비스비용', $serviceEntity->getTitle(), $billingAt->format('Y년 n월')), 'title' => sprintf('[%s] %s 서비스비용', $serviceEntity->getTitle(), $billingAt->format('Y년 n월')),
'amount' => $amount, 'amount' => $serviceEntity->getAmount(),
'billing' => PAYMENT['BILLING']['MONTH'], 'billing' => PAYMENT['BILLING']['MONTH'],
'billing_at' => $billingAt->format('Y-m-d'), 'billing_at' => $billingAt->format('Y-m-d'),
]); ]);
} }
//서비스수정 //서비스수정
public function updateForService(ServiceEntity $serviceEntity, string $payment_uid, int $amount): PaymentEntity public function updateForService(ServiceEntity $serviceEntity): PaymentEntity
{ {
$paymentEntity = $this->getEntity($payment_uid); if ($serviceEntity->getPaymentUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생:서비스정보에 결제정보가 정의되지 않았습니다.");
}
$paymentEntity = $this->getEntity($serviceEntity->getPaymentUID());
if (!$paymentEntity instanceof PaymentEntity) { if (!$paymentEntity instanceof PaymentEntity) {
throw new \Exception("[{$payment_uid}]에 대한 결제정보를 찾을 수 없습니다."); throw new \Exception("[{$serviceEntity->getPaymentUID()}]에 대한 결제정보를 찾을 수 없습니다.");
} }
$billingAt = new DateTimeImmutable($serviceEntity->getBillingAt(), new DateTimeZone('Asia/Tokyo')); $billingAt = new DateTimeImmutable($serviceEntity->getBillingAt(), new DateTimeZone('Asia/Tokyo'));
return $this->getModel()->modify($paymentEntity, [ return $this->getModel()->modify($paymentEntity, [
@ -149,41 +152,40 @@ class PaymentService extends CommonService implements PaymentInterface
'serviceinfo_uid' => $serviceEntity->getPK(), 'serviceinfo_uid' => $serviceEntity->getPK(),
'serverinfo_uid' => $serviceEntity->getServerInfoUID(), 'serverinfo_uid' => $serviceEntity->getServerInfoUID(),
'title' => sprintf('[%s] %s 서비스비용', $serviceEntity->getTitle(), $billingAt->format('Y년 n월')), 'title' => sprintf('[%s] %s 서비스비용', $serviceEntity->getTitle(), $billingAt->format('Y년 n월')),
'amount' => $amount, 'amount' => $serviceEntity->getAmount(),
'billing' => PAYMENT['BILLING']['MONTH'], 'billing' => PAYMENT['BILLING']['MONTH'],
'billing_at' => $billingAt->format('Y-m-d'), 'billing_at' => $billingAt->format('Y-m-d'),
]); ]);
} }
//서비스해지 //서비스해지
public function unlinkFromService(string $payment_uid): PaymentEntity public function unlinkFromService(ServiceEntity $erviceEntity): PaymentEntity
{ {
$paymentEntity = $this->getEntity($payment_uid); $paymentEntity = $this->getEntity($erviceEntity->getPaymentUID());
if (!$paymentEntity instanceof PaymentEntity) { if (!$paymentEntity instanceof PaymentEntity) {
throw new \Exception("[{$payment_uid}]에 대한 결제정보를 찾을 수 없습니다."); throw new \Exception("[{$erviceEntity->getPaymentUID()}]에 대한 결제정보를 찾을 수 없습니다.");
} }
//서비스해지시에는 고객정보로 서비스금액을 전환 서비스정보 NULL처리
return $this->getModel()->modify($paymentEntity, [ return $this->getModel()->modify($paymentEntity, [
'serviceinfo_uid' => null, 'serviceinfo_uid' => null,
'serverinfo_uid' => null,
]); ]);
} }
//서버파트(일회성과금) //서버파트(일회성과금)
final public function createForServerPart(ServerPartEntity $serverPartEntity, int $amount): PaymentEntity public function createForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
{ {
$formDatas = []; $formDatas = [];
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
//서버연결정보 수정시에 필요함 //서버연결정보 수정시에 필요함
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
//타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다.
$formDatas['title'] = $serverPartEntity->getTitle(); $formDatas['title'] = $serverPartEntity->getTitle();
$formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt $formDatas['amount'] = $serverPartEntity->getCalulatedAmount(); //단가*cnt
$formDatas['billing'] = $serverPartEntity->getBilling(); $formDatas['billing'] = $serverPartEntity->getBilling();
//당일결체일로 설정 //당일결체일로 설정
$formDatas['billing_at'] = date("Y-m-d"); $formDatas['billing_at'] = date("Y-m-d");
return parent::create($formDatas); return parent::create($formDatas);
} }
final public function updateForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity public function updateForServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
{ {
if ($serverPartEntity->getPaymentUID() === null) { if ($serverPartEntity->getPaymentUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다."); throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다.");
@ -200,13 +202,12 @@ class PaymentService extends CommonService implements PaymentInterface
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
//서버연결정보 수정시에 필요함 //서버연결정보 수정시에 필요함
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
//타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다.
$formDatas['title'] = $serverPartEntity->getTitle(); $formDatas['title'] = $serverPartEntity->getTitle();
$formDatas['amount'] = $serverPartEntity->getTotalAmount(); //단가*cnt $formDatas['amount'] = $serverPartEntity->getCalulatedAmount(); //단가*cnt
$formDatas['billing'] = $serverPartEntity->getBilling(); $formDatas['billing'] = $serverPartEntity->getBilling();
return parent::modify($entity, $formDatas); return parent::modify($entity, $formDatas);
} }
final public function deleteServerPart(ServerPartEntity $serverPartEntity): void public function unlinkFromServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
{ {
if ($serverPartEntity->getPaymentUID() === null) { if ($serverPartEntity->getPaymentUID() === null) {
throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다."); throw new \Exception(__METHOD__ . "에서 오류발생:일회성서비스정보에 결제정보가 정의되지 않았습니다.");
@ -218,7 +219,10 @@ class PaymentService extends CommonService implements PaymentInterface
if ($entity->getStatus() === STATUS['PAID']) { if ($entity->getStatus() === STATUS['PAID']) {
throw new \Exception(__METHOD__ . "에서 오류발생:결제완료된 서비스는 수정할수 없습니다."); throw new \Exception(__METHOD__ . "에서 오류발생:결제완료된 서비스는 수정할수 없습니다.");
} }
parent::delete($entity); //서비스해지시에는 고객정보로 서비스금액을 전환 서비스정보 NULL처리
return $this->getModel()->modify($entity, [
'serviceinfo_uid' => null,
]);
} }
//Invoice 관련 //Invoice 관련