dbmsv2/app/Services/Customer/PaymentService.php
2025-09-17 14:29:21 +09:00

148 lines
4.7 KiB
PHP

<?php
namespace App\Services\Customer;
use App\Entities\Customer\PaymentEntity;
use App\Entities\Equipment\ServerPartEntity;
use App\Helpers\Customer\PaymentHelper;
use App\Interfaces\Equipment\ServerPartInterface;
use App\Models\Customer\PaymentModel;
class PaymentService extends CustomerService implements ServerPartInterface
{
public function __construct()
{
parent::__construct(new PaymentModel(), new PaymentHelper());
$this->addClassName('Payment');
}
public function getModelClass(): PaymentModel
{
return new PaymentModel();
}
public function getEntityClass(): PaymentEntity
{
return new PaymentEntity();
}
public function getFormFields(): array
{
return [
"clientinfo_uid",
"serviceinfo_uid",
"title",
"amount",
"billing",
"billing_at",
"pay",
"status",
];
}
public function getFormFilters(): array
{
return [
'clientinfo_uid',
"serviceinfo_uid",
'billing',
'pay',
'status',
'user_uid',
];
}
public function getIndexFields(): array
{
return [
'clientinfo_uid',
"serviceinfo_uid",
'billing',
'title',
'amount',
'billing_at',
'pay',
'status',
'updated_at',
'countdown',
'user_uid',
];
}
public function getBatchjobFields(): array
{
return ['pay', 'status'];
}
public function getBatchjobButtons(): array
{
return [
'batchjob' => '일괄 결제 ',
'invoice' => '청구서 발행',
];
}
//기본 기능부분
//FieldForm관련용
public function getFormOption(string $field, array $options = []): array
{
switch ($field) {
case 'user_uid':
$options = $this->getUserService()->getEntities();
break;
case 'clientinfo_uid':
$options = $this->getClientService()->getEntities();
break;
case 'serviceinfo_uid':
$options = $this->getServiceService()->getEntities();
break;
default:
$options = parent::getFormOption($field, $options);
break;
}
return $options;
}
//서비스 설정
public function setServerPart(ServerPartEntity $serverPartEntity, mixed $uid, string $status): PaymentEntity
{
if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['ONETIME']) {
if ($serverPartEntity->getServiceInfoUID() === null) {
throw new \Exception("일회성 부품 추가는 서비스정보가 정의된 후에만 가능합니다.");
}
}
$formDatas = [];
$formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID();
$formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID();
$formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID();
$formDatas['title'] = sprintf("[%s] 일회성 추가", $serverPartEntity->getPartEntity()->getTitle());
$formDatas['amount'] = $serverPartEntity->getAmount();
$formDatas['billing'] = $serverPartEntity->getBilling();
$formDatas['billing_at'] = date("Y-m-d"); //일회성은 지급일이 당일기준처리
return $this->create($formDatas);
}
//List 검색용
//OrderBy 처리
public function setOrderBy(mixed $field = null, mixed $value = null): void
{
$this->getModel()->orderBy('billing_at ASC');
parent::setOrderBy($field, $value);
}
//총 미납건수, 금액
public function getUnPaids(string $group, array $where = []): array
{
return $this->getModel()->groupBy($group)
->select("serviceinfo_uid,COUNT(uid) as cnt, SUM(amount) as amount")
->where(['billing_at <=' => date('Y-m-d')])
->where(['status' => STATUS['UNPAID']])
->where($where)
->get()->getResult();
}
//생성
public function create(array $formDatas): PaymentEntity
{
// 관리자 UID는 현재 인증된 사용자로 설정
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
return parent::create($formDatas);
}
//수정
public function modify(mixed $entity, array $formDatas): PaymentEntity
{
// 관리자 UID는 현재 인증된 사용자로 설정
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
return parent::modify($entity, $formDatas);
}
}