88 lines
2.9 KiB
PHP
88 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Customer;
|
|
|
|
use App\Entities\Customer\ClientEntity;
|
|
use App\Entities\Customer\PointEntity;
|
|
use App\Entities\PaymentEntity;
|
|
use App\Helpers\Customer\PointHelper;
|
|
use App\Interfaces\PaymentInterface;
|
|
use App\Models\Customer\PointModel;
|
|
|
|
class PointService extends CustomerService implements PaymentInterface
|
|
{
|
|
private ?ClientService $_clientService = null;
|
|
public function __construct()
|
|
{
|
|
parent::__construct(new PointModel(), new PointHelper());
|
|
$this->addClassName('Point');
|
|
}
|
|
public function getFormFields(): array
|
|
{
|
|
return [
|
|
"clientinfo_uid",
|
|
"title",
|
|
"amount",
|
|
"status",
|
|
];
|
|
}
|
|
public function getFormFilters(): array
|
|
{
|
|
return [
|
|
"clientinfo_uid",
|
|
"status",
|
|
];
|
|
}
|
|
public function getBatchjobFields(): array
|
|
{
|
|
return ['status'];
|
|
}
|
|
final public function getClientService(): ClientService
|
|
{
|
|
if (!$this->_clientService) {
|
|
$this->_clientService = new ClientService();
|
|
}
|
|
return $this->_clientService;
|
|
}
|
|
public function setPayment(string $action, PaymentEntity $paymentEntity, array $paymentDatas): PaymentEntity
|
|
{
|
|
switch ($action) {
|
|
case 'create':
|
|
$this->create([
|
|
'clientinfo_uid' => $paymentEntity->getClientInfoUID(),
|
|
'bank' => null,
|
|
'title' => "[결제차감] {$paymentEntity->getTitle()}",
|
|
'alias' => array_key_exists('alias', $paymentDatas) ? $paymentDatas['alias'] : null,
|
|
'amount' => $paymentEntity->getAmount(),
|
|
'status' => STATUS['WIDTHDRAWAL'],
|
|
]);
|
|
break;
|
|
// case 'update':
|
|
// case 'delete':
|
|
default:
|
|
throw new \Exception(__METHOD__ . "에서 오류발생: {$action}는 지원하지 않는 기능입니다.");
|
|
}
|
|
return $paymentEntity;
|
|
}
|
|
//기본 기능부분
|
|
private function setBalance(array $formDatas): void
|
|
{
|
|
//point_balance 체크
|
|
$entity = $this->getClientService()->getEntity($formDatas['clientinfo_uid']);
|
|
if (!$entity instanceof ClientEntity) {
|
|
throw new \Exception("{$formDatas['clientinfo_uid']}에 대한 고객정보를 찾을수 없습니다.");
|
|
}
|
|
$amount = intval($formDatas['amount']);
|
|
if ($formDatas['status'] === PointEntity::DEFAULT_STATUS) { //입금, 쿠폰추가
|
|
$entity = $this->getClientService()->deposit($entity, 'point_balance', $amount);
|
|
} else { // 출금, 쿠폰사용
|
|
$entity = $this->getClientService()->withdrawal($entity, 'point_balance', $amount);
|
|
}
|
|
}
|
|
public function create(array $formDatas): PointEntity
|
|
{
|
|
$this->setBalance($formDatas);
|
|
return parent::create($formDatas);
|
|
}
|
|
}
|