73 lines
2.1 KiB
PHP
73 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Customer;
|
|
|
|
use App\Entities\Customer\AccountEntity;
|
|
use App\Models\Customer\AccountModel;
|
|
use App\Entities\Customer\ClientEntity;
|
|
|
|
class AccountService extends CustomerService
|
|
{
|
|
public function __construct(mixed $request = null)
|
|
{
|
|
parent::__construct($request);
|
|
$this->addClassName('Account');
|
|
}
|
|
public function getModelClass(): AccountModel
|
|
{
|
|
return new AccountModel();
|
|
}
|
|
public function getEntityClass(): AccountEntity
|
|
{
|
|
return new AccountEntity();
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"clientinfo_uid",
|
|
"status",
|
|
"alias",
|
|
"title",
|
|
"amount"
|
|
];
|
|
}
|
|
public function getFilterFields(): array
|
|
{
|
|
return ["clientinfo_uid", 'status'];
|
|
}
|
|
public function getBatchJobFields(): array
|
|
{
|
|
return ['status'];
|
|
}
|
|
//Entity의 관련객체정의용
|
|
protected function setRelatedEntity(mixed $entity): AccountEntity
|
|
{
|
|
//고객정보정의
|
|
$entity->setClient($this->getClient($entity->getClientUID()));
|
|
return parent::setRelatedEntity($entity);
|
|
}
|
|
//기본 기능부분
|
|
|
|
//고객예치금처리
|
|
private function setBalance(array $formDatas): ClientEntity
|
|
{
|
|
//account_balance 체크
|
|
$entity = $this->getClientService()->getEntity($formDatas['clientinfo_uid']);
|
|
if (!$entity) {
|
|
throw new \Exception("{$formDatas['clientinfo_uid']}에 대한 고객정보를 찾을수 없습니다.");
|
|
}
|
|
$amount = intval($formDatas['amount']);
|
|
if ($formDatas['status'] === DEFAULTS['STATUS']) { //입금, 쿠폰추가
|
|
$entity = $this->getClientService()->deposit($entity, 'account_balance', $amount);
|
|
} else { // 출금, 쿠폰사용
|
|
$entity = $this->getClientService()->withdrawal($entity, 'account_balance', $amount);
|
|
}
|
|
return $entity;
|
|
}
|
|
public function create(array $formDatas, mixed $entity = null): AccountEntity
|
|
{
|
|
$this->setBalance($formDatas);
|
|
return parent::create($formDatas, $entity);
|
|
}
|
|
}
|