/**
* WK 列出所有分类及品牌
* ============================================================================
* * 版权所有 2005-2012 QQ 80342014,并保留所有权利。
* ;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: catalog.php 17217 2011-01-19 06:29:08Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
/* 初始化分页信息 */
$page = isset($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
$size = isset($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10;
$catid = isset($_REQUEST['category']) && intval($_REQUEST['category']) > 0 ? intval($_REQUEST['category']) : 0;
$price_max = isset($_REQUEST['price_max']) && intval($_REQUEST['price_max']) > 0 ? intval($_REQUEST['price_max']) : 0;
$price_min = isset($_REQUEST['price_min']) && intval($_REQUEST['price_min']) > 0 ? intval($_REQUEST['price_min']) : 0;
/* 排序、显示方式以及类型 */
$default_display_type = $_CFG['show_order_type'] == '0' ? 'list' : ($_CFG['show_order_type'] == '1' ? 'grid' : 'text');
$default_sort_order_method = $_CFG['sort_order_method'] == '0' ? 'DESC' : 'ASC';
$default_sort_order_type = $_CFG['sort_order_type'] == '0' ? 'goods_id' : ($_CFG['sort_order_type'] == '1' ? 'shop_price' : 'last_update');
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'shop_price', 'last_update', 'click_count','salenum'))) ? trim($_REQUEST['sort']) : $default_sort_order_type;
$order = (isset($_REQUEST['order']) && in_array(trim(strtoupper($_REQUEST['order'])), array('ASC', 'DESC'))) ? trim($_REQUEST['order']) : $default_sort_order_method;
$display = (isset($_REQUEST['display']) && in_array(trim(strtolower($_REQUEST['display'])), array('list', 'grid', 'text'))) ? trim($_REQUEST['display']) : (isset($_COOKIE['ECS']['display']) ? $_COOKIE['ECS']['display'] : $default_display_type);
$display = in_array($display, array('list', 'grid', 'text')) ? $display : 'text';
setcookie('ECS[display]', $display, gmtime() + 86400 * 7);
/* 页面的缓存ID */
$cache_id = sprintf('%X', crc32('catalog'.'-'.$catid . '-' . $display . '-' . $sort .'-' . $order .'-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' .
$_CFG['lang'] .'-' . $price_max . '-' .$price_min ));
if (!$smarty->is_cached('catalog.dwt',$cache_id))
{
/* 取出所有分类 */
$cat_list = cat_list(0, 0, false);
foreach ($cat_list AS $key=>$val)
{
if ($val['is_show'] == 0)
{
unset($cat_list[$key]);
}
}
assign_template();
assign_dynamic('catalog');
$position = assign_ur_here(0, $_LANG['catalog']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('cat_list', $cat_list); // 分类列表
$smarty->assign('brand_list', get_brands()); // 所以品牌赋值
$smarty->assign('promotion_info', get_promotion_info());
$smarty->assign('script_name', 'catalog');
/* 获取商品信息 */
$keywords = !empty($_REQUEST['keywords']) ? htmlspecialchars(trim($_REQUEST['keywords'])) : '';
//echo $keywords;
//$category = !empty($_REQUEST['category']) ? intval($_REQUEST['category']) : 0;
$children = ($catid > 0) ? get_children($catid) : '';
$count = get_cagtegory_goods_count($children, $price_min, $price_max, $keywords);
$max_page = ($count> 0) ? ceil($count / $size) : 1;
if ($page > $max_page)
{
$page = $max_page;
}
$goodslist = category_get_goods($children, $price_min, $price_max, $size, $page, $sort, $order, $keywords);
$smarty->assign('goods_list', $goodslist);
/* 分页 */
$pager['search'] = array(
'keywords' => stripslashes(urlencode($_REQUEST['keywords'])),
'category' => $catid,
'sort' => $sort,
'order' => $order,
'price_max' => $price_max,
'price_min' => $price_min
);
$pager['sort'] = $sort;
$pager = get_pager('catalog.php', $pager['search'], $count, $page, $size);
$smarty->assign('pager', $pager);
$smarty->assign('catid',$catid);
$smarty->assign('url_no_price', build_uri('catalog', array('cid'=>$catid, 'price_min'=>$price_min, 'price_max'=>$price_max), 'allcategory'));
$smarty->assign('furl_no_price', build_uri('catalog', array('cid'=>$catid), 'allcategory'));
}
$smarty->display('catalog.dwt');
/**
* 计算指定分类的商品数量
*
* @access public
* @param integer $cat_id
*
* @return void
*/
function calculate_goods_num($cat_list, $cat_id)
{
$goods_num = 0;
foreach ($cat_list AS $cat)
{
if ($cat['parent_id'] == $cat_id && !empty($cat['goods_num']))
{
$goods_num += $cat['goods_num'];
}
}
return $goods_num;
}
/**
* 获得分类下的商品
*
* @access public
* @param string $children
* @return array
*/
function category_get_goods($children, $min, $max, $size, $page, $sort, $order, $keywords='')
{
$where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ".
"g.is_delete = 0 ";
if(!empty($children)){
$where .= "AND ($children OR " . get_extension_goods($children) . ')';
}
if(!empty($keywords))
{
$keywords = preg_replace("/[ ]{1,}/", " ", trim($keywords));
$val = mysql_like_quote(trim($keywords));
$where .= " AND (g.goods_name LIKE '%$val%' OR g.goods_sn LIKE '%$val%' OR g.keywords LIKE '%$val%' $sc_dsad)";
}
/* fanny 判定是否是分销商,如果是则下降的产品不显示 start */
$sql .= ' AND g.goods_id '.db_create_notin(get_goods_down());
/* fanny 判定是否是分销商,如果是则下降的产品不显示 end */
/* 获得商品列表 */
$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.click_count, 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'];
$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;
}
/**
* 获得分类下的商品总数
*
* @access public
* @param string $cat_id
* @return integer
*/
function get_cagtegory_goods_count($children, $min = 0, $max = 0, $keywords='')
{
$where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ";
if(!empty($children)){
$where .= "AND ($children OR " . get_extension_goods($children) . ')';
}
if(!empty($keywords))
{
$keywords = preg_replace("/[ ]{1,}/", " ", trim($keywords));
$val = mysql_like_quote(trim($keywords));
$where .= " AND (g.goods_name LIKE '%$val%' OR g.goods_sn LIKE '%$val%' OR g.keywords LIKE '%$val%' $sc_dsad)";
}
/* fanny 判定是否是分销商,如果是则下降的产品不显示 start */
$sql .= ' AND g.goods_id '.db_create_notin(get_goods_down());
/* fanny 判定是否是分销商,如果是则下降的产品不显示 end */
$sql = "SELECT COUNT(*) FROM ".$GLOBALS['ecs']->table('goods').' AS g WHERE '.$where;
$total = $GLOBALS['db']->getOne($sql);
/* 返回商品总数 */
return $total;
}
?>
一键复制
编辑
Web IDE
原始数据
按行查看
历史