示例#1
0
/**
* 获得cat_id精品列表。
*
* @access  private
* @param   integer
* @return  array
*/
function index_get_cat_id_goods_best_list($cat_id, $num)
{
    $sql = 'Select g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price, g.promote_price, ' . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, " . "g.is_best, g.is_new, g.is_hot, g.is_promote " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "Where g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.is_best = 1 AND (" . $cat_id . " OR " . get_extension_goods($cat_id) . ")";
    $cats = get_children($cat_id);
    $where = !empty($cats) ? "AND ({$cats} OR " . get_extension_goods($cats) . ") " : '';
    $sql .= $where . " LIMIT {$num}";
    $res = $GLOBALS['db']->getAll($sql);
    $goods = array();
    foreach ($res as $idx => $row) {
        $goods[$idx]['id'] = $row['article_id'];
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['brief'] = $row['goods_brief'];
        $goods[$idx]['brand_name'] = $row['brand_name'];
        $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']);
        $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]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
        $goods[$idx]['market_price'] = price_format($row['market_price']);
        $goods[$idx]['shop_price'] = price_format($row['shop_price']);
        $goods[$idx]['thumb'] = empty($row['goods_thumb']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_thumb'];
        $goods[$idx]['goods_img'] = empty($row['goods_img']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_img'];
        $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
    }
    return $goods;
}
示例#2
0
function gz_get_category_recommend_goods($type = '', $cats = '', $brand = 0, $min = 0, $max = 0, $ext = '')
{
    $brand_where = $brand > 0 ? " AND g.brand_id = '{$brand}'" : '';
    $price_where = $min > 0 ? " AND g.shop_price >= {$min} " : '';
    $price_where .= $max > 0 ? " AND g.shop_price <= {$max} " : '';
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, g.original_img, b.brand_name ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . "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 ' . $brand_where . $price_where . $ext;
    $num = 0;
    $type2lib = array('best' => 'recommend_best', 'new' => 'recommend_new', 'hot' => 'recommend_hot', 'promote' => 'recommend_promotion');
    $num = get_library_number($type2lib[$type]);
    switch ($type) {
        case 'best':
            $sql .= ' AND is_best = 1';
            break;
        case 'new':
            $sql .= ' AND is_new = 1';
            break;
        case 'hot':
            $sql .= ' AND is_hot = 1';
            break;
        case 'promote':
            $time = gmtime();
            $sql .= " AND is_promote = 1 AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}'";
            break;
    }
    if (!empty($cats)) {
        $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) . ")";
    }
    $order_type = $GLOBALS['_CFG']['recommend_order'];
    $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()';
    $res = $GLOBALS['db']->selectLimit($sql, $num);
    $idx = 0;
    $goods = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        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]['brand_name'] = $row['brand_name'];
        $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]['market_price'] = price_format($row['market_price']);
        $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]['original_img'] = get_image_path($row['goods_id'], $row['original_img']);
        $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
        $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
        $idx++;
    }
    return $goods;
}
示例#3
0
文件: lib_main.php 项目: qgz/ecshop
/**
 * 获得分类下的商品
 *
 * @access  public
 * @param   string  $children
 * @return  array
 */
function get_cat_goods($cat = '', $size = 0, $brand = 0, $min = 0, $max = 0, $ext = '', $sort = '', $order = '')
{
    $children = get_children($cat);
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND " . "g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')';
    if ($brand > 0) {
        $where .= "AND g.brand_id={$brand} ";
    }
    if ($min > 0) {
        $where .= " AND g.shop_price >= {$min} ";
    }
    if ($max > 0) {
        $where .= " AND g.shop_price <= {$max} ";
    }
    /* 获得商品列表 */
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, g.goods_type, " . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . '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 {$where} {$ext} ORDER BY {$sort} {$order} g.sort_order, g.last_update DESC";
    $res = $GLOBALS['db']->selectLimit($sql, $size);
    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        if ($row['promote_price'] > 0) {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
        } else {
            $promote_price = 0;
        }
        /* 处理商品水印图片 */
        $watermark_img = '';
        if ($promote_price != 0) {
            $watermark_img = "watermark_promote_small";
        } elseif ($row['is_new'] != 0) {
            $watermark_img = "watermark_new_small";
        } elseif ($row['is_best'] != 0) {
            $watermark_img = "watermark_best_small";
        } elseif ($row['is_hot'] != 0) {
            $watermark_img = 'watermark_hot_small';
        }
        if ($watermark_img != '') {
            $arr[$row['goods_id']]['watermark_img'] = $watermark_img;
        }
        $arr[$row['goods_id']]['id'] = $row['goods_id'];
        $arr[$row['goods_id']]['name'] = $row['goods_name'];
        $arr[$row['goods_id']]['brief'] = $row['goods_brief'];
        $arr[$row['goods_id']]['style_name'] = add_style($row['goods_name'], $row['goods_name_style']);
        $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
        $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
        $arr[$row['goods_id']]['type'] = $row['goods_type'];
        $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
        $arr[$row['goods_id']]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $arr[$row['goods_id']]['img'] = get_image_path($row['goods_id'], $row['goods_img']);
        $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
        $arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        $arr[$row['goods_id']]['short_style_name'] = add_style($arr[$row['goods_id']]['short_name'], $row['goods_name_style']);
    }
    return $arr;
}
示例#4
0
     $price_grade *= 10;
 }
 //跨度
 $dx = ceil(($row['max'] - $row['min']) / $cat['grade'] / $price_grade) * $price_grade;
 if ($dx == 0) {
     $dx = $price_grade;
 }
 for ($i = 1; $row['min'] > $dx * $i; $i++) {
 }
 for ($j = 1; $row['min'] > $dx * ($i - 1) + $price_grade * $j; $j++) {
 }
 $row['min'] = $dx * ($i - 1) + $price_grade * ($j - 1);
 for (; $row['max'] >= $dx * $i; $i++) {
 }
 $row['max'] = $dx * $i + $price_grade * ($j - 1);
 $sql = "SELECT (FLOOR((g.shop_price - {$row['min']}) / {$dx})) AS sn, COUNT(*) AS goods_num  " . " FROM " . $ecs->table('goods') . " AS g " . " WHERE ({$children} OR " . get_extension_goods($children) . ') AND g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 ' . " GROUP BY sn ";
 $price_grade = $db->getAll($sql);
 foreach ($price_grade as $key => $val) {
     $temp_key = $key + 1;
     $price_grade[$temp_key]['goods_num'] = $val['goods_num'];
     $price_grade[$temp_key]['start'] = $row['min'] + round($dx * $val['sn']);
     $price_grade[$temp_key]['end'] = $row['min'] + round($dx * ($val['sn'] + 1));
     $price_grade[$temp_key]['price_range'] = $price_grade[$temp_key]['start'] . '&nbsp;-&nbsp;' . $price_grade[$temp_key]['end'];
     $price_grade[$temp_key]['formated_start'] = price_format($price_grade[$temp_key]['start']);
     $price_grade[$temp_key]['formated_end'] = price_format($price_grade[$temp_key]['end']);
     $price_grade[$temp_key]['url'] = build_uri('category', array('cid' => $cat_id, 'bid' => $brand, 'price_min' => $price_grade[$temp_key]['start'], 'price_max' => $price_grade[$temp_key]['end'], 'filter_attr' => $filter_attr_str), $cat['cat_name']);
     /* 判断价格区间是否被选中 */
     if (isset($_REQUEST['price_min']) && $price_grade[$temp_key]['start'] == $price_min && $price_grade[$temp_key]['end'] == $price_max) {
         $price_grade[$temp_key]['selected'] = 1;
     } else {
         $price_grade[$temp_key]['selected'] = 0;
示例#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 = '')
{
    $sql = 'SELECT sort_order FROM ' . $GLOBALS['ecs']->table('template') . " WHERE filename = 'index' AND type = 1 AND remarks ='' AND id = {$cat_id} ";
    $sort_order = $GLOBALS['db']->getOne($sql);
    $cat['sort_order'] = $sort_order;
    $children = get_children($cat_id);
    $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, 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 ' . "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]['market_price'] = intval(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']);
    }
    $cat['goods_level2'] = $goods;
    //print_r($goods);exit;
    if ($from == 'web') {
        $GLOBALS['smarty']->assign('cat_goods_' . $cat_id, $goods);
    } elseif ($from == 'wap') {
        $cat['goods'] = $goods;
    }
    /* 分类信息 */
    $sql = 'SELECT cat_name,cat_desc,is_standalone FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = {$cat_id}";
    $theRow = $GLOBALS['db']->getRow($sql);
    $cat['name'] = $theRow['cat_name'];
    $cat['des'] = $theRow['cat_desc'];
    $cat['id'] = $cat_id;
    $cat['cat_clild'] = get_clild_list($cat_id);
    $cat['isalone'] = $theRow['is_standalone'];
    if ($cat['isalone'] == 0) {
        $cat['url'] = build_uri('category', array('cid' => $cat_id, 'isalone' => $cat['isalone']), $cat['name']);
    } else {
        $cat['url'] = build_uri('category', array('cid' => $cat_id, 'isalone' => $cat['isalone']), $cat['name']);
    }
    //获取二级分类下的商品
    /*$cat_list_arr  = cat_list($cat_id, 0 , false);
    
    	foreach($cat_list_arr as $key=>$value)
    	{
    		if($value['level'] == 1)
    		{
    			 $sql = 'SELECT g.goods_id,g.cat_id, g.goods_name, g.market_price, 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 '.
    					'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 is_delete = 0 AND ' . get_children($value['cat_id']) . ' ORDER BY g.sort_order, g.goods_id DESC';
    			
    			if ($num > 0)
    			{
    				$sql .= ' LIMIT ' . $num;
    			}
    			
    						
    			 $goods_res = $GLOBALS['db']->getAll($sql);
    			 foreach($goods_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_res[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
    					}
    					else
    					{
    						$goods_res[$idx]['promote_price'] = '';
    					}
    					$goods_res[$idx]['market_price']  = $row['market_price'];
    					$goods_res[$idx]['shop_price']    = price_format($row['shop_price'],false);
    					$goods_res[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price,false) : '';
    					$goods_res[$idx]['shop_price']   = price_format($row['shop_price'],false);
    					$goods_res[$idx]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
    					$goods_res[$idx]['url']          = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
    					
    			 }
    			 $cat_list_arr[$key]['goods'] = $goods_res;
    		}
    		else
    		{
    			unset($cat_list_arr[$key]);
    		}
    	}
    	
    	$cat['goods_level2'] = $cat_list_arr;
    	// 获取分类下品牌
    
    	/*$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']), $val['brand_name']);
    		$brands[$key]['logo'] = 'data/brandlogo/'.$val['brand_logo'];
    	}			
    	$cat['brands'] = $brands;*/
    //print_r($cat);exit;
    //$cat['goods_level2'] = $cat_list_arr;
    return $cat;
}
示例#6
0
/**
 * 获得分类下的商品总数
 *
 * @access  public
 * @param   string     $cat_id
 * @return  integer
 */
function get_cagtegory_goods_count($children, $brand = 0, $other_has, $min = 0, $max = 0, $ext = '')
{
    $filter = isset($_REQUEST['filter']) ? intval($_REQUEST['filter']) : 0;
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')';
    if ($filter == 1) {
        $where .= ' AND g.supplier_id=0 ';
    } elseif ($filter == 2) {
        $where .= ' AND g.supplier_id>0 ';
    } else {
    }
    if ($brand > 0) {
        $where .= " AND g.brand_id = {$brand} ";
    }
    if ($min >= 0 && $max > $min) {
        $where .= " AND (g.shop_price between {$min} AND {$max}) ";
    }
    //    if ($max > 0)
    //    {
    //        $where .= " AND g.shop_price <= $max ";
    //    }
    if ($other_has > 0) {
        switch ($other_has) {
            case 1:
                break;
            case 2:
                $where .= " AND g.supplier_id = 0 ";
                break;
            case 3:
                $where .= " AND g.supplier_id > 0 ";
                break;
        }
    }
    /* 返回商品总数 */
    return $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('goods') . " AS g WHERE {$where} {$ext}");
}
示例#7
0
function cat_get_goods($keywords, $children, $brand, $min, $max, $ext, $size, $page, $sort, $order)
{
    $display = $GLOBALS['display'];
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND " . "g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')';
    if ($keywords != '') {
        $where .= " AND g.goods_name LIKE '%{$keywords}%' ";
    }
    if ($brand > 0) {
        $where .= "AND g.brand_id={$brand} ";
    }
    if ($min > 0) {
        $where .= " AND g.shop_price >= {$min} ";
    }
    if ($max > 0) {
        $where .= " AND g.shop_price <= {$max} ";
    }
    /* 获得商品列表 */
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_sn, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, g.goods_type, " . '(select AVG(r.comment_rank) from ' . $GLOBALS['ecs']->table('comment') . ' as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_rank, ' . '(select IFNULL(sum(og.goods_number), 0) from ' . $GLOBALS['ecs']->table('order_goods') . ' as og where og.goods_id = g.goods_id) AS sell_number, ' . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img, click_count ' . '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 {$where} {$ext} ORDER BY {$sort} {$order}";
    $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        if ($row['promote_price'] > 0) {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
        } else {
            $promote_price = 0;
        }
        /* 处理商品水印图片 */
        $watermark_img = '';
        if ($promote_price != 0) {
            $watermark_img = "watermark_promote_small";
        } elseif ($row['is_new'] != 0) {
            $watermark_img = "watermark_new_small";
        } elseif ($row['is_best'] != 0) {
            $watermark_img = "watermark_best_small";
        } elseif ($row['is_hot'] != 0) {
            $watermark_img = 'watermark_hot_small';
        }
        if ($watermark_img != '') {
            $arr[$row['goods_id']]['watermark_img'] = $watermark_img;
        }
        $arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
        if ($display == 'grid') {
            $arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        }
        $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
        $arr[$row['goods_id']]['name'] = $row['goods_name'];
        $arr[$row['goods_id']]['goods_sn'] = $row['goods_sn'];
        $arr[$row['goods_id']]['comment_rank'] = $row['comment_rank'];
        $arr[$row['goods_id']]['sell_number'] = $row['sell_number'];
        $arr[$row['goods_id']]['is_new'] = $row['is_new'];
        $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
        $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']);
        $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
        $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
        $arr[$row['goods_id']]['type'] = $row['goods_type'];
        $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
        $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
        $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
    }
    return $arr;
}
示例#8
0
/**
 * 获得指定分类下的推荐商品
 *
 * @access  public
 * @param   string      $type       推荐类型,可以是 best, new, hot, promote
 * @param   string      $cats       分类的ID
 * @param   integer     $min        商品积分下限
 * @param   integer     $max        商品积分上限
 * @param   string      $ext        商品扩展查询
 * @return  array
 */
function get_exchange_recommend_goods($type = '', $cats = '', $min = 0, $max = 0, $ext = '')
{
    $price_where = $min > 0 ? " AND g.shop_price >= {$min} " : '';
    $price_where .= $max > 0 ? " AND g.shop_price <= {$max} " : '';
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, eg.exchange_integral, ' . 'g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' . 'FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = eg.goods_id ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . 'WHERE eg.is_exchange = 1 AND g.is_delete = 0 ' . $price_where . $ext;
    $num = 0;
    $type2lib = array('best' => 'exchange_best', 'new' => 'exchange_new', 'hot' => 'exchange_hot');
    $num = get_library_number($type2lib[$type], 'exchange_list');
    switch ($type) {
        case 'best':
            $sql .= ' AND eg.is_best = 1';
            break;
        case 'new':
            $sql .= ' AND eg.is_new = 1';
            break;
        case 'hot':
            $sql .= ' AND eg.is_hot = 1';
            break;
    }
    if (!empty($cats)) {
        $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) . ")";
    }
    $order_type = $GLOBALS['_CFG']['recommend_order'];
    $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()';
    $res = $GLOBALS['db']->selectLimit($sql, $num);
    $idx = 0;
    $goods = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['brief'] = $row['goods_brief'];
        $goods[$idx]['brand_name'] = $row['brand_name'];
        $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]['exchange_integral'] = $row['exchange_integral'];
        $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('exchange_goods', array('gid' => $row['goods_id']), $row['goods_name']);
        $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
        $idx++;
    }
    return $goods;
}
示例#9
0
/**
 * 获得指定分类下的推荐商品
 *
 * @access  public
 * @param   string      $type       推荐类型,可以是 best, new, hot, promote
 * @param   string      $cats       分类的ID
 * @param   integer     $min        商品积分下限
 * @param   integer     $max        商品积分上限
 * @param   string      $ext        商品扩展查询
 * @return  array
 */
function get_exchange_recommend_goods($type = '', $cats = '', $min = 0, $max = 0, $ext = '')
{
    $price_where = $min > 0 ? " AND g.shop_price >= {$min} " : '';
    $price_where .= $max > 0 ? " AND g.shop_price <= {$max} " : '';
    $sql = 'SELECT g.goods_id, g.goods_name, eg.needed_money,eg.begin_time, g.shop_price, g.goods_name_style, eg.exchange_integral, ' . 'g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' . 'FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = eg.goods_id ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . 'WHERE eg.is_exchange = 1 AND g.is_delete = 0 AND begin_time < ' . gmtime() . ' ' . $price_where . $ext;
    $num = 0;
    $type2lib = array('best' => 'exchange_best', 'new' => 'exchange_new', 'hot' => 'exchange_hot');
    $num = get_library_number($type2lib[$type], 'exchange_list');
    if (!empty($cats)) {
        $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) . ")";
    }
    switch ($type) {
        case 'best':
            $sql .= ' AND eg.is_best = 1 ORDER BY eg.exchange_integral DESC';
            break;
        case 'new':
            $sql .= ' AND eg.is_new = 1 ORDER BY eg.needed_money DESC';
            break;
        case 'hot':
            $sql .= ' AND eg.is_hot = 1';
            break;
    }
    $res = $GLOBALS['db']->selectLimit($sql, $num);
    $idx = 0;
    $goods = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['shop_price'] = price_format($row['shop_price']);
        $goods[$idx]['brief'] = $row['goods_brief'];
        $goods[$idx]['brand_name'] = $row['brand_name'];
        $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]['exchange_integral'] = $row['exchange_integral'];
        $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('exchange', array('act' => 'view', 'id' => $row['goods_id']));
        $goods[$idx]['needed_money'] = price_format($row['needed_money']);
        $goods[$idx]['begin_date'] = gmdate('m-d', $row['begin_time']);
        $goods[$idx]['begin_hour'] = gmdate('h:i', $row['begin_time']);
        $goods[$idx]['integral_integer'] = floor($row['shop_price'] - $row['needed_money']);
        $goods[$idx]['integral_decimal'] = end(explode('.', number_format($row['shop_price'] - $row['needed_money'], 1)));
        $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']);
        $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
        $idx++;
    }
    return $goods;
}
示例#10
0
/**
 * 获得分类下的商品总数
 *
 * @access  public
 * @param   string     $cat_id
 * @return  integer
 */
function get_cagtegory_goods_count($children, $brand = 0, $min = 0, $max = 0, $ext = '')
{
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')';
    if ($brand > 0) {
        $where .= " AND g.brand_id = {$brand} ";
    }
    if ($min > 0) {
        $where .= " AND g.shop_price >= {$min} ";
    }
    if ($max > 0) {
        $where .= " AND g.shop_price <= {$max} ";
    }
    /* 返回商品总数 */
    return $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('goods') . " AS g WHERE {$where} {$ext}");
}
示例#11
0
/**
* ���ò�Ʒ������������а�
*
* @access  public
* @param   string  $cats   ��ѯ�ķ���
* @return  array
*/
function get_pro_top10($cats)
{
    $where = !empty($cats) ? "AND (g.cat_id = {$cats} OR " . get_extension_goods($cats) . ") " : '';
    /* ����ͳ�Ƶ�ʱ�� */
    switch ($GLOBALS['_CFG']['top10_time']) {
        case 1:
            // һ��
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 365 * 86400) . "'";
            break;
        case 2:
            // ����
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 180 * 86400) . "'";
            break;
        case 3:
            // �����
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 90 * 86400) . "'";
            break;
        case 4:
            // һ����
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 30 * 86400) . "'";
            break;
        default:
            $top10_time = '';
    }
    $sql = 'SELECT g.goods_id, g.goods_name,g.goods_brief, g.shop_price, g.goods_thumb, SUM(og.goods_number) as goods_number ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g, ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' . "WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 {$where} {$top10_time} ";
    //�ж��Ƿ����ÿ�棬������Ƿ����0
    if ($GLOBALS['_CFG']['use_storage'] == 1) {
        $sql .= " AND g.goods_number > 0 ";
    }
    $sql .= ' AND og.order_id = o.order_id AND og.goods_id = g.goods_id ' . "AND o.order_status = '" . OS_CONFIRMED . "' " . "AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') " . "AND (o.shipping_status = '" . SS_SHIPPED . "' OR o.shipping_status = '" . SS_RECEIVED . "') " . 'GROUP BY g.goods_id ORDER BY goods_number DESC, g.goods_id DESC LIMIT ' . $GLOBALS['_CFG']['top_number'];
    $arr = $GLOBALS['db']->getAll($sql);
    for ($i = 0, $count = count($arr); $i < $count; $i++) {
        $arr[$i]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($arr[$i]['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr[$i]['goods_name'];
        $arr[$i]['url'] = build_uri('goods', array('gid' => $arr[$i]['goods_id']), $arr[$i]['goods_name']);
        $arr[$i]['thumb'] = get_image_path($arr[$i]['goods_id'], $arr[$i]['goods_thumb'], true);
        $arr[$i]['price'] = price_format($arr[$i]['shop_price']);
        $arr[$i]['goods_brief'] = $arr[$i]['goods_brief'];
    }
    return $arr;
}
示例#12
0
	public function  prices () {
		global $ecs,$db;
		$cat_id = isset($_REQUEST['id']) ? intval($_REQUEST['id'])  : 0;
	    if (!$cat_id)  {
	    	$result = rpcLang('category.php', 'goodslist_failure');
	        jsonExit("{\"status\":\"$result\"}");
	    }
		$cat = get_cat_info($cat_id);   // 获得分类的相关信息
		$children = get_children($cat_id);
		/* 获取价格分级 */
	    if ($cat['grade'] == 0  && $cat['parent_id'] != 0)
	    {
	        $cat['grade'] = get_parent_grade($cat_id); //如果当前分类级别为空,取最近的上级分类
	    }	
	    if ($cat['grade'] > 1)
	    {
	        /* 需要价格分级 */
	
	        /*
                                   算法思路:
                1、当分级大于1时,进行价格分级
                2、取出该类下商品价格的最大值、最小值
                3、根据商品价格的最大值来计算商品价格的分级数量级:
	                        价格范围(不含最大值) 分级数量级
	                         0-0.1                   0.001
	                        0.1-1                   0.01
	                        1-10                    0.1
	                        10-100                  1
	                        100-1000                10
	                        1000-10000              100
	            4、计算价格跨度:取整((最大值-最小值) / (价格分级数) / 数量级) * 数量级
	            5、根据价格跨度计算价格范围区间
	            6、查询数据库
	
	                      可能存在问题:
	            1、由于价格跨度是由最大值、最小值计算出来的
	                                 然后再通过价格跨度来确定显示时的价格范围区间
	                                 所以可能会存在价格分级数量不正确的问题
	                                 该问题没有证明
	            2、当价格=最大值时,分级会多出来,已被证明存在
	        */
			//获得当前分类下商品价格的最大值、最小值
	        $sql = "SELECT min(g.shop_price) AS min, max(g.shop_price) as max ".
	               " FROM " . $ecs->table('goods'). " AS g ".
	               " WHERE ($children OR " . get_extension_goods($children) . ') AND g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1  ';
	        $row = $db->getRow($sql);
	
	        // 取得价格分级最小单位级数,比如,千元商品最小以100为级数
	        $price_grade = 0.0001;
	        for($i=-2; $i<= log10($row['max']); $i++)
	        {
	            $price_grade *= 10;
	        }	
	        //跨度
	        $dx = ceil(($row['max'] - $row['min']) / ($cat['grade']) / $price_grade) * $price_grade;
	        if($dx == 0)
	        {
	            $dx = $price_grade;
	        }
	
	        for($i = 1; $row['min'] > $dx * $i; $i ++);
	
	        for($j = 1; $row['min'] > $dx * ($i-1) + $price_grade * $j; $j++);
	        $row['min'] = $dx * ($i-1) + $price_grade * ($j - 1);
	
	        for(; $row['max'] >= $dx * $i; $i ++);
	        $row['max'] = $dx * ($i) + $price_grade * ($j - 1);
	
	        $sql = "SELECT (FLOOR((g.shop_price - $row[min]) / $dx)) AS sn, COUNT(*) AS goods_num  ".
	               " FROM " . $ecs->table('goods') . " AS g ".
	               " WHERE ($children OR " . get_extension_goods($children) . ') AND g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 '.
	               " GROUP BY sn ";
	
	        $price_grade = $db->getAll($sql);
	        $price_arr = array();
	        foreach ($price_grade as $key=>$val)
	        {
	            $price_arr[$key]['goods_num'] = $val['goods_num'];
	            $price_arr[$key]['start'] = $row['min'] + round($dx * $val['sn']);
	            $price_arr[$key]['end'] = $row['min'] + round($dx * ($val['sn'] + 1));
	        }
	    } else {
	    	$result = rpcLang('category.php', 'prices_empty');
	        jsonExit("{\"status\":\"$result\"}");
	    }
	     jsonExit($price_arr);	
	}
示例#13
0
function get_hot_cat_goods($type = '', $cat_id, $num = 7)
{
    $children = get_children($cat_id);
    $sql = 'SELECT g.goods_id,g.cat_id, g.goods_name, g.market_price, 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 ' . "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';
    switch ($type) {
        case 'best':
            $sql .= ' AND is_best = 1';
            break;
        case 'new':
            $sql .= ' AND is_new = 1';
            break;
        case 'hot':
            $sql .= ' AND is_hot = 1';
            break;
        case 'promote':
            $time = gmtime();
            $sql .= " AND is_promote = 1 AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}'";
            break;
    }
    $sql .= ' AND (' . $children . 'OR ' . get_extension_goods($children) . ') ' . 'ORDER BY g.sort_order, g.goods_id DESC';
    if ($num > 0) {
        $sql .= ' LIMIT ' . $num;
    }
    //echo $sql;
    $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'] = '';
        }
        $temp = $row['cat_id'];
        $cat_info = get_hot_cat_info($temp);
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['cat_id'] = $row['cat_id'];
        $goods[$idx]['cat_name'] = $cat_info['name'];
        $goods[$idx]['cat_url'] = $cat_info['url'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['brief'] = $row['goods_brief'];
        $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'] = empty($row['goods_thumb']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_thumb'];
        $goods[$idx]['goods_img'] = empty($row['goods_img']) ? $GLOBALS['_CFG']['no_picture'] : $row['goods_img'];
        $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
    }
    return $goods;
}
示例#14
0
/**
 * 获得分类下的商品总数
 *
 * @access  public
 * @param   string     $cat_id
 * @return  integer
 */
function get_cagtegory_goods_count($children, $brand = 0, $min = 0, $max = 0, $ext = '')
{
    $where = "g.is_on_sale = 1   AND g.is_alone_sale = 1 AND g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')';
    global $smarty;
    if ($brand > 0) {
        $where .= " AND g.brand_id = {$brand} ";
    }
    if ($min > 0) {
        $where .= " AND g.shop_price >= {$min} ";
    }
    if ($max > 0) {
        $where .= " AND g.shop_price <= {$max} ";
    }
    $bindusercardme = $smarty->get_template_vars("bindusercardme");
    if (empty($_SESSION['user_id'])) {
        $where .= " and g.is_bind_card!='2'  ";
    }
    /* 返回商品总数 */
    return $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('goods') . " AS g WHERE {$where} {$ext}");
}
/**
 * 调用当前分类的销售排行榜
 *
 * @access  public
 * @param   string  $cats   查询的分类
 * @return  array
 */
function get_top10_supplier($cats = '')
{
    $suppid = isset($_GET['suppId']) && intval($_GET['suppId']) > 0 ? intval($_GET['suppId']) : $_SESSION['supplier_id'];
    $cats = get_children($cats);
    $where = "AND g.supplier_id=" . $suppid;
    $where .= !empty($cats) ? " AND ({$cats} OR " . get_extension_goods($cats) . ") " : '';
    /* 排行统计的时间 */
    switch ($GLOBALS['_CFG']['top10_time']) {
        case 1:
            // 一年
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 365 * 86400) . "'";
            break;
        case 2:
            // 半年
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 180 * 86400) . "'";
            break;
        case 3:
            // 三个月
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 90 * 86400) . "'";
            break;
        case 4:
            // 一个月
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 30 * 86400) . "'";
            break;
        default:
            $top10_time = '';
    }
    $sql = 'SELECT g.goods_id, g.goods_name, g.shop_price, g.market_price, g.original_img, g.goods_thumb, SUM(og.goods_number) as goods_number, g.supplier_id ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g, ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' . "WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 {$where} {$top10_time} ";
    //判断是否启用库存,库存数量是否大于0
    if ($GLOBALS['_CFG']['use_storage'] == 1) {
        $sql .= " AND g.goods_number > 0 ";
    }
    $sql .= ' AND og.order_id = o.order_id AND og.goods_id = g.goods_id ' . "AND (o.order_status = '" . OS_CONFIRMED . "' OR o.order_status = '" . OS_SPLITED . "') " . "AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') " . "AND (o.shipping_status = '" . SS_SHIPPED . "' OR o.shipping_status = '" . SS_RECEIVED . "') " . 'GROUP BY g.goods_id ORDER BY goods_number DESC, g.goods_id DESC LIMIT ' . $GLOBALS['_CFG']['top_number'];
    $arr = $GLOBALS['db']->getAll($sql);
    for ($i = 0, $count = count($arr); $i < $count; $i++) {
        $arr[$i]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($arr[$i]['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $arr[$i]['goods_name'];
        $arr[$i]['url'] = build_uri('goods', array('gid' => $arr[$i]['goods_id']), $arr[$i]['goods_name']);
        $arr[$i]['thumb'] = get_image_path($arr[$i]['goods_id'], $arr[$i]['goods_thumb'], true);
        $arr[$i]['original_img'] = get_image_path($arr[$i]['goods_id'], $arr[$i]['original_img']);
        $arr[$i]['shop_price'] = price_format($arr[$i]['shop_price']);
        $arr[$i]['market_price'] = price_format($arr[$i]['market_price']);
    }
    return $arr;
}
示例#16
0
 $brands[0]['brand_id'] = 0;
 $brands[0]['url'] = build_uri('category', array('cid' => $cat_id, 'bid' => 0, 'price_min' => $price_min, 'price_max' => $price_max, 'filter_attr' => $filter_attr_str), $cat['cat_name']);
 $brands[0]['selected'] = empty($brand) ? 1 : 0;
 $smarty->assign('brands', $brands);
 /* 属性筛选 */
 $ext = '';
 //商品查询条件扩展
 if ($cat['filter_attr'] > 0) {
     $cat_filter_attr = explode(',', $cat['filter_attr']);
     //提取出此分类的筛选属性
     $all_attr_list = array();
     foreach ($cat_filter_attr as $key => $value) {
         $sql = "SELECT a.attr_name FROM " . $ecs->table('attribute') . " AS a, " . $ecs->table('goods_attr') . " AS ga, " . $ecs->table('goods') . " AS g WHERE ({$children} OR " . get_extension_goods($children) . ") AND a.attr_id = ga.attr_id AND g.goods_id = ga.goods_id AND g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND a.attr_id='{$value}'";
         if ($temp_name = $db->getOne($sql)) {
             $all_attr_list[$key]['filter_attr_name'] = $temp_name;
             $sql = "SELECT a.attr_id, MIN(a.goods_attr_id ) AS goods_id, a.attr_value AS attr_value FROM " . $ecs->table('goods_attr') . " AS a, " . $ecs->table('goods') . " AS g" . " WHERE ({$children} OR " . get_extension_goods($children) . ') AND g.goods_id = a.goods_id AND g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 ' . " AND a.attr_id='{$value}' " . " GROUP BY a.attr_value";
             $attr_list = $db->getAll($sql);
             $temp_arrt_url_arr = array();
             for ($i = 0; $i < count($cat_filter_attr); $i++) {
                 $temp_arrt_url_arr[$i] = !empty($filter_attr[$i]) ? $filter_attr[$i] : 0;
             }
             $temp_arrt_url_arr[$key] = 0;
             //“全部”的信息生成
             $temp_arrt_url = implode('.', $temp_arrt_url_arr);
             $all_attr_list[$key]['attr_list'][0]['attr_value'] = $_LANG['all_attribute'];
             $all_attr_list[$key]['attr_list'][0]['url'] = build_uri('category', array('cid' => $cat_id, 'bid' => $brand, 'price_min' => $price_min, 'price_max' => $price_max, 'filter_attr' => $temp_arrt_url), $cat['cat_name']);
             $all_attr_list[$key]['attr_list'][0]['selected'] = empty($filter_attr[$key]) ? 1 : 0;
             foreach ($attr_list as $k => $v) {
                 $temp_key = $k + 1;
                 $temp_arrt_url_arr[$key] = $v['goods_id'];
                 //为url中代表当前筛选属性的位置变量赋值,并生成以‘.’分隔的筛选属性字符串
示例#17
0
文件: function.php 项目: u0mo5/app
/**
 * 调用当前分类的销售排行榜
 *
 * @access  public
 * @param   string  $cats   查询的分类
 * @return  array
 */
function GZ_get_top10($cats = '')
{
    $cats = get_children($cats);
    $where = !empty($cats) ? "AND ({$cats} OR " . get_extension_goods($cats) . ") " : '';
    /* 排行统计的时间 */
    switch ($GLOBALS['_CFG']['top10_time']) {
        case 1:
            // 一年
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 365 * 86400) . "'";
            break;
        case 2:
            // 半年
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 180 * 86400) . "'";
            break;
        case 3:
            // 三个月
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 90 * 86400) . "'";
            break;
        case 4:
            // 一个月
            $top10_time = "AND o.order_sn >= '" . date('Ymd', gmtime() - 30 * 86400) . "'";
            break;
        default:
            $top10_time = '';
    }
    $sql = 'SELECT g.goods_id, g.goods_name, SUM(og.goods_number) as goods_number,g.comments_number, g.goods_brief,g.market_price, g.shop_price, ' . "g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.original_img, g.goods_type " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g, ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' . "WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 {$where} {$top10_time} ";
    //判断是否启用库存,库存数量是否大于0
    if ($GLOBALS['_CFG']['use_storage'] == 1) {
        $sql .= " AND g.goods_number > 0 ";
    }
    $sql .= ' AND og.order_id = o.order_id AND og.goods_id = g.goods_id ' . "AND (o.order_status = '" . OS_CONFIRMED . "' OR o.order_status = '" . OS_SPLITED . "') " . "AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') " . "AND (o.shipping_status = '" . SS_SHIPPED . "' OR o.shipping_status = '" . SS_RECEIVED . "') " . 'GROUP BY g.goods_id ORDER BY goods_number DESC, g.goods_id DESC LIMIT ' . $GLOBALS['_CFG']['top_number'];
    $arr = $GLOBALS['db']->getAll($sql);
    $data = array();
    foreach ($arr as $key => $row) {
        if ($row['promote_price'] > 0) {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
        } else {
            $promote_price = 0;
        }
        /* 处理商品水印图片 */
        /* 处理商品水印图片 */
        $watermark_img = '';
        if ($promote_price != 0) {
            $watermark_img = "watermark_promote_small";
        } elseif ($row['is_new'] != 0) {
            $watermark_img = "watermark_new_small";
        } elseif ($row['is_best'] != 0) {
            $watermark_img = "watermark_best_small";
        } elseif ($row['is_hot'] != 0) {
            $watermark_img = 'watermark_hot_small';
        }
        if ($watermark_img != '') {
            $arr[]['watermark_img'] = $watermark_img;
        }
        $arr = array('goods_id' => $row['goods_id'], 'goods_name' => $row['goods_name'], 'type' => $row['goods_type'], 'market_price' => price_format($row['market_price']), 'shop_price' => price_format($row['shop_price']), 'promote_price' => $promote_price > 0 ? price_format($promote_price) : '', 'goods_brief' => $row['goods_brief'], 'original_img' => get_image_path($row['goods_id'], $row['original_img'], true), 'goods_img' => get_image_path($row['goods_id'], $row['goods_img']), 'goods_thumb' => get_image_path($row['goods_id'], $row['goods_thumb']), 'url' => build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']));
        $data[] = $arr;
    }
    $data = API_DATA("SIMPLEGOODS", $data);
    return $data;
}
示例#18
0
function get_promote_goods_pro($cat_id = array(0))
{
    for ($i = 0; $i < count($cat_id); $i++) {
        if ($i < count($cat_id) - 1) {
            $search .= get_children($cat_id[$i]) . "OR " . get_extension_goods(get_children($cat_id[$i])) . ' OR ';
        } else {
            $search .= get_children($cat_id[$i]) . "OR " . get_extension_goods(get_children($cat_id[$i]));
        }
    }
    $time = gmtime();
    $order_type = $GLOBALS['_CFG']['recommend_order'];
    $num = 12;
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . "g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . "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 g.is_promote = 1 AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}'" . "AND (" . $search . ") ";
    $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd';
    $sql .= " LIMIT {$num} ";
    $result = $GLOBALS['db']->getAll($sql);
    $goods = array();
    foreach ($result 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]['brand_name'] = $row['brand_name'];
        $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']);
        $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]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
        $goods[$idx]['market_price'] = price_format($row['market_price']);
        $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']);
        $time = gmtime();
        if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date']) {
            $goods[$idx]['gmt_end_time'] = local_date('M d, Y H:i:s', $row['promote_end_date']);
        } else {
            $goods[$idx]['gmt_end_time'] = 0;
        }
    }
    return $goods;
}
示例#19
0
function cat_get_goods($keywords, $children, $brand, $min, $max, $ext, $size, $page, $sort, $order)
{
    $display = $GLOBALS['display'];
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND " . ("g.is_delete = 0 AND (" . $children . " OR ") . get_extension_goods($children) . ")";
    if ($keywords != "") {
        $where .= " AND g.goods_name LIKE '%" . $keywords . "%' ";
    }
    if (0 < $brand) {
        $where .= "AND g.brand_id=" . $brand . " ";
    }
    if (0 < $min) {
        $where .= " AND g.shop_price >= " . $min . " ";
    }
    if (0 < $max) {
        $where .= " AND g.shop_price <= " . $max . " ";
    }
    $sql = "SELECT g.goods_id, g.goods_name, g.goods_sn, g.goods_name_style, g.market_price,g.is_promote, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, " . ("IFNULL(mp.user_price, g.shop_price * '" . $_SESSION['discount'] . "') AS shop_price, g.promote_price, g.goods_type, ") . "(select AVG(r.comment_rank) from " . $GLOBALS['ecs']->table("comment") . " as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_rank, (select IFNULL(sum(r.id_value), 0) from " . $GLOBALS['ecs']->table("comment") . " as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_count, (select IFNULL(sum(og.goods_number), 0) from " . $GLOBALS['ecs']->table("order_goods") . " as og where og.goods_id = g.goods_id) AS sell_number, g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img 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 " . $where . " {$ext} ORDER BY {$sort} {$order}");
    $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);
    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        if (0 < $row['promote_price']) {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
        } else {
            $promote_price = 0;
        }
        $watermark_img = "";
        if ($promote_price != 0) {
            $watermark_img = "watermark_promote_small";
        } else {
            if ($row['is_new'] != 0) {
                $watermark_img = "watermark_new_small";
            } else {
                if ($row['is_best'] != 0) {
                    $watermark_img = "watermark_best_small";
                } else {
                    if ($row['is_hot'] != 0) {
                        $watermark_img = "watermark_hot_small";
                    }
                }
            }
        }
        if ($watermark_img != "") {
            $arr[$row['goods_id']]['watermark_img'] = $watermark_img;
        }
        $arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
        $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
        $arr[$row['goods_id']]['name'] = $row['goods_name'];
        $arr[$row['goods_id']]['goods_sn'] = $row['goods_sn'];
        $arr[$row['goods_id']]['comment_rank'] = $row['comment_rank'];
        $arr[$row['goods_id']]['comment_count'] = $row['comment_count'];
        $arr[$row['goods_id']]['sell_number'] = $row['sell_number'];
        $arr[$row['goods_id']]['is_promote'] = $row['is_promote'];
        $arr[$row['goods_id']]['is_new'] = $row['is_new'];
        $arr[$row['goods_id']]['is_best'] = $row['is_best'];
        $arr[$row['goods_id']]['is_hot'] = $row['is_hot'];
        $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
        $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']);
        $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
        $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
        $arr[$row['goods_id']]['type'] = $row['goods_type'];
        $arr[$row['goods_id']]['promote_price'] = 0 < $promote_price ? price_format($promote_price) : "";
        $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], TRUE);
        $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
        $arr[$row['goods_id']]['url'] = build_uri("goods", array("gid" => $row['goods_id']), $row['goods_name']);
    }
    return $arr;
}
示例#20
0
function get_child_tree_goods($tree_id = 0)
{
    $three_arr = array();
    $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '{$tree_id}' AND is_show = 1 ";
    if ($GLOBALS['db']->getOne($sql) || $tree_id == 0) {
        $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' . 'FROM ' . $GLOBALS['ecs']->table('category') . "WHERE parent_id = '{$tree_id}' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC LIMIT 7";
        $res = $GLOBALS['db']->getAll($child_sql);
        foreach ($res as $row) {
            if ($row['is_show']) {
                $three_arr[$row['cat_id']]['id'] = $row['cat_id'];
            }
            $three_arr[$row['cat_id']]['name'] = $row['cat_name'];
            $three_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
            $children = get_children($row['cat_id']);
            $sql = 'SELECT g.goods_id,g.cat_id, g.goods_name, g.market_price, 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 ' . "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 BY g.sort_order, g.goods_id DESC';
            $goods_res = $GLOBALS['db']->getAll($sql);
            $goods = array();
            foreach ($goods_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]['market_price'] = $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']);
            }
            $three_arr[$row['cat_id']]['goods'] = $goods;
            if (isset($row['cat_id']) != NULL) {
                $three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
            }
        }
    }
    return $three_arr;
}
示例#21
0
/**
 * 获得分类下的商品总数
 *
 * @access  public
 * @param   string     $cat_id
 * @return  integer
 */
function get_cagtegory_goods_count($children, $brand = 0, $min = 0, $max = 0, $ext = '')
{
    $filter = isset($_REQUEST['filter']) ? intval($_REQUEST['filter']) : 0;
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')';
    if ($filter == 1) {
        $where .= ' AND g.supplier_id=0 ';
    } elseif ($filter == 2) {
        $where .= ' AND g.supplier_id>0 ';
    } else {
    }
    if ($brand > 0) {
        /* 代码增加_start  By  www.68ecshop.com  */
        if (strstr($brand, '_')) {
            $brand_sql = str_replace("_", ",", $brand);
            $where .= "AND g.brand_id in ({$brand_sql}) ";
        } else {
            $where .= "AND g.brand_id={$brand} ";
        }
        /* 代码增加_end  By  www.68ecshop.com  */
    }
    if ($min > 0) {
        $where .= " AND g.shop_price >= {$min} ";
    }
    if ($max > 0) {
        $where .= " AND g.shop_price <= {$max} ";
    }
    /* 返回商品总数 */
    return $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('goods') . " AS g WHERE {$where} {$ext}");
}
示例#22
0
文件: index.php 项目: qgz/ecshop
function get_recommend_goods_by_suppliers_id($type = '', $cat_id = 0, $region_id = 0)
{
    $brand_where = $region_id > 0 ? ' AND g.suppliers_id in (select suppliers_id from ' . $GLOBALS['ecs']->table('suppliers') . ' where city = ' . $region_id . ') ' : '';
    $price_where = $min > 0 ? " AND g.shop_price >= {$min} " : '';
    $price_where .= $max > 0 ? " AND g.shop_price <= {$max} " : '';
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style,g.goods_sn,  g.market_price, g.shop_price AS org_price, g.promote_price,g.seller_note, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . '(select AVG(r.comment_rank) from ' . $GLOBALS['ecs']->table('comment') . ' as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_rank, ' . '(select IFNULL(sum(og.goods_number), 0) from ' . $GLOBALS['ecs']->table('order_goods') . ' as og where og.goods_id = g.goods_id) AS sell_number, ' . 'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name,b.brand_id,b.brand_logo ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . "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 ' . $brand_where . $price_where . $ext;
    $num = 0;
    $type2lib = array('best' => 'recommend_best', 'new' => 'recommend_new', 'hot' => 'recommend_hot', 'promote' => 'recommend_promotion');
    if ($cat_num == 0) {
        $num = get_library_number($type2lib[$type]);
    } else {
        $num = $cat_num;
    }
    switch ($type) {
        case 'best':
            $sql .= ' AND is_best = 1';
            break;
        case 'new':
            $sql .= ' AND is_new = 1';
            break;
        case 'hot':
            $sql .= ' AND is_hot = 1';
            break;
        case 'promote':
            $time = gmtime();
            $sql .= " AND is_promote = 1 AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}'";
            break;
    }
    $cats = get_children($cat_id);
    if (!empty($cats)) {
        $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) . ")";
    }
    $order_type = $GLOBALS['_CFG']['recommend_order'];
    $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()';
    $res = $GLOBALS['db']->selectLimit($sql, $num);
    $idx = 0;
    $index = 1;
    $goods = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        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) : '';
            $goods[$idx]['promote_price2'] = $promote_price;
            $goods[$idx]['saving'] = $row['market_price'] - $promote_price;
        } else {
            $goods[$idx]['promote_price'] = '';
        }
        $index++;
        $goods[$idx]['i'] = $index;
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['goods_sn'] = $row['goods_sn'];
        $goods[$idx]['comment_rank'] = $row['comment_rank'];
        $goods[$idx]['sell_number'] = $row['sell_number'];
        $goods[$idx]['seller_note'] = $row['seller_note'];
        $goods[$idx]['is_new'] = $row['is_new'];
        $goods[$idx]['brief'] = $row['goods_brief'];
        $goods[$idx]['brand_name'] = $row['brand_name'];
        $goods[$idx]['brand_id'] = $row['brand_id'];
        $goods[$idx]['brand_logo'] = $row['brand_logo'];
        $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]['market_price'] = price_format($row['market_price']);
        $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]['promote_limit_time'] = $row['promote_end_date'] - $row['promote_start_date'];
        $goods[$idx]['promote_end_date'] = local_date('m/d/Y H:i:s', $row['promote_end_date']);
        $goods[$idx]['promote_end_date2'] = $row['promote_end_date'];
        $market_price = $row['market_price'];
        $promote_price = $goods[$idx]['promote_price2'];
        $shop_price = $row['shop_price'];
        $goods[$idx]['saving'] = $market_price - $promote_price;
        $goods[$idx]['save_rate'] = $market_price ? round($promote_price / $market_price, 2) * 10 : 0;
        $goods[$idx]['save_rate2'] = $market_price ? round($shop_price / $market_price, 2) * 10 : 0;
        $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
        $idx++;
    }
    return $goods;
}
示例#23
0
function get_cat_recommend_goods($type = "", $cats = "", $cat_num = 0, $brand = 0, $min = 0, $max = 0, $ext = "")
{
    $brand_where = 0 < $brand ? " AND g.brand_id = '" . $brand . "'" : "";
    $price_where = 0 < $min ? " AND g.shop_price >= " . $min . " " : "";
    $price_where .= 0 < $max ? " AND g.shop_price <= " . $max . " " : "";
    $sql = "SELECT g.goods_id, g.goods_name, g.goods_name_style,g.goods_sn,  g.market_price, g.shop_price AS org_price, g.promote_price, " . ("IFNULL(mp.user_price, g.shop_price * '" . $_SESSION['discount'] . "') AS shop_price, ") . "(select AVG(r.comment_rank) from " . $GLOBALS['ecs']->table("comment") . " as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_rank, (select IFNULL(sum(og.goods_number), 0) from " . $GLOBALS['ecs']->table("order_goods") . " as og where og.goods_id = g.goods_id) AS sell_number, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, b.brand_id, g.is_best, g.is_new, g.is_hot, g.is_promote FROM " . $GLOBALS['ecs']->table("goods") . " AS g LEFT JOIN " . $GLOBALS['ecs']->table("brand") . " AS b ON b.brand_id = g.brand_id 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 " . $brand_where . $price_where . $ext;
    $num = 0;
    $type2lib = array("best" => "recommend_best", "new" => "recommend_new", "hot" => "recommend_hot", "promote" => "recommend_promotion");
    if ($cat_num == 0) {
        $num = get_library_number($type2lib[$type]);
    } else {
        $num = $cat_num;
    }
    switch ($type) {
        case "best":
            $sql .= " AND is_best = 1";
            break;
        case "new":
            $sql .= " AND is_new = 1";
            break;
        case "hot":
            $sql .= " AND is_hot = 1";
            break;
        case "promote":
            $time = gmtime();
            $sql .= " AND is_promote = 1 AND promote_start_date <= '" . $time . "' AND promote_end_date >= '{$time}'";
    }
    if (!empty($cats)) {
        $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) . ")";
    }
    $order_type = $GLOBALS['_CFG']['recommend_order'];
    $sql .= $order_type == 0 ? " ORDER BY g.sort_order, g.last_update DESC" : " ORDER BY RAND()";
    $res = $GLOBALS['db']->selectLimit($sql, $num);
    $idx = 0;
    $goods = array();
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        if (0 < $row['promote_price']) {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
            $goods[$idx]['promote_price'] = 0 < $promote_price ? price_format($promote_price) : "";
        } else {
            $goods[$idx]['promote_price'] = "";
        }
        $row['comment_rank'] = ceil($row['comment_rank']) == 0 ? 5 : ceil($row['comment_rank']);
        $goods[$idx]['id'] = $row['goods_id'];
        $goods[$idx]['name'] = $row['goods_name'];
        $goods[$idx]['goods_sn'] = $row['goods_sn'];
        $goods[$idx]['comment_rank'] = $row['comment_rank'];
        $goods[$idx]['sell_number'] = $row['sell_number'];
        $goods[$idx]['is_new'] = $row['is_new'];
        $goods[$idx]['is_best'] = $row['is_best'];
        $goods[$idx]['is_hot'] = $row['is_hot'];
        $goods[$idx]['is_promote'] = $row['is_promote'];
        $goods[$idx]['brief'] = $row['goods_brief'];
        $goods[$idx]['brand_id'] = $row['brand_id'];
        $goods[$idx]['brand_name'] = $row['brand_name'];
        $goods[$idx]['short_name'] = 0 < $GLOBALS['_CFG']['goods_name_length'] ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        $goods[$idx]['market_price'] = price_format($row['market_price']);
        $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]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
        ++$idx;
    }
    return $goods;
}
示例#24
0
文件: category.php 项目: dlpc/ecshop
/**
 * 获得分类下的商品总数
 *
 * @access  public
 * @param   string     $cat_id
 * @return  integer
 */
function get_cagtegory_goods_count($children, $brand = 0, $min = 0, $max = 0, $ext = '')
{
    //获取显示商品条件 add by hg for date 2014-03-26
    $agency_where = agency_goods();
    if ($agency_where != null) {
        $agency_where = 'g.' . $agency_where;
    }
    $where = "{$agency_where} g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')';
    if ($brand > 0) {
        $where .= " AND g.brand_id = {$brand} ";
    }
    if ($min > 0) {
        $where .= " AND g.shop_price >= {$min} ";
    }
    if ($max > 0) {
        $where .= " AND g.shop_price <= {$max} ";
    }
    /* 返回商品总数 */
    return $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('goods') . " AS g WHERE {$where} {$ext}");
}
示例#25
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, ' . "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 ' . "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]['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']);
    }
    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_clild'] = get_clild_list($cat_id, 2);
    return $cat;
}
示例#26
0
文件: category.php 项目: noikiy/mdwp
/**
 * 获得分类下的商品
 *
 * @access  public
 * @param   string  $children
 * @return  array
 */
function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order)
{
    $display = isset($GLOBALS['display']) ? $GLOBALS['display'] : '';
    $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
            "g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';

    if ($brand > 0)
    {
        $where .=  "AND g.brand_id=$brand ";
    }

    if ($min > 0)
    {
        $where .= " AND g.shop_price >= $min ";
    }

    if ($max > 0)
    {
        $where .= " AND g.shop_price <= $max ";
    }

    /* 获得商品列表 */
    $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' .
                "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, g.goods_type, " .
                'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' .
            '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 $where $ext ORDER BY $sort $order";
   
    $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size);

    $arr = array();
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        if ($row['promote_price'] > 0)
        {
            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
        }
        else
        {
            $promote_price = 0;
        }

        /* 处理商品水印图片 */
        $watermark_img = '';

        if ($promote_price != 0)
        {
            $watermark_img = "watermark_promote_small";
        }
        elseif ($row['is_new'] != 0)
        {
            $watermark_img = "watermark_new_small";
        }
        elseif ($row['is_best'] != 0)
        {
            $watermark_img = "watermark_best_small";
        }
        elseif ($row['is_hot'] != 0)
        {
            $watermark_img = 'watermark_hot_small';
        }

        if ($watermark_img != '')
        {
            $arr[$row['goods_id']]['watermark_img'] =  $watermark_img;
        }

        $arr[$row['goods_id']]['goods_id']         = $row['goods_id'];
        if($display == 'grid')
        {
            $arr[$row['goods_id']]['goods_name']       = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
        }
        else
        {
            $arr[$row['goods_id']]['goods_name']       = $row['goods_name'];
        }
       // $arr[$row['goods_id']]['name']             = $row['goods_name'];
        $arr[$row['goods_id']]['goods_brief']      = $row['goods_brief'];
        $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
        $arr[$row['goods_id']]['market_price']     = price_format($row['market_price']);
        $arr[$row['goods_id']]['shop_price']       = price_format($row['shop_price']);
        $arr[$row['goods_id']]['type']             = $row['goods_type'];
        $arr[$row['goods_id']]['promote_price']    = ($promote_price > 0) ? price_format($promote_price) : '';
        $arr[$row['goods_id']]['goods_thumb']      = get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $arr[$row['goods_id']]['goods_img']        = get_image_path($row['goods_id'], $row['goods_img']);
        $arr[$row['goods_id']]['url']              = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']);
    }

    return $arr;
}