dbmsv4 init...3

This commit is contained in:
최준흠 2025-12-10 13:51:58 +09:00
parent 0db26edf8b
commit d004bbb1e5
10 changed files with 81 additions and 169 deletions

View File

@ -424,6 +424,7 @@ define(
"하나은행" => "하나은행",
"신한은행" => "신한은행",
"농협" => "농협",
"결제차감" => "결제차감",
],
);
//서비스 관련

View File

@ -11,4 +11,8 @@ abstract class WalletEntity extends CustomerEntity
{
parent::__construct($data);
}
final public function getBalance(): int
{
return $this->attributes['balance'] ?? 0;
}
}

View File

@ -126,7 +126,7 @@ class ClientHelper extends CustomerHelper
$label,
$action,
[
"data-src" => "/admin/customer/{$action}?clientinfo_uid={$viewDatas['entity']->getPK()}&ActionTemplate=popup",
"data-src" => "/admin/customer/wallet/{$action}?clientinfo_uid={$viewDatas['entity']->getPK()}&ActionTemplate=popup",
"data-bs-toggle" => "modal",
"data-bs-target" => "#modal_action_form",
"class" => "text-primary",

View File

@ -15,7 +15,7 @@ return [
'created_at' => "작성일",
'deleted_at' => "삭제일",
],
"BANK" => [...BANKS, '결제차감' => '결제차감'],
"BANK" => BANKS,
"STATUS" => [
STATUS['DEPOSIT'] => "입금",
STATUS['WITHDRAWAL'] => "출금",

View File

@ -110,56 +110,6 @@ class ClientService extends CustomerService
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
}
final public function updateBalance(int|ClientEntity $uid, string $title, string $key, int $value, string $status): ClientEntity
{
$entity = is_int($uid) ? $this->getEntity($uid) : $uid;
if (!$entity instanceof ClientEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다.");
}
$calculatedValue = null;
$balance = 0;
$field = "";
switch ($key) {
case PAYMENT['PAY']['ACCOUNT']:
$balance = $entity->getAccountBalance();
$field = "account_balance";
break;
case PAYMENT['PAY']['COUPON']:
$balance = $entity->getCouponBalance();
$field = "coupon_balance";
break;
case PAYMENT['PAY']['POINT']:
$balance = $entity->getPointBalance();
$field = "point_balance";
break;
}
//입금,추가 처리
if ($status === STATUS['DEPOSIT']) {
$calculatedValue = $balance + $value;
}
//출금,사용 처리
if ($status === STATUS['WITHDRAWAL']) {
if ($balance < $value) {
throw new RuntimeException(sprintf(
"%s 에서 오류발생: %s 고객의 %s[ %s ]이/가 사용한 %s 금액/수[ %s ]이/가 부족합니다.",
static::class . '->' . __FUNCTION__,
$entity->getTitle(),
$title,
number_format($balance),
$title,
number_format($value)
));
}
$calculatedValue = $balance - $value;
}
if (!is_int($calculatedValue) || $calculatedValue < 0) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 {$entity->getTitle()} 고객 {$title}의 계산결과 값이 NULL이거나 0보다 작은 값입니다.");
}
//balance 수정
$formDatas = [$field => $calculatedValue];
return parent::modify_process($entity, $formDatas);
}
//기본 기능부분
protected function getEntity_process(mixed $entity): ClientEntity
{

View File

@ -13,6 +13,7 @@ use RuntimeException;
class AccountService extends WalletService
{
const CLIENTINFO_BALANCE_FIELD = 'account_balance';
private $_form = null;
private $_helper = null;
public function __construct(AccountModel $model)
@ -133,49 +134,25 @@ class AccountService extends WalletService
$this->model->orLike($this->model->getTable() . '.alias', $word, 'both');
parent::setSearchWord($word);
}
//결제처리 관련
protected function createByPayment_process(PaymentEntity $paymentEntity, array $formDatas = []): array
//결제 관련 출금 처리
protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array
{
$formDatas['bank'] = $formDatas['alias'] = '결제차감';
$formDatas['amount'] = $paymentEntity->getAmount();
return parent::createByPayment_process($paymentEntity, $formDatas);
}
//입금처리
protected function setDeposit_process(ClientEntity $clientEntity, int $amount): int
{
$calculatedBalance = $balance = $clientEntity->getAccountBalance();
$field = "account_balance";
$amount = $paymentEntity->getAmount();
$balance = $clientEntity->getAccountBalance();
if ($balance < $amount) {
throw new RuntimeException(sprintf(
"%s 에서 오류발생: %s 고객의 예치금액(%s원)이 출금액(%s원) 보다 부족합니다.",
"%s 에서 오류발생: 출금액(%s원) , %s 고객의 예치금액(%s원)이 부족합니다.",
static::class . '->' . __FUNCTION__,
number_format($amount),
$clientEntity->getTitle(),
number_format($balance),
number_format($amount)
number_format($balance)
));
}
//최종처리
$calculatedBalance = $balance - $amount;
service('customer_clientservice')->modify_process($clientEntity, ['account_balance' => $calculatedBalance]);
return $calculatedBalance;
}
//출금처리
protected function setWithdrawal_process(ClientEntity $clientEntity, int $amount): int
{
$calculatedBalance = $balance = $clientEntity->getAccountBalance();
if ($balance < $amount) {
throw new RuntimeException(sprintf(
"%s 에서 오류발생: %s 고객의 예치금액(%s원)이 출금액(%s원) 보다 부족합니다.",
static::class . '->' . __FUNCTION__,
$clientEntity->getTitle(),
number_format($balance),
number_format($amount)
));
}
//최종처리
$calculatedBalance = $balance - $amount;
service('customer_clientservice')->modify_process($clientEntity, ['account_balance' => $calculatedBalance]);
return $calculatedBalance;
$formDatas['bank'] = BANKS['결제차감'];
$formDatas['alias'] = array_key_exists('alias', $formDatas) ? $formDatas['alias'] : $clientEntity->getTitle();
$formDatas['amount'] = $amount;
$formDatas['balance'] = $balance - $amount;
return $formDatas;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Services\Customer\Wallet;
use App\DTOs\Customer\Wallet\CouponDTO;
use App\Entities\Customer\ClientEntity;
use App\Entities\Customer\Wallet\CouponEntity;
use App\Entities\PaymentEntity;
use App\Forms\Customer\Wallet\CouponForm;
@ -120,10 +121,23 @@ class CouponService extends WalletService
//FormFilter 조건절 처리
//검색어조건절처리
//결제처리 관련
protected function createByPayment_process(PaymentEntity $paymentEntity, array $formDatas = []): array
//결제 관련 쿠폰 사용 처리
protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array
{
$formDatas['cnt'] = $paymentEntity->getAmount();
return parent::createByPayment_process($paymentEntity, $formDatas);
$amount = $paymentEntity->getAmount();
$balance = $clientEntity->getCouponBalance();
if ($balance < $amount) {
throw new RuntimeException(sprintf(
"%s 에서 오류발생: 사용쿠폰 수량(%s) , %s 고객의 잔여쿠폰 수량(%s)이 부족합니다.",
static::class . '->' . __FUNCTION__,
number_format($amount),
$clientEntity->getTitle(),
number_format($balance)
));
}
//최종처리
$formDatas['cnt'] = $amount;
$formDatas['balance'] = $balance - $amount;
return $formDatas;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Services\Customer\Wallet;
use App\DTOs\Customer\Wallet\PointDTO;
use App\Entities\Customer\ClientEntity;
use App\Entities\Customer\Wallet\PointEntity;
use App\Entities\PaymentEntity;
use App\Forms\Customer\Wallet\PointForm;
@ -120,10 +121,23 @@ class PointService extends WalletService
//FormFilter 조건절 처리
//검색어조건절처리
//결제처리 관련
protected function createByPayment_process(PaymentEntity $paymentEntity, array $formDatas = []): array
//결제 관련 출금 처리
protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array
{
$formDatas['amount'] = $paymentEntity->getAmount();
return parent::createByPayment_process($paymentEntity, $formDatas);
$amount = $paymentEntity->getAmount();
$balance = $clientEntity->getPointBalance();
if ($balance < $amount) {
throw new RuntimeException(sprintf(
"%s 에서 오류발생: 사용포인트(%s) , %s 고객의 포인트(%s)가 부족합니다.",
static::class . '->' . __FUNCTION__,
number_format($amount),
$clientEntity->getTitle(),
number_format($balance)
));
}
//최종처리
$formDatas['amount'] = $amount;
$formDatas['balance'] = $balance - $amount;
return $formDatas;
}
}

View File

@ -15,80 +15,31 @@ abstract class WalletService extends CustomerService
parent::__construct($model);
$this->addClassPaths('Wallet');
}
abstract protected function setWithdrawal_process(ClientEntity $clientEntity, int $amount): int;
private function setDeposit(int|ClientEntity $uid, string $title, string $key, int $value, string $status): ClientEntity
{
$entity = is_int($uid) ? $this->getEntity($uid) : $uid;
if (!$entity instanceof ClientEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 서비스정보를 찾을수 없습니다.");
}
$calculatedValue = null;
$balance = 0;
$field = "";
switch ($key) {
case PAYMENT['PAY']['ACCOUNT']:
$balance = $entity->getAccountBalance();
$field = "account_balance";
break;
case PAYMENT['PAY']['COUPON']:
$balance = $entity->getCouponBalance();
$field = "coupon_balance";
break;
case PAYMENT['PAY']['POINT']:
$balance = $entity->getPointBalance();
$field = "point_balance";
break;
}
//입금,추가 처리
if ($status === STATUS['DEPOSIT']) {
$calculatedValue = $balance + $value;
}
//출금,사용 처리
if ($status === STATUS['WITHDRAWAL']) {
if ($balance < $value) {
throw new RuntimeException(sprintf(
"%s 에서 오류발생: %s 고객의 %s[ %s ]이/가 사용한 %s 금액/수[ %s ]이/가 부족합니다.",
static::class . '->' . __FUNCTION__,
$entity->getTitle(),
$title,
number_format($balance),
$title,
number_format($value)
));
}
$calculatedValue = $balance - $value;
}
if (!is_int($calculatedValue) || $calculatedValue < 0) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 {$entity->getTitle()} 고객 {$title}의 계산결과 값이 NULL이거나 0보다 작은 값입니다.");
}
//balance 수정
$formDatas = [$field => $calculatedValue];
return parent::modify_process($entity, $formDatas);
}
abstract protected function withdrawalByPayment_process(ClientEntity $clientEntity, PaymentEntity $paymentEntity, array $formDatas): array;
//기본기능
//결제처리 관련
protected function createByPayment_process(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['clientinfo_uid'] = $paymentEntity->getClientInfoUID();
$formDatas = [];
$formDatas['clientinfo_uid'] = $clientEntity->getPK();
$formDatas['title'] = $paymentEntity->getTitle();
$formDatas['issue_at'] = date('Y-m-d');
$formDatas['status'] = STATUS['WITHDRAWAL'];
$formDatas['balance'] = $this->setWithdrawal_process($clientEntity, $paymentEntity->getAmount());
return $formDatas;
}
final public function createByPayment(PaymentEntity $paymentEntity): void
{
$formDatas = $this->createByPayment_process($paymentEntity);
//출금액 계산
$formDatas = $this->withdrawalByPayment_process($clientEntity, $paymentEntity, $formDatas);
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('create', $fields);
$this->create_process($formDatas);
$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()]);
}
}

View File

@ -11,6 +11,7 @@ use App\Entities\PaymentEntity;
use App\Forms\PaymentForm;
use App\Helpers\PaymentHelper;
use App\Models\PaymentModel;
use App\Services\Customer\Wallet\WalletService;
use CodeIgniter\Database\Exceptions\DatabaseException;
use DateTime;
use RuntimeException;
@ -209,25 +210,25 @@ class PaymentService extends CommonService
}
//지불 관련
//pay방식에따른 결제처리
private function updateWallet(PaymentEntity $entity): void
//pay방식에따른 WalletService
private function getWalletService(string $pay): WalletService
{
$service = null;
switch ($entity->getPay()) {
$walletService = null;
switch ($pay) {
case PAYMENT['PAY']['ACCOUNT']:
$service = service('customer_wallet_accountservice');
$walletService = service('customer_wallet_accountservice');
break;
case PAYMENT['PAY']['COUPON']:
$service = service('customer_wallet_couponservice');
$walletService = service('customer_wallet_couponservice');
break;
case PAYMENT['PAY']['POINT']:
$service = service('customer_wallet_pointservice');
$walletService = service('customer_wallet_pointservice');
break;
default:
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$entity->getPay()}는 지정되지 않은 지불방식입니다.");
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$pay}는 지정되지 않은 지불방식입니다.");
// break;
}
$service->createByPayment($entity);
return $walletService;
}
//일괄 지불용
protected function batchjob_process($entity, array $formDatas): object
@ -235,7 +236,7 @@ class PaymentService extends CommonService
// modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함)
$entity = parent::batchjob_process($entity, $formDatas);
//지불방식에 따른 고객 예치금,쿠폰,포인트 처리
$this->updateWallet($entity);
$this->getWalletService($entity->getPay())->withdrawalByPayment($entity);
return $entity;
}
//단일 지불용
@ -252,7 +253,7 @@ class PaymentService extends CommonService
//결제 완료 처리 후 추가정보 처리
$entity = parent::modify_process($entity, ['status' => STATUS['PAID']]);
//지불방식에 따른 고객 예치금,쿠폰,포인트 처리
$this->updateWallet($entity);
$this->getWalletService($entity->getPay())->withdrawalByPayment($entity);
$db->transComplete();
return $entity;
} catch (DatabaseException $e) {