121 lines
4.1 KiB
PHP
121 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Customer;
|
|
|
|
use App\Entities\Customer\ServiceItemEntity;
|
|
use App\Entities\Equipment\Part\IpEntity;
|
|
use App\Models\Customer\ServiceItemModel;
|
|
use App\Services\Customer\CustomerService;
|
|
use App\Services\Customer\ServicePaymentService;
|
|
use App\Services\Customer\ServiceService;
|
|
use App\Services\Equipment\Part\IpService;
|
|
|
|
class ServiceItemService extends CustomerService
|
|
{
|
|
private ?ServiceService $_serviceService = null;
|
|
private ?ServicePaymentService $_servicePaymentService = null;
|
|
private ?IpService $_ipService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->addClassName('ServiceItem');
|
|
}
|
|
public function getModelClass(): ServiceItemModel
|
|
{
|
|
return new ServiceItemModel();
|
|
}
|
|
public function getEntityClass(): ServiceItemEntity
|
|
{
|
|
return new ServiceItemEntity();
|
|
}
|
|
public function getServiceService(): ServiceService
|
|
{
|
|
if (!$this->_serviceService) {
|
|
$this->_serviceService = new ServiceService();
|
|
}
|
|
return $this->_serviceService;
|
|
}
|
|
public function getIpService(): IpService
|
|
{
|
|
if (!$this->_ipService) {
|
|
$this->_ipService = new IpService();
|
|
}
|
|
return $this->_ipService;
|
|
}
|
|
public function getServicePaymentService(): ServicePaymentService
|
|
{
|
|
if (!$this->_servicePaymentService) {
|
|
$this->_servicePaymentService = new ServicePaymentService();
|
|
}
|
|
return $this->_servicePaymentService;
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"serviceinfo_uid",
|
|
"item_type",
|
|
"item_uid",
|
|
"billing_cycle",
|
|
"price",
|
|
"amount",
|
|
"start_at",
|
|
"status",
|
|
];
|
|
}
|
|
public function getFilterFields(): array
|
|
{
|
|
return ["serviceinfo_uid", 'item_type', 'item_uid', 'billing_cycle', 'status'];
|
|
}
|
|
public function getBatchJobFields(): array
|
|
{
|
|
return ['status'];
|
|
}
|
|
public function getIndexFields(): array
|
|
{
|
|
return ['serviceinfo_uid', 'item_type', 'item_uid', 'billing_cycle', 'price', 'amount', 'start_at', 'updated_at', 'status'];
|
|
}
|
|
//Entity의 관련객체정의용
|
|
//FieldForm관련용
|
|
public function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'serviceinfo_uid':
|
|
$options = $this->getServiceService()->getEntities();
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
public function create(array $formDatas): ServiceItemEntity
|
|
{
|
|
$entity = parent::create($formDatas);
|
|
//결제정보 ServicePaymentService에 등록
|
|
$this->getServicePaymentService()->setServiceItemEntity($entity);
|
|
//관리자 정보 자동추가용
|
|
$paymentFormDatas = ['user_uid' => $this->getMyAuth()->getUIDByAuthInfo()];
|
|
$this->getServicePaymentService()->create($paymentFormDatas);
|
|
return $entity;
|
|
}
|
|
public function modify(mixed $entity, array $formDatas): ServiceItemEntity
|
|
{
|
|
//IP가 기존과 다를경우 //toggle,batchjob의 경우 $formDatas에 code가 없을수도 있음
|
|
if (array_key_exists('item_type', $formDatas) && $formDatas['item_type'] !== 'IP') {
|
|
//기존 IP의 경우 반환처리
|
|
$this->getIpService()->setStatus($entity->getItemUID(), IpEntity::STATUS_AVAILABLE);
|
|
//신규 설정된 IP의 경우 서비스중 변경처리
|
|
$this->getIpService()->setStatus($formDatas['item_uid'], IpEntity::STATUS_OCCUPIED);
|
|
}
|
|
return parent::modify($entity, $formDatas);
|
|
}
|
|
public function delete(mixed $entity): ServiceItemEntity
|
|
{
|
|
//기존 Ip의 경우 반환처리
|
|
if ($entity->getItemType() === 'IP') {
|
|
$this->getIpService()->setStatus($entity->getItemUID(), IpEntity::STATUS_AVAILABLE);
|
|
}
|
|
return parent::delete($entity);
|
|
}
|
|
}
|