From c72477a40ddeb6b8933e58627634a290481aa532 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 2 Feb 2022 17:12:55 +0900 Subject: [PATCH 1/3] Coupon Change --- extdbms/Itsolution_Coupon_20220202.txt | 48 ++++++++++++++++++++++++++ extdbms/coupon.php | 22 +++++------- extdbms/lib/Controller/Coupon.php | 39 ++++++++++++--------- extdbms/lib/Core/Model.php | 8 ++--- extdbms/lib/Model/Client.php | 6 ++++ extdbms/lib/Model/Service.php | 26 +++++++++----- 6 files changed, 105 insertions(+), 44 deletions(-) create mode 100644 extdbms/Itsolution_Coupon_20220202.txt diff --git a/extdbms/Itsolution_Coupon_20220202.txt b/extdbms/Itsolution_Coupon_20220202.txt new file mode 100644 index 0000000..ba6367e --- /dev/null +++ b/extdbms/Itsolution_Coupon_20220202.txt @@ -0,0 +1,48 @@ +555||3 +amd360||3 +GOAL||12 +KORODD||18 +PB||12 +VIP||3 +고담유통||9 +금수||9 +김민우||6 +김삼순||3 +날두||3 +넷마블||12 +더존||3 +도실장||12 +드림네트윅.KMK||3 +레모나||6 +로비오||12 +리벤져스||9 +리스보아||3 +몬스터||39 +묵은지||3 +박팀장.드래곤||24 +박팀장.스마일||9 +박팀장.스카이||3 +보로||15 +봉덕.사장님(개발자)||6 +봉덕.실업체||6 +블랙캐쉬||21 +샤오미||9 +세븐||6 +스마트||24 +승열||6 +신나라||6 +씨에이컴||36 +오라클||30 +오매||3 +오세정||3 +용찬||36 +잭블랙||45 +주식회사무지2||9 +카오스||3 +타임||3 +토렌트맥스||6 +포인트||9 +플러스윈||3 +피오피||30 +하와이||9 +헌법||3 \ No newline at end of file diff --git a/extdbms/coupon.php b/extdbms/coupon.php index 122ef66..4f86e8b 100644 --- a/extdbms/coupon.php +++ b/extdbms/coupon.php @@ -3,25 +3,21 @@ namespace lib\Controller; require_once "lib/autoload.php"; -if ($argc < 1) { - die("사용법 : php main.php 데이타파일명 \n"); +if ($argc < 2) { + die("사용법 : php main.php 데이타파일명 [Type]\n"); } if (!is_file($argv[1])) { die($argv[1] . "는 파일형식이 아닙니다. \n"); } +$client_type = isset($argv[2]) ? $argv[2]:'Client_Code'; $lines = file($argv[1]); if (!is_array($lines)) { die($argv[1] . "는 파일데이터에 오류가 있습니다. \n"); } -try { - $coupon = new Coupon(); - $results = $coupon->execute($lines); - - print("Coupon 설정이 완료되었습니다.\n"); - foreach ($results as $result) { - echo $result . "\n"; - } -} catch (\Exception $e) { - echo $e->getMessage(); -} // +$debug = false; +$coupon = new Coupon(); +list($successes,$failes) = $coupon->execute($lines,$client_type,$debug); +print("Coupon 설정이 완료되었습니다.\n"); +print_r($successes); +print_r($failes); diff --git a/extdbms/lib/Controller/Coupon.php b/extdbms/lib/Controller/Coupon.php index 1e004f7..6a7be21 100644 --- a/extdbms/lib/Controller/Coupon.php +++ b/extdbms/lib/Controller/Coupon.php @@ -9,31 +9,38 @@ class Coupon extends Controller { parent::__construct(); } // - final public function getCouponInfo($line, $field) + final public function getCouponInfo($data, $field) { - list($clientData, $coupon) = explode("||", rtrim($line)); - $client = $this->getModel("Client")->getData(sprintf("%s='%s'", $field, $clientData)); - $service = $this->getModel("Service")->getData(sprintf("client_code='%s'", $client['Client_Code'])); + $client = $this->getModel("Client")->getClient(sprintf("%s='%s'", $field, $data)); + $service = $this->getModel("Service")->getOneTime($client->Client_Name); return array( "client" => $client, "service" => $service, - "coupon" => $coupon, ); } // - public function execute(array $lines, $field = "Client_Code") + public function execute(array $lines, $field = "Client_Code", $debug=false) { - $results = array(); - foreach ($this->getCouponInfo($lines, $field) as $coupon) { - //쿠폰 설정 - $where = sprintf("coupon='%s'", $coupon['service']['service_code']); - $this->getModel("Service")->setCoupon($coupon['coupon'], $where); + $loop=1; + $successes = array(); + $failes = array(); + foreach ($lines as $line) { + list($info, $coupon_cnt) = explode("||", rtrim($line)); + $coupon = $this->getCouponInfo($info, $field); + if(isset($coupon['service']->service_code)){ + //쿠폰 설정 + $where = sprintf("service_code='%s'", $coupon['service']->service_code); + $this->getModel("Service")->setCoupon($coupon_cnt, $where, $debug); - //결과정리 - $result = sprintf("%20s[%20s:%15s]=>쿠폰 %3d개 설정\n", $coupon['client']['Client_Name'], - $coupon['service']['server_code'], $coupon['service']['service_code'], $coupon['coupon']); - array_push($results, $result); + $result = sprintf("%20s[%20s:%15s]=>쿠폰 %3d개 설정 성공\n", $coupon['client']->Client_Name, + $coupon['service']->server_code, $coupon['service']->service_code, $coupon_cnt); + array_push($successes, $result); + } else { + $result = sprintf("%5d번째: %s 설정 실패\n", $loop,rtrim($line)); + array_push($failes, $result); + } + $loop++; } - return $results; + return array($successes,$failes); } } diff --git a/extdbms/lib/Core/Model.php b/extdbms/lib/Core/Model.php index cd3e90f..c121a63 100644 --- a/extdbms/lib/Core/Model.php +++ b/extdbms/lib/Core/Model.php @@ -10,7 +10,6 @@ abstract class Model private $_mode = PDO::FETCH_OBJ; protected function __construct() { - try { $envs = parse_ini_file("./env.ini", true); if (!$envs) { throw new \Exception(var_export($envs, true)); @@ -20,9 +19,6 @@ abstract class Model $this->db = new PDO($dsn, $envs['db']['id'], $envs['db']['passwd']); $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } catch (\Exception $e) { - throw new \Exception("DB접속중 에러가 발생 하였습니다. : " . $e->getMessage()); - } } // abstract public function getTable(); @@ -67,13 +63,13 @@ abstract class Model final public function getData($wheres = array(), $column = "*") { $sql = sprintf("SELECT %s FROM %s %s", $column, $this->getTable(), count($wheres) ? "WHERE " . implode("AND", $wheres) : ""); - //echo $sql; + echo $sql; return $this->getRow($sql); } final public function getDatas(array $wheres = array(), $column = "*") { $sql = sprintf("SELECT %s FROM %s %s", $column, $this->getTable(), count($wheres) ? "WHERE " . implode("AND", $wheres) : ""); - //echo $sql; + echo $sql; return $this->getRows($sql); } } //Class diff --git a/extdbms/lib/Model/Client.php b/extdbms/lib/Model/Client.php index 674f72d..1813a5c 100644 --- a/extdbms/lib/Model/Client.php +++ b/extdbms/lib/Model/Client.php @@ -14,4 +14,10 @@ class Client extends Model { return 'clientdb'; } + + final public function getClient($where) + { + $sql = sprintf("SELECT * FROM %s WHERE %s", $this->getTable(), $where); + return $this->getRow($sql); + } // } //Class diff --git a/extdbms/lib/Model/Service.php b/extdbms/lib/Model/Service.php index 97d09f8..3fd21aa 100644 --- a/extdbms/lib/Model/Service.php +++ b/extdbms/lib/Model/Service.php @@ -15,28 +15,36 @@ class Service extends Model return 'servicedb'; } //쿠폰 추가 - final public function addCoupon($coupon, $where = "") + final public function addCoupon($coupon, $where = "",$debug=false) { $sql = sprintf("UPDATE %s SET coupon = coupon+%d %s", $this->getTable(), $coupon, $where ? "WHERE " . $where : $where); - return $this->execute($sql); + if($debug){ + echo $sql."\n"; + }else{ + return $this->execute($sql); + } } // //쿠폰 설정 - final public function setCoupon($coupon, $where = "") + final public function setCoupon($coupon, $where = "",$debug=false) { $sql = sprintf("UPDATE %s SET coupon = %d %s", $this->getTable(), $coupon, $where ? "WHERE " . $where : $where); - return $this->execute($sql); + if($debug){ + echo $sql."\n"; + }else{ + return $this->execute($sql); + } } // //일회성서비스정보 가져오기 - final public function getOneTimes($where = "") + final public function getOneTime($client_name) { - $sql = sprintf("SELECT * FROM %s WHERE server_code LIKE '%일회성%' %s", $this->getTable(), $where ? "WHERE " . $where : $where); - return $this->getRows($sql); + $sql = sprintf("SELECT * FROM %s WHERE server_code = '%s-일회성'", $this->getTable(), $client_name); + echo $sql . "\n"; + return $this->getRow($sql); } // - final public function getCount($where = "") { $sql = sprintf("SELECT COUNT(*) FROM %s WHERE %s ", $this->getTable(), $where); - //echo $sql . "\n"; + echo $sql . "\n"; $stmt = $this->execute($sql); return $stmt->fetchColumn(0); } // From af2dfefdf21d5c144d3bf78e6f2b508fa9e3c097 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 2 Feb 2022 17:13:48 +0900 Subject: [PATCH 2/3] Coupon Change --- extdbms/Itsolution_Coupon_20220202.txt | 48 -------------------------- 1 file changed, 48 deletions(-) delete mode 100644 extdbms/Itsolution_Coupon_20220202.txt diff --git a/extdbms/Itsolution_Coupon_20220202.txt b/extdbms/Itsolution_Coupon_20220202.txt deleted file mode 100644 index ba6367e..0000000 --- a/extdbms/Itsolution_Coupon_20220202.txt +++ /dev/null @@ -1,48 +0,0 @@ -555||3 -amd360||3 -GOAL||12 -KORODD||18 -PB||12 -VIP||3 -고담유통||9 -금수||9 -김민우||6 -김삼순||3 -날두||3 -넷마블||12 -더존||3 -도실장||12 -드림네트윅.KMK||3 -레모나||6 -로비오||12 -리벤져스||9 -리스보아||3 -몬스터||39 -묵은지||3 -박팀장.드래곤||24 -박팀장.스마일||9 -박팀장.스카이||3 -보로||15 -봉덕.사장님(개발자)||6 -봉덕.실업체||6 -블랙캐쉬||21 -샤오미||9 -세븐||6 -스마트||24 -승열||6 -신나라||6 -씨에이컴||36 -오라클||30 -오매||3 -오세정||3 -용찬||36 -잭블랙||45 -주식회사무지2||9 -카오스||3 -타임||3 -토렌트맥스||6 -포인트||9 -플러스윈||3 -피오피||30 -하와이||9 -헌법||3 \ No newline at end of file From 800633fe47b7fec88bc8c027c02be4f605d81259 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 3 Feb 2022 09:45:59 +0900 Subject: [PATCH 3/3] Coupon Change --- extdbms/lib/Core/Model.php | 4 ++-- extdbms/lib/Model/Service.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extdbms/lib/Core/Model.php b/extdbms/lib/Core/Model.php index c121a63..3fb9359 100644 --- a/extdbms/lib/Core/Model.php +++ b/extdbms/lib/Core/Model.php @@ -63,13 +63,13 @@ abstract class Model final public function getData($wheres = array(), $column = "*") { $sql = sprintf("SELECT %s FROM %s %s", $column, $this->getTable(), count($wheres) ? "WHERE " . implode("AND", $wheres) : ""); - echo $sql; + //echo $sql; return $this->getRow($sql); } final public function getDatas(array $wheres = array(), $column = "*") { $sql = sprintf("SELECT %s FROM %s %s", $column, $this->getTable(), count($wheres) ? "WHERE " . implode("AND", $wheres) : ""); - echo $sql; + //echo $sql; return $this->getRows($sql); } } //Class diff --git a/extdbms/lib/Model/Service.php b/extdbms/lib/Model/Service.php index 3fd21aa..43d24c9 100644 --- a/extdbms/lib/Model/Service.php +++ b/extdbms/lib/Model/Service.php @@ -38,13 +38,13 @@ class Service extends Model final public function getOneTime($client_name) { $sql = sprintf("SELECT * FROM %s WHERE server_code = '%s-일회성'", $this->getTable(), $client_name); - echo $sql . "\n"; + //echo $sql . "\n"; return $this->getRow($sql); } // final public function getCount($where = "") { $sql = sprintf("SELECT COUNT(*) FROM %s WHERE %s ", $this->getTable(), $where); - echo $sql . "\n"; + //echo $sql . "\n"; $stmt = $this->execute($sql); return $stmt->fetchColumn(0); } //