118 lines
4.0 KiB
PHP
118 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Customer;
|
|
|
|
use App\Entities\Customer\ServiceEntity;
|
|
use App\Entities\Customer\ServiceItemEntity;
|
|
use App\Entities\Customer\ServicePaymentEntity;
|
|
use App\Models\Customer\ServicePaymentModel;
|
|
use App\Services\Customer\ServiceService;
|
|
|
|
class ServicePaymentService extends CustomerService
|
|
{
|
|
private ?ServiceService $_serviceService = null;
|
|
public function __construct(mixed $request = null)
|
|
{
|
|
parent::__construct($request);
|
|
$this->addClassName('ServicePayment');
|
|
}
|
|
public function getModelClass(): ServicePaymentModel
|
|
{
|
|
return new ServicePaymentModel();
|
|
}
|
|
public function getEntityClass(): ServicePaymentEntity
|
|
{
|
|
return new ServicePaymentEntity();
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"serviceinfo_uid",
|
|
"ownerinfo_uid",
|
|
"item_type",
|
|
"item_uid",
|
|
"billing_cycle",
|
|
"amount",
|
|
"billing_at",
|
|
"issue_at",
|
|
"status",
|
|
];
|
|
}
|
|
public function getFilterFields(): array
|
|
{
|
|
return ["serviceinfo_uid", "ownerinfo_uid", 'item_type', 'item_uid', 'billing_cycle', 'status'];
|
|
}
|
|
public function getBatchJobFields(): array
|
|
{
|
|
return ['status'];
|
|
}
|
|
public function getIndexFields(): array
|
|
{
|
|
return ['serviceinfo_uid', "ownerinfo_uid", 'item_type', 'item_uid', 'billing_cycle', 'amount', 'billing_at', 'issue_at', 'countdown', 'status'];
|
|
}
|
|
|
|
public function getServiceService(): ServiceService
|
|
{
|
|
if (!$this->_serviceService) {
|
|
$this->_serviceService = new ServiceService($this->request);
|
|
}
|
|
return $this->_serviceService;
|
|
}
|
|
//Entity의 관련객체정의용
|
|
//기본 기능부분
|
|
//FieldForm관련용
|
|
public function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case 'serviceinfo_uid':
|
|
$options = $this->getServiceService()->getEntities();
|
|
break;
|
|
case 'item_uid':
|
|
$options = [];
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
//미납서비스 정보
|
|
final public function getEntitiesByUnPaid(): array
|
|
{
|
|
$where = sprintf("billing_at < NOW() AND amount > 0 AND status = '%s'", DEFAULTS['STATUS']);
|
|
return $this->getEntities($where);
|
|
}
|
|
//ServiceItemService에서 사용
|
|
public function createByServiceItem(ServiceItemEntity $serviceItemEntity): ServicePaymentEntity
|
|
{
|
|
$serviceEntity = $this->getServiceService()->getEntity($serviceItemEntity->getServiceUid());
|
|
if (!$serviceEntity) {
|
|
throw new \Exception("{$serviceItemEntity->getServiceUid()}에 대한 서비스정보를 찾을수 없습니다.");
|
|
}
|
|
$formDatas = [
|
|
'serviceinfo_uid' => $serviceItemEntity->getServiceUid(),
|
|
'ownerinfo_uid' => $serviceEntity->getOwnerUid(),
|
|
'item_type' => $serviceItemEntity->getItemType(),
|
|
'item_uid' => $serviceItemEntity->getItemUid(),
|
|
'billing_cycle' => $serviceItemEntity->getBillingCycle(),
|
|
'amount' => $serviceItemEntity->getAmount(),
|
|
'billing_at' => $serviceEntity->getBillingAt(),
|
|
'issue_at' => date('Y-m-d'),
|
|
];
|
|
return $this->create($formDatas);
|
|
}
|
|
|
|
//Service정보 와 관리자가 기존 정보과 같고, 결제가 아직 완료되지 않은 결제정보의 관리자 변경
|
|
public function modifyOwnerByService(ServiceEntity $serviceEntity, int $ownerinfo_uid)
|
|
{
|
|
$wheres = [
|
|
'serviceinfo_uid' => $serviceEntity->getPK(),
|
|
'ownerinfo_uid' => $serviceEntity->getOwnerUID(),
|
|
'status' => DEFAULTS['STATUS']
|
|
];
|
|
foreach ($this->getEntities($wheres) as $entity) {
|
|
$this->modify($entity, ['ownerinfo_uid' => $ownerinfo_uid]);
|
|
}
|
|
}
|
|
}
|