/** * 获得订单中的费用信息 * * @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, 'coupons' => 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 = 0; //compute_discount(); $total['discount'] = $discount['discount']; if ($total['discount'] > $total['goods_price']) { $total['discount'] = $total['goods_price']; } } $total['discount'] = empty($total['discount']) ? 0 : $total['discount']; $total['discount'] += packageBuyDiscountMoney($goods); $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['coupons_id'])) { $coupons = coupons_info($order['coupons_id']); $total['coupons'] = $coupons['coupon_value']; } $total['coupons_formated'] = price_format($total['bonus'], 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(); } // 查看购物车中是否全为免运费商品,若是则把运费赋为零 $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE `session_id` = '" . SESS_ID . "' AND `extension_code` != 'package_buy' AND `is_shipping` = 0"; $shipping_count = 1; //$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); // 购物车中的商品能享受红包支付的总额 $coupon_amount = 0; //compute_discount_amount(); // 红包和积分最多能支付的金额为商品总额 $max_amount = $total['goods_price'] == 0 ? $total['goods_price'] : $total['goods_price'] - $coupon_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']; // 减去购物券金额 $total['coupons_formated'] = price_format($total['coupons'], false); $total['amount'] -= $total['coupons']; // 还需要支付的订单金额 } /* 余额 */ $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); } if ($order['extension_code'] == 'exchange_goods' || $order['extension_code'] == 'vip_goods') { $total['amount'] = 0; $total['pay_fee'] = 0; foreach ($goods as $good) { $total['pay_fee'] += $good['goods_number'] * $good['needed_money']; } $total['pay_fee'] += $total['shipping_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' || $order['extension_code'] == 'vip_goods') { $total['will_get_integral'] = 0; } else { $total['will_get_integral'] = get_give_integral($goods); } $total['will_get_bonus'] = $order['extension_code'] == 'exchange_goods' || $order['extension_code'] == 'vip_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 * c.goods_number) ' . '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; $sql = 'SELECT SUM(c.needed_money * c.goods_number) ' . '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'; $needed_money = $GLOBALS['db']->getOne($sql); $total['needed_money'] = $needed_money; } else { if ($order['extension_code'] == 'vip_goods') { $sql = 'SELECT (vmp.user_integral * c.goods_number) ' . 'FROM ' . $GLOBALS['ecs']->table('cart') . ' AS c,' . $GLOBALS['ecs']->table('vip_member_price') . 'AS vmp ' . "WHERE c.goods_id = vmp.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 AND c.needed_money = vmp.user_price ' . 'GROUP BY vmp.goods_id'; $exchange_integral = $GLOBALS['db']->getOne($sql); $total['exchange_integral'] = $exchange_integral; $sql = 'SELECT (c.needed_money * c.goods_number) ' . 'FROM ' . $GLOBALS['ecs']->table('cart') . ' AS c,' . $GLOBALS['ecs']->table('vip_member_price') . 'AS vmp ' . "WHERE c.goods_id = vmp.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 AND c.needed_money = vmp.user_price ' . 'GROUP BY vmp.goods_id'; $needed_money = $GLOBALS['db']->getOne($sql); $total['needed_money'] = $needed_money; } } return $total; }
} if ($captcha & CAPTCHA_REGISTER) { $smarty->assign('enabled_register_captcha', 1); $smarty->assign('rand', mt_rand()); } /* 如果是一步购物,跳到结算中心 */ /*if ($_CFG['one_step_buy'] == '1') { ecs_header("Location: flow.php?step=checkout\n"); exit; }*/ $buyType == ($_REQUEST['buyType'] == 'buy_now') ? 'buy_now' : ''; /* 取得商品列表,计算合计 */ $cart_goods = get_cart_goods($buyType); /******套餐购的折扣*******/ $packageBuyDiscountMoney = price_format(packageBuyDiscountMoney($cart_goods['goods_list'])); $smarty->assign('packageBuyDiscountMoney', $packageBuyDiscountMoney); $getPackageBuyDiscount = intval(10 * getPackageBuyDiscount()); $smarty->assign('packageBuyDiscount', $getPackageBuyDiscount); /******活动的折扣*******/ $smarty->assign('goods_list', $cart_goods['goods_list']); $smarty->assign('total', $cart_goods['total']); $smarty->assign('total_goods_price', $cart_goods['total']['goods_price']); $smarty->assign('total_saving', $cart_goods['total']['saving']); //购物车的描述的格式化 $smarty->assign('shopping_money', sprintf($_LANG['shopping_money'], $cart_goods['total']['goods_price'])); $smarty->assign('market_price_desc', sprintf($_LANG['than_market_price'], $cart_goods['total']['market_price'], $cart_goods['total']['saving'], $cart_goods['total']['save_rate'])); // 显示收藏夹内的商品 if ($_SESSION['user_id'] > 0) { require_once ROOT_PATH . 'includes/lib_clips.php'; $collection_goods = get_collection_goods($_SESSION['user_id']);