/** * 获得订单中的费用信息 * * @access public * @param array $order * @param array $goods * @param array $consignee * @param bool $is_gb_deposit 是否团购保证金(如果是,应付款金额只计算商品总额和支付费用,可以获得的积分取 $gift_integral) * @return array */ function order_fee($order, $goods, $consignee) { /* 初始化订单的扩展code */ if (!isset($order['extension_code'])) { $order['extension_code'] = ''; } if ($order['extension_code'] == 'group_buy') { $group_buy = group_buy_info($order['extension_id']); } $total = array('real_goods_count' => 0, 'gift_amount' => 0, 'goods_price' => 0, 'market_price' => 0, 'discount' => 0, 'pack_fee' => 0, 'card_fee' => 0, 'shipping_fee' => 0, 'shipping_insure' => 0, 'integral_money' => 0, 'bonus' => 0, 'surplus' => 0, 'cod_fee' => 0, 'pay_fee' => 0, 'tax' => 0); $weight = 0; /* 商品总价 */ foreach ($goods as $val) { /* 统计实体商品的个数 */ if ($val['is_real']) { $total['real_goods_count']++; } $total['goods_price'] += $val['goods_price'] * $val['goods_number']; $total['market_price'] += $val['market_price'] * $val['goods_number']; } $total['saving'] = $total['market_price'] - $total['goods_price']; $total['save_rate'] = $total['market_price'] ? round($total['saving'] * 100 / $total['market_price']) . '%' : 0; $total['goods_price_formated'] = price_format($total['goods_price'], false); $total['market_price_formated'] = price_format($total['market_price'], false); $total['saving_formated'] = price_format($total['saving'], false); /* 折扣 */ if ($order['extension_code'] != 'group_buy') { $discount = compute_discount(); $total['discount'] = $discount['discount']; if ($total['discount'] > $total['goods_price']) { $total['discount'] = $total['goods_price']; } } $total['discount_formated'] = price_format($total['discount'], false); /* 税额 */ if (!empty($order['need_inv']) && $order['inv_type'] != '') { /* 查税率 */ $rate = 0; foreach ($GLOBALS['_CFG']['invoice_type']['type'] as $key => $type) { if ($type == $order['inv_type']) { $rate = floatval($GLOBALS['_CFG']['invoice_type']['rate'][$key]) / 100; break; } } if ($rate > 0) { $total['tax'] = $rate * $total['goods_price']; } } $total['tax_formated'] = price_format($total['tax'], false); /* 包装费用 */ if (!empty($order['pack_id'])) { $total['pack_fee'] = pack_fee($order['pack_id'], $total['goods_price']); } $total['pack_fee_formated'] = price_format($total['pack_fee'], false); /* 贺卡费用 */ if (!empty($order['card_id'])) { $total['card_fee'] = card_fee($order['card_id'], $total['goods_price']); } $total['card_fee_formated'] = price_format($total['card_fee'], false); /* 红包 */ if (!empty($order['bonus_id'])) { $bonus = bonus_info($order['bonus_id']); $total['bonus'] = $bonus['type_money']; } $total['bonus_formated'] = price_format($total['bonus'], false); /* 线下红包 */ if (!empty($order['bonus_kill'])) { $bonus = bonus_info(0, $order['bonus_kill']); $total['bonus_kill'] = $order['bonus_kill']; $total['bonus_kill_formated'] = price_format($total['bonus_kill'], false); } /* 配送费用 */ $shipping_cod_fee = NULL; if ($order['shipping_id'] > 0 && $total['real_goods_count'] > 0) { $region['country'] = $consignee['country']; $region['province'] = $consignee['province']; //$region['city'] = $consignee['city']; //$region['district'] = $consignee['district']; $shipping_info = shipping_area_info($order['shipping_id'], $region); if (!empty($shipping_info)) { if ($order['extension_code'] == 'group_buy') { $weight_price = cart_weight_price(CART_GROUP_BUY_GOODS); } else { $weight_price = cart_weight_price(); } // 查看购物车中是否有免运费商品,若是则把运费赋为零 add by 2014-09-15 20:30*/ //原来的是要全部商品都是免运费的才免运费:$sql = 'SELECT count(*) FROM ' . $ecs->table('cart') . " WHERE `session_id` = '" . SESS_ID. "' AND `extension_code` != 'package_buy' AND `is_shipping` = 0"; $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE `session_id` = '" . SESS_ID . "' AND `extension_code` != 'package_buy' AND `is_shipping` = 1"; $shipping_count = $GLOBALS['db']->getOne($sql); //获取运费 $total['shipping_fee'] = ($shipping_count > 0 and $weight_price['free_shipping'] == 1) ? 0 : shipping_fee($shipping_info['shipping_code'], $shipping_info['configure'], $weight_price['weight'], $total['goods_price'], $weight_price['number']); if (!empty($order['need_insure']) && $shipping_info['insure'] > 0) { $total['shipping_insure'] = shipping_insure_fee($shipping_info['shipping_code'], $total['goods_price'], $shipping_info['insure']); } else { $total['shipping_insure'] = 0; } if ($shipping_info['support_cod']) { $shipping_cod_fee = $shipping_info['pay_fee']; } } } $total['shipping_fee_formated'] = price_format($total['shipping_fee'], false); $total['shipping_insure_formated'] = price_format($total['shipping_insure'], false); // 购物车中的商品能享受红包支付的总额 $bonus_amount = compute_discount_amount(); // 红包和积分最多能支付的金额为商品总额 $max_amount = $total['goods_price'] == 0 ? $total['goods_price'] : $total['goods_price'] - $bonus_amount; /* 计算订单总额 */ if ($order['extension_code'] == 'group_buy' && $group_buy['deposit'] > 0) { $total['amount'] = $total['goods_price']; } else { $total['amount'] = $total['goods_price'] - $total['discount'] + $total['tax'] + $total['pack_fee'] + $total['card_fee'] + $total['shipping_fee'] + $total['shipping_insure'] + $total['cod_fee']; // 减去红包金额 $use_bonus = min($total['bonus'], $max_amount); // 实际减去的红包金额 if (isset($total['bonus_kill'])) { $use_bonus_kill = min($total['bonus_kill'], $max_amount); $total['amount'] -= $price = number_format($total['bonus_kill'], 2, '.', ''); // 还需要支付的订单金额 } $total['bonus'] = $use_bonus; $total['bonus_formated'] = price_format($total['bonus'], false); $total['amount'] -= $use_bonus; // 还需要支付的订单金额 $max_amount -= $use_bonus; // 积分最多还能支付的金额 } /* 余额 */ $order['surplus'] = $order['surplus'] > 0 ? $order['surplus'] : 0; if ($total['amount'] > 0) { if (isset($order['surplus']) && $order['surplus'] > $total['amount']) { $order['surplus'] = $total['amount']; $total['amount'] = 0; } else { $total['amount'] -= floatval($order['surplus']); } } else { $order['surplus'] = 0; $total['amount'] = 0; } $total['surplus'] = $order['surplus']; $total['surplus_formated'] = price_format($order['surplus'], false); /* 积分 */ $order['integral'] = $order['integral'] > 0 ? $order['integral'] : 0; if ($total['amount'] > 0 && $max_amount > 0 && $order['integral'] > 0) { $integral_money = value_of_integral($order['integral']); // 使用积分支付 $use_integral = min($total['amount'], $max_amount, $integral_money); // 实际使用积分支付的金额 $total['amount'] -= $use_integral; $total['integral_money'] = $use_integral; $order['integral'] = integral_of_value($use_integral); } else { $total['integral_money'] = 0; $order['integral'] = 0; } $total['integral'] = $order['integral']; $total['integral_formated'] = price_format($total['integral_money'], false); /* 保存订单信息 */ $_SESSION['flow_order'] = $order; $se_flow_type = isset($_SESSION['flow_type']) ? $_SESSION['flow_type'] : ''; /* 支付费用 */ if (!empty($order['pay_id']) && ($total['real_goods_count'] > 0 || $se_flow_type != CART_EXCHANGE_GOODS)) { $total['pay_fee'] = pay_fee($order['pay_id'], $total['amount'], $shipping_cod_fee); } $total['pay_fee_formated'] = price_format($total['pay_fee'], false); $total['amount'] += $total['pay_fee']; // 订单总额累加上支付费用 $total['amount_formated'] = price_format($total['amount'], false); /* 取得可以得到的积分和红包 */ if ($order['extension_code'] == 'group_buy') { $total['will_get_integral'] = $group_buy['gift_integral']; } elseif ($order['extension_code'] == 'exchange_goods') { $total['will_get_integral'] = 0; } else { $total['will_get_integral'] = get_give_integral($goods); } $total['will_get_bonus'] = $order['extension_code'] == 'exchange_goods' ? 0 : price_format(get_total_bonus(), false); $total['formated_goods_price'] = price_format($total['goods_price'], false); $total['formated_market_price'] = price_format($total['market_price'], false); $total['formated_saving'] = price_format($total['saving'], false); if ($order['extension_code'] == 'exchange_goods') { $sql = 'SELECT SUM(eg.exchange_integral) ' . 'FROM ' . $GLOBALS['ecs']->table('cart') . ' AS c,' . $GLOBALS['ecs']->table('exchange_goods') . 'AS eg ' . "WHERE c.goods_id = eg.goods_id AND c.session_id= '" . SESS_ID . "' " . " AND c.rec_type = '" . CART_EXCHANGE_GOODS . "' " . ' AND c.is_gift = 0 AND c.goods_id > 0 ' . 'GROUP BY eg.goods_id'; $exchange_integral = $GLOBALS['db']->getOne($sql); $total['exchange_integral'] = $exchange_integral; } return $total; }
$smarty->display('order_done.dwt'); exit; } /* 收货人信息 */ foreach ($consignee as $key => $value) { $order[$key] = addslashes($value); } /* 订单中的总额 */ $total = order_fee($order, $cart_goods, $consignee); $order['bonus'] = $total['bonus']; $order['goods_amount'] = $total['goods_price']; $order['discount'] = $total['discount']; $order['surplus'] = $total['surplus']; $order['tax'] = $total['tax']; // 购物车中的商品能享受抵扣券支付的总额 $discount_amout = compute_discount_amount(); // 抵扣券和积分最多能支付的金额为商品总额 $temp_amout = $order['goods_amount'] - $discount_amout; if ($temp_amout <= 0) { $order['bonus_id'] = 0; } /* 配送方式 */ if ($order['shipping_id'] > 0) { $shipping = shipping_info($order['shipping_id']); $order['shipping_name'] = addslashes($shipping['shipping_name']); } $order['shipping_fee'] = $total['shipping_fee']; $order['insure_fee'] = $total['shipping_insure']; /* 支付方式 */ if ($order['pay_id'] > 0) { $payment = payment_info($order['pay_id']);
/* 代码增加_start By www.68ecshop.com */ $order['best_time'] = isset($_POST['best_time']) ? trim($_POST['best_time']) : ''; /* 代码增加_end By www.68ecshop.com */ /*morestock_morecity 把配送方式的价钱算在里面*/ $order['shipping_pay'][$ckey] = $_POST['pay_ship'][$ckey]; /* 订单中的总额 */ $total = order_fee($order, $cart_goods, $consignee); unset($order['shipping_pay'][$ckey]); //morestock_morecity 去掉这条信息以免影响下订单操作 $order['bonus'] = $total['bonus']; $order['goods_amount'] = $total['goods_price']; $order['discount'] = $total['discount']; $order['surplus'] = $total['surplus']; $order['tax'] = $total['tax']; // 购物车中的商品能享受红包支付的总额 $discount_amout = compute_discount_amount($ckey); // 红包和积分最多能支付的金额为商品总额 $temp_amout = $order['goods_amount'] - $discount_amout; if ($temp_amout <= 0) { $order['bonus_id'] = 0; } /* 配送方式 */ if ($order['shipping_id'] > 0) { $shipping = shipping_info($order['shipping_id']); $order['shipping_name'] = addslashes($shipping['shipping_name']); //如果是门店自提,订单需要做特殊标识 if ($order['shipping_id'] == 4 || $order['shipping_name'] == '门店自提') { $order['is_pickup'] = $order['shipping_id']; } } $order['shipping_fee'] = $total['shipping_fee'];
/** * 获得订单中的费用信息 * * @access public * @param array $order * @param array $goods * @param array $consignee * @param bool $is_gb_deposit 是否团购保证金(如果是,应付款金额只计算商品总额和支付费用,可以获得的积分取 $gift_integral) * @return array */ function order_fee($order, $goods, $consignee) { /* 初始化订单的扩展code */ if (!isset($order['extension_code'])) { $order['extension_code'] = ''; } if ($order['extension_code'] == 'group_buy') { $group_buy = group_buy_info($order['extension_id']); } $total = array('real_goods_count' => 0, 'gift_amount' => 0, 'goods_price' => 0, 'market_price' => 0, 'discount' => 0, 'pack_fee' => 0, 'card_fee' => 0, 'shipping_fee' => 0, 'shipping_insure' => 0, 'integral_money' => 0, 'bonus' => 0, 'surplus' => 0, 'cod_fee' => 0, 'pay_fee' => 0, 'tax' => 0); $weight = 0; /* 商品总价 */ foreach ($goods as $val) { /* 统计实体商品的个数 */ if ($val['is_real']) { $total['real_goods_count']++; } $total['goods_price'] += $val['goods_price'] * $val['goods_number']; $total['market_price'] += $val['market_price'] * $val['goods_number']; } $total['saving'] = $total['market_price'] - $total['goods_price']; $total['save_rate'] = $total['market_price'] ? round($total['saving'] * 100 / $total['market_price']) . '%' : 0; $total['goods_price_formated'] = price_format($total['goods_price'], false); $total['market_price_formated'] = price_format($total['market_price'], false); $total['saving_formated'] = price_format($total['saving'], false); /* 折扣 */ if ($order['extension_code'] != 'group_buy') { $discount = compute_discount(isset($order['supplier_id']) ? $order['supplier_id'] : -1); $total['discount'] = $discount['discount']; if ($total['discount'] > $total['goods_price']) { $total['discount'] = $total['goods_price']; } } $total['discount_formated'] = price_format($total['discount'], false); /* 税额 */ if (!empty($order['need_inv']) && $order['inv_type'] != '') { /* 查税率 */ $rate = 0; foreach ($GLOBALS['_CFG']['invoice_type']['type'] as $key => $type) { if ($type == $order['inv_type']) { $rate = floatval($GLOBALS['_CFG']['invoice_type']['rate'][$key]) / 100; break; } } if ($rate > 0) { $total['tax'] = $rate * $total['goods_price']; } } $total['tax_formated'] = price_format($total['tax'], false); /* 包装费用 */ if (!empty($order['pack_id'])) { $total['pack_fee'] = pack_fee($order['pack_id'], $total['goods_price']); } $total['pack_fee_formated'] = price_format($total['pack_fee'], false); /* 贺卡费用 */ if (!empty($order['card_id'])) { $total['card_fee'] = card_fee($order['card_id'], $total['goods_price']); } $total['card_fee_formated'] = price_format($total['card_fee'], false); /* 红包 */ $total['bonus'] = 0; if (!empty($order['bonus_id'])) { $bonus = bonus_info($order['bonus_id']); $total['bonus'] = $bonus['type_money']; } /* 线下红包 */ if (!empty($order['bonus_sn'])) { $bonus = bonus_info(0, $order['bonus_sn']); $total['bonus'] += $bonus['type_money']; //$total['bonus_kill'] = $order['bonus_kill']; //$total['bonus_kill_formated'] = price_format($total['bonus_kill'], false); } $total['bonus_formated'] = price_format($total['bonus'], false); /* 配送费用 */ $shipping_cod_fee = NULL; $sql_where = $_SESSION['user_id'] > 0 ? "user_id='" . $_SESSION['user_id'] . "' " : "session_id = '" . SESS_ID . "' AND user_id=0 "; if ($order['shipping_id'] > 0 && $total['real_goods_count'] > 0) { $region['country'] = $consignee['country']; $region['province'] = $consignee['province']; $region['city'] = $consignee['city']; $region['district'] = $consignee['district']; $shipping_info = shipping_area_info($order['shipping_id'], $region); if (!empty($shipping_info)) { if ($order['extension_code'] == 'group_buy') { $weight_price = cart_weight_price(CART_GROUP_BUY_GOODS); } else { $weight_price = cart_weight_price(); } // 查看购物车中是否全为免运费商品,若是则把运费赋为零 $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE {$sql_where} AND `extension_code` != 'package_buy' AND `is_shipping` = 0 AND rec_id in (" . $_SESSION['sel_cartgoods'] . ")"; //jx $shipping_count = $GLOBALS['db']->getOne($sql); $total['shipping_fee'] = ($shipping_count == 0 and $weight_price['free_shipping'] == 1) ? 0 : shipping_fee($shipping_info['shipping_code'], $shipping_info['configure'], $weight_price['weight'], $total['goods_price'], $weight_price['number']); if (!empty($order['need_insure']) && $shipping_info['insure'] > 0) { $total['shipping_insure'] = shipping_insure_fee($shipping_info['shipping_code'], $total['goods_price'], $shipping_info['insure']); } else { $total['shipping_insure'] = 0; } if ($shipping_info['support_cod']) { $shipping_cod_fee = $shipping_info['pay_fee']; } } } $total['shipping_fee_formated'] = price_format($total['shipping_fee'], false); $total['shipping_insure_formated'] = price_format($total['shipping_insure'], false); /* 代码增加_start By www.68ecshop.com */ foreach ($goods as $val) { $sql_supp = "select g.supplier_id, IF(g.supplier_id='0', '本网站', s.supplier_name) AS supplier_name2 from " . $GLOBALS['ecs']->table('goods') . " AS g left join " . $GLOBALS['ecs']->table('supplier') . " AS s on g.supplier_id=s.supplier_id where g.goods_id='" . $val['goods_id'] . "' "; $row_supp = $GLOBALS['db']->getRow($sql_supp); $row_supp['supplier_id'] = $row_supp['supplier_id'] ? intval($row_supp['supplier_id']) : 0; $total['supplier_shipping'][$row_supp['supplier_id']]['supplier_name'] = $row_supp['supplier_name2']; $total['supplier_shipping'][$row_supp['supplier_id']]['goods_number'] += $val['goods_number']; $total['supplier_goodsnumber'][$row_supp['supplier_id']] += $val['goods_number']; $total['goods_price_supplier'][$row_supp['supplier_id']] += $val['goods_price'] * $val['goods_number']; if ($order['extension_code'] == 'group_buy') { $weight_price2 = cart_weight_price2(CART_GROUP_BUY_GOODS, $row_supp['supplier_id']); } else { $weight_price2 = cart_weight_price2(CART_GENERAL_GOODS, $row_supp['supplier_id']); } // 查看购物车中是否全为免运费商品,若是则把运费赋为零 $sql_where = $_SESSION['user_id'] > 0 ? "c.user_id='" . $_SESSION['user_id'] . "' " : "c.session_id = '" . SESS_ID . "' AND c.user_id=0 "; $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('cart') . " AS c left join " . $GLOBALS['ecs']->table('goods') . " AS g on c.goods_id=g.goods_id WHERE g.supplier_id = '" . $row_supp['supplier_id'] . "' AND {$sql_where} AND c.extension_code != 'package_buy' AND c.is_shipping = 0 AND c.rec_id in (" . $_SESSION['sel_cartgoods'] . ")"; //jx $shipping_count_supp = $GLOBALS['db']->getOne($sql); $total['supplier_shipping'][$row_supp['supplier_id']]['shipping_fee'] = ($shipping_count_supp == 0 and $weight_price2['free_shipping'] == 1) ? 0 : shipping_fee($shipping_info['shipping_code'], $shipping_info['configure'], $weight_price2['weight'], $total['goods_price_supplier'][$row_supp['supplier_id']], $weight_price2['number']); $total['supplier_shipping'][$row_supp['supplier_id']]['formated_shipping_fee'] = price_format($total['supplier_shipping'][$row_supp['supplier_id']]['shipping_fee'], false); } krsort($total['supplier_shipping']); $total['shipping_fee'] = 0; foreach ($total['supplier_shipping'] as $supp_shipping) { $total['shipping_fee'] += $supp_shipping['shipping_fee']; } $total['shipping_fee_formated'] = price_format($total['shipping_fee'], false); /* 代码增加_end By www.68ecshop.com */ // 购物车中的商品能享受红包支付的总额 $bonus_amount = compute_discount_amount(); // 红包和积分最多能支付的金额为商品总额 $max_amount = $total['goods_price'] == 0 ? $total['goods_price'] : $total['goods_price'] - $bonus_amount; /* 计算订单总额 */ if ($order['extension_code'] == 'group_buy' && $group_buy['deposit'] > 0) { $total['amount'] = $total['goods_price']; } else { $total['amount'] = $total['goods_price'] - $total['discount'] + $total['tax'] + $total['pack_fee'] + $total['card_fee'] + $total['shipping_fee'] + $total['shipping_insure'] + $total['cod_fee']; // 减去红包金额 $use_bonus = min($total['bonus'], $max_amount); // 实际减去的红包金额 if (isset($total['bonus_kill'])) { $use_bonus_kill = min($total['bonus_kill'], $max_amount); $total['amount'] -= $price = number_format($total['bonus_kill'], 2, '.', ''); // 还需要支付的订单金额 } $total['bonus'] = $use_bonus; $total['bonus_formated'] = price_format($total['bonus'], false); $total['amount'] -= $use_bonus; // 还需要支付的订单金额 $max_amount -= $use_bonus; // 积分最多还能支付的金额 } /* 余额 */ $order['surplus'] = $order['surplus'] > 0 ? $order['surplus'] : 0; if ($total['amount'] > 0) { if (isset($order['surplus']) && $order['surplus'] > $total['amount']) { $order['surplus'] = $total['amount']; $total['amount'] = 0; } else { $total['amount'] -= floatval($order['surplus']); } } else { $order['surplus'] = 0; $total['amount'] = 0; } $total['surplus'] = $order['surplus']; $total['surplus_formated'] = price_format($order['surplus'], false); /* 积分 */ $order['integral'] = $order['integral'] > 0 ? $order['integral'] : 0; if ($total['amount'] > 0 && $max_amount > 0 && $order['integral'] > 0) { $integral_money = value_of_integral($order['integral']); // 使用积分支付 $use_integral = min($total['amount'], $max_amount, $integral_money); // 实际使用积分支付的金额 $total['amount'] -= $use_integral; $total['integral_money'] = $use_integral; $order['integral'] = integral_of_value($use_integral); } else { $total['integral_money'] = 0; $order['integral'] = 0; } $total['integral'] = $order['integral']; $total['integral_formated'] = price_format($total['integral_money'], false); /* 保存订单信息 */ $_SESSION['flow_order'] = $order; $se_flow_type = isset($_SESSION['flow_type']) ? $_SESSION['flow_type'] : ''; /* 支付费用 */ if (!empty($order['pay_id']) && ($total['real_goods_count'] > 0 || $se_flow_type != CART_EXCHANGE_GOODS)) { $total['pay_fee'] = pay_fee($order['pay_id'], $total['amount'], $shipping_cod_fee); } $total['pay_fee_formated'] = price_format($total['pay_fee'], false); $total['amount'] += $total['pay_fee']; // 订单总额累加上支付费用 $total['amount_formated'] = price_format($total['amount'], false); /* 取得可以得到的积分和红包 */ if ($order['extension_code'] == 'group_buy') { $total['will_get_integral'] = $group_buy['gift_integral']; } elseif ($order['extension_code'] == 'exchange_goods') { $total['will_get_integral'] = 0; } else { $total['will_get_integral'] = get_give_integral($goods); } //$total['will_get_bonus'] = $order['extension_code'] == 'exchange_goods' ? 0 : price_format(get_total_bonus(), false); $total['will_get_bonus'] = $order['extension_code'] == 'exchange_goods' ? 0 : price_format(get_total_bonus($total['goods_price_supplier']), false); $total['formated_goods_price'] = price_format($total['goods_price'], false); $total['formated_market_price'] = price_format($total['market_price'], false); $total['formated_saving'] = price_format($total['saving'], false); if ($order['extension_code'] == 'exchange_goods') { $sql_exchange = $_SESSION['user_id'] > 0 ? "c.user_id='" . $_SESSION['user_id'] . "' " : "c.session_id = '" . SESS_ID . "' AND c.user_id=0 "; $sql = 'SELECT SUM(eg.exchange_integral) ' . 'FROM ' . $GLOBALS['ecs']->table('cart') . ' AS c,' . $GLOBALS['ecs']->table('exchange_goods') . 'AS eg ' . "WHERE c.goods_id = eg.goods_id AND " . $sql_exchange . " AND c.rec_type = '" . CART_EXCHANGE_GOODS . "' " . ' AND c.is_gift = 0 AND c.goods_id > 0 ' . 'GROUP BY eg.goods_id'; $exchange_integral = $GLOBALS['db']->getOne($sql); $total['exchange_integral'] = $exchange_integral; } return $total; }
public function done () { global $ecs,$db,$_CFG; include_once(RPC_ROOT.'includes/lib_clips_ec.php'); include_once(RPC_ROOT.'includes/lib_payment.php'); /* 取得购物类型 */ $flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS; /* 检查购物车中是否有商品 */ $sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') ." WHERE session_id = '" . SESS_ID . "' " . "AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type'"; if ($db->getOne($sql) == 0) { $msg = rpcLang('flow.php', 'no_goods_in_cart'); jsonExit("{\"status\":\"$msg\"}"); } /* 检查商品库存,如果使用库存,且下订单时减库存,则减少库存 */ if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE) { $cart_goods_stock = get_cart_goods(); $_cart_goods_stock = array(); foreach ($cart_goods_stock['goods_list'] as $value) { $_cart_goods_stock[$value['rec_id']] = $value['goods_number']; } zy_flow_cart_stock($_cart_goods_stock); unset($cart_goods_stock, $_cart_goods_stock); } /* * 检查用户是否已经登录 * 如果用户已经登录了则检查是否有默认的收货地址 * 如果没有登录则跳转到登录和注册页面 */ if (empty($_SESSION['direct_shopping']) && $_SESSION['user_id'] == 0) { /* 用户没有登录且没有选定匿名购物,转向到登录页面 */ $msg = rpcLang('user.php', 'nologin'); jsonExit("{\"status\":\"$msg\"}"); } $consignee = get_consignee($_SESSION['user_id']); /* 检查收货人信息是否完整 */ if (!check_consignee_info($consignee, $flow_type)) { $msg = rpcLang('flow.php', 'user_address_not_full'); jsonExit("{\"status\":\"$msg\"}"); } $_GET['how_oos'] = isset($_GET['how_oos']) ? intval($_GET['how_oos']) : 0; $_GET['card_message'] = isset($_GET['card_message']) ? htmlspecialchars($_GET['card_message']) : ''; $_GET['inv_type'] = !empty($_GET['inv_type']) ? htmlspecialchars($_GET['inv_type']) : ''; $_GET['inv_payee'] = isset($_GET['inv_payee']) ? htmlspecialchars($_GET['inv_payee']) : ''; $_GET['inv_content'] = isset($_GET['inv_content']) ? htmlspecialchars($_GET['inv_content']) : ''; $_GET['postscript'] = isset($_GET['postscript']) ? htmlspecialchars($_GET['postscript']) : ''; $referer = empty($_GET['referer']) ? 'Android':trim($_GET['referer']); $order = array( //'shipping_id' => intval($_POST['shipping']), 'shipping_id' => intval($_GET['shipping']),//快递id 'pay_id' => intval($_GET['payment']),//支付方式id 'pack_id' => isset($_GET['pack']) ? intval($_GET['pack']) : 0,//包装 'card_id' => isset($_GET['card']) ? intval($_GET['card']) : 0,//贺卡 'card_message' => trim($_GET['card_message']), 'surplus' => isset($_POST['surplus']) ? floatval($_POST['surplus']) : 0.00, 'integral' => isset($_POST['integral']) ? intval($_POST['integral']) : 0, 'bonus_id' => isset($_GET['bonus']) ? intval($_GET['bonus']) : 0, 'need_inv' => empty($_POST['need_inv']) ? 0 : 1, 'postscript' => trim($_POST['postscript']), 'how_oos' => isset($_LANG['oos'][$_POST['how_oos']]) ? addslashes($_LANG['oos'][$_POST['how_oos']]) : '', 'need_insure' => isset($_POST['need_insure']) ? intval($_POST['need_insure']) : 0, 'user_id' => $_SESSION['user_id'], 'add_time' => gmtime(), 'order_status' => OS_UNCONFIRMED, 'shipping_status' => SS_UNSHIPPED, 'pay_status' => PS_UNPAYED, 'agency_id' => get_agency_by_regions(array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district'])) ); if(EC_CHARSET == 'utf-8'){ $order['inv_type'] = gbktoutf8($_GET['inv_type']); $order['inv_payee'] = gbktoutf8(trim($_GET['inv_payee'])); $order['inv_content'] = gbktoutf8($_GET['inv_content']); }else{ $order['inv_type'] = utf8togbk($_GET['inv_type']); $order['inv_payee'] = utf8togbk(trim($_GET['inv_payee'])); $order['inv_content'] = utf8togbk($_GET['inv_content']); } /* 扩展信息 */ if (isset($_SESSION['flow_type']) && intval($_SESSION['flow_type']) != CART_GENERAL_GOODS) { $order['extension_code'] = $_SESSION['extension_code']; $order['extension_id'] = $_SESSION['extension_id']; } else { $order['extension_code'] = ''; $order['extension_id'] = 0; } $user_id = $_SESSION['user_id']; /* #检查积分余额是否合法 $user_id = $_SESSION['user_id']; if ($user_id > 0) { $user_info = user_info($user_id); $order['surplus'] = min($order['surplus'], $user_info['user_money'] + $user_info['credit_line']); if ($order['surplus'] < 0) { $order['surplus'] = 0; } // 查询用户有多少积分 $flow_points = flow_available_points(); // 该订单允许使用的积分 $user_points = $user_info['pay_points']; // 用户的积分总数 $order['integral'] = min($order['integral'], $user_points, $flow_points); if ($order['integral'] < 0) { $order['integral'] = 0; } } else { $order['surplus'] = 0; $order['integral'] = 0; }*/ #检查红包是否存在 if ($order['bonus_id'] > 0) { $bonus = bonus_info($order['bonus_id']); if (empty($bonus) || $bonus['user_id'] != $user_id || $bonus['order_id'] > 0 || $bonus['min_goods_amount'] > cart_amount(true, $flow_type)) { $order['bonus_id'] = 0; } } elseif (isset($_POST['bonus_sn'])) { $bonus_sn = trim($_POST['bonus_sn']); $bonus = bonus_info(0, $bonus_sn); $now = gmtime(); if (empty($bonus) || $bonus['user_id'] > 0 || $bonus['order_id'] > 0 || $bonus['min_goods_amount'] > cart_amount(true, $flow_type) || $now > $bonus['use_end_date']) { } else { if ($user_id > 0) { $sql = "UPDATE " . $ecs->table('user_bonus') . " SET user_id = '$user_id' WHERE bonus_id = '$bonus[bonus_id]' LIMIT 1"; $db->query($sql); } $order['bonus_id'] = $bonus['bonus_id']; $order['bonus_sn'] = $bonus_sn; } } /* 订单中的商品 */ $cart_goods = cart_goods($flow_type); if (empty($cart_goods)) { $msg = rpcLang('flow.php', 'no_goods_in_cart'); jsonExit("{\"status\":\"$msg\"}"); } /* 检查商品总额是否达到最低限购金额 */ if ($flow_type == CART_GENERAL_GOODS && cart_amount(true, CART_GENERAL_GOODS) < $_CFG['min_goods_amount']) { $msg = rpcLang('flow.php', 'goods_amount_not_enough'); jsonExit("{\"status\":\"$msg\"}"); } /* 收货人信息 */ foreach ($consignee as $key => $value) { $order[$key] = addslashes($value); } /* 订单中的总额 */ $total = order_fee($order, $cart_goods, $consignee); $order['bonus'] = $total['bonus']; $order['goods_amount'] = $total['goods_price']; $order['discount'] = $total['discount']; $order['surplus'] = $total['surplus']; $order['tax'] = $total['tax']; #购物车中的商品能享受红包支付的总额 $discount_amout = compute_discount_amount(); #红包和积分最多能支付的金额为商品总额 $temp_amout = $order['goods_amount'] - $discount_amout; if ($temp_amout <= 0) { $order['bonus_id'] = 0; } /* 配送方式 */ if ($order['shipping_id'] > 0) { $shipping = shipping_info($order['shipping_id']); $order['shipping_name'] = addslashes($shipping['shipping_name']); } $order['shipping_fee'] = $total['shipping_fee']; $order['insure_fee'] = $total['shipping_insure']; /* 支付方式 */ if ($order['pay_id'] > 0) { $payment = payment_info($order['pay_id']); $order['pay_name'] = addslashes($payment['pay_name']); } $order['pay_fee'] = $total['pay_fee']; $order['cod_fee'] = $total['cod_fee']; /* 商品包装 */ if ($order['pack_id'] > 0) { $pack = pack_info($order['pack_id']); $order['pack_name'] = addslashes($pack['pack_name']); } $order['pack_fee'] = $total['pack_fee']; /* 祝福贺卡 */ if ($order['card_id'] > 0) { $card = card_info($order['card_id']); $order['card_name'] = addslashes($card['card_name']); } $order['card_fee'] = $total['card_fee']; $order['order_amount'] = number_format($total['amount'], 2, '.', ''); /* 如果全部使用余额支付,检查余额是否足够 */ if ($payment['pay_code'] == 'balance' && $order['order_amount'] > 0) { if($order['surplus'] >0) //余额支付里如果输入了一个金额 { $order['order_amount'] = $order['order_amount'] + $order['surplus']; $order['surplus'] = 0; } if ($order['order_amount'] > ($user_info['user_money'] + $user_info['credit_line'])) { show_message($_LANG['balance_not_enough']); } else { $order['surplus'] = $order['order_amount']; $order['order_amount'] = 0; } } /* 如果订单金额为0(使用余额或积分或红包支付),修改订单状态为已确认、已付款 */ if ($order['order_amount'] <= 0) { $order['order_status'] = OS_CONFIRMED; $order['confirm_time'] = gmtime(); $order['pay_status'] = PS_PAYED; $order['pay_time'] = gmtime(); $order['order_amount'] = 0; } $order['integral_money'] = $total['integral_money']; $order['integral'] = $total['integral']; if ($order['extension_code'] == 'exchange_goods') { $order['integral_money'] = 0; $order['integral'] = $total['exchange_integral']; } $order['from_ad'] = !empty($_SESSION['from_ad']) ? $_SESSION['from_ad'] : '0'; $order['referer'] = !empty($_SESSION['referer']) ? addslashes($_SESSION['referer']) : ''; /* 记录扩展信息 */ if ($flow_type != CART_GENERAL_GOODS) { $order['extension_code'] = $_SESSION['extension_code']; $order['extension_id'] = $_SESSION['extension_id']; } $affiliate = unserialize($_CFG['affiliate']); if(isset($affiliate['on']) && $affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 1) { //推荐订单分成 $parent_id = get_affiliate(); if($user_id == $parent_id) { $parent_id = 0; } } elseif(isset($affiliate['on']) && $affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 0) { //推荐注册分成 $parent_id = 0; } else { //分成功能关闭 $parent_id = 0; } $order['parent_id'] = $parent_id; /* 插入订单表 */ $error_no = 0; do { $order['order_sn'] = get_order_sn(); //获取新订单号 $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT'); $error_no = $GLOBALS['db']->errno(); if ($error_no > 0 && $error_no != 1062) { die($GLOBALS['db']->errorMsg()); } } while ($error_no == 1062); //如果是订单号重复则重新提交数据 $new_order_id = $db->insert_id(); $order['order_id'] = $new_order_id; /* 插入订单商品 */ $sql = "INSERT INTO " . $ecs->table('order_goods') . "( " . "order_id, goods_id, goods_name, goods_sn, goods_number, market_price, ". "goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id) ". " SELECT '$new_order_id', goods_id, goods_name, goods_sn, goods_number, market_price, ". "goods_price, goods_attr, is_real, extension_code, parent_id, is_gift, goods_attr_id". " FROM " .$ecs->table('cart') . " WHERE session_id = '".SESS_ID."' AND rec_type = '$flow_type'"; $db->query($sql); /* 修改拍卖活动状态 */ if ($order['extension_code']=='auction') { $sql = "UPDATE ". $ecs->table('goods_activity') ." SET is_finished='2' WHERE act_id=".$order['extension_id']; $db->query($sql); } /* 处理余额、积分、红包 */ if ($order['user_id'] > 0 && $order['surplus'] > 0) { log_account_change($order['user_id'], $order['surplus'] * (-1), 0, 0, 0, sprintf($_LANG['pay_order'], $order['order_sn'])); } if ($order['user_id'] > 0 && $order['integral'] > 0) { log_account_change($order['user_id'], 0, 0, 0, $order['integral'] * (-1), sprintf($_LANG['pay_order'], $order['order_sn'])); } if ($order['bonus_id'] > 0 && $temp_amout > 0) { use_bonus($order['bonus_id'], $new_order_id); } /* 如果使用库存,且下订单时减库存,则减少库存 */ if ($_CFG['use_storage'] == '1' && $_CFG['stock_dec_time'] == SDT_PLACE) { //change_order_goods_storage($order['order_id'], true, SDT_PLACE); } error_log('1',3,'flow.log'); /* 给商家发邮件 */ /* 增加是否给客服发送邮件选项 */ if ($_CFG['send_service_email'] && $_CFG['service_email'] != '') { error_log('2',3,'flow.log'); $tpl = get_mail_template('remind_of_new_order'); /* $smarty->assign('order', $order); $smarty->assign('goods_list', $cart_goods); $smarty->assign('shop_name', $_CFG['shop_name']); $smarty->assign('send_date', date($_CFG['time_format'])); $content = $smarty->fetch('str:' . $tpl['template_content']); */ send_mail($_CFG['shop_name'], $_CFG['service_email'], $tpl['template_subject'], $content, $tpl['is_html']); } error_log('2',3,'flow.log'); /* 如果需要,发短信 */ if ($_CFG['sms_order_placed'] == '1' && $_CFG['sms_shop_mobile'] != '') { include_once(RPC_ROOT.'includes/cls_sms.php'); $sms = new sms(); $msg = $order['pay_status'] == PS_UNPAYED ? $_LANG['order_placed_sms'] : $_LANG['order_placed_sms'] . '[' . $_LANG['sms_paid'] . ']'; $sms->send($_CFG['sms_shop_mobile'], sprintf($msg, $order['consignee'], $order['tel']), 0); } error_log('3',3,'flow.log'); /* 如果订单金额为0 处理虚拟卡 */ if ($order['order_amount'] <= 0) { $sql = " SELECT goods_id, goods_name, goods_number AS num FROM ".$GLOBALS['ecs']->table('cart') . " WHERE is_real = 0 AND extension_code = 'virtual_card'". " AND session_id = '".SESS_ID."' AND rec_type = '$flow_type'"; $res = $GLOBALS['db']->getAll($sql); error_log('4',3,'flow.log'); $virtual_goods = array(); foreach ($res AS $row) { $virtual_goods['virtual_card'][] = array('goods_id' => $row['goods_id'], 'goods_name' => $row['goods_name'], 'num' => $row['num']); } if ($virtual_goods AND $flow_type != CART_GROUP_BUY_GOODS) { /* 虚拟卡发货 */ if (virtual_goods_ship($virtual_goods,$msg, $order['order_sn'], true)) { /* 如果没有实体商品,修改发货状态,送积分和红包 */ $sql = "SELECT COUNT(*)" . " FROM " . $ecs->table('order_goods') . " WHERE order_id = '$order[order_id]' " . " AND is_real = 1"; if ($db->getOne($sql) <= 0) { /* 修改订单状态 */ update_order($order['order_id'], array('shipping_status' => SS_SHIPPED, 'shipping_time' => gmtime())); error_log('5',3,'flow.log'); /* 如果订单用户不为空,计算积分,并发给用户;发红包 */ if ($order['user_id'] > 0) { /* 取得用户信息 */ $user = user_info($order['user_id']); /* 计算并发放积分 */ $integral = integral_to_give($order); log_account_change($order['user_id'], 0, 0, intval($integral['rank_points']), intval($integral['custom_points']), sprintf($_LANG['order_gift_integral'], $order['order_sn'])); error_log('6',3,'flow.log'); /* 发放红包 */ send_order_bonus($order['order_id']); } } } } } /* 清空购物车 */ clear_cart($flow_type); error_log('7',3,'flow.log'); /* 清除缓存,否则买了商品,但是前台页面读取缓存,商品数量不减少 */ clear_all_files(); /* 插入支付日志 */ //$order['log_id'] = insert_pay_log($new_order_id, $order['order_amount'], PAY_ORDER); error_log('8',3,'flow.log'); /*取得支付代码 #取得支付信息,生成支付代码 if ($order['order_amount'] > 0) { $payment = payment_info($order['pay_id']); include_once('includes/modules/payment/' . $payment['pay_code'] . '.php'); $pay_obj = new $payment['pay_code']; $pay_online = $pay_obj->get_code($order, unserialize_config($payment['pay_config'])); $order['pay_desc'] = $payment['pay_desc']; $smarty->assign('pay_online', $pay_online); } */ if(!empty($order['shipping_name'])) { $order['shipping_name']=trim(stripcslashes($order['shipping_name'])); } error_log('9',3,'flow.log'); /* #订单信息 $smarty->assign('order', $order); $smarty->assign('total', $total); $smarty->assign('goods_list', $cart_goods); $smarty->assign('order_submit_back', sprintf($_LANG['order_submit_back'], $_LANG['back_home'], $_LANG['goto_user_center'])); // 返回提示 */ //user_uc_call('add_feed', array($order['order_id'], BUY_GOODS)); //推送feed到uc unset($_SESSION['flow_consignee']); // 清除session中保存的收货人信息 unset($_SESSION['flow_order']); unset($_SESSION['direct_shopping']); $order_done = array('order'=>$order,'total'=>$total,'cart_goods'=>$cart_goods); //var_dump($order_done);exit; error_log('10',3,'flow.log'); $order_id = $order['order_id']; $price = $order['order_amount']; $order = array ('order_id'=>$order_id,'order_number'=>$order['order_sn'],'price'=>$price) ; error_log('11',3,'flow.log'); //print_r($order);die; jsonExit($order); }