1、创建new_arrival.php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
/* 初始化分页信息 */
$date = isset($_REQUEST['date']) ? $_REQUEST['date'] : 'all';
$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;
$brand = isset($_REQUEST['brand']) && intval($_REQUEST['brand']) > 0 ? intval($_REQUEST['brand']) : 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;
$filter_attr_str = isset($_REQUEST['filter_attr']) ? htmlspecialchars(trim($_REQUEST['filter_attr'])) : '0';
$filter_attr_str = trim(urldecode($filter_attr_str));
$filter_attr_str = preg_match('/^[\d\.]+$/',$filter_attr_str) ? $filter_attr_str : '';
$filter_attr = empty($filter_attr_str) ? '' : explode('.', $filter_attr_str);
/* 排序、显示方式以及类型 */
$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'))) ? 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);
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
/* 页面的缓存ID */
$cache_id = sprintf('%X', crc32($date . '-' . $display . '-' . $sort .'-' . $order .'-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' .
$_CFG['lang'] .'-'. $brand. '-' . $price_max . '-' .$price_min . '-' . $filter_attr_str));
if (!$smarty->is_cached('new_arrival.dwt', $cache_id))
{
/* 如果页面没有被缓存则重新获取页面的内容 */
$smarty->assign('keywords', '新品');
$smarty->assign('description', '新品');
/*日期导航*/
$sql = "SELECT FROM_UNIXTIME(add_time, '%Y-%m-%d') as `datelist` FROM " .$GLOBALS['ecs']->table('goods'). " WHERE is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 group by FROM_UNIXTIME(add_time, '%Y-%m-%d') order by FROM_UNIXTIME(add_time, '%Y-%m-%d') desc";
$datelist = $GLOBALS['db']->getAll($sql);
$datearr = array();
foreach($datelist as $k => $val){
$datearr[$k]['name'] = $val['datelist'];
$datearr[$k]['url'] = build_uri('new_arrival', array('date' => $val['datelist']));
}
$new_arrival = array();
$new_arrival['name'] = '新品';
$new_arrival['url'] = build_uri('new_arrival', array('date' => 'all'));
$smarty->assign('new_arrival', $new_arrival);
$smarty->assign('datelist', $datearr);
/* 赋值固定内容 */
if ($brand > 0)
{
$sql = "SELECT brand_name FROM " .$GLOBALS['ecs']->table('brand'). " WHERE brand_id = '$brand'";
$brand_name = $db->getOne($sql);
}
else
{
$brand_name = '';
}
/* 品牌筛选 */
if($date == 'all'){
$children = '1';
}else{
$children = "FROM_UNIXTIME(g.add_time, '%Y-%m-%d') = '" . $date . "'";
}
$sql = "SELECT b.brand_id, b.brand_name, 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 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";
$brands = $GLOBALS['db']->getAll($sql);
foreach ($brands AS $key => $val)
{
$temp_key = $key + 1;
$brands[$temp_key]['brand_name'] = $val['brand_name'];
$brands[$temp_key]['url'] = build_uri('new_arrival', array('date' => $date, 'bid' => $val['brand_id'], 'price_min'=>$price_min, 'price_max'=> $price_max, 'filter_attr'=>$filter_attr_str));
/* 判断品牌是否被选中 */
if ($brand == $brands[$key]['brand_id'])
{
$brands[$temp_key]['selected'] = 1;
}
else
{
$brands[$temp_key]['selected'] = 0;
}
}
$brands[0]['brand_name'] = $_LANG['all_attribute'];
$brands[0]['url'] = build_uri('new_arrival', array('date' => $date, 'bid' => 0, 'price_min'=>$price_min, 'price_max'=> $price_max, 'filter_attr'=>$filter_attr_str));
$brands[0]['selected'] = empty($brand) ? 1 : 0;
$smarty->assign('brands', $brands);
$ext = '';
assign_template('c');
//$position = assign_ur_here(0, $brand_name);
$ur_here = '<a href=".">' . $GLOBALS['_LANG']['home'] . '</a>';
if($date == 'all'){
$ur_here .= ' <code>></code> 新品';
}else{
$ur_here .= ' <code>></code> <a href="' . build_uri('new_arrival', array('date' => 'all')) . '">新品</a> <code>></code> ' . $date;
}
$smarty->assign('page_title', $date); // 页面标题
$smarty->assign('ur_here', $ur_here); // 当前位置
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('top_goods', get_top10()); // 销售排行
$smarty->assign('show_marketprice', $_CFG['show_marketprice']);
//$smarty->assign('category', $cat_id);
$smarty->assign('brand_id', $brand);
$smarty->assign('price_max', $price_max);
$smarty->assign('price_min', $price_min);
$smarty->assign('filter_attr', $filter_attr_str);
//$smarty->assign('feed_url', ($_CFG['rewrite'] == 1) ? "feed-c$cat_id.xml" : 'feed.php?cat=' . $cat_id); // RSS URL
$smarty->assign('data_dir', DATA_DIR);
$smarty->assign('promotion_info', get_promotion_info());
//$smarty->assign('best_goods', get_category_recommend_goods('best', $children, $brand, $price_min, $price_max, $ext));
//$smarty->assign('promotion_goods', get_category_recommend_goods('promote', $children, $brand, $price_min, $price_max, $ext));
//$smarty->assign('hot_goods', get_category_recommend_goods('hot', $children, $brand, $price_min, $price_max, $ext));
$count = get_cagtegory_goods_count($children, $brand, $price_min, $price_max, $ext);
$max_page = ($count> 0) ? ceil($count / $size) : 1;
if ($page > $max_page)
{
$page = $max_page;
}
$goodslist = category_get_goods($children, $brand, $price_min, $price_max, $ext, $size, $page, $sort, $order);
if($display == 'grid')
{
if(count($goodslist) % 2 != 0)
{
$goodslist[] = array();
}
}
$smarty->assign('goods_list', $goodslist);
//$smarty->assign('category', $cat_id);
//$smarty->assign('script_name', 'category');
assign_pager('new_arrival', $date, $count, $size, $sort, $order, $page, '', $brand, $price_min, $price_max, $display, $filter_attr_str); // 分页
//assign_dynamic('category'); // 动态内容
}
$smarty->display('new_arrival.dwt', $cache_id);
/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */
/**
* 获得分类下的商品
*
* @access public
* @param string $children
* @return array
*/
function category_get_goods($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";
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;
}
/**
* 获得分类下的商品总数
*
* @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";
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");
}
2、复制category.dwt改名为new_arrival.dwt添加如下代码到左侧导航(不同模板样式不同)
<div id="category_tree">
<div class="tit">{$new_arrival.name}</div>
<!--{foreach from=$datelist item=date}-->
<dl><dt><a href="{$date.url}">{$date.name|escape:html}</a></dt></dl>
<!--{/foreach}-->
</div>
<div class="blank"></div>
3、修改includes/lib_main.php中的assign_pager函数,添加如下代码
case 'new_arrival':
$uri_args = array('date' => $cat, 'bid' => $brand, 'price_min'=>$price_min, 'price_max'=>$price_max, 'filter_attr'=>$filter_attr, 'sort' => $sort, 'order' => $order, 'display' => $display_type);
break;
4、修改includes/lib_common.php中的build_uri函数:
$args = array('cid' => 0,
'gid' => 0,
'bid' => 0,
'acid' => 0,
'aid' => 0,
'sid' => 0,
'gbid' => 0,
'auid' => 0,
'sort' => '',
'order' => '',
);
改为:
$args = array('cid' => 0,
'date' => 0,
'gid' => 0,
'bid' => 0,
'acid' => 0,
'aid' => 0,
'sid' => 0,
'gbid' => 0,
'auid' => 0,
'sort' => '',
'order' => '',
);
switch语句中添加
case 'new_arrival':
if (empty($date))
{
return false;
}
else
{
if ($rewrite)
{
$uri = 'new_arrival-' . $date;
if (isset($bid))
{
$uri .= '-b' . $bid;
}
if (isset($price_min))
{
$uri .= '-min'.$price_min;
}
if (isset($price_max))
{
$uri .= '-max'.$price_max;
}
if (isset($filter_attr))
{
$uri .= '-attr' . $filter_attr;
}
if (!empty($page))
{
$uri .= '-' . $page;
}
if (!empty($sort))
{
$uri .= '-' . $sort;
}
if (!empty($order))
{
$uri .= '-' . $order;
}
}
else
{
$uri = 'new_arrival.php?date=' . $date;
if (!empty($bid))
{
$uri .= '&brand=' . $bid;
}
if (isset($price_min))
{
$uri .= '&price_min=' . $price_min;
}
if (isset($price_max))
{
$uri .= '&price_max=' . $price_max;
}
if (!empty($filter_attr))
{
$uri .='&filter_attr=' . $filter_attr;
}
if (!empty($page))
{
$uri .= '&page=' . $page;
}
if (!empty($sort))
{
$uri .= '&sort=' . $sort;
}
if (!empty($order))
{
$uri .= '&order=' . $order;
}
}
}
break;
5、修改.htaccess为新品重写URL,添加如下代码:
RewriteRule ^new_arrival-([a-z0-9-]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ new_arrival\.php\?date=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 [QSA,L]
RewriteRule ^new_arrival-([a-z0-9-]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$ new_arrival\.php\?date=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 [QSA,L]
RewriteRule ^new_arrival-([a-z0-9-]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$ new_arrival\.php\?date=$1&brand=$2&page=$3&sort=$4&order=$5 [QSA,L]
RewriteRule ^new_arrival-([a-z0-9-]+)-b([0-9]+)-([0-9]+)(.*)\.html$ new_arrival\.php\?date=$1&brand=$2&page=$3 [QSA,L]
RewriteRule ^new_arrival-([a-z0-9-]+)-b([0-9]+)(.*)\.html$ new_arrival\.php\?date=$1&brand=$2 [QSA,L]
RewriteRule ^new_arrival-([a-z0-9-]+)(.*)\.html$ new_arrival\.php\?date=$1 [QSA,L]
nginx下URL重写代码与apache相同,修改配置后重启nginx生效