105 lines
3.4 KiB
PHP
105 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Customer;
|
|
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
|
|
use App\Models\Customer\ServiceItemModel;
|
|
use App\Entities\Customer\ServiceItemEntity;
|
|
use App\Services\Customer\ServiceService;
|
|
use App\Entities\Customer\ServiceEntity;
|
|
use App\Entities\Customer\ServicePaymentEntity;
|
|
|
|
class ServiceItemService extends CustomerService
|
|
{
|
|
protected ?IncomingRequest $request = null;
|
|
private ?ServiceService $_serviceService = null;
|
|
public function __construct(?IncomingRequest $request = null)
|
|
{
|
|
parent::__construct($request);
|
|
$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($this->request);
|
|
}
|
|
return $this->_serviceService;
|
|
}
|
|
public function getServicePaymentService(): ServicePaymentService
|
|
{
|
|
if (!$this->_servicePaymentService) {
|
|
$this->_servicePaymentService = new ServicePaymentService($this->request);
|
|
}
|
|
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'];
|
|
}
|
|
|
|
private function createPayment(ServiceEntity $serviceEntity,): ServicePaymentEntity
|
|
{
|
|
//서비스 결제정보를 생성함
|
|
$entity = $this->getServicePaymentService()->create([
|
|
'serviceinfo_uid' => $serviceEntity->getPK(),
|
|
'item_type' => $formDatas['item_type'],
|
|
'item_uid' => $formDatas['item_uid'],
|
|
'billing_cycle' => $formDatas['billing_cycle'],
|
|
'amount' => $formDatas['amount'],
|
|
'billing_at' => $serviceEntity->getBillingAt(),
|
|
'issue_at' => $formDatas['issue_at'],
|
|
]);
|
|
dd($formDatas);
|
|
return $entity;
|
|
}
|
|
public function create(array $formDatas, mixed $entity = null): ServiceItemEntity
|
|
{
|
|
$serviceEntity = $this->getServiceService()->getEntity($formDatas['serviceinfo_uid']);
|
|
if (!$serviceEntity) {
|
|
throw new \Exception("{$formDatas['serviceinfo_uid']}에 대한 서비스정보를 찾을수 없습니다.");
|
|
}
|
|
$entity = parent::create($formDatas, $entity);
|
|
// 결제정보 ServicePaymentService에 등록
|
|
$this->createPayment($serviceEntity, $formDatas);
|
|
return $entity;
|
|
}
|
|
public function modify(mixed $entity, array $formDatas): ServiceItemEntity
|
|
{
|
|
return parent::modify($entity, $formDatas);
|
|
}
|
|
final public function delete(mixed $entity): bool
|
|
{
|
|
return parent::delete($entity);
|
|
}
|
|
}
|