$it_stock_qty) $error .= "{$row['ct_option']} 의 재고수량이 부족합니다. 현재고수량 : $it_stock_qty 개\\n\\n"; } if($i == 0) alert('장바구니가 비어 있습니다.\\n\\n이미 주문하셨거나 장바구니에 담긴 상품이 없는 경우입니다.', G5_SHOP_URL.'/cart.php'); if ($error != "") { $error .= "다른 고객님께서 {$od_name}님 보다 먼저 주문하신 경우입니다. 불편을 끼쳐 죄송합니다."; alert($error); } $i_price = (int)$_POST['od_price']; $i_send_cost = (int)$_POST['od_send_cost']; $i_send_cost2 = (int)$_POST['od_send_cost2']; $i_send_coupon = (int)$_POST['od_send_coupon']; $i_temp_point = (int)$_POST['od_temp_point']; // 주문금액이 상이함 $sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as od_price, COUNT(distinct it_id) as cart_count from {$g5['g5_shop_cart_table']} where od_id = '$tmp_cart_id' and ct_select = '1' "; $row = sql_fetch($sql); $tot_ct_price = $row['od_price']; $cart_count = $row['cart_count']; $tot_od_price = $tot_ct_price; // 쿠폰금액계산 $tot_cp_price = 0; if($is_member) { // 상품쿠폰 $tot_it_cp_price = $tot_od_cp_price = 0; $it_cp_cnt = count($_POST['cp_id']); $arr_it_cp_prc = array(); for($i=0; $i<$it_cp_cnt; $i++) { $cid = $_POST['cp_id'][$i]; $it_id = $_POST['it_id'][$i]; $sql = " select cp_id, cp_method, cp_target, cp_type, cp_price, cp_trunc, cp_minimum, cp_maximum from {$g5['g5_shop_coupon_table']} where cp_id = '$cid' and mb_id IN ( '{$member['mb_id']}', '전체회원' ) and cp_start <= '".G5_TIME_YMD."' and cp_end >= '".G5_TIME_YMD."' and cp_method IN ( 0, 1 ) "; $cp = sql_fetch($sql); if(!$cp['cp_id']) continue; // 사용한 쿠폰인지 if(is_used_coupon($member['mb_id'], $cp['cp_id'])) continue; // 분류할인인지 if($cp['cp_method']) { $sql2 = " select it_id, ca_id, ca_id2, ca_id3 from {$g5['g5_shop_item_table']} where it_id = '$it_id' "; $row2 = sql_fetch($sql2); if(!$row2['it_id']) continue; if($row2['ca_id'] != $cp['cp_target'] && $row2['ca_id2'] != $cp['cp_target'] && $row2['ca_id3'] != $cp['cp_target']) continue; } else { if($cp['cp_target'] != $it_id) continue; } // 상품금액 $sql = " select SUM( IF(io_type = '1', io_price * ct_qty, (ct_price + io_price) * ct_qty)) as sum_price from {$g5['g5_shop_cart_table']} where od_id = '$tmp_cart_id' and it_id = '$it_id' and ct_select = '1' "; $ct = sql_fetch($sql); $item_price = $ct['sum_price']; if($cp['cp_minimum'] > $item_price) continue; $dc = 0; if($cp['cp_type']) { $dc = floor(($item_price * ($cp['cp_price'] / 100)) / $cp['cp_trunc']) * $cp['cp_trunc']; } else { $dc = $cp['cp_price']; } if($cp['cp_maximum'] && $dc > $cp['cp_maximum']) $dc = $cp['cp_maximum']; if($item_price < $dc) continue; $tot_it_cp_price += $dc; $arr_it_cp_prc[$it_id] = $dc; } $tot_od_price -= $tot_it_cp_price; // 주문쿠폰 if($_POST['od_cp_id']) { $sql = " select cp_id, cp_type, cp_price, cp_trunc, cp_minimum, cp_maximum from {$g5['g5_shop_coupon_table']} where cp_id = '{$_POST['od_cp_id']}' and mb_id IN ( '{$member['mb_id']}', '전체회원' ) and cp_start <= '".G5_TIME_YMD."' and cp_end >= '".G5_TIME_YMD."' and cp_method = '2' "; $cp = sql_fetch($sql); // 사용한 쿠폰인지 $cp_used = is_used_coupon($member['mb_id'], $cp['cp_id']); $dc = 0; if(!$cp_used && $cp['cp_id'] && ($cp['cp_minimum'] <= $tot_od_price)) { if($cp['cp_type']) { $dc = floor(($tot_od_price * ($cp['cp_price'] / 100)) / $cp['cp_trunc']) * $cp['cp_trunc']; } else { $dc = $cp['cp_price']; } if($cp['cp_maximum'] && $dc > $cp['cp_maximum']) $dc = $cp['cp_maximum']; if($tot_od_price < $dc) die('Order coupon error.'); $tot_od_cp_price = $dc; $tot_od_price -= $tot_od_cp_price; } } $tot_cp_price = $tot_it_cp_price + $tot_od_cp_price; } if ((int)($row['od_price'] - $tot_cp_price) !== $i_price) { die("Error."); } // 배송비가 상이함 $send_cost = get_sendcost($tmp_cart_id); $tot_sc_cp_price = 0; if($is_member && $send_cost > 0) { // 배송쿠폰 if($_POST['sc_cp_id']) { $sql = " select cp_id, cp_type, cp_price, cp_trunc, cp_minimum, cp_maximum from {$g5['g5_shop_coupon_table']} where cp_id = '{$_POST['sc_cp_id']}' and mb_id IN ( '{$member['mb_id']}', '전체회원' ) and cp_start <= '".G5_TIME_YMD."' and cp_end >= '".G5_TIME_YMD."' and cp_method = '3' "; $cp = sql_fetch($sql); // 사용한 쿠폰인지 $cp_used = is_used_coupon($member['mb_id'], $cp['cp_id']); $dc = 0; if(!$cp_used && $cp['cp_id'] && ($cp['cp_minimum'] <= $tot_od_price)) { if($cp['cp_type']) { $dc = floor(($send_cost * ($cp['cp_price'] / 100)) / $cp['cp_trunc']) * $cp['cp_trunc']; } else { $dc = $cp['cp_price']; } if($cp['cp_maximum'] && $dc > $cp['cp_maximum']) $dc = $cp['cp_maximum']; if($dc > $send_cost) $dc = $send_cost; $tot_sc_cp_price = $dc; } } } if ((int)($send_cost - $tot_sc_cp_price) !== (int)($i_send_cost - $i_send_coupon)) { die("Error.."); } // 추가배송비가 상이함 $od_b_zip1 = preg_replace('/[^0-9]/', '', $od_b_zip1); $od_b_zip2 = preg_replace('/[^0-9]/', '', $od_b_zip2); $zipcode = $od_b_zip1 . $od_b_zip2; $sql = " select sc_id, sc_price from {$g5['g5_shop_sendcost_table']} where sc_zip1 <= '$zipcode' and sc_zip2 >= '$zipcode' "; $tmp = sql_fetch($sql); if(!$tmp['sc_id']) $send_cost2 = 0; else $send_cost2 = (int)$tmp['sc_price']; if($send_cost2 !== $i_send_cost2) die("Error..."); // 결제포인트가 상이함 // 회원이면서 포인트사용이면 $temp_point = 0; if ($is_member && $config['cf_use_point']) { if($member['mb_point'] >= $default['de_settle_min_point']) { $temp_point = (int)$default['de_settle_max_point']; if($temp_point > (int)$tot_od_price) $temp_point = (int)$tot_od_price; if($temp_point > (int)$member['mb_point']) $temp_point = (int)$member['mb_point']; $point_unit = (int)$default['de_settle_point_unit']; $temp_point = (int)((int)($temp_point / $point_unit) * $point_unit); } } if (($i_temp_point > (int)$temp_point || $i_temp_point < 0) && $config['cf_use_point']) die("Error...."); if ($od_temp_point) { if ($member['mb_point'] < $od_temp_point) alert('회원님의 포인트가 부족하여 포인트로 결제 할 수 없습니다.'); } $i_price = $i_price + $i_send_cost + $i_send_cost2 - $i_temp_point - $i_send_coupon; $order_price = $tot_od_price + $send_cost + $send_cost2 - $tot_sc_cp_price - $od_temp_point; $od_status = '주문'; if ($od_settle_case == "무통장") { $od_receipt_point = $i_temp_point; $od_receipt_price = 0; $od_misu = $i_price - $od_receipt_price; if($od_misu == 0) { $od_status = '입금'; $od_receipt_time = G5_TIME_YMDHIS; } } else if ($od_settle_case == "계좌이체") { switch($default['de_pg_service']) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_result.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_result.php'; break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub.php'; $bank_name = iconv("cp949", "utf-8", $bank_name); break; } $od_tno = $tno; $od_receipt_price = $amount; $od_receipt_point = $i_temp_point; $od_receipt_time = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time); $od_bank_account = $od_settle_case; $od_deposit_name = $od_name; $od_bank_account = $bank_name; $pg_price = $amount; $od_misu = $i_price - $od_receipt_price; if($od_misu == 0) $od_status = '입금'; } else if ($od_settle_case == "가상계좌") { switch($default['de_pg_service']) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_result.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_result.php'; $od_app_no = $app_no; break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub.php'; $bankname = iconv("cp949", "utf-8", $bankname); $depositor = iconv("cp949", "utf-8", $depositor); break; } $od_receipt_point = $i_temp_point; $od_tno = $tno; $od_receipt_price = 0; $od_bank_account = $bankname.' '.$account; $od_deposit_name = $depositor; $pg_price = $amount; $od_misu = $i_price - $od_receipt_price; } else if ($od_settle_case == "휴대폰") { switch($default['de_pg_service']) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_result.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_result.php'; break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub.php'; break; } $od_tno = $tno; $od_receipt_price = $amount; $od_receipt_point = $i_temp_point; $od_receipt_time = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time); $od_bank_account = $commid . ($commid ? ' ' : '').$mobile_no; $pg_price = $amount; $od_misu = $i_price - $od_receipt_price; if($od_misu == 0) $od_status = '입금'; } else if ($od_settle_case == "신용카드") { switch($default['de_pg_service']) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_result.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_result.php'; break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub.php'; $card_name = iconv("cp949", "utf-8", $card_name); break; } $od_tno = $tno; $od_app_no = $app_no; $od_receipt_price = $amount; $od_receipt_point = $i_temp_point; $od_receipt_time = preg_replace("/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1-\\2-\\3 \\4:\\5:\\6", $app_time); $od_bank_account = $card_name; $pg_price = $amount; $od_misu = $i_price - $od_receipt_price; if($od_misu == 0) $od_status = '입금'; } else { die("od_settle_case Error!!!"); } // 주문금액과 결제금액이 일치하는지 체크 if($tno) { if((int)$order_price !== (int)$pg_price) { $cancel_msg = '결제금액 불일치'; switch($default['de_pg_service']) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_cancel.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_cancel.php'; break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub_cancel.php'; break; } die("Receipt Amount Error"); } } if ($is_member) $od_pwd = $member['mb_password']; else $od_pwd = get_encrypt_string($_POST['od_pwd']); // 주문번호를 얻는다. $od_id = get_session('ss_order_id'); $od_escrow = 0; if($escw_yn == 'Y') $od_escrow = 1; // 복합과세 금액 $od_tax_mny = round($i_price / 1.1); $od_vat_mny = $i_price - $od_tax_mny; $od_free_mny = 0; if($default['de_tax_flag_use']) { $od_tax_mny = (int)$_POST['comm_tax_mny']; $od_vat_mny = (int)$_POST['comm_vat_mny']; $od_free_mny = (int)$_POST['comm_free_mny']; } $od_pg = $default['de_pg_service']; $od_email = get_email_address($od_email); $od_name = clean_xss_tags($od_name); $od_tel = clean_xss_tags($od_tel); $od_hp = clean_xss_tags($od_hp); $od_zip1 = preg_replace('/[^0-9]/', '', $od_zip1); $od_zip2 = preg_replace('/[^0-9]/', '', $od_zip2); $od_addr1 = clean_xss_tags($od_addr1); $od_addr2 = clean_xss_tags($od_addr2); $od_addr3 = clean_xss_tags($od_addr3); $od_addr_jibeon = preg_match("/^(N|R)$/", $od_addr_jibeon) ? $od_addr_jibeon : ''; $od_b_name = clean_xss_tags($od_b_name); $od_b_tel = clean_xss_tags($od_b_tel); $od_b_hp = clean_xss_tags($od_b_hp); $od_b_addr1 = clean_xss_tags($od_b_addr1); $od_b_addr2 = clean_xss_tags($od_b_addr2); $od_b_addr3 = clean_xss_tags($od_b_addr3); $od_b_addr_jibeon = preg_match("/^(N|R)$/", $od_b_addr_jibeon) ? $od_b_addr_jibeon : ''; $od_memo = clean_xss_tags($od_memo); $od_deposit_name = clean_xss_tags($od_deposit_name); // 주문서에 입력 $sql = " insert {$g5['g5_shop_order_table']} set od_id = '$od_id', mb_id = '{$member['mb_id']}', od_pwd = '$od_pwd', od_name = '$od_name', od_email = '$od_email', od_tel = '$od_tel', od_hp = '$od_hp', od_zip1 = '$od_zip1', od_zip2 = '$od_zip2', od_addr1 = '$od_addr1', od_addr2 = '$od_addr2', od_addr3 = '$od_addr3', od_addr_jibeon = '$od_addr_jibeon', od_b_name = '$od_b_name', od_b_tel = '$od_b_tel', od_b_hp = '$od_b_hp', od_b_zip1 = '$od_b_zip1', od_b_zip2 = '$od_b_zip2', od_b_addr1 = '$od_b_addr1', od_b_addr2 = '$od_b_addr2', od_b_addr3 = '$od_b_addr3', od_b_addr_jibeon = '$od_b_addr_jibeon', od_deposit_name = '$od_deposit_name', od_memo = '$od_memo', od_cart_count = '$cart_count', od_cart_price = '$tot_ct_price', od_cart_coupon = '$tot_it_cp_price', od_send_cost = '$od_send_cost', od_send_coupon = '$tot_sc_cp_price', od_send_cost2 = '$od_send_cost2', od_coupon = '$tot_od_cp_price', od_receipt_price = '$od_receipt_price', od_receipt_point = '$od_receipt_point', od_bank_account = '$od_bank_account', od_receipt_time = '$od_receipt_time', od_misu = '$od_misu', od_pg = '$od_pg', od_tno = '$od_tno', od_app_no = '$od_app_no', od_escrow = '$od_escrow', od_tax_flag = '{$default['de_tax_flag_use']}', od_tax_mny = '$od_tax_mny', od_vat_mny = '$od_vat_mny', od_free_mny = '$od_free_mny', od_status = '$od_status', od_shop_memo = '', od_hope_date = '$od_hope_date', od_time = '".G5_TIME_YMDHIS."', od_ip = '$REMOTE_ADDR', od_settle_case = '$od_settle_case' "; $result = sql_query($sql, false); // 주문정보 입력 오류시 결제 취소 if(!$result) { if($tno) { $cancel_msg = '주문정보 입력 오류'; switch($default['de_pg_service']) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_cancel.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_cancel.php'; break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub_cancel.php'; break; } } // 관리자에게 오류 알림 메일발송 $error = 'order'; include G5_SHOP_PATH.'/ordererrormail.php'; die('
고객님의 주문 정보를 처리하는 중 오류가 발생해서 주문이 완료되지 않았습니다.
'.strtoupper($default['de_pg_service']).'를 이용한 전자결제(신용카드, 계좌이체, 가상계좌 등)은 자동 취소되었습니다.'); } // 장바구니 상태변경 // 신용카드로 주문하면서 신용카드 포인트 사용하지 않는다면 포인트 부여하지 않음 $cart_status = $od_status; $sql_card_point = ""; if ($od_receipt_price > 0 && !$default['de_card_point']) { $sql_card_point = " , ct_point = '0' "; } $sql = "update {$g5['g5_shop_cart_table']} set od_id = '$od_id', ct_status = '$cart_status' $sql_card_point where od_id = '$tmp_cart_id' and ct_select = '1' "; $result = sql_query($sql, false); // 주문정보 입력 오류시 결제 취소 if(!$result) { if($tno) { $cancel_msg = '주문상태 변경 오류'; switch($default['de_pg_service']) { case 'lg': include G5_SHOP_PATH.'/lg/xpay_cancel.php'; break; case 'inicis': include G5_SHOP_PATH.'/inicis/inipay_cancel.php'; break; default: include G5_SHOP_PATH.'/kcp/pp_ax_hub_cancel.php'; break; } } // 관리자에게 오류 알림 메일발송 $error = 'status'; include G5_SHOP_PATH.'/ordererrormail.php'; // 주문삭제 sql_query(" delete from {$g5['g5_shop_order_table']} where od_id = '$od_id' "); die('
고객님의 주문 정보를 처리하는 중 오류가 발생해서 주문이 완료되지 않았습니다.
'.strtoupper($default['de_pg_service']).'를 이용한 전자결제(신용카드, 계좌이체, 가상계좌 등)은 자동 취소되었습니다.');
}
// 회원이면서 포인트를 사용했다면 테이블에 사용을 추가
if ($is_member && $od_receipt_point)
insert_point($member['mb_id'], (-1) * $od_receipt_point, "주문번호 $od_id 결제");
$od_memo = nl2br(htmlspecialchars2(stripslashes($od_memo))) . " ";
// 쿠폰사용내역기록
if($is_member) {
$it_cp_cnt = count($_POST['cp_id']);
for($i=0; $i<$it_cp_cnt; $i++) {
$cid = $_POST['cp_id'][$i];
$cp_it_id = $_POST['it_id'][$i];
$cp_prc = (int)$arr_it_cp_prc[$cp_it_id];
if(trim($cid)) {
$sql = " insert into {$g5['g5_shop_coupon_log_table']}
set cp_id = '$cid',
mb_id = '{$member['mb_id']}',
od_id = '$od_id',
cp_price = '$cp_prc',
cl_datetime = '".G5_TIME_YMDHIS."' ";
sql_query($sql);
}
// 쿠폰사용금액 cart에 기록
$cp_prc = (int)$arr_it_cp_prc[$cp_it_id];
$sql = " update {$g5['g5_shop_cart_table']}
set cp_price = '$cp_prc'
where od_id = '$od_id'
and it_id = '$cp_it_id'
and ct_select = '1'
order by ct_id asc
limit 1 ";
sql_query($sql);
}
if($_POST['od_cp_id']) {
$sql = " insert into {$g5['g5_shop_coupon_log_table']}
set cp_id = '{$_POST['od_cp_id']}',
mb_id = '{$member['mb_id']}',
od_id = '$od_id',
cp_price = '$tot_od_cp_price',
cl_datetime = '".G5_TIME_YMDHIS."' ";
sql_query($sql);
}
if($_POST['sc_cp_id']) {
$sql = " insert into {$g5['g5_shop_coupon_log_table']}
set cp_id = '{$_POST['sc_cp_id']}',
mb_id = '{$member['mb_id']}',
od_id = '$od_id',
cp_price = '$tot_sc_cp_price',
cl_datetime = '".G5_TIME_YMDHIS."' ";
sql_query($sql);
}
}
include_once(G5_SHOP_PATH.'/ordermail1.inc.php');
include_once(G5_SHOP_PATH.'/ordermail2.inc.php');
// SMS BEGIN --------------------------------------------------------
// 주문고객과 쇼핑몰관리자에게 SMS 전송
if($config['cf_sms_use'] && ($default['de_sms_use2'] || $default['de_sms_use3'])) {
$is_sms_send = false;
// 충전식일 경우 잔액이 있는지 체크
if($config['cf_icode_id'] && $config['cf_icode_pw']) {
$userinfo = get_icode_userinfo($config['cf_icode_id'], $config['cf_icode_pw']);
if($userinfo['code'] == 0) {
if($userinfo['payment'] == 'C') { // 정액제
$is_sms_send = true;
} else {
$minimum_coin = 100;
if(defined('G5_ICODE_COIN'))
$minimum_coin = intval(G5_ICODE_COIN);
if((int)$userinfo['coin'] >= $minimum_coin)
$is_sms_send = true;
}
}
}
if($is_sms_send) {
$sms_contents = array($default['de_sms_cont2'], $default['de_sms_cont3']);
$recv_numbers = array($od_hp, $default['de_sms_hp']);
$send_numbers = array($default['de_admin_company_tel'], $od_hp);
include_once(G5_LIB_PATH.'/icode.sms.lib.php');
$SMS = new SMS; // SMS 연결
$SMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $config['cf_icode_server_port']);
$sms_count = 0;
for($s=0; $s