dbmsv3 init...1

This commit is contained in:
choi.jh 2025-10-28 18:44:32 +09:00
parent 07c98fa942
commit 475dcb0236
20 changed files with 188 additions and 107 deletions

View File

@ -150,15 +150,16 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au
//일회성결제관련용
$routes->get('create', 'PaymentController::create_form');
$routes->post('create', 'PaymentController::create');
// $routes->get('modify/(:num)', 'PaymentController::modify_form/$1');
// $routes->post('modify/(:num)', 'PaymentController::modify/$1');
$routes->get('modify/(:num)', 'PaymentController::modify_form/$1');
$routes->post('modify/(:num)', 'PaymentController::modify/$1');
$routes->get('view/(:num)', 'PaymentController::view/$1');
// $routes->get('delete/(:num)', 'PaymentController::delete/$1');
// $routes->get('toggle/(:num)/(:any)', 'PaymentController::toggle/$1/$2');
//일괄결제용
$routes->get('delete/(:num)', 'PaymentController::delete/$1');
$routes->get('toggle/(:num)/(:any)', 'PaymentController::toggle/$1/$2');
$routes->post('batchjob', 'PaymentController::batchjob');
// $routes->post('batchjob_delete', 'PaymentController::batchjob_delete');
$routes->post('batchjob_delete', 'PaymentController::batchjob_delete');
$routes->get('download/(:alpha)', 'PaymentController::download/$1');
//결체처리
$routes->post('paid', 'PaymentController::paid');
//청구서발행용
$routes->post('invoice', 'PaymentController::invoice');
});

View File

@ -51,6 +51,15 @@ class PaymentController extends CustomerController
return $result;
}
//Index,FieldForm관련
//일회성추가작업
protected function create_form_process(): void
{
$formDatas = $this->getService()->getFormDatas();
$formDatas['billing'] = PAYMENT['BILLING']['ONETIME'];
$formDatas['billing_at'] = date("Y-m-d");
$this->getService()->setFormDatas($formDatas);
parent::create_form_process();
}
//Invoice 관련
public function invoice(): RedirectResponse|string
{
@ -96,7 +105,7 @@ class PaymentController extends CustomerController
$serviceEntities[$entity->getServiceInfoUid()] = $serviceEntity;
}
//Invoice Data 가져오기
$rows = $this->getService()->getInvoiceData($clientEntity, $serviceEntity, $entity, $rows);
$rows = $this->getService()->getInvoices($clientEntity, $serviceEntity, $entity, $rows);
}
}
// dd($rows);
@ -107,13 +116,38 @@ class PaymentController extends CustomerController
}
}
//일회성결제작업
protected function create_form_process(): void
//결제처리
public function paid(): RedirectResponse|string
{
$formDatas = $this->getService()->getFormDatas();
$formDatas['billing'] = PAYMENT['BILLING']['ONETIME'];
$formDatas['billing_at'] = date("Y-m-d");
$this->getService()->setFormDatas($formDatas);
parent::create_form_process();
//Transaction Start
$db = \Config\Database::connect();
$db->transStart();
try {
$this->getService()->setAction(__FUNCTION__);
//변경할 UIDS 정의
$uids = $this->request->getPost('batchjob_uids[]');
if (!is_array($uids) || !count($uids)) {
throw new \Exception("적용할 리스트을 선택하셔야합니다.");
}
$entities = [];
foreach ($uids as $uid) {
//기존 Entity 가져오기
$entity = $this->getService()->getEntity($uid);
if (!$entity) {
throw new \Exception("{$uid}에 대한 정보를 찾을수 없습니다.");
}
$entities[] = $this->getService()->setPaid($entity);
}
$db->transCommit();
sprintf(
"<script>alert('총 %s개중 %s개 결제처리을 완료하였습니다.'); history.back();</script>",
count($uids),
count($entities)
);
return $this->getResultSuccess();
} catch (\Exception $e) {
$db->transRollback();
return $this->getResultFail($e->getMessage());
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,10 @@ class ServiceEntity extends CustomerEntity
const PK = ServiceModel::PK;
const TITLE = ServiceModel::TITLE;
const DEFAULT_STATUS = STATUS['AVAILABLE'];
final public function getUserUID(): int|null
{
return $this->attributes['user_uid'] ?? null;
}
final public function getClientInfoUID(): int|null
{
return $this->attributes['clientinfo_uid'] ?? null;
@ -25,7 +28,7 @@ class ServiceEntity extends CustomerEntity
//기본기능용
public function getCustomTitle(mixed $title = null): string
{
return sprintf("[%s]%s", $this->getCode(), $this->getTitle());
return $this->getTitle();
}
final public function getCode(): string
{

View File

@ -444,7 +444,7 @@ class CommonHelper
"checked" => in_array($viewDatas['entity']->getPK(), $oldBatchJobUids)
]);
$action = $checkbox . form_label(
$label,
$label ? $label : '수정',
$action,
[
"data-src" => current_url() . '/' . $action . '/' . $viewDatas['entity']->getPK() . '?' . $viewDatas['uri']->getQuery(),

View File

@ -11,6 +11,21 @@ class AccountHelper extends CustomerHelper
parent::__construct();
$this->setTitleField(AccountModel::TITLE);
}
public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
{
switch ($field) {
case 'amount':
$value = number_format($value) . "";
break;
default:
$value = parent::getFieldView($field, $value, $viewDatas, $extras);
break;
}
if (is_array($value)) {
throw new \Exception(__METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다");
}
return $value;
}
public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string
{
switch ($action) {

View File

@ -11,6 +11,21 @@ class CouponHelper extends CustomerHelper
parent::__construct();
$this->setTitleField(CouponModel::TITLE);
}
public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
{
switch ($field) {
case 'cnt':
$value = number_format($value);
break;
default:
$value = parent::getFieldView($field, $value, $viewDatas, $extras);
break;
}
if (is_array($value)) {
throw new \Exception(__METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다");
}
return $value;
}
public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string
{
switch ($action) {

View File

@ -11,6 +11,21 @@ class PointHelper extends CustomerHelper
parent::__construct();
$this->setTitleField(field: PointModel::TITLE);
}
public function getFieldView(string $field, mixed $value, array $viewDatas, array $extras = []): string|null
{
switch ($field) {
case 'amount':
$value = number_format($value);
break;
default:
$value = parent::getFieldView($field, $value, $viewDatas, $extras);
break;
}
if (is_array($value)) {
throw new \Exception(__METHOD__ . "에서 오류: {$field}의 값이 Array형태입니다");
}
return $value;
}
public function getListButton(string $action, string $label, array $viewDatas, array $extras = []): string
{
switch ($action) {

View File

@ -18,6 +18,9 @@ class PaymentHelper extends CommonHelper
case "countdown": //결제일Countdown
$value = $viewDatas['entity']->getCountDueAt();
break;
case 'amount':
$value = number_format($value) . "";
break;
default:
$value = parent::getFieldView($field, $value, $viewDatas, $extras);
break;
@ -31,6 +34,7 @@ class PaymentHelper extends CommonHelper
{
switch ($action) {
case 'create':
case 'batchjob':
case 'batchjob_delete':
$action = "";
break;
@ -53,9 +57,15 @@ class PaymentHelper extends CommonHelper
case 'delete':
$action = "";
if ($this->getMyAuth()->isAccessRole(['security'])) {
$action = $viewDatas['entity']->getStatus() !== $viewDatas['entity']::DEFAULT_STATUS ? "" : parent::getListButton($action, $label, $viewDatas, $extras);
$action = parent::getListButton($action, $label, $viewDatas, $extras);
}
break;
case 'paid':
$action = form_submit($action . "_submit", $label ? $label : '결제 처리', [
"formaction" => current_url() . '/' . $action,
"class" => "btn btn-outline btn-warning",
]);
break;
case 'invoice':
$action = form_submit($action . "_submit", $label ? $label : '청구서 발행', [
"formaction" => current_url() . '/' . $action,

View File

@ -155,6 +155,7 @@ abstract class CommonModel extends Model
}
}
// 최종 저장 시 오류 발생하면
// dd($convertedFormDatas);
if (!$this->save($convertedFormDatas)) {
$message = sprintf(
"\n------%s 오류-----\n%s\n%s\n------------------------------\n",

View File

@ -90,17 +90,14 @@ class ServerPartV1Processor
}
// 1) 수정전 정보
//파트값이 정의되어 있으면
$formDatas['part_uid'] = null; //null이면 기존정보 유지
$isPartChanged = false;
if (array_key_exists('part_uid', $formDatas) && !$formDatas['part_uid']) {
//기존파트값과 다르면
if ($entity->getPartUID() != $formDatas['part_uid']) {
//기존파트값이 있으면 해지
if ($entity->getPartUID() != null) {
$this->service->getPartService($entity->getType())->detachFromServerPart($entity);
}
$isPartChanged = true;
$isChangedPart = false;
//기존파트값과 다르면
if ($entity->getPartUID() != $formDatas['part_uid']) {
//기존 Part_UID값과 다르고 기존 Part_UID값이 있으면 해지
if ($entity->getPartUID()) {
$this->service->getPartService($entity->getType())->detachFromServerPart($entity);
}
$isChangedPart = true;
}
// 2) 서버연결정보 수정
$serverEntity = $this->serverService->getEntity($formDatas['serverinfo_uid']);
@ -111,8 +108,8 @@ class ServerPartV1Processor
$formDatas["serviceinfo_uid"] = $serverEntity->getServiceInfoUID();
$formDatas["serverinfo_uid"] = $serverEntity->getPK();
$entity = $this->service->getModel()->modify($entity, $formDatas);
// 3) Type에 따른 각 파트 정의
if ($isPartChanged) { //파트가 바뀐경우 추가작업
// 3) Part_UID값이 있고 신규값인경우
if ($entity->getPartUID() && $isChangedPart) {
$this->service->getPartService($entity->getType())->attachToServerPart($entity);
}
// 3) 과금정의

View File

@ -29,22 +29,22 @@ class ServerV1Processor
$this->db->transStart();
//1) 서버정보 생성
//switch값이 없으면 null처리
if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) {
if (!array_key_exists('switch', $formDatas) || !$formDatas['switch']) {
$formDatas['switch'] = null;
}
//ip값이 없으면 null처리
if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) {
//switch값이 없으면 null처리
if (!array_key_exists('ip', $formDatas) || !$this->service->getHelper()->isIPAddress($formDatas['ip'])) {
$formDatas['ip'] = null;
}
$entity = $this->service->getModel()->create($formDatas);
//2) 서버의 Type별 서버파트정보등록(서버파트연결 자동등록용)
$this->serverPartService->attachToServer($entity);
//3) Switch가 정의되어 있으면
if ($entity->getSwitch() !== null) { //
if ($entity->getSwitch()) {
$this->switchService->attachToServer($entity);
}
//4) //IP가 정의되어 있으면
if ($entity->getIP() !== null) {
if ($entity->getIP()) {
$this->ipService->attachToServer($entity);
}
//5) Log처리
@ -63,30 +63,23 @@ class ServerV1Processor
$this->db->transStart();
//1) 사전처리 작업
//Switch값이 정의되어 있으면
$formDatas['switch'] = null; //null이면 기존정보 유지
$isChangedSwitch = false;
if (array_key_exists('switch', $formDatas) && !$formDatas['switch']) {
//기존 Switch값과 다르면
if ($entity->getSwitch() != $formDatas['switch']) {
//기존 Switch값이 있으면 해지
if ($entity->getSwitch() != null) {
$this->switchService->detachFromServer($entity);
}
$isChangedSwitch = true;
if ($entity->getSwitch() != $formDatas['switch']) {
//기존 Switch값과 다르고 기존 Switch값이 있으면 해지
if ($entity->getSwitch()) {
$this->switchService->detachFromServer($entity);
}
$isChangedSwitch = true;
}
//IP값이 정의되어 있으면
$formDatas['ip'] = null; //null이면 기존정보 유지
$isChangedIP = false;
if (array_key_exists('ip', $formDatas) && !$formDatas['ip']) {
//기존 IP값과 다르면
if ($entity->getSwitch() != $formDatas['ip']) {
//기존 IP값이 있으면 해지
if ($entity->getIP() != null) {
$this->ipService->detachFromServer($entity);
}
$isChangedIP = true;
//기존 IP값과 다르면
if ($entity->getIP() != $formDatas['ip']) {
//기존IP값과 다르고 기존 Switch값이 있으면 해지
if ($entity->getIP()) {
$this->ipService->detachFromServer($entity);
}
$isChangedIP = true;
}
//2) 서버정보 수정
$entity = $this->service->getModel()->modify($entity, $formDatas);
@ -122,20 +115,16 @@ class ServerV1Processor
}
$this->db->transStart();
// 1) 기존 Switch값이 있으면 해지
if ($entity->getSwitch() != null) {
$this->switchService->detachFromServer($entity);
}
// 2) 기존 Switch값이 있으면 해지
if ($entity->getSwitch() != null) {
if ($entity->getSwitch()) {
$this->switchService->detachFromServer($entity);
}
// 2) 기존 IP값이 있으면 해지
if ($entity->getIP() != null) {
if ($entity->getIP()) {
$this->ipService->detachFromServer($entity);
}
// 4) 서버정보 삭제
// 3) 서버정보 삭제
$this->service->getModel()->delete($entity->getPK());
// 5) 로그
// 4) 로그
$this->logService->getModel()->create(formDatas: [
'title' => "{$entity->getTitle()} 서버 삭제",
'status' => $entity->getStatus(),

View File

@ -53,7 +53,7 @@ class AccountService extends CustomerService
return $this->getClientService()->setAccount($formDatas['status'], $entity, intval($formDatas['amount']));
}
//결제관련 예치금 차감 처리용
public function setPaymentPaid(PaymentEntity $paymentEntity): AccountEntity
public function setPaid(PaymentEntity $paymentEntity): AccountEntity
{
$formDatas = [
'clientinfo_uid' => $paymentEntity->getClientInfoUID(),
@ -73,7 +73,10 @@ class AccountService extends CustomerService
$this->setBalance($formDatas);
$entity = parent::create($formDatas);
//Log처리
$this->getMylogService()->create(['title' => "[{$entity->getTitle()}] 예치금 처리", 'status' => $entity->getStatus()]);
$this->getMylogService()->create([
'title' => "[{$entity->getTitle()}] 예치금 처리",
'status' => $entity->getStatus()
]);
return $entity;
}
//List 검색용

View File

@ -90,7 +90,7 @@ class ClientService extends CustomerService
break;
case STATUS['WITHDRAWAL']:
if ($entity->getAccountBalance() < $amount) {
throw new \Exception("예치금액[{$entity->getAccountBalance()}]이 출금액:{$amount}보다 부족합니다.");
throw new \Exception("예치금액[" . number_format($entity->getAccountBalance()) . "원 / 출금액:" . number_format($amount) . "원 예치금이 부족합니다.");
}
$amount = $entity->getAccountBalance() - $amount;
break;
@ -112,7 +112,7 @@ class ClientService extends CustomerService
break;
case STATUS['WITHDRAWAL']:
if ($entity->getCouponBalance() < $cnt) {
throw new \Exception("쿠폰수[{$entity->getCouponBalance()}]가 사용쿠폰:{$cnt}보다 부족합니다.");
throw new \Exception("쿠폰수[" . number_format($entity->getCouponBalance()) . " / 사용쿠폰:" . number_format($cnt) . "원 쿠폰이 부족합니다.");
}
$cnt = $entity->getCouponBalance() - $cnt;
break;
@ -134,7 +134,7 @@ class ClientService extends CustomerService
break;
case STATUS['WITHDRAWAL']:
if ($entity->getPointBalance() < $amount) {
throw new \Exception("포인트금액[{$entity->getPointBalance()}]이 사용포인트:{$amount}보다 부족합니다.");
throw new \Exception("포인트[" . number_format($entity->getPointBalance()) . " / 사용포인트:" . number_format($amount) . "원 포인트가 부족합니다.");
}
$amount = $entity->getPointBalance() - $amount;
break;

View File

@ -178,9 +178,10 @@ class ServiceService extends CustomerService
throw new \Exception(__METHOD__ . "에서 오류발생: [{$entity->getServerInfoUID()}]에 대한 서버정보를 찾을수 없습니다.");
}
$amount = $this->getCalculatedAmount($entity, $serverEntity);
$entity = parent::modify($entity, ['amount' => $amount]);
//결제정보 수정
$this->getPaymentService()->updateForService($entity);
return parent::modify($entity, ['amount' => $amount]);
return $entity;
}
//기본 기능부분
//FieldForm관련용

View File

@ -200,6 +200,7 @@ class ServerPartService extends EquipmentService implements ServerPartInterface
$partEntity = $this->getPartService($parttype)->getEntity($part['UID']);
//해당 파트정보 가져오기
$formDatas = [];
$formDatas['serverinfo_uid'] = $serverEntity->getPK();
$formDatas["part_uid"] = $partEntity->getPK();
$formDatas['billing'] = PAYMENT['BILLING']['BASE'];
$formDatas['type'] = $parttype;

View File

@ -181,7 +181,7 @@ class ServerService extends EquipmentService implements ServerInterface
//해당 서비스(서버) 관련 결제방식(Billing)이 Month인 ServerPart 전체를 다시 검사하여 월청구액을 합산한다.
foreach ($this->getServerPartService()->getEntities(['serverinfo_uid' => $entity->getPK()]) as $serverPartEntity) {
if ($serverPartEntity->getBilling() === PAYMENT['BILLING']['MONTH']) { //월비용일때만 적용
$caculatedAmount += $serverPartEntity->getCalculatedAmount(); //단가*Cnt
$caculatedAmount += $serverPartEntity->getTotalAmount(); //단가*Cnt
}
}
return $caculatedAmount;

View File

@ -74,8 +74,8 @@ class PaymentService extends CommonService implements PaymentInterface
final public function getBatchjobButtons(): array
{
return [
'batchjob' => '결제 처리',
'invoice' => '청구서 발행',
'paid' => '결제 처리',
];
}
final public function getServiceService(): ServiceService
@ -226,7 +226,7 @@ class PaymentService extends CommonService implements PaymentInterface
}
//Invoice 관련
public function getInvoiceData(ClientEntity $clientEntity, ServiceEntity $serviceEntity, PaymentEntity $entity, array $rows): array
public function getInvoices(ClientEntity $clientEntity, ServiceEntity $serviceEntity, PaymentEntity $entity, array $rows): array
{
if (!array_key_exists($clientEntity->getPK(), $rows)) {
$rows[$clientEntity->getPK()] = [
@ -252,6 +252,20 @@ class PaymentService extends CommonService implements PaymentInterface
$rows[$clientEntity->getPK()]['total_amount'] += $entity->getAmount();
return $rows;
}
//결제 처리
public function setPaid(PaymentEntity $entity): PaymentEntity
{
//결제 완료 처리 후 추가정보 처리
$entity = parent::modify($entity, ['pay' => PAYMENT['PAY']['ACCOUNT'], 'status' => STATUS['PAID']]);
//Log처리
$this->getMylogService()->create([
'title' => "[{$entity->getTitle()}] 월과금 결제처리",
'status' => $entity->getStatus()
]);
//예치금처리
$this->getAccountService()->setPaid($entity);
return $entity;
}
//기본 기능부분
//FieldForm관련용
final public function getFormOption(string $field, array $options = []): array
@ -283,29 +297,11 @@ class PaymentService extends CommonService implements PaymentInterface
$entity = parent::create($formDatas);
//Log처리
$this->getMylogService()->create([
'title' => "[{$entity->getTitle()}] 일회성 결제",
'title' => "[{$entity->getTitle()}] 일회성 추가",
'status' => $entity->getStatus()
]);
return $entity;
}
//월과금용 일괄결제처리(결제는 무조건 예치금으로만 처리)
public function batchjob(mixed $entity, array $formDatas): mixed
{
if (!$entity instanceof PaymentEntity) {
throw new \Exception(__METHOD__ . "에서 오류발생:결제정보가 정의되지 않았습니다.");
}
//결제 완료 처리 후 추가정보 처리
$formDatas['status'] = STATUS['PAID'];
$entity = parent::batchjob($entity, $formDatas);
//Log처리
$this->getMylogService()->create([
'title' => "[{$entity->getTitle()}] 월과금 결제",
'status' => $entity->getStatus()
]);
//예치금처리
$this->getAccountService()->setPaymentPaid($entity);
return $entity;
}
//결제정보 삭제
public function delete(mixed $entity): PaymentEntity
{

View File

@ -13,7 +13,7 @@
<div><?= $entity->getTitle() ?></div>
<div><?= $serviceCellDatas['service']->getHelper()->getFieldView('site', $entity->getSite(), $serviceCellDatas) ?></div>
<div><?= $serviceCellDatas['service']->getHelper()->getFieldView('location', $entity->getLocation(), $serviceCellDatas) ?></div>
<div class="mt-3"><?= $serviceCellDatas['service']->getHelper()->getListButton('addServer', '대체서버 입력', ['entity' => $entity], ['class' => 'btn btn-sm btn-primary']) ?></div>
<div class="mt-3"><?= $serviceCellDatas['service']->getHelper()->getListButton('addServer', '대체서버추가', ['entity' => $entity], ['class' => 'btn btn-sm btn-primary']) ?></div>
</td>
<td class="text-center" nowrap><?= view('cells/service/server', ['serviceEntity' => $entity, 'serverEntities' => $serviceCellDatas['childServers'][$entity->getPK()]]) ?></td>
<td class="text-center" nowrap>

View File

@ -27,6 +27,6 @@
</td>
</tr>
<tr>
<td colspan="2" class="text-center"><?= $serviceCellDatas['service']->getHelper()->getListButton('onetime', '일회성 입력', ['entity' => $serviceEntity], ['class' => 'btn btn-sm btn-primary']) ?></td>
<td colspan="2" class="text-center"><?= $serviceCellDatas['service']->getHelper()->getListButton('onetime', '일회성추가', ['entity' => $serviceEntity], ['class' => 'btn btn-sm btn-primary']) ?></td>
</tr>
</table>