dbmsv4 init...3

This commit is contained in:
최준흠 2025-12-17 13:03:37 +09:00
parent 8349f3318b
commit 1eac94698f
5 changed files with 125 additions and 54 deletions

View File

@ -37,6 +37,10 @@ class ServerPartEntity extends EquipmentEntity
{
return $this->attributes['billing'];
}
public function getBillingAt(): string
{
return $this->attributes['billing_at'];
}
public function getAmount(): int
{
return $this->attributes['amount'];

View File

@ -173,7 +173,7 @@ class ServiceService extends CustomerService
return $date->format('Y-m-d');
}
// 서비스금액관련처리
private function saveAmount(ServiceEntity $entity): ServiceEntity
final public function updateAmount(ServiceEntity $entity): ServiceEntity
{
//총 서비스금액 구하기
$server_amount = service('equipment_serverservice')->getCalculatedAmount($entity->getServerInfoUID());
@ -187,13 +187,20 @@ class ServiceService extends CustomerService
}
return $entity;
}
final public function saveAmountByPK(int $uid): ServiceEntity
// 서비스금액관련처리
final public function updateBillingAt($uid, string $billing_at): ServiceEntity
{
$entity = $this->getEntity($uid);
if (!$entity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServiceEntity만 가능");
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:{$uid}에 해당하는 서비스정보를 찾을 수 업습니다.");
}
return $this->saveAmount($entity);
$entity->billing_at = $billing_at;
if (!$this->model->save($entity)) {
// 저장 실패 시 예외 처리
$errors = $this->model->errors();
throw new RuntimeException("금액 업데이트 중 DB 저장 오류: " . implode(', ', $errors));
}
return $entity;
}
//기본 기능부분
protected function getEntity_process(mixed $entity): ServiceEntity
@ -212,7 +219,7 @@ class ServiceService extends CustomerService
//서버정보 연결
service('equipment_serverservice')->attatchToService($entity, $entity->getServerInfoUID());
//서비스비용 설정
$entity = $this->saveAmount($entity);
$entity = $this->updateAmount($entity);
//결제정보 생성
service('paymentservice')->createByService($entity);
return $entity;
@ -231,7 +238,7 @@ class ServiceService extends CustomerService
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServiceEntity만 가능");
}
//신규 서비스 서버의 비용으로 재계산 서비스 금액 설정
$entity = $this->saveAmount($entity);
$entity = $this->updateAmount($entity);
//기존 서비스용 결제비용 과 신규 서버스용으로 결제비용이 다르면 수정
service('paymentservice')->modifyByService($oldEntity, $entity);
//서버정보 연결 신규서버로 변경

View File

@ -4,6 +4,7 @@ namespace App\Services\Equipment;
use App\DTOs\Equipment\ServerPartDTO;
use App\Entities\CommonEntity;
use App\Entities\Customer\ServiceEntity;
use App\Entities\Equipment\ServerEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Entities\Part\PartEntity;
@ -116,29 +117,68 @@ class ServerPartService extends EquipmentService
{
return $entity;
}
protected function create_process(array $formDatas): CommonEntity
private function getFormDatasForServerPart(array $formDatas): array
{
if (!array_key_exists('serverinfo_uid', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서버번호가 지정되지 않았습니다.");
}
if (!array_key_exists('type', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:부품형식이 지정되지 않았습니다.");
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 부품형식이 지정되지 않았습니다.");
}
if (!array_key_exists('billing', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 청구방법이 지정되지 않았습니다.");
}
//서버정보 가져오기
$serverEntity = service('equipment_serverservice')->getEntity($formDatas['serverinfo_uid']);
if (!$serverEntity instanceof ServerEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$formDatas['serverinfo_uid']}에 해당하는 서버정보을 찾을수 없습니다.");
}
//서비스정보 가져오기
$serviceEntity = null;
if ($serverEntity->getServiceInfoUID()) {
$serviceEntity = service('customer_serviceservice')->getEntity($serverEntity->getServiceInfoUID());
}
//각 파트정보 가져오기
$partEntity = $this->getPartService($formDatas['type'])->getEntity($formDatas['part_uid']);
//해당 파트정보 Title 설정용
if (!$serviceEntity instanceof ServiceEntity) {
}
//해당 파트정보에 고객번호,서비스번호 설정
$formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID();
//해당 파트정보의 Title을 서버파트정보의 Titlte 설정
$formDatas['title'] = $partEntity->getTitle();
//청구방식에 따른 결제일 설정
$formDatas['billing_at'] = null;
if ($formDatas['billing'] === PAYMENT['BILLING']['MONTH']) {
if (!$serviceEntity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 매월결제 상품은 서비스정보가 지정된 후 설정하실 수 있습니다.");
}
$formDatas['billing_at'] = $serviceEntity->getBillingAt();
} elseif ($formDatas['billing'] === PAYMENT['BILLING']['ONETIME']) {
if (!$serviceEntity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 매월결제 상품은 서비스정보가 지정된 후 설정하실 수 있습니다.");
}
$formDatas['billing_at'] = date("Y-m-d");
}
return array($serverEntity, $serviceEntity, $partEntity, $formDatas);
}
protected function create_process(array $formDatas): CommonEntity
{
//서버파트 생성
list($serverEntity, $serviceEntity, $partEntity, $formDatas) = $this->getFormDatasForServerPart($formDatas);
$entity = parent::create_process($formDatas);
if (!$entity instanceof ServerPartEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServerPartEntity만 가능");
}
//해당 파트별 설정 수정
//해당 파트정보를 서버파트정보에 추가
$this->getPartService($entity->getType())->attachToServerPart($entity);
//서비스가 정의 되어 있으면
if ($entity->getServiceInfoUID() !== null) {
if ($serviceEntity instanceof ServiceEntity) {
//Billing형식이 Month이면 서비스 금액설정 호출
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) {
service('customer_serviceservice')->saveAmountByPK($entity->getServiceInfoUID());
service('customer_serviceservice')->updateAmount($serviceEntity);
}
//Billing형식이 Onetime이면 일회성결제 추가
//Billing형식이 Onetime이면 일회성결제 생성
if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) {
service('paymentservice')->createByServerPart($entity);
}
@ -147,28 +187,28 @@ class ServerPartService extends EquipmentService
}
protected function modify_process($entity, array $formDatas): CommonEntity
{
if (!array_key_exists('type', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:부품형식이 지정되지 않았습니다.");
}
//각 파트정보 가져오기
$partEntity = $this->getPartService($formDatas['type'])->getEntity($formDatas['part_uid']);
//해당 파트정보 Title 설정용
$formDatas['title'] = $partEntity->getTitle();
list($serverEntity, $serviceEntity, $partEntity, $formDatas) = $this->getFormDatasForServerPart($formDatas);
//서버파트 수정
$oldEntity = clone $entity;
$entity = parent::modify_process($entity, $formDatas);
if (!$entity instanceof ServerPartEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
}
//서비스가 정의 되어 있으면
if ($entity->getServiceInfoUID() !== null) {
//월비용 서버파트 인경우 서비스 금액 재설정
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) {
service('customer_serviceservice')->saveAmountByPK($entity->getServiceInfoUID());
//해당 파트정보가 변경
if ($oldEntity->getPartUID() != $entity->getPartUID()) {
$this->getPartService($entity->getType())->detachFromServerPart($oldEntity);
$this->getPartService($entity->getType())->attachToServerPart($entity);
}
//서비스가 정의 되어 있으면
if ($serviceEntity instanceof ServiceEntity) {
//Billing형식이 Month이면 서비스 금액설정 호출
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) {
service('customer_serviceservice')->updateAmount($serviceEntity);
}
//Billing형식이 Onetime이면 일회성결제 수정
if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) {
service('paymentservice')->modifyByServerPart($oldEntity, $entity);
}
//Billing형식이 Onetime이면 일회성결제 수정 (필요없는듯 하여 주석처리)
// if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) {
// service('paymentservice')->modifyByServerPart($entity);
// }
}
return $entity;
}
@ -180,15 +220,14 @@ class ServerPartService extends EquipmentService
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
}
//서비스가 정의 되어 있으면
if ($entity->getServiceInfoUID() !== null) {
//월비용 서버파트 인경우 서비스 금액 재설정
if ($entity->getBilling() == PAYMENT['BILLING']['MONTH']) {
service('customer_serviceservice')->saveAmountByPK($entity->getServiceInfoUID());
if ($entity->getServiceInfoUID() !== null && $entity->getBilling() == PAYMENT['BILLING']['MONTH']) {
//서비스정보 가져오기
$serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUID());
if (!$serviceEntity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getServiceInfoUID()}에 해당하는 서비스정보를 찾을 수 없습니다.");
}
//Billing형식이 Onetime이면 일회성결제 수정 (필요없는듯 하여 주석처리)
// if ($entity->getBilling() == PAYMENT['BILLING']['ONETIME']) {
// service('paymentservice')->modifyByServerPart($entity);
// }
service('customer_serviceservice')->updateAmount($serviceEntity);
}
return $entity;
}

View File

@ -250,7 +250,11 @@ class ServerService extends EquipmentService
service('equipment_chassisservice')->attachToServer($entity);
}
if ($entity->getServiceInfoUID() !== null) { //서비스가 정의 되어 있으면
service('customer_serviceservice')->saveAmountByPK($entity->getServiceInfoUID());
$serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUID());
if (!$serviceEntity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getServiceInfoUID()}에 해당하는 서비스정보을 찾을수 없습니다.");
}
service('customer_serviceservice')->updateAmount($entity);
}
return $entity;
}

View File

@ -12,6 +12,7 @@ use App\Forms\PaymentForm;
use App\Helpers\PaymentHelper;
use App\Models\PaymentModel;
use App\Services\Customer\Wallet\WalletService;
use DateTime;
use RuntimeException;
@ -176,10 +177,10 @@ class PaymentService extends CommonService
}
//추가기능
//pay방식에따른 WalletService 등록
private function setWallet(PaymentEntity $entity): void
private function getWalletService($pay): WalletService
{
$walletService = null;
switch ($entity->getPay()) {
switch ($pay) {
case PAYMENT['PAY']['ACCOUNT']:
$walletService = service('customer_wallet_accountservice');
break;
@ -190,10 +191,10 @@ class PaymentService extends CommonService
$walletService = service('customer_wallet_pointservice');
break;
default:
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getPay()}는 지정되지 않은 지불방식입니다.");
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$pay}는 지정되지 않은 지불방식입니다.");
// break;
}
$walletService->withdrawalByPayment($entity);
return $walletService;
}
//일회성,선결제,쿠폰,포인트 입력 관련
protected function create_process(array $formDatas): PaymentEntity
@ -202,6 +203,9 @@ class PaymentService extends CommonService
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스가 정의되지 않았습니다.");
}
$serviceEntity = service('customer_serviceservice')->getEntity($formDatas['serviceinfo_uid']);
if (!$serviceEntity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$formDatas['serviceinfo_uid']}에 해당하는 서비스정보를 찾을 수 없습니다.");
}
$formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID();
$entity = parent::create_process($formDatas);
if (!$entity instanceof PaymentEntity) {
@ -209,11 +213,11 @@ class PaymentService extends CommonService
}
//지불이 완료된경우 지불처리
if ($entity->getStatus() === STATUS['PAID']) {
$this->setWallet($entity);
$this->getWalletService($entity->getPay())->withdrawalByPayment($entity);;
}
//선결제인경우 서비스정보에 결제일 변경용
if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) {
service('customer_serviceservice')->modify($entity->getServiceInfoUID(), ['billing_at' => $entity->getBillingAt()]);
service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt());
}
return $entity;
}
@ -223,6 +227,14 @@ class PaymentService extends CommonService
if ($entity->getStatus() === STATUS['PAID']) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 이미 지불된 결제정보는 수정이 불가합니다.");
}
if (!array_key_exists('serviceinfo_uid', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스가 정의되지 않았습니다.");
}
$serviceEntity = service('customer_serviceservice')->getEntity($formDatas['serviceinfo_uid']);
if (!$serviceEntity instanceof ServiceEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$formDatas['serviceinfo_uid']}에 해당하는 서비스정보를 찾을 수 없습니다.");
}
$formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUID();
//수정된 결제정보
$entity = parent::modify_process($entity, $formDatas);
if (!$entity instanceof PaymentEntity) {
@ -230,11 +242,11 @@ class PaymentService extends CommonService
}
//지불이 된경우 지불처리
if ($entity->getStatus() === STATUS['PAID']) {
$this->setWallet($entity);
$this->getWalletService($entity->getPay())->withdrawalByPayment($entity);;
}
//선결제인경우 서비스정보에 결제일 변경용
if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) {
service('customer_serviceservice')->modify($entity->getServiceInfoUID(), ['billing_at' => $entity->getBillingAt()]);
service('customer_serviceservice')->updateBillingAt($entity->getServiceInfoUID(), $entity->getBillingAt());
}
return $entity;
}
@ -315,7 +327,7 @@ class PaymentService extends CommonService
static::class . '->' . __FUNCTION__,
$this->model->getLastQuery() ?? "No Query Available",
));
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 기존 서비스정보의 {$oldServiceEntity->getPK()}에 해당하는 결제정보가 존재하지 않습니다.");
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 기존 서비스정보의 {$oldServiceEntity->getTitle()}에 해당하는 결제정보가 존재하지 않습니다.");
}
//신규 서비스정보에 맞게 수정
$formDatas = $this->getFormDatasFromService($serviceEntity);
@ -332,7 +344,7 @@ class PaymentService extends CommonService
$formDatas["clientinfo_uid"] = $serverPartEntity->getClientInfoUID();
$formDatas['amount'] = $serverPartEntity->getAmount();
$formDatas['billing'] = $formDatas['billing'] ?? PAYMENT['BILLING']['ONETIME'];
$formDatas['billing_at'] = date('Y-m-d');
$formDatas['billing_at'] = $serverPartEntity->getBillingAt();
$formDatas['pay'] = $formDatas['pay'] ?? PAYMENT['PAY']['ACCOUNT'];
$formDatas['status'] = $formDatas['status'] ?? STATUS['UNPAID'];
$formDatas['title'] = sprintf("%s 일회성비용", $formDatas['title'] ?? $serverPartEntity->getTitle());
@ -346,24 +358,29 @@ class PaymentService extends CommonService
$formDatas = $this->getFormDatasFromServerPart($serverPartEntity);
return parent::create_process($formDatas);
}
public function modifyByServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
public function modifyByServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity): PaymentEntity
{
if ($serverPartEntity->getServiceInfoUID() === null) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보가 정의되지 않아 일회성 상품을 설정하실수 없습니다.");
}
//서버파트정보의 서비스번호가 같고, 청구방식이 onetime이고 상태가 UNPAID인 결제정보 가져와서 결제정보 수정
$entity = $this->getEntity([
'serverpartinfo_uid' => $serverPartEntity->getPK(),
'serviceinfo_uid' => $serverPartEntity->getServiceInfoUID(),
'serverpartinfo_uid' => $oldServerPartEntity->getPK(),
'serviceinfo_uid' => $oldServerPartEntity->getServiceInfoUID(),
'billing' => PAYMENT['BILLING']['ONETIME'],
'billing_at' => $oldServerPartEntity->getBillingAt(),
'status' => STATUS['UNPAID']
]);
if (!$entity instanceof PaymentEntity) {
$entity = $this->createByServerPart($serverPartEntity);
} else {
if (!$entity instanceof PaymentEntity) { //해당조건에 맞는게 없으면 생성
log_message('error', sprintf(
"\n------Last Query (%s)-----\nQuery: %s\n------------------------------\n",
static::class . '->' . __FUNCTION__,
$this->model->getLastQuery() ?? "No Query Available",
));
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 기존 서버파트정보의 {$oldServerPartEntity->getTitle()}에 해당하는 결제정보가 존재하지 않습니다.");
}
$formDatas = $this->getFormDatasFromServerPart($serverPartEntity);
$entity = parent::modify_process($entity, $formDatas);
}
return $entity;
}
}