From de2b73436236311c7c4e2bae31b83489dca0b122 Mon Sep 17 00:00:00 2001 From: chicpro Date: Wed, 5 Nov 2014 17:40:45 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A3=BC=EB=AC=B8=ED=8F=BC=20=EC=A0=91?= =?UTF-8?q?=EA=B7=BC=20=EB=95=8C=20=EC=9E=AC=EA=B3=A0=20=EC=B2=B4=ED=81=AC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/shop.extend.php | 4 ++ install/gnuboard5shop.sql | 1 + js/shop.order.js | 13 ++++ lib/shop.lib.php | 30 ++++++++- mobile/shop/orderform.php | 7 ++ orderupgrade.php | 10 ++- shop/ajax.orderstock.php | 67 +++++++++++++++++++ shop/cartupdate.php | 137 +++++++++++++++++++++++++++----------- shop/orderform.php | 10 +++ 9 files changed, 235 insertions(+), 44 deletions(-) create mode 100644 js/shop.order.js create mode 100644 shop/ajax.orderstock.php diff --git a/extend/shop.extend.php b/extend/shop.extend.php index fc82199a7..b76428664 100644 --- a/extend/shop.extend.php +++ b/extend/shop.extend.php @@ -131,6 +131,10 @@ if($default['de_card_test']) { define('G5_CASH_RECEIPT_URL', 'https://admin.kcp.co.kr/Modules/Service/Cash/Cash_Bill_Common_View.jsp?term_id=PGNW'); } +// 주문폼의 상품이 재고 차감에 포함되는 기준 시간설정 +// 0 이면 재고 차감에 계속 포함됨 +define('G5_CART_STOCK_LIMIT', 3); + // 아이코드 코인 최소금액 설정 // 코인 잔액이 설정 금액보다 작을 때는 주문시 SMS 발송 안함 define('G5_ICODE_COIN', 100); diff --git a/install/gnuboard5shop.sql b/install/gnuboard5shop.sql index 3a847cdfa..b3cfb1cbe 100644 --- a/install/gnuboard5shop.sql +++ b/install/gnuboard5shop.sql @@ -56,6 +56,7 @@ CREATE TABLE IF NOT EXISTS `g5_shop_cart` ( `ct_send_cost` tinyint(4) NOT NULL DEFAULT '0', `ct_direct` tinyint(4) NOT NULL DEFAULT '0', `ct_select` tinyint(4) NOT NULL DEFAULT '0', + `ct_select_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`ct_id`), KEY `od_id` (`od_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/js/shop.order.js b/js/shop.order.js new file mode 100644 index 000000000..312eef4e9 --- /dev/null +++ b/js/shop.order.js @@ -0,0 +1,13 @@ +var order_stock_check = function() { + var result = ""; + $.ajax({ + type: "POST", + url: g5_url+"/shop/ajax.orderstock.php", + cache: false, + async: false, + success: function(data) { + result = data; + } + }); + return result; +} \ No newline at end of file diff --git a/lib/shop.lib.php b/lib/shop.lib.php index 044776ce1..178d015d3 100644 --- a/lib/shop.lib.php +++ b/lib/shop.lib.php @@ -2138,12 +2138,38 @@ function cart_item_clean() { global $g5, $default; + // 장바구니 보관일 $keep_term = $default['de_cart_keep_term']; if(!$keep_term) $keep_term = 15; // 기본값 15일 - $beforetime = G5_SERVER_TIME - (86400 * $keep_term); - sql_query(" delete from {$g5['g5_shop_cart_table']} where ct_status = '쇼핑' and UNIX_TIMESTAMP(ct_time) < '$beforetime' "); + // ct_select_time이 기준시간 이상 경과된 경우 변경 + if(defined('G5_CART_STOCK_LIMIT')) + $cart_stock_limit = G5_CART_STOCK_LIMIT; + else + $cart_stock_limit = 3; + + $stocktime = 0; + if($cart_stock_limit > 0) { + if($cart_stock_limit > $keep_term * 24) + $cart_stock_limit = $keep_term * 24; + + $stocktime = G5_SERVER_TIME - (3600 * $cart_stock_limit); + $sql = " update {$g5['g5_shop_cart_table']} + set ct_select = '0' + where ct_select = '1' + and ct_status = '쇼핑' + and UNIX_TIMESTAMP(ct_select_time) < '$stocktime' "; + sql_query($sql); + } + + // 설정 시간이상 경과된 상품 삭제 + $statustime = G5_SERVER_TIME - (86400 * $keep_term); + + $sql = " delete from {$g5['g5_shop_cart_table']} + where ct_status = '쇼핑' + and UNIX_TIMESTAMP(ct_time) < '$statustime' "; + sql_query($sql); } //============================================================================== diff --git a/mobile/shop/orderform.php b/mobile/shop/orderform.php index 77f4ed9ce..3ac4b333a 100644 --- a/mobile/shop/orderform.php +++ b/mobile/shop/orderform.php @@ -1130,6 +1130,13 @@ var temp_point = 0; function pay_approval() { + // 재고체크 + var stock_msg = order_stock_check(); + if(stock_msg != "") { + alert(stock_msg); + return false; + } + var f = document.sm_form; var pf = document.forderform; diff --git a/orderupgrade.php b/orderupgrade.php index 3c5914002..6aa3533f0 100644 --- a/orderupgrade.php +++ b/orderupgrade.php @@ -38,9 +38,15 @@ if(!sql_query(" select it_sc_type from {$g5['g5_shop_cart_table']} limit 1 ", fa where ct_id = '{$row['ct_id']}' "; sql_query($sql); } - - echo '

장바구니 테이블 업그레이드 완료!

'; } +// 장바구니 상품 주문폼 등록시간 기록 필드 추가 +if(!sql_query(" select ct_select_time from {$g5['g5_shop_cart_table']} limit 1 ", false)) { + sql_query(" ALTER TABLE `{$g5['g5_shop_cart_table']}` + ADD `ct_select_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `ct_select` ", true); +} + +echo '

장바구니 테이블 업그레이드 완료!

'; + include_once(G5_PATH.'/tail.sub.php'); ?> \ No newline at end of file diff --git a/shop/ajax.orderstock.php b/shop/ajax.orderstock.php new file mode 100644 index 000000000..a2bb40502 --- /dev/null +++ b/shop/ajax.orderstock.php @@ -0,0 +1,67 @@ + 0) { + if($cart_stock_limit > $keep_term * 24) + $cart_stock_limit = $keep_term * 24; + + $stocktime = G5_SERVER_TIME - (3600 * $cart_stock_limit); + + $sql = " select count(*) as cnt + from {$g5['g5_shop_cart_table']} + where od_id = '$tmp_cart_id' + and ct_status = '쇼핑' + and ct_select = '1' + and UNIX_TIMESTAMP(ct_select_time) > '$stocktime' "; + $row = sql_fetch($sql); + + if(!$row['cnt']) + die("주문 요청 때까지 ".$cart_stock_limit."시간 이상 경과되어 주문 상품이 초기화 됐습니다.\n\n 장바구니에서 주문하실 상품을 다시 확인해 주십시오."); +} + +// 재고체크 +$sql = " select * + from {$g5['g5_shop_cart_table']} + where od_id = '$tmp_cart_id' + and ct_select = '1' + and ct_status = '쇼핑' "; +$result = sql_query($sql); + +for($i=0; $row=sql_fetch_array($result); $i++) { + $ct_qty = $row['ct_qty']; + + if(!$row['io_id']) + $it_stock_qty = get_it_stock_qty($row['it_id']); + else + $it_stock_qty = get_option_stock_qty($row['it_id'], $row['io_id'], $row['io_type']); + + if ($ct_qty > $it_stock_qty) + { + $item_option = $row['it_name']; + if($row['io_id']) + $item_option .= '('.$row['ct_option'].')'; + + die($item_option." 의 재고수량이 부족합니다.\n\n현재 재고수량 : " . number_format($it_stock_qty) . " 개"); + } +} + +die(""); +?> \ No newline at end of file diff --git a/shop/cartupdate.php b/shop/cartupdate.php index c00c6f8a9..c2c2c46dd 100644 --- a/shop/cartupdate.php +++ b/shop/cartupdate.php @@ -37,9 +37,48 @@ if($act == "buy") $ct_chk = $_POST['ct_chk'][$i]; if($ct_chk) { $it_id = $_POST['it_id'][$i]; + + // 주문 상품의 재고체크 + $sql = " select ct_qty, it_name, ct_option, io_id, io_type + from {$g5['g5_shop_cart_table']} + where od_id = '$tmp_cart_id' + and it_id = '$it_id' "; + $result = sql_query($sql); + + for($k=0; $row=sql_fetch_array($result); $k++) { + $sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']} + where od_id <> '$tmp_cart_id' + and it_id = '$it_id' + and io_id = '{$row['io_id']}' + and io_type = '{$row['io_type']}' + and ct_stock_use = 0 + and ct_status = '쇼핑' + and ct_select = '1' "; + $sum = sql_fetch($sql); + $sum_qty = $sum['cnt']; + + // 재고 구함 + $ct_qty = $row['ct_qty']; + if(!$row['io_id']) + $it_stock_qty = get_it_stock_qty($it_id); + else + $it_stock_qty = get_option_stock_qty($it_id, $row['io_id'], $row['io_type']); + + if ($ct_qty + $sum_qty > $it_stock_qty) + { + $item_option = $row['it_name']; + if($row['io_id']) + $item_option .= '('.$row['ct_option'].')'; + + alert($item_option." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개"); + } + } + $sql = " update {$g5['g5_shop_cart_table']} - set ct_select = '1' - where it_id = '$it_id' and od_id = '$tmp_cart_id' "; + set ct_select = '1', + ct_select_time = '".G5_TIME_YMDHIS."' + where od_id = '$tmp_cart_id' + and it_id = '$it_id' "; sql_query($sql); } } @@ -144,58 +183,64 @@ else // 장바구니에 담기 $lst_count++; } - //-------------------------------------------------------- - // 재고 검사 - //-------------------------------------------------------- - // 이미 장바구니에 있는 같은 상품의 수량합계를 구한다. - for($k=0; $k<$opt_count; $k++) { - $io_id = $_POST['io_id'][$it_id][$k]; - $io_type = $_POST['io_type'][$it_id][$k]; - $io_value = $_POST['io_value'][$it_id][$k]; - - $sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']} - where od_id <> '$tmp_cart_id' - and it_id = '$it_id' - and io_id = '$io_id' - and io_type = '$io_type' - and ct_stock_use = 0 - and ct_status = '쇼핑' "; - $row = sql_fetch($sql); - $sum_qty = $row['cnt']; - - // 재고 구함 - $ct_qty = $_POST['ct_qty'][$it_id][$k]; - if(!$io_id) - $it_stock_qty = get_it_stock_qty($it_id); - else - $it_stock_qty = get_option_stock_qty($it_id, $io_id, $io_type); - - if ($ct_qty + $sum_qty > $it_stock_qty) - { - alert($io_value." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개"); - } - } - //-------------------------------------------------------- - // 바로구매에 있던 장바구니 자료를 지운다. if($i == 0 && $sw_direct) sql_query(" delete from {$g5['g5_shop_cart_table']} where od_id = '$tmp_cart_id' and ct_direct = 1 ", false); + //-------------------------------------------------------- + // 재고 검사, 바로구매일 때만 체크 + //-------------------------------------------------------- + // 이미 주문폼에 있는 같은 상품의 수량합계를 구한다. + if($sw_direct) { + for($k=0; $k<$opt_count; $k++) { + $io_id = $_POST['io_id'][$it_id][$k]; + $io_type = $_POST['io_type'][$it_id][$k]; + $io_value = $_POST['io_value'][$it_id][$k]; + + $sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']} + where od_id <> '$tmp_cart_id' + and it_id = '$it_id' + and io_id = '$io_id' + and io_type = '$io_type' + and ct_stock_use = 0 + and ct_status = '쇼핑' + and ct_select = '1' "; + $row = sql_fetch($sql); + $sum_qty = $row['cnt']; + + // 재고 구함 + $ct_qty = $_POST['ct_qty'][$it_id][$k]; + if(!$io_id) + $it_stock_qty = get_it_stock_qty($it_id); + else + $it_stock_qty = get_option_stock_qty($it_id, $io_id, $io_type); + + if ($ct_qty + $sum_qty > $it_stock_qty) + { + alert($io_value." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개"); + } + } + } + //-------------------------------------------------------- + // 옵션수정일 때 기존 장바구니 자료를 먼저 삭제 if($act == 'optionmod') sql_query(" delete from {$g5['g5_shop_cart_table']} where od_id = '$tmp_cart_id' and it_id = '$it_id' "); // 장바구니에 Insert // 바로구매일 경우 장바구니가 체크된것으로 강제 설정 - if($sw_direct) + if($sw_direct) { $ct_select = 1; - else + $ct_select_time = G5_TIME_YMDHIS; + } else { $ct_select = 0; + $ct_select_time = '0000-00-00 00:00:00'; + } // 장바구니에 Insert $comma = ''; $sql = " INSERT INTO {$g5['g5_shop_cart_table']} - ( od_id, mb_id, it_id, it_name, it_sc_type, it_sc_method, it_sc_price, it_sc_minimum, it_sc_qty, ct_status, ct_price, ct_point, ct_point_use, ct_stock_use, ct_option, ct_qty, ct_notax, io_id, io_type, io_price, ct_time, ct_ip, ct_send_cost, ct_direct, ct_select ) + ( od_id, mb_id, it_id, it_name, it_sc_type, it_sc_method, it_sc_price, it_sc_minimum, it_sc_qty, ct_status, ct_price, ct_point, ct_point_use, ct_stock_use, ct_option, ct_qty, ct_notax, io_id, io_type, io_price, ct_time, ct_ip, ct_send_cost, ct_direct, ct_select, ct_select_time ) VALUES "; for($k=0; $k<$opt_count; $k++) { @@ -224,7 +269,7 @@ else // 장바구니에 담기 } // 동일옵션의 상품이 있으면 수량 더함 - $sql2 = " select ct_id + $sql2 = " select ct_id, io_type, ct_qty from {$g5['g5_shop_cart_table']} where od_id = '$tmp_cart_id' and it_id = '$it_id' @@ -232,6 +277,18 @@ else // 장바구니에 담기 and ct_status = '쇼핑' "; $row2 = sql_fetch($sql2); if($row2['ct_id']) { + // 재고체크 + $tmp_ct_qty = $row2['ct_qty']; + if(!$io_id) + $tmp_it_stock_qty = get_it_stock_qty($it_id); + else + $tmp_it_stock_qty = get_option_stock_qty($it_id, $io_id, $row2['io_type']); + + if ($tmp_ct_qty + $ct_qty > $tmp_it_stock_qty) + { + alert($io_value." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($tmp_it_stock_qty) . " 개"); + } + $sql3 = " update {$g5['g5_shop_cart_table']} set ct_qty = ct_qty + '$ct_qty' where ct_id = '{$row2['ct_id']}' "; @@ -258,7 +315,7 @@ else // 장바구니에 담기 else if($it['it_sc_type'] > 1 && $it['it_sc_method'] == 1) $ct_send_cost = 1; // 착불 - $sql .= $comma."( '$tmp_cart_id', '{$member['mb_id']}', '{$it['it_id']}', '".addslashes($it['it_name'])."', '{$it['it_sc_type']}', '{$it['it_sc_method']}', '{$it['it_sc_price']}', '{$it['it_sc_minimum']}', '{$it['it_sc_qty']}', '쇼핑', '{$it['it_price']}', '$point', '0', '0', '$io_value', '$ct_qty', '{$it['it_notax']}', '$io_id', '$io_type', '$io_price', '".G5_TIME_YMDHIS."', '$REMOTE_ADDR', '$ct_send_cost', '$sw_direct', '$ct_select' )"; + $sql .= $comma."( '$tmp_cart_id', '{$member['mb_id']}', '{$it['it_id']}', '".addslashes($it['it_name'])."', '{$it['it_sc_type']}', '{$it['it_sc_method']}', '{$it['it_sc_price']}', '{$it['it_sc_minimum']}', '{$it['it_sc_qty']}', '쇼핑', '{$it['it_price']}', '$point', '0', '0', '$io_value', '$ct_qty', '{$it['it_notax']}', '$io_id', '$io_type', '$io_price', '".G5_TIME_YMDHIS."', '$REMOTE_ADDR', '$ct_send_cost', '$sw_direct', '$ct_select', '$ct_select_time' )"; $comma = ' , '; $ct_count++; } diff --git a/shop/orderform.php b/shop/orderform.php index 968ab1b7c..4be4b95f2 100644 --- a/shop/orderform.php +++ b/shop/orderform.php @@ -4,6 +4,9 @@ include_once('./_common.php'); // add_javascript('js 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨 add_javascript(G5_POSTCODE_JS, 0); //다음 주소 js +// 주문상품 재고체크 js 파일 +add_javascript('', 0); + if (G5_IS_MOBILE) { include_once(G5_MSHOP_PATH.'/orderform.php'); return; @@ -1145,6 +1148,13 @@ function calculate_tax() function forderform_check(f) { + // 재고체크 + var stock_msg = order_stock_check(); + if(stock_msg != "") { + alert(stock_msg); + return false; + } + errmsg = ""; errfld = ""; var deffld = "";