78 lines
4.7 KiB
PHP
78 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Payment;
|
|
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Entities\PaymentEntity;
|
|
use App\Interfaces\Equipment\ServerPartInterface;
|
|
use App\Services\PaymentService;
|
|
|
|
class ServicePart extends PaymentService implements ServerPartInterface
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
//서버연결정보용 등록
|
|
public function setServerPart(string $action, ServerPartEntity $serverPartEntity, array $serverPartDatas = []): ServerPartEntity
|
|
{
|
|
$formDatas = [];
|
|
switch ($serverPartEntity->getBilling()) {
|
|
case PAYMENT['BILLING']['MONTH']:
|
|
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()}]에 대한 서비스정보를 찾을수 없습니다.");
|
|
}
|
|
//월비용인경우 서비스 제공가에 서버연결정보 제공가 합산금액으로 설정
|
|
if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) {
|
|
$formDatas['serverinfo_uid'] = $serviceEntity->getServerInfoUID();
|
|
$formDatas['billing_at'] = $serviceEntity->getBillingAt();
|
|
$formDatas['amount'] = $serviceEntity->getAmount() + $serverPartEntity->getAmount();
|
|
$this->getServiceService()->modify($serviceEntity, $formDatas);
|
|
}
|
|
break;
|
|
case PAYMENT['BILLING']['ONETIME']:
|
|
if ($serverPartEntity->getServiceInfoUID() === null) {
|
|
throw new \Exception(lang("{$this->getClassName()}.BILLING." . PAYMENT['BILLING']['ONETIME']) . "지급 상품은 서비스정보가 정의된 후에만 가능합니다.");
|
|
}
|
|
//Service Entity 가져오기
|
|
$serviceEntity = $this->getServiceService()->getEntity($serverPartEntity->getServiceInfoUID());
|
|
if (!$serviceEntity) {
|
|
throw new \Exception("[{$serverPartEntity->getServiceInfoUID()}]에 대한 서비스정보를 찾을수 없습니다.");
|
|
}
|
|
//일회성인경우
|
|
if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME']) {
|
|
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
|
|
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
|
|
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
|
|
$formDatas['serverpartinfo_uid'] = $serverPartEntity->getPK();
|
|
$formDatas['title'] = $serverPartEntity->getType() === 'ETC' ? $serverPartEntity->getTitle() : $serverPartEntity->getPartEntity()->getTitle();
|
|
$formDatas['amount'] = $serverPartEntity->getAmount();
|
|
$formDatas['billing'] = $serverPartEntity->getBilling();
|
|
$formDatas['billing_at'] = $serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME'] ? date("Y-m-d") : $serviceEntity->getBillingAT();
|
|
if ($action === 'create') {
|
|
//지급기한일 설정
|
|
$formDatas['billing_at'] = $serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME'] ? date("Y-m-d") : $serviceEntity->getBillingAT();
|
|
$this->create($formDatas);
|
|
}
|
|
if ($action === 'modify') {
|
|
if (!array_key_exists('serverpartinfo_uid', $formDatas)) {
|
|
throw new \Exception(__METHOD__ . "에서 오류발생: 기존 결제정보가 지정되지 않았습니다.");
|
|
}
|
|
$entity = $this->getEntity(['serverpartinfo_uid' => $serverPartEntity->getPK(), 'status' => STATUS['UNPAID']]);
|
|
if (!$entity instanceof PaymentEntity) {
|
|
throw new \Exception(__METHOD__ . "에서 오류발생: {$serverPartEntity->getPK()}에 해당하는 결제정보를 찾을수 없습니다.");
|
|
}
|
|
$this->modify($entity, $formDatas);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return $serverPartEntity;
|
|
}
|
|
}
|