dbmsv4 init...3

This commit is contained in:
최준흠 2025-12-11 18:01:32 +09:00
parent 5de9ccac2e
commit 8130974b1c
4 changed files with 92 additions and 52 deletions

View File

@ -774,4 +774,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2025-12-10 18:15:34 -- Dump completed on 2025-12-11 13:04:30

View File

@ -134,25 +134,26 @@ class AccountService extends WalletService
$this->model->orLike($this->model->getTable() . '.alias', $word, 'both'); $this->model->orLike($this->model->getTable() . '.alias', $word, 'both');
parent::setSearchWord($word); parent::setSearchWord($word);
} }
//결제 관련 출금 처리 //결제 관련 출금 처리
protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array protected function withdrawal_process(ClientEntity $clientEntity, array $formDatas): array
{ {
$amount = $paymentEntity->getAmount(); if (!array_key_exists('amount', $formDatas)) {
$balance = $clientEntity->getAccountBalance(); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 출금액이 정의되지 않았습니다.");
if ($balance < $amount) { }
if ($clientEntity->getAccountBalance() < $formDatas['amount']) {
throw new RuntimeException(sprintf( throw new RuntimeException(sprintf(
"%s 에서 오류발생: 출금액(%s원) , %s 고객의 예치금액(%s원)이 부족합니다.", "%s 에서 오류발생: 출금액(%s원) , %s 고객의 예치금액(%s원)이 부족합니다.",
static::class . '->' . __FUNCTION__, static::class . '->' . __FUNCTION__,
number_format($amount), number_format($formDatas['amount']),
$clientEntity->getTitle(), $clientEntity->getTitle(),
number_format($balance) number_format($clientEntity->getAccountBalance())
)); ));
} }
//최종처리 //최종처리
$formDatas['bank'] = BANKS['결제차감']; $formDatas['bank'] = BANKS['결제차감'];
$formDatas['alias'] = array_key_exists('alias', $formDatas) ? $formDatas['alias'] : $clientEntity->getTitle(); $formDatas['alias'] = array_key_exists('alias', $formDatas) ? $formDatas['alias'] : $clientEntity->getTitle();
$formDatas['amount'] = $amount; $formDatas['balance'] = $clientEntity->getAccountBalance() - $formDatas['amount'];
$formDatas['balance'] = $balance - $amount; return parent::withdrawal_process($clientEntity, $formDatas);
return $formDatas;
} }
} }

View File

@ -6,6 +6,7 @@ use App\Entities\Customer\ClientEntity;
use App\Entities\PaymentEntity; use App\Entities\PaymentEntity;
use App\Models\CommonModel; use App\Models\CommonModel;
use App\Services\Customer\CustomerService; use App\Services\Customer\CustomerService;
use GuzzleHttp\Client;
use RuntimeException; use RuntimeException;
abstract class WalletService extends CustomerService abstract class WalletService extends CustomerService
@ -15,31 +16,52 @@ abstract class WalletService extends CustomerService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Wallet'); $this->addClassPaths('Wallet');
} }
abstract protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array;
//기본기능 //기본기능
//결제 관련 출금 처리 //생성
final public function withdrawalByPayment(PaymentEntity $paymentEntity): void protected function create_process(array $formDatas): object
{ {
//고객정보 if (!array_key_exists('clientinfo_uid', $formDatas)) {
$clientEntity = service('customer_clientservice')->getEntity($paymentEntity->getClientInfoUID()); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 고객정보가 정의되지 않았습니다.");
if (!$clientEntity instanceof ClientEntity) { }
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$paymentEntity->getClientInfoUID()}에 해당하는 고객정보를 찾을수 없습니다."); 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;
} }
$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); $fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields); $this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('create', $fields); $this->getFormService()->setFormRules('create', $fields);
$entity = $this->create_process($formDatas); $entity = $this->create_process($formDatas);
if (!$entity) { if (!$entity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__, "에서 오류발생: {$clientEntity->getTitle()} 고객의 입금(쿠폰추가)처리중 Wallet정보 생성에 실패하였습니다."); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 고객의 Wallet정보 생성에 실패하였습니다.");
} }
//고객정보 수정
service('customer_clientservice')->modify_process($clientEntity, [constant("static::CLIENTINFO_BALANCE_FIELD") => $entity->getBalance()]); 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;
} }
} }

View File

@ -25,26 +25,6 @@ class PaymentService extends CommonService
parent::__construct($model); parent::__construct($model);
$this->addClassPaths('Payment'); $this->addClassPaths('Payment');
} }
//pay방식에따른 WalletService
private function getWalletService(string $pay): WalletService
{
$walletService = null;
switch ($pay) {
case PAYMENT['PAY']['ACCOUNT']:
$walletService = service('customer_wallet_accountservice');
break;
case PAYMENT['PAY']['COUPON']:
$walletService = service('customer_wallet_couponservice');
break;
case PAYMENT['PAY']['POINT']:
$walletService = service('customer_wallet_pointservice');
break;
default:
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$pay}는 지정되지 않은 지불방식입니다.");
// break;
}
return $walletService;
}
protected function getDTOClass(): string protected function getDTOClass(): string
{ {
return PaymentDTO::class; return PaymentDTO::class;
@ -197,6 +177,32 @@ class PaymentService extends CommonService
parent::setSearchWord($word); parent::setSearchWord($word);
} }
//추가기능 //추가기능
//pay방식에따른 WalletService 등록
private function setWallet(PaymentEntity $entity): void
{
$walletService = null;
switch ($entity->getPay()) {
case PAYMENT['PAY']['ACCOUNT']:
$walletService = service('customer_wallet_accountservice');
break;
case PAYMENT['PAY']['COUPON']:
$walletService = service('customer_wallet_couponservice');
break;
case PAYMENT['PAY']['POINT']:
$walletService = service('customer_wallet_pointservice');
break;
default:
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getPay()}는 지정되지 않은 지불방식입니다.");
// break;
}
$formDatas = [
'clientinfo_uid' => $entity->getClientInfoUID(),
'title' => $entity->getTitle(),
'amount' => $entity->getAmount(),
'status' => STATUS['WITHDRAWAL'],
];
$walletService->create_process($formDatas);
}
//일회성,선결제,쿠폰,포인트 입력 관련 //일회성,선결제,쿠폰,포인트 입력 관련
protected function create_process(array $formDatas): PaymentEntity protected function create_process(array $formDatas): PaymentEntity
{ {
@ -211,7 +217,7 @@ class PaymentService extends CommonService
} }
//지불이 완료된경우 지불처리 //지불이 완료된경우 지불처리
if ($entity->getStatus() === STATUS['PAID']) { if ($entity->getStatus() === STATUS['PAID']) {
$this->getWalletService($entity->getPay())->withdrawalByPayment($entity); $this->setWallet($entity);
} }
//선결제인경우 서비스정보에 결제일 변경용 //선결제인경우 서비스정보에 결제일 변경용
if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) { if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) {
@ -222,13 +228,17 @@ class PaymentService extends CommonService
protected function modify_process($entity, array $formDatas): PaymentEntity protected function modify_process($entity, array $formDatas): PaymentEntity
{ {
if ($entity->getStatus() === STATUS['PAID']) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 이미 지불된 결제정보는 수정이 불가합니다.");
}
//수정된 결제정보
$entity = parent::modify_process($entity, $formDatas); $entity = parent::modify_process($entity, $formDatas);
if (!$entity instanceof PaymentEntity) { if (!$entity instanceof PaymentEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 PaymentEntity만 가능"); throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생:Return Type은 PaymentEntity만 가능");
} }
//지불이 완료된경우 지불처리 //지불이 된경우 지불처리
if ($entity->getStatus() === STATUS['PAID']) { if ($entity->getStatus() === STATUS['PAID']) {
$this->getWalletService($entity->getPay())->withdrawalByPayment($entity); $this->setWallet($entity);
} }
//선결제인경우 서비스정보에 결제일 변경용 //선결제인경우 서비스정보에 결제일 변경용
if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) { if ($entity->getBilling() === PAYMENT['BILLING']['PREPAYMENT']) {
@ -236,17 +246,24 @@ class PaymentService extends CommonService
} }
return $entity; return $entity;
} }
protected function delete_process($entity): PaymentEntity
{
if ($entity->getStatus() === STATUS['PAID']) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 이미 지불된 결제정보는 수정이 불가합니다.");
}
return parent::delete_process($entity);
}
//지불 관련 //지불 관련
//일괄 지불용 //일괄 지불용
protected function batchjob_process($entity, array $formDatas): object protected function batchjob_process($entity, array $formDatas): object
{ {
// modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함) // modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함)
$entity = parent::batchjob_process($entity, $formDatas); $entity = parent::batchjob_process($entity, $formDatas);
//지불방식에 따른 고객 예치금,쿠폰,포인트 처리 if ($entity->getStatus() === STATUS['PAID']) {
$this->getWalletService($entity->getPay())->withdrawalByPayment($entity); $this->setWallet($entity);
}
return $entity; return $entity;
} }
//청구서 관련 //청구서 관련
public function getInvoices(ClientEntity $clientEntity, ServiceEntity $serviceEntity, PaymentEntity $entity, array $rows): array public function getInvoices(ClientEntity $clientEntity, ServiceEntity $serviceEntity, PaymentEntity $entity, array $rows): array
{ {