주문폼 접근 때 재고 체크하도록 수정

This commit is contained in:
chicpro
2014-11-05 17:40:45 +09:00
parent 5e558626da
commit de2b734362
9 changed files with 235 additions and 44 deletions

View File

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

View File

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

13
js/shop.order.js Normal file
View File

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

View File

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

View File

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

View File

@ -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);
}
}
// 장바구니 상품 주문폼 등록시간 기록 필드 추가
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 '<p>장바구니 테이블 업그레이드 완료!</p>';
}
include_once(G5_PATH.'/tail.sub.php');
?>

67
shop/ajax.orderstock.php Normal file
View File

@ -0,0 +1,67 @@
<?php
include_once('./_common.php');
if (get_session('ss_direct'))
$tmp_cart_id = get_session('ss_cart_direct');
else
$tmp_cart_id = get_session('ss_cart_id');
if (get_cart_count($tmp_cart_id) == 0)// 장바구니에 담기
die("장바구니가 비어 있습니다.\n\n이미 주문하셨거나 장바구니에 담긴 상품이 없는 경우입니다.");
$keep_term = $default['de_cart_keep_term'];
if(!$keep_term)
$keep_term = 15; // 기본값 15일
if(defined('G5_CART_STOCK_LIMIT'))
$cart_stock_limit = G5_CART_STOCK_LIMIT;
else
$cart_stock_limit = 3;
// 기준 시간을 초과한 경우 체크
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 = " 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("");
?>

View File

@ -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,10 +183,15 @@ else // 장바구니에 담기
$lst_count++;
}
// 바로구매에 있던 장바구니 자료를 지운다.
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];
@ -159,7 +203,8 @@ else // 장바구니에 담기
and io_id = '$io_id'
and io_type = '$io_type'
and ct_stock_use = 0
and ct_status = '쇼핑' ";
and ct_status = '쇼핑'
and ct_select = '1' ";
$row = sql_fetch($sql);
$sum_qty = $row['cnt'];
@ -175,27 +220,27 @@ else // 장바구니에 담기
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($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++;
}

View File

@ -4,6 +4,9 @@ include_once('./_common.php');
// add_javascript('js 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_javascript(G5_POSTCODE_JS, 0); //다음 주소 js
// 주문상품 재고체크 js 파일
add_javascript('<script src="'.G5_JS_URL.'/shop.order.js"></script>', 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 = "";