dbmsv4/app/Services/Customer/Wallet/WalletService.php
2025-12-10 13:51:58 +09:00

46 lines
2.1 KiB
PHP

<?php
namespace App\Services\Customer\Wallet;
use App\Entities\Customer\ClientEntity;
use App\Entities\PaymentEntity;
use App\Models\CommonModel;
use App\Services\Customer\CustomerService;
use RuntimeException;
abstract class WalletService extends CustomerService
{
protected function __construct(CommonModel $model)
{
parent::__construct($model);
$this->addClassPaths('Wallet');
}
abstract protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array;
//기본기능
//결제 관련 출금 처리
final public function withdrawalByPayment(PaymentEntity $paymentEntity): void
{
//고객정보
$clientEntity = service('customer_clientservice')->getEntity($paymentEntity->getClientInfoUID());
if (!$clientEntity instanceof ClientEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$paymentEntity->getClientInfoUID()}에 해당하는 고객정보를 찾을수 없습니다.");
}
$formDatas = [];
$formDatas['clientinfo_uid'] = $clientEntity->getPK();
$formDatas['title'] = $paymentEntity->getTitle();
$formDatas['issue_at'] = date('Y-m-d');
$formDatas['status'] = STATUS['WITHDRAWAL'];
//출금액 계산
$formDatas = $this->withdrawalByPayment_process($clientEntity, $paymentEntity, $formDatas);
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('create', $fields);
$entity = $this->create_process($formDatas);
if (!$entity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__, "에서 오류발생: {$clientEntity->getTitle()} 고객의 입금(쿠폰추가)처리중 Wallet정보 생성에 실패하였습니다.");
}
//고객정보 수정
service('customer_clientservice')->modify_process($clientEntity, [constant("static::CLIENTINFO_BALANCE_FIELD") => $entity->getBalance()]);
}
}