diff --git a/extdbms/lib/Configs/Constant.php b/extdbms/lib/Configs/Constant.php index c02e6a6..1dae4f9 100644 --- a/extdbms/lib/Configs/Constant.php +++ b/extdbms/lib/Configs/Constant.php @@ -194,6 +194,10 @@ define('DBMS_GEARLIST_CPU_TYPES', [ 'DX3', 'DQ233' ]); +define('DBMS_CLIENT_COUPON_TYPE', [ + 'domain' => '도메인구매', + 'etc' => '기타', +]); define('DBMS_CLIENT_POINT_TYPE', [ 'deposit' => '입금', 'withdrawal' => '출금', diff --git a/extdbms/lib/Configs/Route.php b/extdbms/lib/Configs/Route.php index 06368d1..2cd805b 100644 --- a/extdbms/lib/Configs/Route.php +++ b/extdbms/lib/Configs/Route.php @@ -52,6 +52,11 @@ $router->group('dbms/client', function (Router $router) { return $controller->update(); // Response::view($result); }); + $router->add('POST', 'use', function ($params) { + $controller = new CouponController(params: $params); + return $controller->use(); + // Response::view($result); + }); }); //Point관련 $router->group('point', function (Router $router) { diff --git a/extdbms/lib/Controllers/Client/CouponController.php b/extdbms/lib/Controllers/Client/CouponController.php index 27ab0eb..768b7fc 100644 --- a/extdbms/lib/Controllers/Client/CouponController.php +++ b/extdbms/lib/Controllers/Client/CouponController.php @@ -68,37 +68,44 @@ class CouponController extends ClientController //IdcCouponBuyMK.jsp -> domain_coupon_buy.php //CLI 접속방법 : php index.php site/client/counpon/insert_form //WEB 접속방법 : http://localhost/site/client/coupon/insert_form - public function update() + public function use() { - //기본적으로 필요한 client_code, member_code, service_code를 설정합니다. - list($this->client, $this->member, $this->service) = $this->setDefaultRequestData(null, true, true); - //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 { + //기본적으로 필요한 client_code, member_code, service_code를 설정합니다. + list($this->client, $this->member, $this->service) = $this->setDefaultRequestData(null, true, true); + //onetime_case 사용용도 + $onetime_case = $this->request->get('type'); + if (! $onetime_case) { + throw new \Exception("쿠폰 사용용도를 선택하세요"); + } + //onetime_note 사용내역 + $title = $this->request->get('title'); + if (! $title) { + throw new \Exception("쿠폰 사용제목을 입력하세요"); + } + //onetime_sub 사용수량 + $coupon_select = $this->request->get('select_coupon'); + if (! $coupon_select) { + throw new \Exception("쿠폰 수량 값이 정의되지 않았거나, 도메인 구매 수량은 1개 이상이어야 합니다."); + } + //onetime_note 비고 + $note = $this->request->get('coupon_note'); + //onetime_request_date 사용일 + $onetime_request_date = $this->request->get('onetime_request_date') ?? date("Y-m-d"); $this->getServiceService()->beginTransaction(); //서비스쿠폰 갯수 수정 - $this->getServiceService()->useCouponByService($this->service, $coupon); + $this->getServiceService()->useCouponByService($this->service, $coupon_select); //쿠폰 사용내역 onetime에 등록 - $this->getOnetimeService()->useCouponByService($this->service, $this->client, $this->member, $onetime_case, $coupon, $note, $onetime_request_date); + $this->getOnetimeService()->useCouponByService($this->service, $this->client, $this->member, $onetime_case, $title, $coupon_select, $note, $onetime_request_date); //쿠폰 사용내역 history에 등록 - $this->getHistoryService()->useCouponByService($this->service, $this->client, $onetime_case, $coupon, $note, $onetime_request_date);; + $this->getHistoryService()->useCouponByService($this->service, $this->client, $onetime_case, $coupon_select, $note, $onetime_request_date);; $this->getServiceService()->commit(); - return $this->redirect->to(DBMS_SITE_URL . "/IdcCouponUseMK.cup?client_code=" . $this->service->getClientCode()); - } catch (\Exception $e) { + return $this->redirect->to(DBMS_SITE_URL . "/IdcCouponUseMK.cup?client_code=" . $this->service->getClientCode())->send(); + } catch (\PDOException $e) { $this->getServiceService()->rollback(); - return $this->redirect->back()->withInput()->with('error', ['message' => '쿠폰 사용에 실패하였습니다.:' . $e->getMessage()]); + return $this->redirect->back()->withInput()->with('error', '쿠폰 사용에 실패하였습니다.:' . $e->getMessage())->send(); + } catch (\Exception $e) { + return $this->redirect->back()->withInput()->with('error', '쿠폰 사용에 실패하였습니다.:' . $e->getMessage())->send(); } } } //Class diff --git a/extdbms/lib/Core/Controller.php b/extdbms/lib/Core/Controller.php index 4e388c9..5672897 100644 --- a/extdbms/lib/Core/Controller.php +++ b/extdbms/lib/Core/Controller.php @@ -6,13 +6,11 @@ use lib\Core\Logger; use lib\Core\Http\Redirect; use lib\Core\Http\Request; use lib\Core\Http\Session; -use lib\Core\Http\Url; use lib\Core\Http\Response; abstract class Controller { protected ?View $_view = null; - protected ?Url $url = null; protected ?Request $request = null; protected ?Session $session = null; protected ?Redirect $redirect = null; @@ -26,12 +24,16 @@ abstract class Controller error_reporting(0); ini_set('display_errors', '0'); } - $this->url = new Url(); $this->request = new Request($params); $this->session = new Session(); $this->redirect = new Redirect($this->session); $this->logger = new Logger(); $this->_view = new View(); + $this->_view->request = $this->request; + $this->_view->session = $this->session; + $this->_view->redirect = $this->redirect; + $this->_view->logger = $this->logger; + $this->session->set('_previous_url', $this->request->currentUrl()); } // final public function __get($name): mixed { diff --git a/extdbms/lib/Core/Http/Redirect.php b/extdbms/lib/Core/Http/Redirect.php index b41007a..f023948 100644 --- a/extdbms/lib/Core/Http/Redirect.php +++ b/extdbms/lib/Core/Http/Redirect.php @@ -5,13 +5,14 @@ namespace lib\Core\Http; class Redirect { protected Session $session; + protected ?string $targetUrl = null; public function __construct(Session $session) { $this->session = $session; } - // 리다이렉트할 때 캐시를 방지하는 헤더 추가 + // 캐시 방지 헤더 private function noCacheHeaders(): void { header("Cache-Control: no-cache, no-store, must-revalidate"); @@ -19,34 +20,43 @@ class Redirect header("Expires: 0"); } - // 이전 페이지로 리다이렉트 (캐시 방지) + // 이전 페이지로 이동 설정 public function back(): self { - $this->noCacheHeaders(); // 캐시 방지 - $backUrl = $_SERVER['HTTP_REFERER'] ?? '/'; - header("Location: {$backUrl}"); + $this->targetUrl = $_SERVER['HTTP_REFERER'] ?? $this->session->get('_previous_url') ?? '/'; return $this; } - // 특정 URL로 리다이렉트 (캐시 방지) + // 특정 URL로 이동 설정 public function to(string $url): self { - $this->noCacheHeaders(); // 캐시 방지 - header("Location: {$url}"); - return $this;; + $this->targetUrl = $url; + return $this; } - // 세션에 값 추가 후 리다이렉트 + // POST 데이터 저장 public function withInput(): self { $this->session->flashInput($_POST); return $this; } - // 세션에 에러 메시지 저장 후 리다이렉트 + // 기타 flash 데이터 저장 public function with(string $key, mixed $value): self { $this->session->flash($key, $value); return $this; } + + // 실제 리다이렉트 전송 + public function send(): void + { + if (!$this->targetUrl) { + throw new \Exception("Redirect URL is not set."); + } + + $this->noCacheHeaders(); + header("Location: {$this->targetUrl}"); + exit; + } } diff --git a/extdbms/lib/Core/Http/Request.php b/extdbms/lib/Core/Http/Request.php index 4f7ff96..88e55df 100644 --- a/extdbms/lib/Core/Http/Request.php +++ b/extdbms/lib/Core/Http/Request.php @@ -5,12 +5,27 @@ namespace lib\Core\Http; class Request extends Http { private array $_datas = []; + private array $_files = []; + private array $_server = []; + + protected string $baseUrl; + protected string $uri; + public function __construct(array $params = []) { parent::__construct(); + $this->_datas = array_merge($_GET, $_POST, $params); + $this->_files = $_FILES ?? []; + $this->_server = $_SERVER ?? []; + + $this->baseUrl = $this->detectBaseUrl(); + $this->uri = $this->detectUri(); } + // -------------------- + // 요청 데이터 관련 + // -------------------- public function all(): array { return $this->_datas; @@ -34,25 +49,96 @@ class Request extends Http return array_key_exists($key, $this->_datas); } - /** - * Validator 연동 - */ - //사용예: - // $request = new Request(); + public function file(string $key): mixed + { + return $this->_files[$key] ?? null; + } - // $validation = $request->validate([ - // 'username' => 'required|alpha_numeric|min[4]', - // 'email' => 'required|email', - // 'password' => 'required|min[6]' - // ]); + public function method(): string + { + return strtoupper($_SERVER['REQUEST_METHOD'] ?? 'GET'); + } - // if ($validation !== true) { - // // 에러 처리 - // print_r($validation); - // } else { - // // 통과 - // echo "유효성 검사 통과!"; - // } + public function isPost(): bool + { + return $this->method() === 'POST'; + } + + public function isGet(): bool + { + return $this->method() === 'GET'; + } + + // -------------------- + // URL/경로 관련 + // -------------------- + public function baseUrl(): string + { + return $this->baseUrl; + } + + public function currentUrl(): string + { + return $this->baseUrl . '/' . ltrim($this->uri, '/'); + } + + public function previousUrl(): ?string + { + return $_SESSION['_previous_url'] ?? null; + } + + public function segments(): array + { + return explode('/', trim($this->uri, '/')); + } + + public function segment(int $n): ?string + { + $segments = $this->segments(); + return $segments[$n - 1] ?? null; + } + + public function urlIs(string $pattern): bool + { + $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); + $pattern = str_replace('*', '.*', preg_quote($pattern, '/')); + return preg_match("/^{$pattern}$/", $uri) === 1; + } + + public function to(string $path): string + { + return rtrim($this->baseUrl, '/') . '/' . ltrim($path, '/'); + } + + // 현재 URI 반환 (도메인 제외) + public function path(): string + { + return $this->uri; + } + + // -------------------- + // 내부 URL 추출 로직 + // -------------------- + protected function detectUri(): string + { + $uri = $_SERVER['REQUEST_URI'] ?? '/'; + $scriptName = dirname($_SERVER['SCRIPT_NAME'] ?? ''); + $uri = str_replace($scriptName, '', $uri); + $uri = strtok($uri, '?'); // 쿼리 스트링 제거 + return $uri; + } + + protected function detectBaseUrl(): string + { + $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; + $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; + $scriptDir = rtrim(dirname($_SERVER['SCRIPT_NAME'] ?? ''), '/'); + return $scheme . '://' . $host . $scriptDir; + } + + // -------------------- + // Validator 연동 + // -------------------- public function validate(array $rules, array $messages = []): bool|array { $validator = new Validator(); diff --git a/extdbms/lib/Core/Http/Session.php b/extdbms/lib/Core/Http/Session.php index 0a1893d..d948b86 100644 --- a/extdbms/lib/Core/Http/Session.php +++ b/extdbms/lib/Core/Http/Session.php @@ -8,6 +8,7 @@ class Session extends Http { parent::__construct(); $this->init(); + $this->sweepFlash(); // flash 생명주기 관리 } // 세션 시작 @@ -22,51 +23,65 @@ class Session extends Http } } - // 세션에 값 저장 + // 일반 세션 저장 public function set(string $key, $value): void { $_SESSION[$key] = $value; } - // 세션에서 값 가져오기 + // 일반 세션 가져오기 public function get(string $key): mixed { return $_SESSION[$key] ?? null; } - // 세션에서 값 삭제 + // 일반 세션 제거 public function remove(string $key): void { unset($_SESSION[$key]); } - // 세션에 에러 메시지 설정 - public function flash(string $key, $message): void + // flash 메시지 저장 (다음 요청까지) + public function flash(string $key, $value): void { - $_SESSION['flash'][$key] = $message; - } - - // 세션에 입력값 설정 (입력값 유지) - public function flashInput(array $input): void - { - $_SESSION['flash']['input'] = $input; - } - - // 세션에 flash 메시지가 있는지 확인 - public function hasFlash(string $key): bool - { - return isset($_SESSION['flash'][$key]); + $_SESSION['_flash_new'][$key] = $value; } // flash 메시지 가져오기 public function getFlash(string $key): mixed { - return $_SESSION['flash'][$key] ?? null; + return $_SESSION['_flash_old'][$key] ?? null; } - // flash 메시지 삭제 + // flash 메시지 존재 여부 + public function hasFlash(string $key): bool + { + return isset($_SESSION['_flash_old'][$key]); + } + + // 입력값을 flash로 저장 + public function flashInput(array $input): void + { + $_SESSION['_flash_new']['_old_input'] = $input; + } + + // 이전 입력값 가져오기 + public function old(string $key, $default = null): mixed + { + return $_SESSION['_flash_old']['_old_input'][$key] ?? $default; + } + + // 모든 flash 제거 (사용 후 직접 호출할 경우) public function clearFlash(): void { - unset($_SESSION['flash']); + unset($_SESSION['_flash_new']); + unset($_SESSION['_flash_old']); + } + + // 요청 시작 시 flash 생명주기 관리 (자동 호출) + private function sweepFlash(): void + { + $_SESSION['_flash_old'] = $_SESSION['_flash_new'] ?? []; + unset($_SESSION['_flash_new']); } } diff --git a/extdbms/lib/Core/Http/Url.php b/extdbms/lib/Core/Http/Url.php deleted file mode 100644 index 77ff698..0000000 --- a/extdbms/lib/Core/Http/Url.php +++ /dev/null @@ -1,103 +0,0 @@ -baseUrl = $this->detectBaseUrl(); - $this->uri = $this->detectUri(); - } - - // 현재 전체 URL 반환 - public function current(): string - { - return $this->baseUrl . '/' . ltrim($this->uri, '/'); - } - - // base URL만 반환 - public function base(): string - { - return $this->baseUrl; - } - - // 세그먼트 배열 반환 - public function segments(): array - { - return explode('/', trim($this->uri, '/')); - } - - // N번째 세그먼트 반환 (1부터 시작) - public function segment(int $n): ?string - { - $segments = $this->segments(); - return $segments[$n - 1] ?? null; - } - - // 특정 경로에 대한 URL 생성 - public function to(string $path): string - { - return rtrim($this->baseUrl, '/') . '/' . ltrim($path, '/'); - } - - // URI 추출 (도메인 제외) - protected function detectUri(): string - { - $uri = $_SERVER['REQUEST_URI'] ?? '/'; - $scriptName = dirname($_SERVER['SCRIPT_NAME'] ?? ''); - $uri = str_replace($scriptName, '', $uri); - $uri = strtok($uri, '?'); // 쿼리 스트링 제거 - return $uri; - } - - // base URL 추출 - protected function detectBaseUrl(): string - { - $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; - $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; - $scriptDir = rtrim(dirname($_SERVER['SCRIPT_NAME'] ?? ''), '/'); - return $scheme . '://' . $host . $scriptDir; - } - - public static function baseUrl(): string - { - $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https://" : "http://"; - $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; - $script = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); - - return rtrim($protocol . $host . $script, '/'); - } - - public static function currentUrl(): string - { - $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https://" : "http://"; - $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; - $uri = $_SERVER['REQUEST_URI'] ?? ''; - - return $protocol . $host . $uri; - } - - public static function previousUrl(): ?string - { - return $_SERVER['HTTP_REFERER'] ?? null; - } - - public static function urlIs(string $pattern): bool - { - $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); - $pattern = str_replace('*', '.*', preg_quote($pattern, '/')); - return preg_match("/^{$pattern}$/", $uri) === 1; - } - - public static function getSegment(int $index): ?string - { - $uri = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); - $segments = explode('/', $uri); - return $segments[$index - 1] ?? null; - } -} diff --git a/extdbms/lib/Core/View.php b/extdbms/lib/Core/View.php index 78700bf..face51b 100644 --- a/extdbms/lib/Core/View.php +++ b/extdbms/lib/Core/View.php @@ -46,8 +46,17 @@ class View { // Blade 템플릿 렌더링 $file = implode('.', $this->_paths) . '.' . $file; + + // session 값을 BladeOne에 전역 공유 + if (isset($this->_values['session'])) { + $this->_blade->share('session', $this->_values['session']); + } + if (APP_VIEW_DEBUG) { echo "
VIwe DEBUG:" . __METHOD__ . "에서 [" . $file . "]를 렌더링합니다."; + // echo "
Blade View 전달 값:\n"; + // print_r($this->_values); + echo ""; } return $this->_blade->run($file, $this->_values); } diff --git a/extdbms/lib/Services/OnetimeService.php b/extdbms/lib/Services/OnetimeService.php index cfbab15..67fed64 100644 --- a/extdbms/lib/Services/OnetimeService.php +++ b/extdbms/lib/Services/OnetimeService.php @@ -33,13 +33,13 @@ class OnetimeService extends CommonService } //도메인쿠폰 사용용 - public function useCouponByService(ServiceEntity $service, ClientEntity $client, MemberEntity $member, string $onetime_case, int $coupon, string $note, string $onetime_request_date): bool + public function useCouponByService(ServiceEntity $service, ClientEntity $client, MemberEntity $member, string $onetime_case, $onetime_sub, 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_sub" => $onetime_sub, "onetime_amount" => 0, "onetime_payment" => 0, "onetime_nonpayment" => 0, diff --git a/extdbms/lib/Views/dbms/client/coupon/index.php b/extdbms/lib/Views/dbms/client/coupon/index.php index 488d429..2ec2958 100644 --- a/extdbms/lib/Views/dbms/client/coupon/index.php +++ b/extdbms/lib/Views/dbms/client/coupon/index.php @@ -18,9 +18,124 @@ background-color: #f2f2f2; } + @if ($client)
| 고객명 | 서비스코드 | 장비명 | -사용내역 | -남은 쿠폰수 | -사용된 쿠폰수 | +사용용도 | +사용제목 | +남은수/사용된수 | +사용쿠폰수 | 비고 | 작업 | @@ -40,21 +156,44 @@ @php $i=0 @endphp @foreach($entities as $key=>$entity) - ++ + + + + | + + @php $i++ @endphp @endforeach
|---|