Coupon Change

This commit is contained in:
root 2022-02-02 17:12:55 +09:00
parent de6664358a
commit c72477a40d
6 changed files with 105 additions and 44 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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

View File

@ -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

View File

@ -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);
} //