dbmsv4 init...3

This commit is contained in:
최준흠 2025-12-12 11:46:28 +09:00
parent 8130974b1c
commit a1c5c3471b
15 changed files with 113 additions and 52 deletions

View File

@ -2,7 +2,6 @@
namespace App\Controllers;
use App\Entities\CommonEntity;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\Validation\Exceptions\ValidationException;
use RuntimeException;

View File

@ -2,9 +2,11 @@
namespace App\Controllers\Admin\Customer\Wallet;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use RuntimeException;
class AccountController extends WalletController
{
@ -18,4 +20,27 @@ class AccountController extends WalletController
}
//기본 함수 작업
//Custom 추가 함수
final public function create_form(): string|RedirectResponse
{
try {
$uid = $this->request->getVar('clientinfo_uid');
if (!$uid) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 고객정보 번호가 정의되지 않았습니다..");
}
$clientEntity = service('customer_clientservice')->getEntity($uid);
if (!$clientEntity) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: {$uid}에 해당하는 고객정보을 찾을수 없습니다.");
}
$action = __FUNCTION__;
$formDatas = [];
$formDatas['clientinfo_uid'] = $uid;
$formDatas['alias'] = $clientEntity->getTitle();
$formDatas['issue_at'] = date('Y-m-d');
$this->action_init_process($action, $formDatas);
$this->addViewDatas('formDatas', $formDatas);
return $this->action_render_process($action, $this->getViewDatas(), $this->request->getVar('ActionTemplate'));
} catch (\Throwable $e) {
return $this->action_redirect_process('error', static::class . '->' . __FUNCTION__ . "에서 {$this->getTitle()} 생성폼 오류:" . $e->getMessage());
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -138,6 +138,7 @@ abstract class CommonForm
$dynamicRules[$field] = $rule; // 규칙만 저장
$dynamicLabels[$field] = $this->getFormFields()[$field];
}
log_message('debug', 'Fields: ' . var_export($this->getFormFields(), true));
log_message('debug', 'Rules: ' . var_export($dynamicRules, true));
log_message('debug', 'Data: ' . var_export($formDatas, true));
// setRules의 세 번째 인자로 레이블 전달
@ -176,7 +177,7 @@ abstract class CommonForm
{
switch ($field) {
case $this->getAttribute('pk_field'):
if (!$this->$this->getAttribute('useAutoIncrement')) {
if (!$this->getAttribute('useAutoIncrement')) {
$rule = sprintf("required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]%s", in_array($action, ["create"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
} else {
$rule = "required|numeric";

View File

@ -14,6 +14,7 @@ class AccountForm extends WalletForm
case "user_uid":
case "clientinfo_uid":
case "amount":
case "balance":
$rule = "required|numeric";
break;
case "bank":

View File

@ -11,4 +11,24 @@ abstract class WalletHelper extends CustomerHelper
{
parent::__construct();
}
public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string
{
switch ($action) {
case 'delete':
case 'batchjob':
case 'batchjob_delete':
//역활이 보안관리자가 아니면 사용불가
$action = $this->getAuthContext()->isAccessRole([ROLE['USER']['SECURITY']]) ? parent::getListButton($action, $label, $viewDatas, $extras) : "";
break;
case 'modify':
//역활이 보안관리자가 아니면 수정불가
$action = $this->getAuthContext()->isAccessRole([ROLE['USER']['SECURITY']]) ? parent::getListButton($action, $label, $viewDatas, $extras) : $label;
break;
default:
$action = parent::getListButton($action, $label, $viewDatas, $extras);
break;
}
return $action;
}
}

View File

@ -22,6 +22,7 @@ class AccountModel extends WalletModel
"alias",
"issue_at",
"amount",
"balance",
"status",
"updated_at",
];

View File

@ -169,15 +169,12 @@ abstract class CommonService
//생성용
protected function create_process(array $formDatas): object
{
// $fields = array_keys($formDatas);
// $this->getFormService()->setFormFields($fields);
// $this->getFormService()->setFormRules('create', $fields);
//FormData 검증
//관리자 정보추가용
$formDatas['user_uid'] = $this->getAuthContext()->getUID();
// 데이터 검증
if (!$this->getFormService()->validate($formDatas)) {
throw new ValidationException(implode("\n", service('validation')->getErrors()));
}
//관리자 정보추가용
$formDatas['user_uid'] = $this->getAuthContext()->getUID();
// 💡 동적으로 가져온 Entity 클래스 이름으로 instanceof 검사
$entityClass = $this->getEntityClass();
$entity = new $entityClass($formDatas);
@ -214,7 +211,7 @@ abstract class CommonService
), $e->getCode(), $e);
} catch (\Throwable $e) {
$db->transRollback(); // 예외 발생 시 수동으로 롤백
throw new RuntimeException($e->getMessage(), 0, $e);
throw new RuntimeException($e->getMessage());
}
}
@ -224,14 +221,14 @@ abstract class CommonService
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('modify', $fields);
// 검증
//관리자 정보추가용
$formDatas['user_uid'] = $this->getAuthContext()->getUID();
// 데이터 검증
if (!$this->getFormService()->validate($formDatas)) {
throw new ValidationException(
implode("\n", service('validation')->getErrors())
);
}
//관리자 정보추가용
$formDatas['user_uid'] = $this->getAuthContext()->getUID();
//PK 추가
$pkField = $this->model->getPKField();
if (!isset($formDatas[$pkField]) && !empty($entity->getPK())) {

View File

@ -79,6 +79,7 @@ class AccountService extends WalletService
"status",
];
$indexFilter = $filters;
$actionButtons = ['view' => ICONS['SEARCH']];
$batchjobFilters = ['bank', 'status'];
switch ($action) {
case 'create':
@ -110,6 +111,7 @@ class AccountService extends WalletService
$this->getFormService()->setFormFilters($filters);
$this->getFormService()->setFormOptions($action, $filters, $formDatas);
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setActionButtons($actionButtons);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
}
//기본 기능부분
@ -134,7 +136,21 @@ class AccountService extends WalletService
$this->model->orLike($this->model->getTable() . '.alias', $word, 'both');
parent::setSearchWord($word);
}
//입금,쿠폰 충전 처리
protected function deposit_process(ClientEntity $clientEntity, array $formDatas): array
{
if (!array_key_exists('amount', $formDatas)) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 출금액이 정의되지 않았습니다.");
}
//최종처리
$formDatas['balance'] = $clientEntity->getAccountBalance() + $formDatas['amount'];
if ($formDatas['balance'] < 0) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔액이 0보다 값이 정의 되었습니다.");
}
//고객 잔액 갱신
service('customer_clientservice')->modify_process($clientEntity, [self::CLIENTINFO_BALANCE_FIELD => $formDatas['balance']]);
return parent::deposit_process($clientEntity, $formDatas);
}
//결제 관련 출금 처리
protected function withdrawal_process(ClientEntity $clientEntity, array $formDatas): array
{
@ -154,6 +170,11 @@ class AccountService extends WalletService
$formDatas['bank'] = BANKS['결제차감'];
$formDatas['alias'] = array_key_exists('alias', $formDatas) ? $formDatas['alias'] : $clientEntity->getTitle();
$formDatas['balance'] = $clientEntity->getAccountBalance() - $formDatas['amount'];
if ($formDatas['balance'] < 0) {
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 잔액이 0보다 값이 정의 되었습니다.");
}
//고객 잔액 갱신
service('customer_clientservice')->modify_process($clientEntity, [self::CLIENTINFO_BALANCE_FIELD => $formDatas['balance']]);
return parent::withdrawal_process($clientEntity, $formDatas);
}
}

View File

@ -74,6 +74,7 @@ class CouponService extends WalletService
"status",
];
$indexFilter = $filters;
$actionButtons = ['view' => ICONS['SEARCH']];
$batchjobFilters = ['status'];
switch ($action) {
case 'create':
@ -100,6 +101,7 @@ class CouponService extends WalletService
$this->getFormService()->setFormFilters($filters);
$this->getFormService()->setFormOptions($action, $filters, $formDatas);
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setActionButtons($actionButtons);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
}
//기본 기능부분

View File

@ -74,6 +74,7 @@ class PointService extends WalletService
"status",
];
$indexFilter = $filters;
$actionButtons = ['view' => ICONS['SEARCH']];
$batchjobFilters = ['status'];
switch ($action) {
case 'create':
@ -100,6 +101,7 @@ class PointService extends WalletService
$this->getFormService()->setFormFilters($filters);
$this->getFormService()->setFormOptions($action, $filters, $formDatas);
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setActionButtons($actionButtons);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
}
//기본 기능부분

View File

@ -6,7 +6,6 @@ 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
@ -26,7 +25,7 @@ abstract class WalletService extends CustomerService
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']}에 해당하는 고객정보를 찾을수 없습니다.");
@ -40,16 +39,11 @@ abstract class WalletService extends CustomerService
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);
$entity = parent::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;
}
//입금,쿠폰 충전 처리
@ -64,4 +58,20 @@ abstract class WalletService extends CustomerService
$formDatas['issue_at'] = array_key_exists('issue_at', $formDatas) ? $formDatas['issue_at'] : date('Y-m-d');
return $formDatas;
}
//결제관련 출금 처리
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(),
'title' => $paymentEntity->getTitle(),
'amount' => $paymentEntity->getAmount(),
'status' => STATUS['WITHDRAWAL'],
];
$this->withdrawal_process($clientEntity, $formDatas);
}
}

View File

@ -212,10 +212,6 @@ class ServerPartService extends EquipmentService
$formDatas['amount'] = $partEntity->getPrice(); //파트 금액
$formDatas['cnt'] = $part["CNT"];
$formDatas['extra'] = $part["EXTRA"];
//action 초기화
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('create', $fields);
$this->create_process($formDatas);
}
}

View File

@ -11,7 +11,6 @@ use App\Entities\PaymentEntity;
use App\Forms\PaymentForm;
use App\Helpers\PaymentHelper;
use App\Models\PaymentModel;
use App\Services\Customer\Wallet\WalletService;
use DateTime;
use RuntimeException;
@ -131,7 +130,6 @@ class PaymentService extends CommonService
$this->getFormService()->setIndexFilters($indexFilter);
$this->getFormService()->setActionButtons($actionButtons);
$this->getFormService()->setBatchjobFilters($batchjobFilters);
$this->getFormService()->setBatchjobButtons($batchjobButtons);
}
//총 미납건수, 금액
final public function getUnPaids(string $group, array $where = []): array
@ -195,13 +193,7 @@ class PaymentService extends CommonService
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);
$walletService->withdrawalByPayment($entity);
}
//일회성,선결제,쿠폰,포인트 입력 관련
protected function create_process(array $formDatas): PaymentEntity
@ -316,9 +308,6 @@ class PaymentService extends CommonService
public function createByService(ServiceEntity $serviceEntity): PaymentEntity
{
$formDatas = $this->getFormDatasByService($serviceEntity);
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('create', $fields);
return parent::create_process($formDatas);
}
public function modifyByService(ServiceEntity $serviceEntity): PaymentEntity
@ -360,9 +349,6 @@ class PaymentService extends CommonService
throw new RuntimeException(static::class . '->' . __FUNCTION__ . "에서 오류발생: 서비스정보가 정의되지 않아 일회성 상품을 설정하실수 없습니다.");
}
$formDatas = $this->getFormDatasByServerPart($serverPartEntity);
$fields = array_keys($formDatas);
$this->getFormService()->setFormFields($fields);
$this->getFormService()->setFormRules('create', $fields);
return parent::create_process($formDatas);
}
public function modifyByServerPart(ServerPartEntity $serverPartEntity): PaymentEntity