Example #1
0
/**
 * 获得订单中的费用信息
 *
 * @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;
}
Example #2
0
function flow_available_points()
{
    $sql = "SELECT SUM(g.integral * c.goods_number) " . "FROM " . $GLOBALS['ecs']->table('cart') . " AS c, " . $GLOBALS['ecs']->table('goods') . " AS g " . "WHERE c.session_id = '" . SESS_ID . "' AND c.goods_id = g.goods_id AND c.is_gift = 0 AND g.integral > 0 " . "AND c.rec_type = '" . CART_GENERAL_GOODS . "'";
    $val = intval($GLOBALS['db']->getOne($sql));
    return integral_of_value($val);
}
Example #3
0
                     /* 检查余额是否足够 */
                     $order['surplus'] = round(floatval($_POST['surplus']), 2);
                     if ($old_order['surplus'] + $user['user_money'] + $user['credit_line'] < $order['surplus']) {
                         sys_msg($_LANG['user_money_not_enough']);
                     }
                     /* 如果红包和积分和余额足以支付,把待付款金额改为0,退回部分积分余额 */
                     $order['order_amount'] -= $order['surplus'];
                     if ($order['order_amount'] < 0) {
                         $order['surplus'] += $order['order_amount'];
                         $order['order_amount'] = 0;
                     }
                 }
             } else {
                 /* 如果红包和积分足以支付,把待付款金额改为0,退回部分积分 */
                 $order['integral_money'] += $order['order_amount'];
                 $order['integral'] = integral_of_value($order['integral_money']);
                 $order['order_amount'] = 0;
             }
         } else {
             /* 如果红包足以支付,把待付款金额设为0 */
             $order['order_amount'] = 0;
         }
     }
 }
 update_order($order_id, $order);
 /* 更新 pay_log */
 update_pay_log($order_id);
 /* todo 记录日志 */
 $sn = $old_order['order_sn'];
 $new_order = order_info($order_id);
 if ($old_order['total_fee'] != $new_order['total_fee']) {
Example #4
0
 /**
  * 获得订单中的费用信息
  *
  * @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'] = '';
     }
     $total = array('real_goods_count' => 0, 'gift_amount' => 0, 'goods_price' => 0, 'market_price' => 0, 'discount' => 0, 'shipping_fee' => 0, 'shipping_insure' => 0, 'integral_money' => 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);
     $discount = model('Order')->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;
         $invoice_type = C('invoice_type');
         foreach ($invoice_type['type'] as $key => $type) {
             if ($type == $order['inv_type']) {
                 $rate = floatval($invoice_type['rate'][$key]) / 100;
                 break;
             }
         }
         if ($rate > 0) {
             $total['tax'] = $rate * $total['goods_price'];
         }
     }
     $total['tax_formated'] = price_format($total['tax'], 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 = model('Shipping')->shipping_area_info($order['shipping_id'], $region);
         if (!empty($shipping_info)) {
             $weight_price = model('Order')->cart_weight_price();
             // 查看购物车中是否全为免运费商品,若是则把运费赋为零
             $sql = 'SELECT count(*) as count FROM ' . $this->pre . "cart WHERE  `session_id` = '" . SESS_ID . "' AND `is_shipping` = 0";
             $res = $this->row($sql);
             $shipping_count = $res['count'];
             $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);
     // 积分最多能支付的金额为商品总额
     $max_amount = $total['goods_price'];
     $total['amount'] = $total['goods_price'] - $total['discount'] + $total['tax'] + $total['shipping_fee'] + $total['shipping_insure'] + $total['cod_fee'];
     /* 余额 */
     $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'] == 'exchange_goods') {
         $total['will_get_integral'] = 0;
     } else {
         $total['will_get_integral'] = model('Order')->get_give_integral($goods);
     }
     $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) ' . 'as sum FROM ' . $this->pre . 'cart AS c,' . $this->pre . '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';
         $res = $this->row($sql);
         $exchange_integral = $res['sum'];
         $total['exchange_integral'] = $exchange_integral;
     }
     return $total;
 }
Example #5
0
/**
 * 获得订单中的费用信息
 *
 * @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;
}
Example #6
0
/**
 * 获得用户的可用积分
 *
 * @access  private
 * @return  integral
 */
function flow_available_points()
{
    /* 代码修改_start  By  www.68ecshop.com  将这块替换掉*/
    $sql_where = $_SESSION['user_id'] > 0 ? "c.user_id='" . $_SESSION['user_id'] . "' " : "c.session_id = '" . SESS_ID . "' AND c.user_id=0 ";
    $sql = "SELECT SUM(g.integral * c.goods_number) as integral,g.supplier_id " . "FROM " . $GLOBALS['ecs']->table('cart') . " AS c, " . $GLOBALS['ecs']->table('goods') . " AS g " . "WHERE {$sql_where} AND c.goods_id = g.goods_id AND c.is_gift = 0 AND g.integral > 0 " . "AND c.rec_type = '" . CART_GENERAL_GOODS . "' GROUP BY g.supplier_id";
    /* 代码修改_end  By  www.68ecshop.com */
    $info = $GLOBALS['db']->getAll($sql);
    $ret = array();
    foreach ($info as $key => $val) {
        $ret[$val['supplier_id']] = integral_of_value(intval($val['integral']));
    }
    return $ret;
}
Example #7
0
 /**
  * 获得用户的可用积分
  *
  * @access private
  * @return integral
  */
 function flow_available_points()
 {
     $sql = "SELECT SUM(g.integral * c.goods_number) as sum " . "FROM " . $this->pre . "cart AS c, " . $this->pre . "goods AS g " . "WHERE c.session_id = '" . SESS_ID . "' AND c.goods_id = g.goods_id AND c.is_gift = 0 AND g.integral > 0 " . "AND c.rec_type = '" . CART_GENERAL_GOODS . "'";
     $res = $this->row($sql);
     $val = intval($res['sum']);
     return integral_of_value($val);
 }
Example #8
0
/**
 * 获得订单中的费用信息
 *
 * @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)
{
    //echo "<pre>";print_r($consignee);echo "</pre>";exit;
    $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']++;
        }
        /*K金的兑礼不计入总费用 bisc*/
        if ($val['is_integral'] == 1) {
            if ($val['cat_id'] != 4) {
                $total['gifts_integral'] += $val['integral'] * $val['goods_number'];
            } else {
                $total['goods_integral'] += $val['goods_price'] * $val['goods_number'];
            }
        } else {
            $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);
    /* 折扣$NowDiscount */
    $discount = compute_discount();
    $total['discount'] = $discount['discount'];
    $total['discount_formated'] = price_format($total['discount'], 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);
    /* 配送费用 */
    $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)) {
            $weight_price = cart_weight_price();
            if ($consignee['province'] == '502') {
                $sql = "select shipping_fee from ecs_shipping_fee where locate(address,'" . $consignee['address'] . "') >0 ";
                $fee = $GLOBALS['db']->getOne($sql);
                $total['shipping_fee'] = $fee ? $fee : shipping_fee($shipping_info['shipping_code'], $shipping_info['configure'], $weight_price['weight'], $total['goods_price']);
            } else {
                $total['shipping_fee'] = shipping_fee($shipping_info['shipping_code'], $shipping_info['configure'], $weight_price['weight'], $total['goods_price']);
            }
        }
    }
    $total['shipping_fee_formated'] = price_format($total['shipping_fee'], false);
    $total['shipping_insure_formated'] = price_format($total['shipping_insure'], false);
    // 红包和积分最多能支付的金额为商品总额
    $max_amount = $total['goods_price'];
    /*储值卡金额*/
    if (!empty($order['surplus'])) {
        $total['surplus'] = $order['surplus'];
    }
    $total['surplus_formated'] = price_format($total['surplus'], false);
    /* 计算订单总额 */
    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);
        // 实际减去的红包金额
        $total['bonus'] = $use_bonus;
        $total['bonus_formated'] = price_format($total['bonus'], false);
        $total['amount'] -= $use_bonus;
        // 还需要支付的订单金额
        $max_amount -= $use_bonus;
        // 积分最多还能支付的金额
        //减去储值卡金额
        $total['amount'] -= $order['surplus'];
    }
    /* 积分 */
    $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['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;
    /* 支付费用 */
    if (!empty($order['pay_id'])) {
        $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'];
    } else {
        $total['will_get_integral'] = get_give_integral($goods);
    }
    $total['will_get_bonus'] = 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);
    return $total;
}