Ejemplo n.º 1
0
/**
 * 获得购物车中的商品
 *
 * @access  public
 * @return  array
 */
function get_cart_goods()
{
    /* 初始化 */
    $goods_list = array();
    $total = array('goods_price' => 0, 'market_price' => 0, 'saving' => 0, 'save_rate' => 0, 'goods_amount' => 0);
    /* 循环、统计 */
    $sql = "SELECT *, IF(parent_id, parent_id, goods_id) AS pid " . " FROM " . $GLOBALS['ecs']->table('cart') . " " . " WHERE " . get_cart_cond() . " AND rec_type = '" . CART_GENERAL_GOODS . "'" . " ORDER BY pid, parent_id";
    $res = $GLOBALS['db']->query($sql);
    /* 用于统计购物车中实体商品和虚拟商品的个数 */
    $virtual_goods_count = 0;
    $real_goods_count = 0;
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        $total['goods_price'] += $row['goods_price'] * $row['goods_number'];
        $total['market_price'] += $row['market_price'] * $row['goods_number'];
        $total['total_number'] += $row['goods_number'];
        //by Leah
        $row['subtotal'] = price_format($row['goods_price'] * $row['goods_number'], false);
        $row['goods_price'] = price_format($row['goods_price'], false);
        $row['market_price'] = price_format($row['market_price'], false);
        $row['free_more_desc'] = get_free_more_desc($row['free_more']);
        /* 统计实体商品和虚拟商品的个数 */
        if ($row['is_real']) {
            $real_goods_count += $row['goods_number'];
        } else {
            $virtual_goods_count += $row['goods_number'];
        }
        /* 查询规格 */
        if (trim($row['goods_attr']) != '') {
            $row['goods_attr'] = addslashes($row['goods_attr']);
            $sql = "SELECT attr_value FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_attr_id " . db_create_in($row['goods_attr']);
            $attr_list = $GLOBALS['db']->getCol($sql);
            foreach ($attr_list as $attr) {
                $row['goods_name'] .= ' [' . $attr . '] ';
            }
        }
        /* 增加是否在购物车里显示商品图 */
        if (($GLOBALS['_CFG']['show_goods_in_cart'] == "2" || $GLOBALS['_CFG']['show_goods_in_cart'] == "3") && $row['extension_code'] != 'package_buy') {
            $goods_thumb = $GLOBALS['db']->getOne("SELECT `goods_thumb` FROM " . $GLOBALS['ecs']->table('goods') . " WHERE `goods_id`='{$row['goods_id']}'");
            $row['goods_thumb'] = get_image_path($row['goods_id'], $goods_thumb, true);
        }
        if ($row['extension_code'] == 'package_buy') {
            $row['package_goods_list'] = get_package_goods($row['goods_id']);
        }
        $goods_list[] = $row;
    }
    $total['goods_amount'] = $total['goods_price'];
    $total['saving'] = price_format($total['market_price'] - $total['goods_price'], false);
    if ($total['market_price'] > 0) {
        $total['save_rate'] = $total['market_price'] ? round(($total['market_price'] - $total['goods_price']) * 100 / $total['market_price']) . '%' : 0;
    }
    $total['goods_price'] = price_format($total['goods_price'], false);
    $total['market_price'] = price_format($total['market_price'], false);
    $total['real_goods_count'] = $real_goods_count;
    $total['virtual_goods_count'] = $virtual_goods_count;
    return array('goods_list' => $goods_list, 'total' => $total);
}
Ejemplo n.º 2
0
         $filename = ROOT_PATH . 'plugins/' . $row['extension_code'] . '/languages/common_' . $_CFG['lang'] . '.php';
         if (file_exists($filename)) {
             include_once $filename;
             if (!empty($_LANG[$row['extension_code'] . '_link'])) {
                 $row['goods_name'] = $row['goods_name'] . sprintf($_LANG[$row['extension_code'] . '_link'], $row['goods_id'], $order['order_sn']);
             }
         }
     }
     $row['formated_subtotal'] = price_format($row['goods_price'] * $row['goods_number']);
     $row['formated_goods_price'] = price_format($row['goods_price']);
     $_goods_thumb = get_image_path($row['goods_id'], $row['goods_thumb'], true);
     $_goods_thumb = strpos($_goods_thumb, 'http://') === 0 ? $_goods_thumb : $ecs->url() . $_goods_thumb;
     $row['goods_thumb'] = $_goods_thumb;
     $goods_attr[] = explode(' ', trim($row['goods_attr']));
     //将商品属性拆分为一个数组
     $row['free_more_desc'] = get_free_more_desc($row['free_more']);
     $goods_list[] = $row;
 }
 $attr = array();
 $arr = array();
 foreach ($goods_attr as $index => $array_val) {
     foreach ($array_val as $value) {
         $arr = explode(':', $value);
         //以 : 号将属性拆开
         $attr[$index][] = @array('name' => $arr[0], 'value' => $arr[1]);
     }
 }
 $smarty->assign('goods_attr', $attr);
 $smarty->assign('goods_list', $goods_list);
 $str = $smarty->fetch('order_goods_info.htm');
 $goods[] = array('order_id' => $order_id, 'str' => $str);
Ejemplo n.º 3
0
/**
 * 获得指定分类下的商品
 *
 * @access  public
 * @param   integer     $cat_id     分类ID
 * @param   integer     $num        数量
 * @param   string      $from       来自web/wap的调用
 * @param   string      $order_rule 指定商品排序规则
 * @return  array
 */
function assign_cat_goods($cat_id, $num = 0, $from = 'web', $order_rule = '')
{
    $children = get_children($cat_id);
    $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.comments_number ,g.sales_volume,g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, g.free_more, g.amount_desc, g.promote_tag ' . "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ' . 'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') ';
    $order_rule = empty($order_rule) ? 'ORDER BY g.sort_order, g.goods_id DESC' : $order_rule;
    $sql .= $order_rule;
    if ($num > 0) {
        $sql .= ' LIMIT ' . $num;
    }
    $res = $GLOBALS['db']->getAll($sql);
    $goods = array();
    foreach ($res as $idx => $row) {
        if ($row['promote_price'] > 0) {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
            $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
        } else {
            $goods[$idx]['promote_price'] = '';
        }
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['brief'] = $row['goods_brief'];
        /* 折扣节省计算 by ecmoban start */
        if ($row['market_price'] > 0) {
            $discount_arr = get_discount($row['goods_id']);
            //函数get_discount参数goods_id
        }
        $goods[$idx]['zhekou'] = $discount_arr['discount'];
        //zhekou
        $goods[$idx]['jiesheng'] = $discount_arr['jiesheng'];
        //jiesheng
        /* 折扣节省计算 by ecmoban end */
        $goods[$idx]['comments_number'] = $row['comments_number'];
        $goods[$idx]['sales_volume'] = $row['sales_volume'];
        $goods[$idx]['market_price'] = price_format($row['market_price']);
        $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        $goods[$idx]['shop_price'] = price_format($row['shop_price']);
        $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
        $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
        $goods[$idx]['free_more'] = $row['free_more'];
        $goods[$idx]['free_more_desc'] = get_free_more_desc($row['free_more']);
        $goods[$idx]['amount_desc'] = $row['amount_desc'];
        $goods[$idx]['promote_tag'] = $row['promote_tag'];
    }
    if ($from == 'web') {
        $goods['id'] = $cat_id;
        $GLOBALS['smarty']->assign('cat_goods_' . $cat_id, $goods);
    } elseif ($from == 'wap') {
        $cat['goods'] = $goods;
    }
    /* 分类信息 */
    $sql = 'SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '{$cat_id}'";
    $cat['name'] = $GLOBALS['db']->getOne($sql);
    $cat['url'] = build_uri('category', array('cid' => $cat_id), $cat['name']);
    $cat['id'] = $cat_id;
    /* 获取分类下品牌 */
    $sql = "SELECT b.brand_id, b.brand_name, brand_logo , COUNT(*) AS goods_num " . "FROM " . $GLOBALS['ecs']->table('brand') . "AS b, " . $GLOBALS['ecs']->table('goods') . " AS g LEFT JOIN " . $GLOBALS['ecs']->table('goods_cat') . " AS gc ON g.goods_id = gc.goods_id " . "WHERE g.brand_id = b.brand_id AND ({$children} OR " . 'gc.cat_id ' . db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list($cat_id, 0, false))))) . ") AND b.is_show = 1 " . " AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " . "GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY b.sort_order, b.brand_id ASC LIMIT 10";
    $brands = $GLOBALS['db']->getAll($sql);
    foreach ($brands as $key => $val) {
        $brands[$key]['brand_name'] = $val['brand_name'];
        $brands[$key]['url'] = build_uri('brand', array('bid' => $val['brand_id'], 'price_min' => $price_min, 'price_max' => $price_max, 'filter_attr' => $filter_attr_str), $val['brand_name']);
        $brands[$key]['logo'] = 'data/brandlogo/' . $val['brand_logo'];
        /* 判断品牌是否被选中 */
        if ($brand == $brands[$key]['brand_id']) {
            $brands[$key]['selected'] = 1;
        } else {
            $brands[$key]['selected'] = 0;
        }
    }
    $cat['brands'] = $brands;
    $cat['cat_clild'] = get_clild_list($cat_id);
    return $cat;
}
Ejemplo n.º 4
0
/**
 * 获取指定用户可取货的订单列表
 *
 * @param array $pids
 */
function get_pickup_orders($pids)
{
    global $ecs, $db;
    $sql = "SELECT o.order_id, o.order_sn, o.mobile, o.pay_time, og.goods_id, og.goods_sn, og.goods_name, og.goods_number, og.free_more " . " FROM " . $ecs->table('order_info', 'o') . "," . $ecs->table('order_goods', 'og') . " WHERE o.order_id = og.order_id AND o.package_id IN (" . implode(',', $pids) . ")" . " ORDER BY o.order_id";
    $rs = $db->getAll($sql);
    $orders = array();
    $order_id = 0;
    foreach ($rs as $g) {
        if ($order_id != $g['order_id']) {
            $orders[] = array('order_id' => $g['order_id'], 'order_sn' => $g['order_sn'], 'mobile' => $g['mobile'], 'pay_time' => date('Y-m-d H:i', $g['pay_time']), 'goods' => array());
            $order_id = $g['order_id'];
        }
        unset($g['order_id']);
        unset($g['order_sn']);
        unset($g['pay_time']);
        $g['free_more_desc'] = get_free_more_desc($g['free_more']);
        $orders[count($orders) - 1]['goods'][] = $g;
    }
    return $orders;
}
Ejemplo n.º 5
0
/**
 * 获得指定分类下的商品
 *
 * @access  public
 * @param   integer     $cat_id     分类ID
 * @param   integer     $num        数量
 * @param   string      $from       来自web/wap的调用
 * @param   string      $order_rule 指定商品排序规则
 * @return  array
 */
function assign_cat_goods($cat_id, $num = 0, $from = 'web', $order_rule = '')
{
    $children = get_children($cat_id);
    $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, g.goods_number, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, g.free_more, g.amount_desc, g.promote_tag ' . "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ' . 'g.is_delete = 0 AND (' . $children . 'OR ' . get_extension_goods($children) . ') ';
    $order_rule = empty($order_rule) ? 'ORDER BY g.sort_order, g.goods_id DESC' : $order_rule;
    $sql .= $order_rule;
    if ($num > 0) {
        $sql .= ' LIMIT ' . $num;
    }
    $res = $GLOBALS['db']->getAll($sql);
    $goods = array();
    foreach ($res as $idx => $row) {
        if ($row['promote_price'] > 0) {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
            $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
        } else {
            $goods[$idx]['promote_price'] = '';
        }
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['brief'] = $row['goods_brief'];
        $goods[$idx]['goods_number'] = $row['goods_number'];
        $goods[$idx]['market_price'] = price_format($row['market_price']);
        $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        $goods[$idx]['shop_price'] = price_format($row['shop_price']);
        $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
        $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
        $goods[$idx]['free_more'] = $row['free_more'];
        $goods[$idx]['free_more_desc'] = get_free_more_desc($row['free_more']);
        $goods[$idx]['amount_desc'] = $row['amount_desc'];
        $goods[$idx]['promote_tag'] = $row['promote_tag'];
    }
    if ($from == 'web') {
        $GLOBALS['smarty']->assign('cat_goods_' . $cat_id, $goods);
    } elseif ($from == 'wap') {
        $cat['goods'] = $goods;
    }
    /* 分类信息 */
    $sql = 'SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '{$cat_id}'";
    $cat['name'] = $GLOBALS['db']->getOne($sql);
    $cat['url'] = build_uri('category', array('cid' => $cat_id), $cat['name']);
    $cat['id'] = $cat_id;
    $cat['cat_id'] = get_child_tree($cat_id);
    //增加子类别调用 by Bragg
    return $cat;
}