|
|
<?php
|
|
|
|
|
|
define('IN_ASC', true);
|
|
|
|
|
|
require(dirname(__FILE__) . '/includes/init.php');
|
|
|
|
|
|
if ((DEBUG_MODE & 2) != 2)
|
|
|
{
|
|
|
$smarty->caching = true;
|
|
|
}
|
|
|
|
|
|
/*------------------------------------------------------ */
|
|
|
//-- INPUT
|
|
|
/*------------------------------------------------------ */
|
|
|
|
|
|
/* 獲得請求的分類 ID */
|
|
|
if (isset($_REQUEST['id']))
|
|
|
{
|
|
|
$cat_id = intval($_REQUEST['id']);
|
|
|
}
|
|
|
elseif (isset($_REQUEST['category']))
|
|
|
{
|
|
|
$cat_id = intval($_REQUEST['category']);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
/* 如果分類ID為0,則返回首頁 */
|
|
|
ecs_header("Location: ./\n");
|
|
|
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
|
|
|
/* 初始化分頁信息 */
|
|
|
$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);
|
|
|
$filter_attr_sum = 0;
|
|
|
foreach($filter_attr as $value)
|
|
|
{
|
|
|
$filter_attr_sum += $value;
|
|
|
}
|
|
|
|
|
|
|
|
|
/* 排序、顯示方式以及類型 */
|
|
|
$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' ? 'sales_volume_base' : ($_CFG['sort_order_type'] == '1' ? 'sales_volume_base' : 'last_update');
|
|
|
|
|
|
$sort = (isset($_REQUEST['sort']) && in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'shop_price', 'last_update','sales_volume_base','comments_number'))) ? 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($cat_id . '-' . $display . '-' . $sort .'-' . $order .'-' . $page . '-' . $size . '-' . $_SESSION['user_rank'] . '-' .
|
|
|
$_CFG['lang'] .'-'. $brand. '-' . $price_max . '-' .$price_min . '-' . $filter_attr_str));
|
|
|
|
|
|
if (!$smarty->is_cached('category.dwt', $cache_id) || 1==1)
|
|
|
{
|
|
|
/* 如果頁面沒有被緩存則重新獲取頁面的內容 */
|
|
|
|
|
|
$children = get_children($cat_id);
|
|
|
|
|
|
$cat = get_cat_info($cat_id); // 獲得分類的相關信息
|
|
|
|
|
|
if (!empty($cat))
|
|
|
{
|
|
|
$smarty->assign('keywords', htmlspecialchars($cat['keywords']));
|
|
|
$smarty->assign('description', htmlspecialchars($cat['cat_desc']));
|
|
|
$smarty->assign('cat_style', htmlspecialchars($cat['style']));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
/* 如果分類不存在則返回首頁 */
|
|
|
ecs_header("Location: ./\n");
|
|
|
|
|
|
exit;
|
|
|
}
|
|
|
|
|
|
/* 賦值固定內容 */
|
|
|
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 ($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);
|
|
|
|
|
|
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'] . ' - ' . $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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$price_grade[0]['start'] = 0;
|
|
|
$price_grade[0]['end'] = 0;
|
|
|
$price_grade[0]['price_range'] = $_LANG['all_attribute'];
|
|
|
$price_grade[0]['url'] = build_uri('category', array('cid'=>$cat_id, 'bid'=>$brand, 'price_min'=>0, 'price_max'=> 0, 'filter_attr'=>$filter_attr_str), $cat['cat_name']);
|
|
|
$price_grade[0]['selected'] = empty($price_max) ? 1 : 0;
|
|
|
|
|
|
$smarty->assign('price_grade', $price_grade);
|
|
|
|
|
|
}
|
|
|
|
|
|
/* 品牌篩選 */
|
|
|
|
|
|
$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 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";
|
|
|
|
|
|
$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('category', array('cid' => $cat_id, 'bid' => $val['brand_id'], 'price_min'=>$price_min, 'price_max'=> $price_max, 'filter_attr'=>$filter_attr_str), $cat['cat_name']);
|
|
|
|
|
|
/* 判斷品牌是否被選中 */
|
|
|
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('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++) //獲取當前url中已選擇屬性的值,並保留在數組中
|
|
|
{
|
|
|
$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;
|
|
|
|
|
|
$i = 0;//zhouhuan
|
|
|
foreach ($attr_list as $k => $v)
|
|
|
{
|
|
|
$temp_key = $k + 1;
|
|
|
$temp_arrt_url_arr[$key] = $v['goods_id']; //為url中代表當前篩選屬性的位置變量賦值,並生成以‘.’分隔的篩選屬性字符串
|
|
|
$temp_arrt_url = implode('.', $temp_arrt_url_arr);
|
|
|
|
|
|
$all_attr_list[$key]['attr_list'][$temp_key]['attr_value'] = $v['attr_value'];
|
|
|
$all_attr_list[$key]['attr_list'][$temp_key]['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']);
|
|
|
//zhouhuan
|
|
|
$all_attr_list[$key]['attr_list'][$temp_key]['del_url'] = $all_attr_list[$key]['attr_list'][0]['url'];
|
|
|
|
|
|
if (!empty($filter_attr[$key]) AND $filter_attr[$key] == $v['goods_id'])
|
|
|
{
|
|
|
$i++;//zhouhuan
|
|
|
$all_attr_list[$key]['attr_list'][$temp_key]['selected'] = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$all_attr_list[$key]['attr_list'][$temp_key]['selected'] = 0;
|
|
|
}
|
|
|
}
|
|
|
//zhouhuan
|
|
|
if($i > 0)
|
|
|
{
|
|
|
$all_attr_list[$key]['selected'] = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$all_attr_list[$key]['selected'] = 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$smarty->assign('filter_attr_list', $all_attr_list);
|
|
|
|
|
|
/* 擴展商品查詢條件 */
|
|
|
if (!empty($filter_attr))
|
|
|
{
|
|
|
$ext_sql = "SELECT DISTINCT(b.goods_id) FROM " . $ecs->table('goods_attr') . " AS a, " . $ecs->table('goods_attr') . " AS b " . "WHERE ";
|
|
|
$ext_group_goods = array();
|
|
|
|
|
|
foreach ($filter_attr AS $k => $v) // 查出符合所有篩選屬性條件的商品id */
|
|
|
{
|
|
|
if (is_numeric($v) && $v !=0 &&isset($cat_filter_attr[$k]))
|
|
|
{
|
|
|
$sql = $ext_sql . "b.attr_value = a.attr_value AND b.attr_id = " . $cat_filter_attr[$k] ." AND a.goods_attr_id = " . $v;
|
|
|
$ext_group_goods = $db->getColCached($sql);
|
|
|
$ext .= ' AND ' . db_create_in($ext_group_goods, 'g.goods_id');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
assign_template('c', array($cat_id));
|
|
|
|
|
|
$position = assign_ur_here($cat_id, $brand_name);
|
|
|
$smarty->assign('page_title', $position['title']); // 頁面標題
|
|
|
$smarty->assign('ur_here', $position['ur_here']); // 當前位置
|
|
|
|
|
|
$smarty->assign('cat_info', $cat); // 當前分類信息
|
|
|
|
|
|
$smarty->assign('filter_attr_sum', $filter_attr_sum); //zhouhuan
|
|
|
$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);
|
|
|
|
|
|
if ($brand > 0)
|
|
|
{
|
|
|
$arr['all'] = array('brand_id' => 0,
|
|
|
'brand_name' => $GLOBALS['_LANG']['all_goods'],
|
|
|
'brand_logo' => '',
|
|
|
'goods_num' => '',
|
|
|
'url' => build_uri('category', array('cid'=>$cat_id), $cat['cat_name'])
|
|
|
);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$arr = array();
|
|
|
}
|
|
|
|
|
|
$brand_list = array_merge($arr, get_brands($cat_id, 'category'));
|
|
|
|
|
|
$smarty->assign('data_dir', DATA_DIR);
|
|
|
$smarty->assign('brand_list', $brand_list);
|
|
|
$smarty->assign('promotion_info', get_promotion_info());
|
|
|
|
|
|
|
|
|
/* 調查 */
|
|
|
$vote = get_vote();
|
|
|
if (!empty($vote))
|
|
|
{
|
|
|
$smarty->assign('vote_id', $vote['id']);
|
|
|
$smarty->assign('vote', $vote['content']);
|
|
|
}
|
|
|
|
|
|
$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('list_count', $count);
|
|
|
$smarty->assign('category', $cat_id);
|
|
|
$smarty->assign('script_name', 'category');
|
|
|
|
|
|
assign_pager('category', $cat_id, $count, $size, $sort, $order, $page, '', $brand, $price_min, $price_max, $display, $filter_attr_str); // 分頁
|
|
|
assign_dynamic('category'); // 動態內容
|
|
|
}
|
|
|
|
|
|
$smarty->display('category.dwt', $cache_id);
|
|
|
|
|
|
/*------------------------------------------------------ */
|
|
|
//-- PRIVATE FUNCTION
|
|
|
/*------------------------------------------------------ */
|
|
|
|
|
|
/**
|
|
|
* 獲得分類的信息
|
|
|
*
|
|
|
* @param integer $cat_id
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
function get_cat_info($cat_id)
|
|
|
{
|
|
|
$row = $GLOBALS['db']->getRow('SELECT cat_name, keywords, cat_id,cat_desc, style, grade, filter_attr, parent_id FROM ' . $GLOBALS['ecs']->table('category') .
|
|
|
" WHERE cat_id = '$cat_id'");
|
|
|
|
|
|
$row['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
|
|
|
|
|
|
return $row;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 獲得分類下的商品
|
|
|
*
|
|
|
* @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 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.sales_volume_base, g.comments_number, 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']]['sales_volume_base'] = get_sales_counts($row['goods_id']);
|
|
|
$arr[$row['goods_id']]['comments_number'] = $row['comments_number'];
|
|
|
$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 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");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取得最近的上級分類的grade值
|
|
|
*
|
|
|
* @access public
|
|
|
* @param int $cat_id //當前的cat_id
|
|
|
*
|
|
|
* @return int
|
|
|
*/
|
|
|
function get_parent_grade($cat_id)
|
|
|
{
|
|
|
static $res = NULL;
|
|
|
|
|
|
if ($res === NULL)
|
|
|
{
|
|
|
$data = read_static_cache('cat_parent_grade');
|
|
|
if ($data === false)
|
|
|
{
|
|
|
$sql = "SELECT parent_id, cat_id, grade ".
|
|
|
" FROM " . $GLOBALS['ecs']->table('category');
|
|
|
$res = $GLOBALS['db']->getAll($sql);
|
|
|
write_static_cache('cat_parent_grade', $res);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
$res = $data;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!$res)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
$parent_arr = array();
|
|
|
$grade_arr = array();
|
|
|
|
|
|
foreach ($res as $val)
|
|
|
{
|
|
|
$parent_arr[$val['cat_id']] = $val['parent_id'];
|
|
|
$grade_arr[$val['cat_id']] = $val['grade'];
|
|
|
}
|
|
|
|
|
|
while ($parent_arr[$cat_id] >0 && $grade_arr[$cat_id] == 0)
|
|
|
{
|
|
|
$cat_id = $parent_arr[$cat_id];
|
|
|
}
|
|
|
|
|
|
return $grade_arr[$cat_id];
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|