diff --git a/extdbms/lib/Utils/Pagination.php b/extdbms/lib/Configs/Pagination.php
similarity index 91%
rename from extdbms/lib/Utils/Pagination.php
rename to extdbms/lib/Configs/Pagination.php
index cd504de..a9170ef 100644
--- a/extdbms/lib/Utils/Pagination.php
+++ b/extdbms/lib/Configs/Pagination.php
@@ -1,6 +1,6 @@
getServiceService()->getModel()->where('client_code', $this->client->getClientCode());
}
//업체명_일회성만 나오게하기 위해서
- $this->getServiceService()->getModel()->like('server_code', '%_일회성');
- $this->curPage = intval($this->request->get('curPage', 1));
- $this->perPage = intval($this->request->get('perPage', APP_VIEW_LIST_PERPAGE));
- [$this->total, $this->entities] = $this->getServiceService()->getList($this->curPage, $this->perPage);
- $this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
-
+ $this->getServiceService()->getModel()->like('server_code', "%\-일회성");
+ [$this->total, $this->entities, $this->pagination, $this->curPage, $this->perPage] = $this->getServiceService()->getList(
+ $this->request->get('curPage'),
+ $this->request->get('perPage')
+ );
//전체 사용자정보
$this->clients = $this->getClientService()->getEntities();
return $this->render(__FUNCTION__);
diff --git a/extdbms/lib/Controllers/Client/PaymentController.php b/extdbms/lib/Controllers/Client/PaymentController.php
index 77e1cdc..bfc26e7 100644
--- a/extdbms/lib/Controllers/Client/PaymentController.php
+++ b/extdbms/lib/Controllers/Client/PaymentController.php
@@ -2,7 +2,8 @@
namespace lib\Controllers\Client;
-use lib\Utils\Pagination;
+use lib\Models\AddDbModel;
+use lib\Models\ClientModel;
class PaymentController extends ClientController
{
@@ -62,10 +63,20 @@ class PaymentController extends ClientController
break;
}
$this->mode = $mode;
- $this->curPage = intval($this->request->get('curPage', 1));
- $this->perPage = intval($this->request->get('perPage', APP_VIEW_LIST_PERPAGE));
- [$this->total, $this->entities] = $this->getServiceService()->getEntitiesForNonPayment($this->curPage, $this->perPage, $exclude_clients);
- $this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
+
+ $table = $this->getServiceService()->getModel()->getTable();
+ $clientTable = ClientModel::TABLE;
+ $addDbTable = AddDbModel::TABLE;
+ $this->getServiceService()->getModel()->select("{$clientTable}.Client_Name,{$table}.service_code,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,addDB_case,addDB_nonpayment,addDB_payment,addDB_accountStatus,addDB_ip,addDB_payment_date");
+ $this->getServiceService()->getModel()->join($clientTable, "{$table}.client_code = {$clientTable}.Client_Code");
+ $this->getServiceService()->getModel()->join($addDbTable, "{$table}.service_code = {$addDbTable}.service_code");
+ $this->getServiceService()->getModel()->whereNotIn("{$addDbTable}.client_code", $exclude_clients);
+ $this->getServiceService()->getModel()->whereNotIn("{$addDbTable}.addDB_accountStatus", ["complete"]);
+ $this->getServiceService()->getModel()->orderBy("service_payment_date", "DESC");
+ [$this->total, $this->entities, $this->pagination, $this->curPage, $this->perPage] = $this->getServiceService()->getList(
+ $this->request->get('curPage'),
+ $this->request->get('perPage')
+ );
return $this->render(__FUNCTION__);
}
} //Class
diff --git a/extdbms/lib/Controllers/Client/PointController.php b/extdbms/lib/Controllers/Client/PointController.php
index 9ab850a..5924286 100644
--- a/extdbms/lib/Controllers/Client/PointController.php
+++ b/extdbms/lib/Controllers/Client/PointController.php
@@ -5,7 +5,7 @@ namespace lib\Controllers\Client;
use lib\Services\HistoryService;
use lib\Services\OnetimeService;
use lib\Services\PointService;
-use lib\Utils\Pagination;
+use lib\Configs\Pagination;
use lib\Helpers\Client\PointHelper;
class PointController extends ClientController
@@ -53,11 +53,11 @@ class PointController extends ClientController
if ($client_code) {
$this->getPointService()->getModel()->where('client_code', $client_code);
}
+ [$this->total, $this->entities, $this->pagination, $this->curPage, $this->perPage] = $this->getPointService()->getList(
+ $this->request->get('curPage'),
+ $this->request->get('perPage')
+ );
$this->client_code = $client_code;
- $this->curPage = intval($this->request->get('curPage', 1));
- $this->perPage = intval($this->request->get('perPage', APP_VIEW_LIST_PERPAGE));
- [$this->total, $this->entities] = $this->getPointService()->getList($this->curPage, $this->perPage);
- $this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
return $this->render(__FUNCTION__);
}
diff --git a/extdbms/lib/Controllers/DefenceController.php b/extdbms/lib/Controllers/DefenceController.php
index 5cb3916..5d8a5ca 100644
--- a/extdbms/lib/Controllers/DefenceController.php
+++ b/extdbms/lib/Controllers/DefenceController.php
@@ -3,7 +3,7 @@
namespace lib\Controllers;
use lib\Services\DefenceService;
-use lib\Utils\Pagination;
+use lib\Configs\Pagination;
class DefenceController extends DBMSController
{
@@ -33,10 +33,10 @@ class DefenceController extends DBMSController
$this->zone = urldecode($zone);
$this->getDefenceService()->getModel()->where(['zone' => $this->zone]);
$this->getDefenceService()->getModel()->orderBy(['zone' => 'asc', 'parents' => 'asc', 'child' => 'asc']);
- $this->curPage = intval($this->request->get('curPage', 1));
- $this->perPage = intval($this->request->get('perPage', APP_VIEW_LIST_PERPAGE));
- [$this->total, $this->entities] = $this->getDefenceService()->getList($this->curPage, $this->perPage);
- $this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
+ [$this->total, $this->entities, $this->pagination, $this->curPage, $this->perPage] = $this->getDefenceService()->getList(
+ $this->request->get('curPage'),
+ $this->request->get('perPage')
+ );
return $this->render(__FUNCTION__);
}
} //Class
diff --git a/extdbms/lib/Controllers/OnetimeController.php b/extdbms/lib/Controllers/OnetimeController.php
index 726d5ef..69c74df 100644
--- a/extdbms/lib/Controllers/OnetimeController.php
+++ b/extdbms/lib/Controllers/OnetimeController.php
@@ -5,7 +5,6 @@ namespace lib\Controllers;
use lib\Entities\ClientEntity;
use lib\Services\ClientService;
use lib\Services\OnetimeService;
-use lib\Utils\Pagination;
class OnetimeController extends DBMSController
{
@@ -43,11 +42,11 @@ class OnetimeController extends DBMSController
}
//업체명_일회성만 나오게하기 위해서
$this->getOnetimeService()->getModel()->where('service_code', $this->service->getServiceCode());
- $this->curPage = intval($this->request->get('curPage', 1));
- $this->perPage = intval($this->request->get('perPage', APP_VIEW_LIST_PERPAGE));
- [$this->total, $this->entities] = $this->getOnetimeService()->getList($this->curPage, $this->perPage);
- $this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
-
+ $this->getOnetimeService()->getModel()->orderBy('onetime_num', 'DESC');
+ [$this->total, $this->entities, $this->pagination, $this->curPage, $this->perPage] = $this->getOnetimeService()->getList(
+ $this->request->get('curPage'),
+ $this->request->get('perPage')
+ );
//전체 사용자정보
$this->clients = $this->getClientService()->getEntities();
//전체 관리자정보
diff --git a/extdbms/lib/Controllers/ServerController.php b/extdbms/lib/Controllers/ServerController.php
index 4078904..12546bf 100644
--- a/extdbms/lib/Controllers/ServerController.php
+++ b/extdbms/lib/Controllers/ServerController.php
@@ -4,7 +4,6 @@ namespace lib\Controllers;
use lib\Services\ClientService;
use lib\Services\ServerService;
-use lib\Utils\Pagination;
class ServerController extends DBMSController
{
diff --git a/extdbms/lib/Controllers/ServiceController.php b/extdbms/lib/Controllers/ServiceController.php
index bdcc14c..1bc88e3 100644
--- a/extdbms/lib/Controllers/ServiceController.php
+++ b/extdbms/lib/Controllers/ServiceController.php
@@ -4,7 +4,7 @@ namespace lib\Controllers;
use lib\Services\AddDbService;
use lib\Services\ClientService;
-use lib\Utils\Pagination;
+use lib\Configs\Pagination;
class ServiceController extends DBMSController
{
@@ -76,11 +76,11 @@ class ServiceController extends DBMSController
//전체 사용자정보
$this->clients = $this->getClientService()->getEntities();
//부가서비스용 서비스목록 가져오기
- $this->curPage = intval($this->request->get('curPage', 1));
- $this->perPage = intval($this->request->get('perPage', APP_VIEW_LIST_PERPAGE));
$this->getServiceService()->getModel()->whereIn('service_code', $service_codes);
- [$this->total, $this->entities] = $this->getServiceService()->getList($this->curPage, $this->perPage);
- $this->pagination = new Pagination($this->total, (int)$this->curPage, (int)$this->perPage);
+ [$this->total, $this->entities, $this->pagination, $this->curPage, $this->perPage] = $this->getServiceService()->getList(
+ $this->request->get('curPage'),
+ $this->request->get('perPage')
+ );
return $this->render(__FUNCTION__);
}
} //Class
diff --git a/extdbms/lib/Core/Database/QueryBuilder.php b/extdbms/lib/Core/Database/QueryBuilder.php
index 225b4bb..337d078 100644
--- a/extdbms/lib/Core/Database/QueryBuilder.php
+++ b/extdbms/lib/Core/Database/QueryBuilder.php
@@ -45,9 +45,11 @@ class QueryBuilder
if (!empty($this->joins)) {
$sql .= ' ' . implode(' ', $this->joins);
}
+ // Where 처리
if (!empty($this->where)) {
$sql .= " WHERE " . $this->buildWhereSql();
}
+ // Order 처리
if (!empty($this->order)) {
$sql .= " ORDER BY " . implode(', ', $this->order);
}
@@ -153,17 +155,19 @@ class QueryBuilder
// $model->orLikeIn(['name', 'nickname'], '%철수%');
public function like(array|string $column, ?string $value = null, string $operator = 'LIKE', string $boolean = "AND"): static
{
+ $escapeClause = in_array(strtoupper($operator), ['LIKE', 'NOT LIKE']) ? " ESCAPE '\\\\'" : '';
+
if (is_array($column)) {
$conditions = [];
foreach ($column as $col => $val) {
$placeholder = ':l_' . count($this->bindings);
- $conditions[] = "$col $operator $placeholder";
+ $conditions[] = "$col $operator $placeholder$escapeClause";
$this->bindings[$placeholder] = $val;
}
$this->where[] = ['condition' => '(' . implode(" $boolean ", $conditions) . ')', 'boolean' => $boolean];
} else {
$placeholder = ':l_' . count($this->bindings);
- $condition = "$column $operator $placeholder";
+ $condition = "$column $operator $placeholder$escapeClause";
$this->bindings[$placeholder] = $value;
$this->where[] = ['condition' => $condition, 'boolean' => $boolean];
}
@@ -173,15 +177,22 @@ class QueryBuilder
{
return $this->like($column, $value, $operator, $boolean);
}
-
+ public function notLike(array|string $column, ?string $value = null, string $operator = 'NOT LIKE', string $boolean = "AND"): static
+ {
+ return $this->like($column, $value, $operator, $boolean);
+ }
+ //likeIn 사용예:
public function likeIn(array $columns, string $value, string $operator = "LIKE", string $boolean = "AND"): static
{
+ $escapeClause = in_array(strtoupper($operator), ['LIKE', 'NOT LIKE']) ? " ESCAPE '\\\\'" : '';
$orConditions = [];
+
foreach ($columns as $col) {
$placeholder = ':li_' . count($this->bindings);
- $orConditions[] = "$col $operator $placeholder";
+ $orConditions[] = "$col $operator $placeholder$escapeClause";
$this->bindings[$placeholder] = $value;
}
+
$this->where[] = '(' . implode(" $boolean ", $orConditions) . ')';
return $this;
}
diff --git a/extdbms/lib/Core/Database/QueryBuilder_Ver2.php b/extdbms/lib/Core/Database/QueryBuilder_Ver2.php
new file mode 100644
index 0000000..72f09eb
--- /dev/null
+++ b/extdbms/lib/Core/Database/QueryBuilder_Ver2.php
@@ -0,0 +1,219 @@
+pdo = $pdo;
+ }
+
+ final public function setDebug(bool $debug): void
+ {
+ $this->_debug = $debug;
+ }
+
+ public function table(string $table): self
+ {
+ $this->table = $table;
+ return $this;
+ }
+
+ public function select(...$columns): self
+ {
+ $this->selects = array_merge($this->selects, $columns);
+ return $this;
+ }
+
+ public function where(string $column, mixed $value = null, ?string $operator = null, string $boolean = "AND")
+ {
+ $this->wheres[] = "{$this->escapeIdentifier($column)} {$operator} ?";
+ $this->bindings[] = $value;
+ return $this;
+ }
+
+ public function like(string $column, string $value): self
+ {
+ $this->likes[] = $this->escapeIdentifier($column) . " LIKE ?";
+ $this->bindings[] = "%" . $this->escapeLikeString($value) . "%";
+ return $this;
+ }
+
+ public function orLike(string $column, string $value): self
+ {
+ $last = array_pop($this->likes);
+ $condition = $last ? "({$last} OR {$this->escapeIdentifier($column)} LIKE ?)" : "{$this->escapeIdentifier($column)} LIKE ?";
+ $this->likes[] = $condition;
+ $this->bindings[] = "%" . $this->escapeLikeString($value) . "%";
+ return $this;
+ }
+
+ public function likeIn(string $column, array $values): self
+ {
+ $clauses = [];
+ foreach ($values as $val) {
+ $clauses[] = $this->escapeIdentifier($column) . " LIKE ?";
+ $this->bindings[] = "%" . $this->escapeLikeString($val) . "%";
+ }
+ $this->likeIns[] = '(' . implode(' OR ', $clauses) . ')';
+ return $this;
+ }
+
+ public function notLikeIn(string $column, array $values): self
+ {
+ $clauses = [];
+ foreach ($values as $val) {
+ $clauses[] = $this->escapeIdentifier($column) . " NOT LIKE ?";
+ $this->bindings[] = "%" . $this->escapeLikeString($val) . "%";
+ }
+ $this->notLikeIns[] = '(' . implode(' AND ', $clauses) . ')';
+ return $this;
+ }
+
+ public function orderBy(string $column, string $direction = 'ASC'): self
+ {
+ $this->orderBy = "ORDER BY {$this->escapeIdentifier($column)} {$direction}";
+ return $this;
+ }
+
+ public function groupBy(string $column): self
+ {
+ $this->groupBy = "GROUP BY {$this->escapeIdentifier($column)}";
+ return $this;
+ }
+
+ public function limit(int $limit, int $offset = 0): self
+ {
+ $this->limit = "LIMIT {$offset}, {$limit}";
+ return $this;
+ }
+
+ public function get(): array
+ {
+ $stmt = $this->execute();
+ return $stmt->fetchAll(PDO::FETCH_ASSOC);
+ }
+
+ public function first(): ?array
+ {
+ $this->limit(1);
+ $stmt = $this->execute();
+ return $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
+ }
+
+ public function count(): int
+ {
+ $this->select("COUNT(*) as count");
+ $stmt = $this->execute();
+ return (int)($stmt->fetch(PDO::FETCH_ASSOC)['count'] ?? 0);
+ }
+
+ public function debug(bool $debug = true): self
+ {
+ $this->debug = $debug;
+ return $this;
+ }
+
+ public function beginTransaction(): void
+ {
+ if (!$this->inTransaction) {
+ $this->pdo->beginTransaction();
+ $this->inTransaction = true;
+ }
+ }
+
+ public function commit(): void
+ {
+ if ($this->inTransaction) {
+ $this->pdo->commit();
+ $this->inTransaction = false;
+ }
+ }
+
+ public function rollback(): void
+ {
+ if ($this->inTransaction) {
+ $this->pdo->rollBack();
+ $this->inTransaction = false;
+ }
+ }
+
+ public function execute(): \PDOStatement
+ {
+ $sql = $this->buildSelectQuery();
+
+ if ($this->debug) {
+ echo "[SQL]: {$sql}\n";
+ echo "[Bindings]: " . json_encode($this->bindings, JSON_UNESCAPED_UNICODE) . "\n";
+ }
+
+ $stmt = $this->pdo->prepare($sql);
+ $stmt->execute($this->bindings);
+ return $stmt;
+ }
+
+ protected function buildSelectQuery(): string
+ {
+ $columns = $this->selects ? implode(', ', array_map([$this, 'escapeIdentifier'], $this->selects)) : '*';
+ $sql = "SELECT {$columns} FROM {$this->escapeIdentifier($this->table)}";
+
+ $conditions = array_merge($this->wheres, $this->likes, $this->likeIns, $this->notLikeIns);
+ if (!empty($conditions)) {
+ $sql .= " WHERE " . implode(' AND ', $conditions);
+ }
+
+ if ($this->groupBy) {
+ $sql .= " {$this->groupBy}";
+ }
+
+ if ($this->orderBy) {
+ $sql .= " {$this->orderBy}";
+ }
+
+ if ($this->limit) {
+ $sql .= " {$this->limit}";
+ }
+
+ return $sql;
+ }
+
+ // Escape helpers
+
+ public function escape(mixed $value): string
+ {
+ return $this->pdo->quote($value);
+ }
+
+ public function escapeIdentifier(string $identifier): string
+ {
+ return "`" . str_replace("`", "``", $identifier) . "`";
+ }
+
+ public function escapeLikeString(string $value): string
+ {
+ return str_replace(['%', '_'], ['\\%', '\\_'], $value);
+ }
+
+ public function escapeLikeIn(array $values): array
+ {
+ return array_map([$this, 'escapeLikeString'], $values);
+ }
+}
diff --git a/extdbms/lib/Models/OnetimeModel.php b/extdbms/lib/Models/OnetimeModel.php
index d7eebdc..96208cf 100644
--- a/extdbms/lib/Models/OnetimeModel.php
+++ b/extdbms/lib/Models/OnetimeModel.php
@@ -9,7 +9,7 @@ class OnetimeModel extends Model
const TABLE = "onetimedb";
const PKField = "onetime_num";
const TitleField = "onetime_sub";
- const PairField = self::TitleField;
+ const PairField = self::PKField;
public function __construct()
{
parent::__construct();
diff --git a/extdbms/lib/Services/CommonService.php b/extdbms/lib/Services/CommonService.php
index 77d7fd3..864c143 100644
--- a/extdbms/lib/Services/CommonService.php
+++ b/extdbms/lib/Services/CommonService.php
@@ -3,6 +3,7 @@
namespace lib\Services;
use lib\Core\Service as Core;
+use lib\Configs\Pagination;
abstract class CommonService extends Core
{
@@ -38,24 +39,30 @@ abstract class CommonService extends Core
$entityClass = $this->getEntityClass();
$entity = new $entityClass($result);
$pairField = $this->getModel()->getPairField();
+ // echo "pairField:" . $pairField . "
";
$entitys[$entity->$pairField] = $entity;
}
return $entitys;
} //
final public function getCount(string $select = "COUNT(*) as cnt", string $column = 'cnt'): int
{
- $count = $this->getModel()->count($select, $column);
- // echo "
" . $this->getModel()->getLastQuery();
- return $count;
+ return $this->getModel()->count($select, $column);
}
- final public function getList(int $curPage = 1, int $perPage = APP_VIEW_LIST_PERPAGE): array
+ final public function getList($curPage = null, $perPage = null): array
{
$total = $this->getCount();
+ $curPage = $curPage ?? 1;
+ $perPage = $perPage ?? APP_VIEW_LIST_PERPAGE;
+ $curPage = (int)$curPage;
+ $perPage = (int)$perPage;
+ $curPage = intval($curPage > 0 ? $curPage : 1);
+ $perPage = intval($perPage > 0 ? $perPage : APP_VIEW_LIST_PERPAGE);
//limit, offset 설정
$this->getModel()->limit($perPage);
$this->getModel()->offset(($curPage - 1) * $perPage);
$entities = $this->getEntities();
- return [$total, $entities];
+ $pagination = new Pagination($total, $curPage, $perPage);
+ return [$total, $entities, $pagination, $curPage, $perPage];
}
protected function insert(array $formData): mixed
diff --git a/extdbms/lib/Services/ServiceService.php b/extdbms/lib/Services/ServiceService.php
index 3326153..c69e128 100644
--- a/extdbms/lib/Services/ServiceService.php
+++ b/extdbms/lib/Services/ServiceService.php
@@ -32,25 +32,6 @@ class ServiceService extends CommonService
return Entity::class;
}
- //미지급금 리스트
- public function getEntitiesForNonPayment(int $curPage, int $perPage, array $exclude_clients): array
- {
- $table = $this->getModel()->getTable();
- $clientTable = ClientModel::TABLE;
- $addDbTable = AddDbModel::TABLE;
- $this->getModel()->select("{$clientTable}.Client_Name,{$table}.service_code,service_line,server_code,service_ip,service_payment_date,service_amount,service_nonpayment,service_note,addDB_case,addDB_nonpayment,addDB_payment,addDB_accountStatus,addDB_ip,addDB_payment_date");
- $this->getModel()->join($clientTable, "{$table}.client_code = {$clientTable}.Client_Code");
- $this->getModel()->join($addDbTable, "{$table}.service_code = {$addDbTable}.service_code");
- $this->getModel()->whereNotIn("{$addDbTable}.client_code", $exclude_clients);
- $this->getModel()->whereNotIn("{$addDbTable}.addDB_accountStatus", ["complete"]);
- $this->getModel()->orderBy("service_payment_date", "DESC");
- $total = $this->getCount();
- //limit, offset 설정
- $this->getModel()->limit($perPage);
- $this->getModel()->offset(($curPage - 1) * $perPage);
- return [$total, $this->getEntities()];
- }
-
//지역(치바,도쿄등)에 따른 DASHBOARD용 서비스 카운트
private function getDistrictCountForDashboard(string $where, string $type, array $switchcodes): int
{
diff --git a/extdbms/lib/Views/dbms/client/coupon/index.php b/extdbms/lib/Views/dbms/client/coupon/index.php
index f02d5f0..488d429 100644
--- a/extdbms/lib/Views/dbms/client/coupon/index.php
+++ b/extdbms/lib/Views/dbms/client/coupon/index.php
@@ -19,7 +19,7 @@
}
@if ($client)
-