dbms_primeidc_init...1

This commit is contained in:
최준흠 2025-04-11 11:07:53 +09:00
parent 0c53fd6c30
commit 98ae65b5e9
6 changed files with 140 additions and 35 deletions

View File

@ -2,11 +2,15 @@
namespace lib\Controllers\DBMS\Client;
use lib\Services\HistoryService;
use lib\Services\MemberService;
use lib\Services\OnetimeService;
use lib\Utils\Pagination;
class CouponController extends ClientController
{
private ?OnetimeService $_onetimeService = null;
private ?HistoryService $_historyService = null;
private ?MemberService $_memberService = null;
public function __construct()
{
@ -20,6 +24,20 @@ class CouponController extends ClientController
}
return $this->_memberService;
}
public function getOnetimeService(): OnetimeService
{
if ($this->_onetimeService === null) {
$this->_onetimeService = new OnetimeService();
}
return $this->_onetimeService;
}
public function getHistoryService(): HistoryService
{
if ($this->_historyService === null) {
$this->_historyService = new HistoryService();
}
return $this->_historyService;
}
//IdcCouponUseMK.jsp -> domain_coupon_use.php
//CLI 접속방법 : php index.php site/client/counpon/index
//WEB 접속방법 : http://localhost/site/client/coupon/index
@ -130,13 +148,11 @@ class CouponController extends ClientController
if (!$service) {
throw new \Exception("[$service_code]에 해당하는 서비스정보가 존재하지 않습니다.");
}
$this->service = $service;
//사용자정보
$client = $this->getClientService()->getEntityByCode($service->getClientCode());
if (!$client) {
throw new \Exception("[{$service->getClientCode()}]에 해당하는 사용자정보가 존재하지 않습니다.");
}
$this->client = $client;
//전체 관리자정보(등록자)
if (!array_key_exists('mkid', $params)) {
throw new \Exception("mkid 값이 정의되지 않았습니다.");
@ -146,20 +162,29 @@ class CouponController extends ClientController
if (!$member) {
throw new \Exception("[$member_code]에 해당하는 관리자정보가 존재하지 않습니다.");
}
$this->member = $member;
//onetime_sub 도메인 구매 수량
$coupon = $this->request->get('coupon');
if (! $coupon || $coupon < 1) {
throw new \Exception("도메인 구매 수량 값이 정의되지 않았거나, 도메인 구매 수량은 1개 이상이어야 합니다.");
}
//onetime_note 도메인 구매 수량
$note = $this->request->get('note');
if (!$note) {
throw new \Exception("도메인 리스트 값이 정의되지 않았습니다.");
}
//onetime_case 사용용도
$onetime_case = $this->request->get('onetime_case') ?? 'domain';
//onetime_request_date 사용일
$onetime_request_date = $this->request->get('onetime_request_date') ?? date("Y-m-d");
try {
$this->getServiceService()->getModel()->setTransaction(true);
//서비스 수정
// $this->getServiceService()->getModel()->where("client_code", $client_code);
// $this->getServiceService()->update();
// $coupon_query = "update servicedb set coupon=(coupon-$_GET[onetime_sub]), coupon_use=(coupon_use+$_GET[onetime_sub]) where service_code='$_GET[service_code]'";
// @mysql_query($coupon_query, $db_connect) or die($db_i_error);
// $onetime_query = "INSERT INTO `onetimedb` (`client_code`, `service_code`, `onetime_case`, `onetime_sub`, `onetime_amount`, `onetime_payment`, `onetime_nonpayment`, `onetime_accountStatus`, `onetime_request_date`, `onetime_payment_date`, `onetime_note`, `onetime_handle_date`, `onetime_manager`, `client_name`, `server_code`) VALUES ('$_GET[client_code]', '$_GET[service_code]', 'domain', '$_GET[onetime_sub]', '0', '0', '0', 'complete', '$_GET[onetime_request_date]', '$_GET[onetime_request_date]', '도메인 쿠폰사용 / $_GET[onetime_note]', '$_GET[onetime_request_date]', '$_GET[mkid]', '$member[name]', '$service[server_code]')";
// @mysql_query($onetime_query, $db_connect) or die($db_i_error);
// $history_query = "INSERT INTO `historydb` (`service_code`, `server_code`, `behavior_case`, `behavior`, `behavior_date`, `note`, `client_name`) VALUES ('$_GET[service_code]', '$service[server_code]', '도메인 쿠폰 구매 / $_GET[onetime_sub] 개', '도메인 쿠폰 구매', '$_GET[onetime_request_date]', '$member[name]', '$service[Client_Name]')";
// @mysql_query($history_query, $db_connect) or die($db_i_error);
//서비스쿠폰 갯수 수정
$this->getServiceService()->useCouponForDomain($service, $coupon);
//쿠폰 사용내역 onetime에 등록
$this->getOnetimeService()->useCouponForDomain($service, $client, $member, $onetime_case, $coupon, $note, $onetime_request_date);
//쿠폰 사용내역 history에 등록
$this->getHistoryService()->useCouponForDomain($service, $client, $onetime_case, $coupon, $note, $onetime_request_date);;
$this->getServiceService()->getModel()->commit();
return $this->redirect->to(DBMS_SITE_URL . "/IdcCouponUseMK.cup?client_code=" . $this->client->getClientCode());
} catch (\PDOException $e) {

View File

@ -299,28 +299,44 @@ class QueryBuilder
//CUD부분
final public function insert(array $data): bool
{
$columns = array_keys($data);
$placeholders = array_map(fn($c) => ':' . $c, $columns);
$sql = "INSERT INTO {$this->table} (" . implode(',', $columns) . ") VALUES (" . implode(',', $placeholders) . ")";
$stmt = $this->pdo->prepare($sql);
$columns = [];
$placeholders = [];
foreach ($data as $col => $val) {
$stmt->bindValue(':' . $col, $val);
if ($val === null) {
// $val이 null이면 $col을 그대로 SQL로 사용
$columns[] = ''; // placeholder로 인해 생략
$placeholders[] = $col; // 예: col2=(SELECT something)
} else {
$safePlaceholder = ':i_' . preg_replace('/\W+/', '_', $col); // 안전한 바인딩 키
$columns[] = $col;
$placeholders[] = $safePlaceholder;
$this->bindings[$safePlaceholder] = $val;
}
}
if ($stmt->execute()) {
return (int)$this->pdo->lastInsertId();
$sql = "INSERT INTO {$this->table} (" . implode(', ', array_filter($columns)) . ") "
. "VALUES (" . implode(', ', $placeholders) . ")";
$stmt = $this->pdo->prepare($sql);
foreach ($this->bindings as $k => $v) {
$stmt->bindValue($k, $v);
}
return false;
return $stmt->execute() && $stmt->rowCount() > 0 ? (int)$this->pdo->lastInsertId() : false;
}
final public function update(array $data): bool
{
if (empty($this->where)) throw new \Exception("Update without WHERE is not allowed.");
if (empty($this->where)) {
throw new \Exception(__FUNCTION__ . " 구문은 WHERE절 없이 사용할수 없습니다.");
}
$setParts = [];
foreach ($data as $col => $val) {
$placeholder = ':u_' . $col;
$setParts[] = "$col = $placeholder";
$this->bindings[$placeholder] = $val;
if ($val === null) {
// 값이 null이면 $col을 SQL로 직접 사용
$setParts[] = $col;
} else {
$placeholder = ':u_' . preg_replace('/\W+/', '_', $col); // 안전한 placeholder 이름
$setParts[] = "$col = $placeholder";
$this->bindings[$placeholder] = $val;
}
}
$sql = "UPDATE {$this->table} SET " . implode(', ', $setParts)
. " WHERE " . implode(' AND ', $this->where);
@ -333,7 +349,9 @@ class QueryBuilder
final public function delete(): bool
{
if (empty($this->where)) throw new \Exception("Delete without WHERE is not allowed.");
if (empty($this->where)) {
throw new \Exception(__FUNCTION__ . " 구문은 WHERE절 없이 사용할수 없습니다.");
}
$sql = "DELETE FROM {$this->table} WHERE " . implode(' AND ', $this->where);
$stmt = $this->pdo->prepare($sql);
foreach ($this->bindings as $k => $v) {

View File

@ -2,7 +2,10 @@
namespace lib\Services;
use lib\Entities\ClientEntity;
use lib\Entities\HistoryEntity as Entity;
use lib\Entities\MemberEntity;
use lib\Entities\ServiceEntity;
use lib\Models\HistoryModel as Model;
class HistoryService extends CommonService
@ -33,4 +36,18 @@ class HistoryService extends CommonService
$this->getModel()->limit($limit);
return $this->getEntities();
}
//도메인쿠폰 사용용
public function useCouponForDomain(ServiceEntity $service, ClientEntity $client, string $onetime_case, int $coupon, string $note, string $onetime_request_date): bool
{
$formDatas = [
"service_code" => $service->getServiceCode(),
"server_code" => $service->getServerCode(),
"behavior_case" => $onetime_case,
"behavior" => "도메인 쿠폰 구매 / {$coupon}",
"behavior_date" => $onetime_request_date,
"note" => trim($note),
"client_name" => $client->getTitle()
];
return $this->getModel()->insert($formDatas);
}
}

View File

@ -2,7 +2,10 @@
namespace lib\Services;
use lib\Entities\ClientEntity;
use lib\Entities\MemberEntity;
use lib\Entities\OnetimeEntity as Entity;
use lib\Entities\ServiceEntity;
use lib\Models\OnetimeModel as Model;
class OnetimeService extends CommonService
@ -38,4 +41,27 @@ class OnetimeService extends CommonService
$this->getModel()->where("client_code", $client_code);
return $this->getCount();
}
//도메인쿠폰 사용용
public function useCouponForDomain(ServiceEntity $service, ClientEntity $client, MemberEntity $member, string $onetime_case, int $coupon, string $note, string $onetime_request_date): bool
{
$formDatas = [
"client_code" => $service->getClientCode(),
"service_code" => $service->getServiceCode(),
"onetime_case" => $onetime_case,
"onetime_sub" => "도메인 쿠폰 구매 / {$coupon}",
"onetime_amount" => 0,
"onetime_payment" => 0,
"onetime_nonpayment" => 0,
"onetime_accountStatus" => 'complete',
"onetime_request_date" => $onetime_request_date,
"onetime_payment_date" => $onetime_request_date,
"onetime_note" => trim($note),
"onetime_handle_date" => $onetime_request_date,
"onetime_manager" => $member->getPK(),
"client_name" => $client->getTitle(),
"server_code" => $service->getServerCode(),
];
return $this->getModel()->insert($formDatas);
}
}

View File

@ -2,7 +2,9 @@
namespace lib\Services;
use lib\Entities\ClientEntity;
use lib\Entities\ServiceEntity as Entity;
use lib\Entities\ServiceEntity;
use lib\Models\ServiceModel as Model;
class ServiceService extends CommonService
@ -118,4 +120,25 @@ class ServiceService extends CommonService
$this->getModel()->whereNotIn("service_line", ['vpn', 'test', 'solo', 'substitution', 'event']);
return $this->getCount("SUM(coupon) as cnt");
}
//도메인쿠폰 사용용
public function useCouponForDomain(ServiceEntity $service, int $coupon): bool
{
if ($coupon < 0) {
throw new \Exception("쿠폰수량이 잘못되었습니다. 쿠폰수량 : $coupon");
}
$this->getModel()->where("service_code", $service->getServiceCode());
$this->getModel()->update(["coupon=(coupon-{$coupon})" => null, "coupon_use=(coupon_use+{$coupon})" => null]);
return true;
} //setCoupon
public function resetCouponByClient(ClientEntity $client, int $coupon): bool
{
if ($coupon < 0) {
throw new \Exception("쿠폰수량이 잘못되었습니다. 쿠폰수량 : $coupon");
}
$this->getModel()->where("client_code", $client->getClientCode());
$this->getModel()->where("server_code", $client->getTitle() . "_일회성");
$this->getModel()->update(["coupon" => $coupon, "coupon_use" => 0]);
return true;
} //setCoupon
}

View File

@ -1,7 +1,5 @@
<div class="table-responsive">
<form method="post" action="<?= DBMS_SITE_HOST ?>/dbms/client/coupon/insert/service_code/<?= $this->service->getServiceCode() ?>/client_code/<?= $this->service->getClientCode() ?>/mkid/<?= $this->member->getPK() ?>">
<input type="hidden" name="onetime_case" id="onetime_case" value="domain">
<input type="hidden" name="onetime_request_date" value="<?= $this->today ?>" />
<form method="post" action="<?= DBMS_SITE_HOST ?>/dbms/client/coupon/insert/service_code/<?= $this->service->getServiceCode() ?>/mkid/<?= $this->member->getPK() ?>">
<table class="table table-bordered table-hover table-striped">
<thead></thead>
<tbody>
@ -20,13 +18,11 @@
<tr>
<td>도메인 구매 수량</td>
<td colspan="5">
<select name="onetime_sub" id="onetime_sub">
<select name="coupon" id="coupon">
<?php for ($i = 1; $i < $this->service->getCoupon(); $i++) { ?>
<option value="<?= $i ?>"><?= $i ?>개</option>
<?php } ?>
</select> (개별 서버에 할당된 남은 쿠폰 수량 : <?= $this->service->getCoupon() ?>)
<!--<input type="text" name="onetime_sub" id="onetime_sub"/> (개별 서버에 할당된 남은 쿠폰 수량 : <?= $service['coupon'] ?>)
<br>* 도메인 쿠폰 사용시 반드시 숫자로만 갯수를 입력하세요 (* 3 구매시 작성 예제 : <font color=red><b>3</b></font>)-->
</td>
</tr>
<tr>
@ -41,7 +37,7 @@
</tr>
<tr>
<td>도메인 리스트</td>
<td colspan="5"><textarea cols="100" rows="4" type="text" name="onetime_note" id="onetime_note"></textarea>
<td colspan="5"><textarea cols="100" rows="4" type="text" name="note" id="note"></textarea>
<br>(공백을 허용하지 않습니다. 예제처럼 붙여쓰기 하세요 / 예제 : test.com/123.com/idcjp.jp)
</td>
</tr>