caching = true;
}
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";
if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
$Loaction = 'mobile/category.php?c_id='.$_REQUEST['id'];
if (!empty($Loaction))
{
ecs_header("Location: $Loaction\n");
exit;
}
}
/*------------------------------------------------------ */
//-- 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);
/* 鎺掑簭銆佹樉绀烘柟寮忎互鍙婄被鍨� */
$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'))) ? 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
/*------------------------------------------------------ */
/* 椤甸潰鐨勭紦瀛業D */
$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))
{
/* 濡傛灉椤甸潰娌℃湁琚紦瀛樺垯閲嶆柊鑾峰彇椤甸潰鐨勫唴瀹� */
$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']));
$smarty->assign('cat_name', htmlspecialchars($cat['cat_name']));
$smarty->assign('cat_parent_id', $cat['parent_id']); //鏄惁椤剁骇鍒嗙被
$smarty->assign('is_wshow', $cat['is_wshow']);
}
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;
foreach ($attr_list as $k => $v)
{
$temp_key = $k + 1;
$temp_arrt_url_arr[$key] = $v['goods_id']; //涓簎rl涓唬琛ㄥ綋鍓嶇瓫閫夊睘鎬х殑浣嶇疆鍙橀噺璧嬪€�,骞剁敓鎴愪互鈥�.鈥欏垎闅旂殑绛涢€夊睘鎬у瓧绗︿覆
$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']);
if (!empty($filter_attr[$key]) AND $filter_attr[$key] == $v['goods_id'])
{
$all_attr_list[$key]['attr_list'][$temp_key]['selected'] = 1;
}
else
{
$all_attr_list[$key]['attr_list'][$temp_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);
/* 椤甸潰鏍囬 edit by lepor.x 2016 08 31*/
if(!empty($cat['cat_title'])){
$position['title'] = $cat['cat_title'] . '_' . $GLOBALS['_CFG']['shop_title'];
}
/* end */
$smarty->assign('page_title', $position['title']); // 椤甸潰鏍囬
$smarty->assign('ur_here', $position['ur_here']); // 褰撳墠浣嶇疆
$smarty->assign('categories', get_categories_tree($cat_id)); // 鍒嗙被鏍�
$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
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));
$smarty->assign('new_goods', get_category_recommend_goods('new', $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');
/* 鑾峰緱椤剁骇鍒嗙被 */
$cat_arr = get_parent_cats($cat_id);
foreach ($cat_arr AS $val)
{
$topcat_id=$val['cat_id'];
$topcat_name=$val['cat_name'];
}
$smarty->assign('topcat_id', $topcat_id);
$smarty->assign('topcat_name', $topcat_name);
$smarty->assign('ecy_adpicr', get_ecy_classpic($cat_id,3));
$smarty->assign('ecy_adflash', get_ecy_classpic($cat_id,2));
$smarty->assign('ecy_adpicl', get_ecy_classpic($cat_id,4));
$smarty->assign('ecy_adtext', get_ecy_classpic($cat_id,6));
assign_pager('category', $cat_id, $count, $size, $sort, $order, $page, '', $brand, $price_min, $price_max, $display, $filter_attr_str); // 鍒嗛〉
assign_dynamic('category'); // 鍔ㄦ€佸唴瀹�
}
if ($cat['is_wshow'] ==1 and $cat['parent_id'] == 0){
$smarty->display('channel.dwt', $cache_id);
}
else{
$smarty->display('category.dwt', $cache_id);
}
/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */
/**
* 鑾峰緱鍒嗙被鐨勪俊鎭�
*
* @param integer $cat_id
*
* @return void
*/
function get_cat_info($cat_id)
{
return $GLOBALS['db']->getRow('SELECT cat_name, keywords, cat_desc, cat_title, style, grade, filter_attr, parent_id,is_wshow FROM ' . $GLOBALS['ecs']->table('category') .
" WHERE cat_id = '$cat_id'");
}
/**
* 鑾峰緱鍒嗙被涓嬬殑鍟嗗搧
*
* @access public
* @param string $children
* @return array
*/
function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order)
{
if($sort=='goods_id'){
$sort = "sort_order";
$order = "asc";
}
$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, g.test_one, g.test_two, g.test_three ' .
'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']);
if($row['shop_price'] > 0){
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
}else{
$qq = explode(",",$GLOBALS['_CFG']['qq']);
$arr[$row['goods_id']]['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']);
$arr[$row['goods_id']]['test_one'] = $row['test_one'];
$arr[$row['goods_id']]['test_two'] = $row['test_two'];
$arr[$row['goods_id']]['test_three'] = $row['test_three'];
}
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");
}
/**
* 鍙栧緱鏈€杩戠殑涓婄骇鍒嗙被鐨刧rade鍊�
*
* @access public
* @param int $cat_id //褰撳墠鐨刢at_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];
}
/**
* 鑾峰緱鎸囧畾鍟嗗搧鍒嗙被鍥剧墖
*/
function get_ecy_classpic($cat,$pclassid)
{
$sql = "SELECT brand_name,brand_logo,site_url,sort_order,brand_desc FROM ".$GLOBALS['ecs']->table('ecyclass')." WHERE porduct_id=$cat and pclassid=$pclassid and is_show=1 ORDER BY sort_order ASC";
$row = $GLOBALS['db']->getAll($sql);
foreach ($row AS $key => $val)
{
$row[$key]['brand_name'] = $val['brand_name'];
$row[$key]['site_url'] = $val['site_url'];
$row[$key]['brand_logo'] = $val['brand_logo'];
}
return $row;
}
function get_child_treec($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,is_wshow ' .
'FROM ' . $GLOBALS['ecs']->table('category') .
"WHERE parent_id = '$tree_id' AND is_show = 1 AND is_wshow=1 ORDER BY sort_order ASC, cat_id ASC";
$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']);
if (isset($row['cat_id']) != NULL)
{
$three_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
}
}
}
return $three_arr;
}
/**
* 鑾峰緱鎸囧畾鍒嗙被涓嬬殑鍟嗗搧
*
* @access public
* @param integer $cat_id 鍒嗙被ID
* @param integer $num 鏁伴噺
* @param string $from 鏉ヨ嚜web/wap鐨勮皟鐢�
* @param string $order_rule 鎸囧畾鍟嗗搧鎺掑簭瑙勫垯
* @return array
*/
function ecy_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.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, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, g.test_one, g.test_two, g.test_three ' .
"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'] = '';
}
$watermark_img = '';
if ($promote_price != 0)
{
$watermark_img = "watermark_promote_small";
}
if ($row['is_new'] != 0)
{
$watermark_img1 = "watermark_new_small";
$goods[$idx]['watermark_img1'] = $watermark_img1;
}
if ($row['is_best'] != 0)
{
$watermark_img2 = "watermark_best_small";
$goods[$idx]['watermark_img2'] = $watermark_img2;
}
if ($row['is_hot'] != 0)
{
$watermark_img3 = 'watermark_hot_small';
$goods[$idx]['watermark_img3'] = $watermark_img3;
}
if ($watermark_img != '')
{
$goods[$idx]['watermark_img'] = $watermark_img;
}
$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'];
if($row['shop_price'] > 0){
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
}else{
$qq = explode(",",$GLOBALS['_CFG']['qq']);
$goods[$idx]['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]['test_one'] = $row['test_one'];
$goods[$idx]['test_two'] = $row['test_two'];
$goods[$idx]['test_three'] = $row['test_three'];
}
return $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;
return $cat;
}
?>