dbmsv4/app/Services/Customer/Wallet/WalletService.php
2025-12-11 18:01:32 +09:00

68 lines
3.0 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 GuzzleHttp\Client;
use RuntimeException;
abstract class WalletService extends CustomerService
{
protected function __construct(CommonModel $model)
{
parent::__construct($model);
$this->addClassPaths('Wallet');
}
//기본기능
//생성
protected function create_process(array $formDatas): object
{
if (!array_key_exists('clientinfo_uid', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 고객정보가 정의되지 않았습니다.");
}
if (!array_key_exists('status', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 상태정보가 정의되지 않았습니다.");
}
//고객 정보 잔액 수정
$clientEntity = service('customer_clientservice')->getEntity($formDatas['clientinfo_uid']);
if (!$clientEntity instanceof ClientEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$formDatas['clientinfo_uid']}에 해당하는 고객정보를 찾을수 없습니다.");
}
switch ($formDatas['status']) {
case STATUS['DEPOSIT']:
$formDatas = $this->deposit_process($clientEntity, $formDatas);
break;
case STATUS['WITHDRAWAL']:
$formDatas = $this->withdrawal_process($clientEntity, $formDatas);
break;
default:
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 정의되지 않은 상태정보입니다.");
//break;
}
$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__ . "에서 오류발생: 고객의 Wallet정보 생성에 실패하였습니다.");
}
service('customer_clientservice')->modify_process($clientEntity, [constant("static::CLIENTINFO_BALANCE_FIELD") => $entity->getBalance()]);
return $entity;
}
//입금,쿠폰 충전 처리
protected function deposit_process(ClientEntity $clientEntity, array $formDatas): array
{
$formDatas['issue_at'] = array_key_exists('issue_at', $formDatas) ? $formDatas['issue_at'] : date('Y-m-d');
return $formDatas;
}
//출금,쿠폰 사용 처리
protected function withdrawal_process(ClientEntity $clientEntity, array $formDatas): array
{
$formDatas['issue_at'] = array_key_exists('issue_at', $formDatas) ? $formDatas['issue_at'] : date('Y-m-d');
return $formDatas;
}
}