Files
firstgarden-web-gnu/adm/shop_admin/ordercartupdate.php
2013-09-13 16:23:29 +09:00

286 lines
9.9 KiB
PHP

<?php
$sub_menu = '400400';
include_once('./_common.php');
auth_check($auth[$sub_menu], "w");
$ct_chk_count = count($_POST['ct_chk']);
if(!$ct_chk_count)
alert('처리할 자료를 하나 이상 선택해 주십시오.');
switch($_POST['act_button'])
{
case '주문':
$ct_status = '주문';
break;
case '상품준비중':
$ct_status = '준비';
break;
case '배송중':
$ct_status = '배송';
break;
case '완료':
$ct_status = '완료';
break;
case '취소':
$ct_status = '취소';
break;
case '반품':
$ct_status = '반품';
break;
case '품절':
$ct_status = '품절';
break;
default:
alert('변경할 상태가 올바르지 않습니다.');
break;
}
$mod_history = '';
$cnt = count($_POST['ct_id']);
for ($i=0; $i<$cnt; $i++)
{
$k = $_POST['ct_chk'][$i];
$ct_id = $_POST['ct_id'][$k];
$sql = " select * from {$g5['g5_shop_cart_table']}
where od_id = '$od_id'
and ct_id = '$ct_id' ";
$ct = sql_fetch($sql);
if(!$ct['ct_id'])
continue;
// 수량이 변경됐다면
$ct_qty = $_POST['ct_qty'][$k];
if($ct['ct_qty'] != $ct_qty) {
$diff_qty = $ct['ct_qty'] - $ct_qty;
// 재고에 차이 반영.
if($ct['ct_stock_use']) {
if($ct['io_id']) {
$sql = " update {$g5['g5_shop_item_option_table']}
set io_stock_qty = io_stock_qty + '$diff_qty'
where it_id = '{$ct['it_id']}'
and io_id = '{$ct['io_id']}'
and io_type = '{$ct['io_type']}' ";
} else {
$sql = " update {$g5['g5_shop_item_table']}
set it_stock_qty = it_stock_qty + '$diff_qty'
where it_id = '{$ct['it_id']}' ";
}
sql_query($sql);
}
// 수량변경
$sql = " update {$g5['g5_shop_cart_table']}
set ct_qty = '$ct_qty'
where ct_id = '$ct_id'
and od_id = '$od_id' ";
sql_query($sql);
$mod_history .= G5_TIME_YMDHIS.' '.$ct['ct_option'].' 수량변경 '.$ct['ct_qty'].' -> '.$ct_qty."\n";
}
// 재고를 이미 사용했다면 (재고에서 이미 뺐다면)
$stock_use = $ct['ct_stock_use'];
if ($ct['ct_stock_use'])
{
if ($ct_status == '주문' || $ct_status == '취소' || $ct_status == '반품' || $ct_status == '품절')
{
$stock_use = 0;
// 재고에 다시 더한다.
if($ct['io_id']) {
$sql = " update {$g5['g5_shop_item_option_table']}
set io_stock_qty = io_stock_qty + '{$ct['ct_qty']}'
where it_id = '{$ct['it_id']}'
and io_id = '{$ct['io_id']}'
and io_type = '{$ct['io_type']}' ";
} else {
$sql = " update {$g5['g5_shop_item_table']}
set it_stock_qty = it_stock_qty + '{$ct['ct_qty']}'
where it_id = '{$ct['it_id']}' ";
}
sql_query($sql);
}
}
else
{
// 재고 오류로 인한 수정
if ($ct_status == '배송' || $ct_status == '완료')
{
$stock_use = 1;
// 재고에서 뺀다.
if($ct['io_id']) {
$sql = " update {$g5['g5_shop_item_option_table']}
set io_stock_qty = io_stock_qty - '{$ct['ct_qty']}'
where it_id = '{$ct['it_id']}'
and io_id = '{$ct['io_id']}'
and io_type = '{$ct['io_type']}' ";
} else {
$sql = " update {$g5['g5_shop_item_table']}
set it_stock_qty = it_stock_qty - '{$ct['ct_qty']}'
where it_id = '{$ct['it_id']}' ";
}
sql_query($sql);
}
/* 주문 수정에서 "품절" 선택시 해당 상품 자동 품절 처리하기
else if ($ct_status == '품절') {
$stock_use = 1;
// 재고에서 뺀다.
$sql =" update {$g5['g5_shop_item_table']} set it_stock_qty = 0 where it_id = '{$ct['it_id']}' ";
sql_query($sql);
} */
}
$point_use = $ct['ct_point_use'];
// 회원이면서 포인트가 0보다 크면
// 이미 포인트를 부여했다면 뺀다.
if ($mb_id && $ct['ct_point'] && $ct['ct_point_use'])
{
$point_use = 0;
//insert_point($mb_id, (-1) * ($ct[ct_point] * $ct[ct_qty]), "주문번호 $od_id ($ct_id) 취소");
delete_point($mb_id, "@delivery", $mb_id, "$od_id,$ct_id");
}
// 히스토리에 남김
// 히스토리에 남길때는 작업|시간|IP|그리고 나머지 자료
$ct_history="\n$ct_status|$now|$REMOTE_ADDR";
$sql = " update {$g5['g5_shop_cart_table']}
set ct_point_use = '$point_use',
ct_stock_use = '$stock_use',
ct_status = '$ct_status',
ct_history = CONCAT(ct_history,'$ct_history')
where od_id = '$od_id'
and ct_id = '$ct_id' ";
sql_query($sql);
}
// 주문정보
$sql = " select * from {$g5['g5_shop_order_table']} where od_id = '$od_id' ";
$od = sql_fetch($sql);
// 주문 합계
$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,
SUM(cp_price) as coupon,
COUNT(distinct it_id) as cnt
from {$g5['g5_shop_cart_table']}
where od_id = '$od_id'
and ct_status IN ( '주문', '준비', '배송', '완료' ) ";
$sum = sql_fetch($sql);
$cart_price = $sum['price'];
$cart_coupon = $sum['coupon'];
$cart_count = $sum['cnt'];
// 배송비
$send_cost = get_sendcost($cart_price, $od_id);
$tot_od_cp_price = $tot_sc_cp_price = 0;
if($od['mb_id']) {
// 주문할인 쿠폰
$sql = " select a.cp_id, a.cp_type, a.cp_price, a.cp_trunc, a.cp_minimum, a.cp_maximum
from {$g5['g5_shop_coupon_table']} a right join {$g5['g5_shop_coupon_log_table']} b on ( a.cp_id = b.cp_id )
where b.od_id = '$od_id'
and b.mb_id = '{$od['mb_id']}'
and a.cp_method = '2' ";
$cp = sql_fetch($sql);
$tot_od_price = $cart_price - $cart_coupon;
if($cp['cp_id']) {
$dc = 0;
if($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)
$dc = $tot_od_price;
$tot_od_price -= $dc;
$tot_od_cp_price = $dc;
}
}
// 배송쿠폰 할인
$sql = " select a.cp_id, a.cp_type, a.cp_price, a.cp_trunc, a.cp_minimum, a.cp_maximum
from {$g5['g5_shop_coupon_table']} a right join {$g5['g5_shop_coupon_log_table']} b on ( a.cp_id = b.cp_id )
where b.od_id = '$od_id'
and b.mb_id = '{$od['mb_id']}'
and a.cp_method = '3' ";
$cp = sql_fetch($sql);
if($cp['cp_id']) {
$dc = 0;
if($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;
}
}
}
// 취소 합계
$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price
from {$g5['g5_shop_cart_table']}
where od_id = '$od_id'
and ct_status IN ( '취소', '반품', '품절' ) ";
$sum = sql_fetch($sql);
$cancel_price = $sum['price'];
// 미수
$od_misu = ( $cart_price + $send_cost + $od['od_send_cost2'] )
- ( $cart_coupon + $tot_od_cp_price + $tot_sc_cp_price )
- ( $od['od_receipt_price'] + $od['od_receipt_point'] - $od['od_refund_price'] );
// 주문정보 반영
$sql = " update {$g5['g5_shop_order_table']}
set od_cart_price = '$cart_price',
od_cart_coupon = '$cart_coupon',
od_coupon = '$tot_od_cp_price',
od_send_coupon = '$tot_sc_cp_price',
od_cancel_price = '$cancel_price',
od_send_cost = '$send_cost',
od_misu = '$od_misu'
where od_id = '$od_id' ";
sql_query($sql);
$qstr = "sort1=$sort1&amp;sort2=$sort2&amp;sel_field=$sel_field&amp;search=$search&amp;page=$page";
$url = "./orderform.php?od_id=$od_id&amp;$qstr";
// 수량변경 히스토리 기록
if($mod_history) {
$sql = " update {$g5['g5_shop_order_table']}
set od_mod_history = CONCAT(od_mod_history,'$mod_history')
where od_id = '$od_id' ";
sql_query($sql);
}
// 1.06.06
$od = sql_fetch(" select od_receipt_point from {$g5['g5_shop_order_table']} where od_id = '$od_id' ");
if ($od['od_receipt_point'])
alert("포인트로 결제한 주문은,\\n\\n주문상태 변경으로 인해 포인트의 가감이 발생하는 경우\\n\\n회원관리 > 포인트관리에서 수작업으로 포인트를 맞추어 주셔야 합니다.\\n\\n만약, 미수금이 발생하는 경우에는 DC에 금액을 음수로 입력하시면 해결됩니다.", $url);
else
goto_url($url);
?>