dbmsv4 init...5
This commit is contained in:
parent
c95b8c8dac
commit
26ad454d1d
@ -185,10 +185,9 @@ class ServerPartService extends EquipmentService
|
|||||||
}
|
}
|
||||||
|
|
||||||
//서버추가시 기본파트 자동추가용
|
//서버추가시 기본파트 자동추가용
|
||||||
public function attachToServer(ServerEntity $serverEntity): void
|
public function initToServer(ServerEntity $serverEntity): void
|
||||||
{
|
{
|
||||||
$chassisEntity = service("equipment_chassisservice")->getEntity($serverEntity->getChassisInfoUid());
|
$chassisEntity = service("equipment_chassisservice")->getEntity($serverEntity->getChassisInfoUid());
|
||||||
|
|
||||||
foreach (SERVERPART['SERVER_PARTTYPES'] as $parttype) {
|
foreach (SERVERPART['SERVER_PARTTYPES'] as $parttype) {
|
||||||
$uid_function = "get{$parttype}InfoUid";
|
$uid_function = "get{$parttype}InfoUid";
|
||||||
$cnt_function = "get{$parttype}Cnt";
|
$cnt_function = "get{$parttype}Cnt";
|
||||||
|
|||||||
@ -114,21 +114,27 @@ class ServerService extends EquipmentService
|
|||||||
return $caculatedAmount;
|
return $caculatedAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//서버관련 정보가 변경되었을때 호출(금액이나,서버파트정보가 변경되었을때)
|
||||||
public function recalcAmount(ServerEntity $entity): void
|
public function recalcAmount(ServerEntity $entity): void
|
||||||
{
|
{
|
||||||
if ($entity->getServiceInfoUid()) {
|
if (!$entity->getServiceInfoUid()) {
|
||||||
$serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUid());
|
return;
|
||||||
if (!$serviceEntity instanceof ServiceEntity) {
|
|
||||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getServiceInfoUid()} 서비스정보를 찾을수 없습니다.");
|
|
||||||
}
|
|
||||||
// ✅ 핵심 추가: 서비스금액 변경 및 payment Sync용
|
|
||||||
if ($serviceEntity->getServerInfoUid() === $entity->getServiceInfoUid()) {
|
|
||||||
$oldServiceEntity = clone $serviceEntity;
|
|
||||||
$serviceEntity = service('customer_serviceservice')->recalcAmount($serviceEntity);
|
|
||||||
//결제비 설정
|
|
||||||
service('paymentservice')->modifyByService($oldServiceEntity, $serviceEntity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$serviceEntity = service('customer_serviceservice')->getEntity($entity->getServiceInfoUid());
|
||||||
|
if (!$serviceEntity instanceof ServiceEntity) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getServiceInfoUid()} 서비스정보를 찾을수 없습니다."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//해당 서비스의 메인서버가 아닌경우 변경없음
|
||||||
|
if ($serviceEntity->getServerInfoUid() !== $entity->getPK()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//서비스의 금액을 변경
|
||||||
|
$oldServiceEntity = clone $serviceEntity;
|
||||||
|
$serviceEntity = service('customer_serviceservice')->recalcAmount($serviceEntity);
|
||||||
|
//서비스의 금액을 변경 적용 후 결제정보를 sync하기 위해
|
||||||
|
service('paymentservice')->modifyByService($oldServiceEntity, $serviceEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function create_process(array $formDatas): ServerEntity
|
protected function create_process(array $formDatas): ServerEntity
|
||||||
@ -144,7 +150,7 @@ class ServerService extends EquipmentService
|
|||||||
service('part_switchservice')->attachToServer($entity);
|
service('part_switchservice')->attachToServer($entity);
|
||||||
}
|
}
|
||||||
service('equipment_chassisservice')->attachToServer($entity);
|
service('equipment_chassisservice')->attachToServer($entity);
|
||||||
service('equipment_serverpartservice')->attachToServer($entity);
|
service('equipment_serverpartservice')->initToServer($entity);
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -193,11 +193,13 @@ class PaymentService extends CommonService
|
|||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
//서비스관련
|
// ------------------------------
|
||||||
|
// 서비스정보 기준 월 결제 관련
|
||||||
|
// ------------------------------
|
||||||
private function getFormDatasFromService(ServiceEntity $serviceEntity, array $formDatas = []): array
|
private function getFormDatasFromService(ServiceEntity $serviceEntity, array $formDatas = []): array
|
||||||
{
|
{
|
||||||
$formDatas['serviceinfo_uid'] = $serviceEntity->getPK();
|
$formDatas['serviceinfo_uid'] = $serviceEntity->getPK();
|
||||||
$formDatas["clientinfo_uid"] = $serviceEntity->getClientInfoUid();
|
$formDatas['clientinfo_uid'] = $serviceEntity->getClientInfoUid();
|
||||||
$formDatas['amount'] = $serviceEntity->getAmount();
|
$formDatas['amount'] = $serviceEntity->getAmount();
|
||||||
$formDatas['billing'] = $formDatas['billing'] ?? PAYMENT['BILLING']['MONTH'];
|
$formDatas['billing'] = $formDatas['billing'] ?? PAYMENT['BILLING']['MONTH'];
|
||||||
$formDatas['billing_at'] = $serviceEntity->getBillingAt();
|
$formDatas['billing_at'] = $serviceEntity->getBillingAt();
|
||||||
@ -208,87 +210,166 @@ class PaymentService extends CommonService
|
|||||||
$formDatas['title'] ?? $serviceEntity->getTitle(),
|
$formDatas['title'] ?? $serviceEntity->getTitle(),
|
||||||
DateTime::createFromFormat('Y-m-d', $formDatas['billing_at'])->format('Y년 m월')
|
DateTime::createFromFormat('Y-m-d', $formDatas['billing_at'])->format('Y년 m월')
|
||||||
);
|
);
|
||||||
|
|
||||||
return $formDatas;
|
return $formDatas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getPaymentEntityByService(ServiceEntity $serviceEntity): ?PaymentEntity
|
||||||
|
{
|
||||||
|
$entity = $this->getEntity([
|
||||||
|
'serviceinfo_uid' => $serviceEntity->getPK(),
|
||||||
|
'billing' => PAYMENT['BILLING']['MONTH'],
|
||||||
|
'billing_at' => $serviceEntity->getBillingAt(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($entity === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$entity instanceof PaymentEntity) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 PaymentEntity만 가능"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 서비스 기준 결제정보 생성/수정 공통 처리
|
||||||
|
* - 기존 결제정보가 있으면 수정
|
||||||
|
* - 없으면 생성
|
||||||
|
* - 조회는 존재 여부 기준
|
||||||
|
* - status는 조회 후 수정 가능 여부 판단
|
||||||
|
*/
|
||||||
|
private function saveProcessByService(ServiceEntity $targetServiceEntity, ServiceEntity $serviceEntity): PaymentEntity
|
||||||
|
{
|
||||||
|
$entity = $this->getPaymentEntityByService($targetServiceEntity);
|
||||||
|
$formDatas = $this->getFormDatasFromService($serviceEntity);
|
||||||
|
|
||||||
|
if ($entity === null) {
|
||||||
|
return parent::create_process($formDatas);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($entity->getStatus() !== STATUS['UNPAID']) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
static::class . '->' . __FUNCTION__ . "에서 오류발생: 이미 생성된 결제정보가 있으며 수정 가능한 상태가 아닙니다."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::modify_process($entity, $formDatas);
|
||||||
|
}
|
||||||
|
|
||||||
public function createByService(ServiceEntity $serviceEntity): PaymentEntity
|
public function createByService(ServiceEntity $serviceEntity): PaymentEntity
|
||||||
{
|
{
|
||||||
$formDatas = $this->getFormDatasFromService($serviceEntity);
|
return $this->saveProcessByService($serviceEntity, $serviceEntity);
|
||||||
return $this->create_process($formDatas);
|
|
||||||
}
|
}
|
||||||
//서비스정보로 결제정보 생성 또는 수정 (일반 운영용: upsert 유지)
|
|
||||||
public function modifyByService(ServiceEntity $oldServiceEntity, ServiceEntity $serviceEntity): PaymentEntity
|
public function modifyByService(ServiceEntity $oldServiceEntity, ServiceEntity $serviceEntity): PaymentEntity
|
||||||
{
|
{
|
||||||
$entity = $this->getEntity([
|
return $this->saveProcessByService($oldServiceEntity, $serviceEntity);
|
||||||
'serviceinfo_uid' => $oldServiceEntity->getPK(),
|
|
||||||
'billing' => PAYMENT['BILLING']['MONTH'],
|
|
||||||
'billing_at' => $oldServiceEntity->getBillingAt(),
|
|
||||||
'status' => STATUS['UNPAID']
|
|
||||||
]);
|
|
||||||
if (!$entity instanceof PaymentEntity) {
|
|
||||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 ServiceEntity만 가능");
|
|
||||||
}
|
|
||||||
//매칭되는게 있으면(기존 서비스인경우) 아니면 신규등록
|
|
||||||
$formDatas = $this->getFormDatasFromService($serviceEntity);
|
|
||||||
return $this->modify_process($entity, $formDatas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//서버파트별 일회성 관련
|
// ------------------------------
|
||||||
|
// 서버파트 기준 일회성 결제 관련
|
||||||
|
// ------------------------------
|
||||||
private function getFormDatasFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): array
|
private function getFormDatasFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): array
|
||||||
{
|
{
|
||||||
if ($serverPartEntity->getServiceInfoUid() === null) {
|
if ($serverPartEntity->getServiceInfoUid() === null) {
|
||||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보가 정의되지 않아 일회성 상품을 설정하실수 없습니다.");
|
throw new RuntimeException(
|
||||||
|
static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보가 정의되지 않아 일회성 상품을 설정하실수 없습니다."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUid();
|
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUid();
|
||||||
$formDatas["clientinfo_uid"] = $serverPartEntity->getClientInfoUid();
|
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUid();
|
||||||
$formDatas["serverpartinfo_uid"] = $serverPartEntity->getPK();
|
$formDatas['serverpartinfo_uid'] = $serverPartEntity->getPK();
|
||||||
$formDatas['amount'] = $serverPartEntity->getCalculatedAmount();
|
$formDatas['amount'] = $serverPartEntity->getCalculatedAmount();
|
||||||
$formDatas['billing'] = $formDatas['billing'] ?? PAYMENT['BILLING']['ONETIME'];
|
$formDatas['billing'] = $formDatas['billing'] ?? PAYMENT['BILLING']['ONETIME'];
|
||||||
$formDatas['billing_at'] = $serverPartEntity->getBillingAt();
|
$formDatas['billing_at'] = $serverPartEntity->getBillingAt();
|
||||||
$formDatas['pay'] = $formDatas['pay'] ?? PAYMENT['PAY']['ACCOUNT'];
|
$formDatas['pay'] = $formDatas['pay'] ?? PAYMENT['PAY']['ACCOUNT'];
|
||||||
$formDatas['status'] = $formDatas['status'] ?? STATUS['UNPAID'];
|
$formDatas['status'] = $formDatas['status'] ?? STATUS['UNPAID'];
|
||||||
$formDatas['title'] = sprintf("%s 일회성비용", $formDatas['title'] ?? $serverPartEntity->getCustomTitle());
|
$formDatas['title'] = sprintf(
|
||||||
|
"%s 일회성비용",
|
||||||
|
$formDatas['title'] ?? $serverPartEntity->getCustomTitle()
|
||||||
|
);
|
||||||
|
|
||||||
return $formDatas;
|
return $formDatas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getPaymentEntityByServerPart(ServerPartEntity $serverPartEntity): ?PaymentEntity
|
||||||
|
{
|
||||||
|
$entity = $this->getEntity([
|
||||||
|
'serverpartinfo_uid' => $serverPartEntity->getPK(),
|
||||||
|
'serviceinfo_uid' => $serverPartEntity->getServiceInfoUid(),
|
||||||
|
'billing' => PAYMENT['BILLING']['ONETIME'],
|
||||||
|
'billing_at' => $serverPartEntity->getBillingAt(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($entity === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$entity instanceof PaymentEntity) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 PaymentEntity만 가능"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 서버파트 기준 결제정보 생성/수정 공통 처리
|
||||||
|
* - 기존 결제정보가 있으면 수정
|
||||||
|
* - 없으면 생성
|
||||||
|
* - 조회는 존재 여부 기준
|
||||||
|
* - status는 조회 후 수정 가능 여부 판단
|
||||||
|
*/
|
||||||
|
private function saveProcessByServerPart(ServerPartEntity $targetServerPartEntity, ServerPartEntity $serverPartEntity): PaymentEntity
|
||||||
|
{
|
||||||
|
$entity = $this->getPaymentEntityByServerPart($targetServerPartEntity);
|
||||||
|
$formDatas = $this->getFormDatasFromServerPart($serverPartEntity);
|
||||||
|
|
||||||
|
if ($entity === null) {
|
||||||
|
return parent::create_process($formDatas);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($entity->getStatus() !== STATUS['UNPAID']) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
static::class . '->' . __FUNCTION__ . "에서 오류발생: 이미 생성된 서버파트 결제정보가 있으며 수정 가능한 상태가 아닙니다."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::modify_process($entity, $formDatas);
|
||||||
|
}
|
||||||
|
|
||||||
public function createByServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
|
public function createByServerPart(ServerPartEntity $serverPartEntity): PaymentEntity
|
||||||
{
|
{
|
||||||
$formDatas = $this->getFormDatasFromServerPart($serverPartEntity);
|
return $this->saveProcessByServerPart($serverPartEntity, $serverPartEntity);
|
||||||
return parent::create_process($formDatas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function modifyByServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity): PaymentEntity
|
public function modifyByServerPart(ServerPartEntity $oldServerPartEntity, ServerPartEntity $serverPartEntity): PaymentEntity
|
||||||
{
|
{
|
||||||
$entity = $this->getEntity([
|
return $this->saveProcessByServerPart($oldServerPartEntity, $serverPartEntity);
|
||||||
'serverpartinfo_uid' => $oldServerPartEntity->getPK(),
|
|
||||||
'serviceinfo_uid' => $oldServerPartEntity->getServiceInfoUid(),
|
|
||||||
'billing' => $oldServerPartEntity->getBilling(),
|
|
||||||
'billing_at' => $oldServerPartEntity->getBillingAt(),
|
|
||||||
'status' => STATUS['UNPAID']
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!$entity instanceof PaymentEntity) {
|
|
||||||
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 기존 서버파트정보의 {$oldServerPartEntity->getTitle()}에 해당하는 결제정보가 존재하지 않습니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$formDatas = $this->getFormDatasFromServerPart($serverPartEntity);
|
|
||||||
return parent::modify_process($entity, $formDatas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ 서비스 해지(서버 분리) 시: 월비용 파트정보는 고객만 연결
|
/**
|
||||||
|
* 서비스 해지(서버 분리) 시: 월비용 파트정보는 고객만 연결
|
||||||
|
*/
|
||||||
public function terminateByServerPart(ServiceEntity $oldServiceEntity): void
|
public function terminateByServerPart(ServiceEntity $oldServiceEntity): void
|
||||||
{
|
{
|
||||||
$entity = $this->getEntity([
|
$entity = $this->getPaymentEntityByService($oldServiceEntity);
|
||||||
'serviceinfo_uid' => $oldServiceEntity->getPK(),
|
|
||||||
'billing' => PAYMENT['BILLING']['MONTH'],
|
|
||||||
'billing_at' => $oldServiceEntity->getBillingAt(),
|
|
||||||
'status' => STATUS['UNPAID'],
|
|
||||||
]);
|
|
||||||
if (!$entity instanceof PaymentEntity) {
|
if (!$entity instanceof PaymentEntity) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//매칭되는게 있으면(기존 파트정보서비스인경우)
|
|
||||||
|
if ($entity->getStatus() !== STATUS['UNPAID']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
parent::modify_process($entity, ['status' => STATUS['TERMINATED']]);
|
parent::modify_process($entity, ['status' => STATUS['TERMINATED']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user