153 lines
4.5 KiB
PHP
153 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Entities\Customer\ServiceEntity;
|
|
use App\Entities\PaymentEntity;
|
|
use App\Helpers\PaymentHelper;
|
|
use App\Models\PaymentModel;
|
|
use App\Services\CommonService;
|
|
use App\Services\Customer\ClientService;
|
|
use App\Services\Customer\ServiceService;
|
|
use App\Services\UserService;
|
|
|
|
class PaymentService extends CommonService
|
|
{
|
|
private ?UserService $_userService = null;
|
|
private ?ClientService $_clientService = null;
|
|
private ?ServiceService $_serviceService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new PaymentModel(), new PaymentHelper());
|
|
$this->addClassName('Payment');
|
|
}
|
|
final public function getFormFields(): array
|
|
{
|
|
return [
|
|
"clientinfo_uid",
|
|
"serviceinfo_uid",
|
|
"title",
|
|
"amount",
|
|
"billing",
|
|
"billing_at",
|
|
"pay",
|
|
"status",
|
|
];
|
|
}
|
|
final public function getFormFilters(): array
|
|
{
|
|
return [
|
|
'clientinfo_uid',
|
|
"serviceinfo_uid",
|
|
'billing',
|
|
'pay',
|
|
'status',
|
|
'user_uid',
|
|
];
|
|
}
|
|
final public function getIndexFields(): array
|
|
{
|
|
return [
|
|
'clientinfo_uid',
|
|
"serviceinfo_uid",
|
|
'billing',
|
|
'title',
|
|
'amount',
|
|
'billing_at',
|
|
'pay',
|
|
'status',
|
|
'updated_at',
|
|
'countdown',
|
|
'user_uid',
|
|
];
|
|
}
|
|
final public function getBatchjobFields(): array
|
|
{
|
|
return ['pay', 'status'];
|
|
}
|
|
final public function getBatchjobButtons(): array
|
|
{
|
|
return [
|
|
'batchjob' => '일괄 결제 ',
|
|
'invoice' => '청구서 발행',
|
|
];
|
|
}
|
|
final public function getClientService(): ClientService
|
|
{
|
|
if (!$this->_clientService) {
|
|
$this->_clientService = new ClientService();
|
|
}
|
|
return $this->_clientService;
|
|
}
|
|
final public function getUSerService(): UserService
|
|
{
|
|
if (!$this->_userService) {
|
|
$this->_userService = new UserService();
|
|
}
|
|
return $this->_userService;
|
|
}
|
|
final public function getServiceService(): ServiceService
|
|
{
|
|
if (!$this->_serviceService) {
|
|
$this->_serviceService = new ServiceService();
|
|
}
|
|
return $this->_serviceService;
|
|
}
|
|
//기본 기능부분
|
|
//FieldForm관련용
|
|
final 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;
|
|
}
|
|
//List 검색용
|
|
//OrderBy 처리
|
|
final public function setOrderBy(mixed $field = null, mixed $value = null): void
|
|
{
|
|
$this->getModel()->orderBy('billing_at ASC');
|
|
parent::setOrderBy($field, $value);
|
|
}
|
|
//당일 기준으로 총 미납건수, 금액
|
|
final public function getUnPaids(string $group, array $where = []): array
|
|
{
|
|
$rows = $this->getModel()->groupBy($group)
|
|
->select("{$group},COUNT(uid) as cnt, SUM(amount) as amount")
|
|
->where(['billing_at <=' => date('Y-m-d')])
|
|
->where(['status' => STATUS['UNPAID']])
|
|
->where($where)
|
|
->get()->getResult();
|
|
$unPaids = [];
|
|
foreach ($rows as $row) {
|
|
$unPaids[$row->$group] = ['cnt' => $row->cnt, 'amount' => $row->amount];
|
|
}
|
|
return $unPaids;
|
|
}
|
|
//생성
|
|
final public function create(array $formDatas): PaymentEntity
|
|
{
|
|
// 관리자 UID는 현재 인증된 사용자로 설정
|
|
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
|
|
return parent::create($formDatas);
|
|
}
|
|
//수정
|
|
final public function modify(mixed $entity, array $formDatas): PaymentEntity
|
|
{
|
|
// 관리자 UID는 현재 인증된 사용자로 설정
|
|
$formDatas['user_uid'] = $this->getMyAuth()->getUIDByAuthInfo();
|
|
return parent::modify($entity, $formDatas);
|
|
}
|
|
}
|