} // 배송비 switch ($row['ct_send_cost']) { case 1: $ct_send_cost = '착불'; break; case 2: $ct_send_cost = '무료'; break; default: $ct_send_cost = '선불'; break; } // 조건부무료 if ($row['it_sc_type'] == 2) { $sendcost = get_item_sendcost($row['it_id'], $sum['price'], $sum['qty'], $s_cart_id); if ($sendcost == 0) { $ct_send_cost = '무료'; } } ?> <li class="sod_li"> <input type="hidden" name="it_id[<?php echo $i; ?> ]" value="<?php echo $row['it_id']; ?> "> <input type="hidden" name="it_name[<?php
$sum = sql_fetch($sql); // 배송비 switch ($row['ct_send_cost']) { case 1: $ct_send_cost = '착불'; break; case 2: $ct_send_cost = '무료'; break; default: $ct_send_cost = '선불'; break; } // 조건부무료 if ($row['it_sc_type'] == 2) { $sendcost = get_item_sendcost($row['it_id'], $sum['price'], $sum['qty'], $od['od_id']); if ($sendcost == 0) { $ct_send_cost = '무료'; } } for ($k = 0; $opt = sql_fetch_array($res); $k++) { $opt_msg = $opt['ct_option']; if ($opt['pt_msg1']) { $opt_msg .= '<div style="color:#888;">'; if ($row['pt_msg1']) { $opt_msg .= $row['pt_msg1'] . ' : '; } $opt_msg .= $opt['pt_msg1'] . '</div>'; } if ($opt['pt_msg2']) { $opt_msg .= '<div style="color:#888;">';
function get_sendcost($cart_id, $selected = 1) { global $default, $g5; $send_cost = 0; $total_price = 0; $total_send_cost = 0; $sql = " select distinct it_id\n from {$g5['g5_shop_cart_table']}\n where od_id = '{$cart_id}'\n and ct_send_cost = '0'\n and ct_status IN ( '쇼핑', '주문', '입금', '준비', '배송', '완료' )\n and ct_select = '{$selected}' "; $result = sql_query($sql); for ($i = 0; $sc = sql_fetch_array($result); $i++) { // 합계 $sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,\n SUM(ct_qty) as qty\n from {$g5['g5_shop_cart_table']}\n where it_id = '{$sc['it_id']}'\n and od_id = '{$cart_id}'\n and ct_status IN ( '쇼핑', '주문', '입금', '준비', '배송', '완료' )\n and ct_select = '{$selected}'"; $sum = sql_fetch($sql); $send_cost = get_item_sendcost($sc['it_id'], $sum['price'], $sum['qty'], $cart_id); if ($send_cost > 0) { $total_send_cost += $send_cost; } if ($default['de_send_cost_case'] == '차등' && $send_cost == -1) { $total_price += $sum['price']; } } $send_cost = 0; if ($default['de_send_cost_case'] == '차등' && $total_price > 0) { // 금액별차등 : 여러단계의 배송비 적용 가능 $send_cost_limit = explode(";", $default['de_send_cost_limit']); $send_cost_list = explode(";", $default['de_send_cost_list']); $send_cost = 0; for ($k = 0; $k < count($send_cost_limit); $k++) { // 총판매금액이 배송비 상한가 보다 작다면 if ($total_price < preg_replace('/[^0-9]/', '', $send_cost_limit[$k])) { $send_cost = preg_replace('/[^0-9]/', '', $send_cost_list[$k]); break; } } } return $total_send_cost + $send_cost; }
function apms_order($od_id, $od_status, $od_mk = '') { global $g5; if (!$od_id) { return; } $arr_it_id = array(); $arr_no_auto = array(); $account = array(); $now = G5_TIME_YMDHIS; $od_ok = $od_status == "입금" ? true : false; // APMS $mk_id = ''; $mk_brate = 0; if (USE_PARTNER) { $apms = sql_fetch(" select * from {$g5['apms']} ", false); if ($od_mk) { // 추천인 아이디가 있으면 $mk = apms_marketer($od_mk, 'pt_id, pt_benefit'); if ($mk['pt_id']) { $mk_id = $mk['pt_id']; $lvl = isset($mk['pt_level']) && $mk['pt_level'] > 0 ? $mk['pt_level'] : 1; $mk_lvrate = isset($apms['apms_benefit' . $lvl]) && $apms['apms_benefit' . $lvl] > 0 ? $apms['apms_benefit' . $lvl] : 0; $mk_brate = ($mk_lvrate + $mk['pt_benefit']) / 100; } } } // 장바구니에서 내역가져오기 $result = sql_query("select * from {$g5['g5_shop_cart_table']} where od_id = '{$od_id}' and ct_select = '1' order by pt_id, it_id", false); while ($row = sql_fetch_array($result)) { $it = apms_it($row['it_id']); //상품정보 $query = ""; if ($od_ok && in_array($it['pt_it'], $g5['apms_automation'])) { //자동처리 상품일 때 입금상태이면 재고반영, 포인트반영, 결제완료 처리함 //상태변경 $ct_status = '완료'; // 장바구니 업데이트 $query .= ", ct_status = '{$ct_status}'"; // 판매량 반영 $arr_it_id[] = $row['it_id']; // 재고량 반영 if (!$row['ct_stock_use']) { //YC5 관리자용 차용 apms_stock($row['it_id'], $row['ct_qty'], $row['io_id'], $row['io_type']); $query .= ", ct_stock_use = '1'"; } // 포인트 반영 - 컨텐츠 상품은 설정일과 상관없이 반영함 if ($row['mb_id'] && $row['ct_point'] > 0 && !$row['ct_point_use']) { $po_point = $row['ct_point'] * $row['ct_qty']; $po_content = "주문번호 {$od_id} ({$row['it_id']} : {$row['ct_id']}) 결제완료"; insert_point($row['mb_id'], $po_point, $po_content, "@delivery", $row['mb_id'], "{$od_id},{$row['ct_id']}"); $query .= ", ct_point_use = '1'"; } // 정산일 반영 $query .= ", pt_datetime = '{$now}'"; // 히스토리에 남김 - 히스토리에 남길때는 작업|아이디|시간|IP|그리고 나머지 자료 $ct_history = "\n{$ct_status}|automation|{$now}|"; $query .= ", ct_history = CONCAT(ct_history,'{$ct_history}')"; // 멤버쉽 아이템 체크 - 멤버쉽 함수가 있을 때만 작동 if (function_exists('apms_membership_order')) { apms_membership_order($row, $ct_status, $now); } } else { // 자동처리 아닌 상품 $arr_no_auto[] = $row['it_id']; } //커미션, 인센티브 if (USE_PARTNER) { if ($it['pt_id']) { // 판매자 list($commission, $incentive) = apms_pt_rate($apms, $it['pt_it'], $it['pt_id'], $it['pt_commission'], $it['pt_incentive']); $row['pt_commission_rate'] = $commission ? $commission : 0; $row['pt_incentive_rate'] = $incentive ? $incentive : 0; // 가정산 $account = apms_account($row); $query .= " , pt_id = '{$it['pt_id']}'\n\t\t\t\t\t\t\t, pt_commission_rate = '{$row['pt_commission_rate']}'\n\t\t\t\t\t\t\t, pt_incentive_rate = '{$row['pt_incentive_rate']}'\n\t\t\t\t\t\t\t, pt_sale = '{$account['sale']}'\n\t\t\t\t\t\t\t, pt_commission = '{$account['commission']}'\n\t\t\t\t\t\t\t, pt_point = '{$account['point']}'\n\t\t\t\t\t\t\t, pt_incentive = '{$account['incentive']}'\n\t\t\t\t\t\t\t, pt_net = '{$account['net']}' "; } if ($mk_id && isset($it['pt_marketer']) && $it['pt_marketer'] > 0) { // 추천인 $mk_prate = $it['pt_marketer'] / 100; $mk_amount = $row['ct_price'] * $row['ct_qty']; //총금액 if ($row['ct_notax']) { $mk_net = $mk_amount; } else { list($mk_net) = apms_vat($mk_amount); } $mk_profit = floor($mk_net * $mk_prate); if ($mk_profit > 0) { $mk_benefit = floor($mk_profit * $mk_brate); $query .= " , mk_id = '{$mk_id}'\n\t\t\t\t\t\t\t\t, mk_profit = '{$mk_profit}'\n\t\t\t\t\t\t\t\t, mk_benefit = '{$mk_benefit}' "; } } } if ($query) { $sql = " update {$g5['g5_shop_cart_table']} \n\t\t\t\t\t\tset pt_it = '{$it['pt_it']}'\n\t\t\t\t\t\t\t{$query} \n\t\t\t\t\t\twhere od_id = '{$od_id}' and ct_id = '{$row['ct_id']}'\n\t\t\t\t\t"; sql_query($sql); } } // 판매량 일괄반영 if (is_array($arr_it_id) && !empty($arr_it_id)) { $unq_it_id = array_unique($arr_it_id); foreach ($unq_it_id as $it_id) { $row2 = sql_fetch(" select sum(ct_qty) as sum_qty from {$g5['g5_shop_cart_table']} where it_id = '{$it_id}' and ct_status = '완료' "); sql_query(" update {$g5['g5_shop_item_table']} set it_sum_qty = '{$row2['sum_qty']}' where it_id = '{$it_id}' "); } } // 주문서가 자동처리 상품으로 되어 있으면 주문서도 완료처리 $is_sendcost = true; if ($od_ok && is_array($arr_no_auto) && empty($arr_no_auto)) { $info = get_order_info($od_id); if ($info && $info['od_misu'] == 0) { sql_query(" update {$g5['g5_shop_order_table']} set od_status = '완료' where od_id = '{$od_id}' "); $is_sendcost = false; } } // 개별배송비처리 - 무료가 아니고 기본배송비가 있는 경우만 체크 if ($is_sendcost) { $where_sql = !empty($g5['apms_automation']) ? " and pt_it not in (" . implode(', ', $g5['apms_automation']) . ") " : ""; $sql = " select * from {$g5['g5_shop_cart_table']} where od_id = '{$od_id}' and ct_select = '1' {$where_sql} group by it_id order by ct_id "; $result = sql_query($sql); for ($i = 0; $row = sql_fetch_array($result); $i++) { // 합계금액 계산 $sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,\n\t\t\t\t\t\t\tSUM(ct_point * ct_qty) as point,\n\t\t\t\t\t\t\tSUM(ct_qty) as qty\n\t\t\t\t\t\tfrom {$g5['g5_shop_cart_table']}\n\t\t\t\t\t\twhere it_id = '{$row['it_id']}'\n\t\t\t\t\t\t and od_id = '{$od_id}' "; $sum = sql_fetch($sql); // 배송비 $sc_price = 0; switch ($row['ct_send_cost']) { case 1: $sc_type = '착불'; break; case 2: $sc_type = '무료'; break; default: $sc_type = '선불'; $sc_price = $row['it_sc_price']; break; } // 조건부무료 if ($sc_price && $row['it_sc_type'] == 2) { $sc_price = get_item_sendcost($row['it_id'], $sum['price'], $sum['qty'], $od_id); if ($sc_price == 0) { $sc_type = '무료'; } } // 개별배송비 등록 sql_query(" insert into {$g5['apms_sendcost']} set od_id = '{$od_id}', it_id = '{$row['it_id']}', pt_id = '{$row['pt_id']}', sc_price = '{$sc_price}', sc_type = '{$sc_type}', sc_datetime = '" . G5_TIME_YMDHIS . "' ", false); } } return; }