102 lines
5.3 KiB
PHP
102 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Payment;
|
|
|
|
use App\Entities\Customer\ServiceEntity;
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Entities\PaymentEntity;
|
|
use App\Interfaces\Equipment\ServerPartInterface;
|
|
use App\Services\Equipment\ServerPartService;
|
|
use App\Services\PaymentService;
|
|
|
|
class ServerPart extends PaymentService implements ServerPartInterface
|
|
{
|
|
private ?ServerPartService $_serverPartService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
final public function getServerPartService(): ServerPartService
|
|
{
|
|
if (!$this->_serverPartService) {
|
|
$this->_serverPartService = new ServerPartService();
|
|
}
|
|
return $this->_serverPartService;
|
|
}
|
|
|
|
//월과금은 해당 서비스의 항목별 금액을 총 합산후 청구금액을 설정후 결제정보에 신규등록/수정한다
|
|
private function serverPart_process_month(ServiceEntity $serviceEntity, ServerPartEntity $serverPartEntity): ServiceEntity
|
|
{
|
|
//월비용인경우 서비스 제공가에 서버연결정보 제공가 합산금액으로 설정
|
|
$serviceFormDatas = [];
|
|
$serviceFormDatas['serverinfo_uid'] = $serviceEntity->getServerInfoUID();
|
|
$serviceFormDatas['billing_at'] = $serviceEntity->getBillingAt();
|
|
//해당 서비스(서버) 관련 경제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 수정한다.
|
|
$serviceFormDatas['amount'] = $serviceEntity->getServerEntity()->getPrice(); //서버금액(price)
|
|
//월과금용 ServerPartEntity의 금액을 모두 총합산한 금액을 설정한다.
|
|
foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $serviceEntity->getServerInfoUID()]) as $serverPartEntity) {
|
|
$serviceFormDatas['amount'] += $serverPartEntity->getAmount();
|
|
}
|
|
return $this->getServiceService()->modify($serviceEntity, $serviceFormDatas);
|
|
}
|
|
private function serverPart_process(ServerPartEntity $serverPartEntity, array $formDatas = []): array
|
|
{
|
|
//Service Entity 가져오기
|
|
$serviceEntity = $this->getServiceService()->getEntity($serverPartEntity->getServiceInfoUID());
|
|
if (!$serviceEntity) {
|
|
throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다.");
|
|
}
|
|
|
|
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
|
|
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
|
|
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); //서버연결정보 수정시에 필요함
|
|
$formDatas['serverpartinfo_uid'] = $serverPartEntity->getPK();
|
|
//타이틀은 기타의 경우 직접작성한 제목을 등록하고 아닌경우는 Part의 Title을 사용한다.
|
|
$formDatas['title'] = $serverPartEntity->getType() === 'ETC' ? $serverPartEntity->getTitle() : $serverPartEntity->getPartEntity()->getTitle();
|
|
$formDatas['amount'] = $serverPartEntity->getAmount();
|
|
$formDatas['billing'] = $serverPartEntity->getBilling();
|
|
//월과금인경우
|
|
if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) {
|
|
//결제일설정
|
|
$formDatas['billing_at'] = $serviceEntity->getBillingAt();
|
|
$this->serverPart_process_month($serviceEntity, $serverPartEntity);
|
|
}
|
|
//일회성인경우
|
|
if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME']) {
|
|
//당일결체일로 설정
|
|
$formDatas['billing_at'] = date("Y-m-d");
|
|
}
|
|
return $formDatas;
|
|
}
|
|
public function createServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas = []): ServerPartEntity
|
|
{
|
|
if ($serverPartEntity->getServiceInfoUID() === null) {
|
|
throw new \Exception(lang("{$this->getClassName()}.BILLING." . PAYMENT['BILLING']['MONTH']) . "지급 상품은 서비스정보가 정의된 후에만 가능합니다.");
|
|
}
|
|
//Service Entity 가져오기
|
|
$serviceEntity = $this->getServiceService()->getEntity($serverPartEntity->getServiceInfoUID());
|
|
if (!$serviceEntity) {
|
|
throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다.");
|
|
}
|
|
//기본 처리 후 FormData 가져오기
|
|
$formDatas = $this->serverPart_process($serverPartEntity);
|
|
//결제정보등록
|
|
$this->create($formDatas);
|
|
return $serverPartEntity;
|
|
}
|
|
public function modifyServerPart(ServerPartEntity $serverPartEntity, array $serverPartDatas = []): ServerPartEntity
|
|
{
|
|
//serverpartinfo_uid에 해당하는 결제정보 가져오기
|
|
$entity = $this->getEntity(['serverpartinfo_uid' => $serverPartEntity->getPK(), 'status' => STATUS['UNPAID']]);
|
|
if (!$entity instanceof PaymentEntity) {
|
|
throw new \Exception(__METHOD__ . "에서 오류발생: {$serverPartEntity->getPK()}에 해당하는 결제정보를 찾을수 없습니다.");
|
|
}
|
|
//기본 처리 후 FormData 가져오기
|
|
$formDatas = $this->serverPart_process($serverPartEntity);
|
|
//결제수정등록
|
|
$this->modify($entity, $formDatas);
|
|
return $serverPartEntity;
|
|
}
|
|
}
|