Ejemplo n.º 1
0
function get_clild_list($pid)
{
    //开始获取子分类
    $sql_sub = "select * from " . $GLOBALS['ecs']->table('category') . " where parent_id=" . $pid . " and is_show=1 order by sort_order asc, cat_id asc";
    $subres = $GLOBALS['db']->getAll($sql_sub);
    if ($subres) {
        foreach ($subres as $sidx => $subrow) {
            $children[$sidx]['id'] = $subrow['cat_id'];
            $children[$sidx]['name'] = $subrow['cat_name'];
            $children[$sidx]['url'] = build_uri('category', array('cid' => $subrow['cat_id']), $subrow['cat_name']);
            $children[$sidx]['children'] = get_clild_list($subrow['cat_id']);
        }
    } else {
        $children = null;
    }
    return $children;
}
Ejemplo n.º 2
0
/**
 * 通过传入参数的url判断是否为目录分类,从而获取子菜单
 *
 * @param string $url
 */
function get_subcate_byurl($url)
{
    $rs = strpos($url, "category");
    if ($rs !== false) {
        preg_match("/\\d+/i", $url, $matches);
        $cid = $matches[0];
        $cat_arr = array();
        $sql = "select * from " . $GLOBALS['ecs']->table('category') . " where parent_id=" . $cid . " and is_show=1";
        $res = $GLOBALS['db']->getAll($sql);
        foreach ($res as $idx => $row) {
            $cat_arr[$idx]['id'] = $row['cat_id'];
            $cat_arr[$idx]['name'] = $row['cat_name'];
            $cat_arr[$idx]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);
            $cat_arr[$idx]['children'] = get_clild_list($row['cat_id']);
        }
        return $cat_arr;
    } else {
        return false;
    }
}
Ejemplo n.º 3
0
	  </div>
      </form>

   </div>
    </div>
</div>

<div class="blank"></div>
<div class="block clearfix">
<div class="AreaL">

<div class="box_1 clearfix">
   <div class="category_all"><div class="tit">相关分类</div></div>
  <div class="category_box">
		 <?php 
$GLOBALS['smarty']->assign('clild_list', get_clild_list($GLOBALS['smarty']->_var['parent_id']));
?>
		 <dl>
		 <?php 
$_from = $this->_var['clild_list'];
if (!is_array($_from) && !is_object($_from)) {
    settype($_from, 'array');
}
$this->push_vars('', 'childer');
$this->_foreach['curn'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['curn']['total'] > 0) {
    foreach ($_from as $this->_var['childer']) {
        $this->_foreach['curn']['iteration']++;
        ?>
		 <dd><a href="<?php 
        echo $this->_var['childer']['url'];
Ejemplo n.º 4
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 is_style_show,set_cat_style,set_style_color FROM ' . $GLOBALS['ecs']->table('category') . ' WHERE cat_id =' . $cat_id;
    $cat_info = $GLOBALS['db']->getRow($sql);
    $cat['is_style_show'] = $cat_info['is_style_show'];
    $cat['set_cat_style'] = $cat_info['set_cat_style'];
    $cat['set_style_color'] = $cat_info['set_style_color'] + 1;
    $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 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]['soldnum'] = get_soldnum($row['goods_id']);
        $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']);
    }
    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_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'] = price_format($row['market_price']);
                $goods_res[$idx]['shop_price'] = price_format($row['shop_price']);
                $goods_res[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
                $goods_res[$idx]['shop_price'] = price_format($row['shop_price']);
                $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 g.goods_name,sum(og.goods_number) AS number,g.shop_price,g.goods_thumb FROM '.$GLOBALS['ecs']->table('goods').' AS g LEFT JOIN '.$GLOBALS['ecs']->table('order_goods').' AS og ON g.goods_id=og.goods_id WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND (' . $children . 'OR ' . get_extension_goods($children) . ') GROUP BY g.goods_id ORDER BY number DESC LIMIT 10';
    	$sales_volume = $GLOBALS['db']->getAll($sql);
    
    	$cat['sales_volume'] = $sales_volume;
    	
    	
    	// 获取分类下品牌
    
    			$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('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']);
    				$brands[$key]['logo'] = 'data/brandlogo/'.$val['brand_logo'];
    				// 判断品牌是否被选中 
    				if ($brand == $brands[$key]['brand_id'])
    				{
    					$brands[$key]['selected'] = 1;
    				}
    				else
    				{
    					$brands[$key]['selected'] = 0;
    				}
    			}			
    			$cat['brands'] = $brands;*/
    $cat['cat_clild'] = get_clild_list($cat_id);
    return $cat;
}
Ejemplo n.º 5
0
/**
 * 获得指定分类下的商品
 *
 * @access  public
 * @param   integer     $cat_id     分类ID
 * @param   integer     $num        数量
 * @param   string      $from       来自web/wap的调用
 * @param   string      $order_rule 指定商品排序规则
 * @param   string      $tmp        模板
 * @param   string      $nature        模板
 * @return  array
 */
function assign_cat_goods($cat_id, $num = 0, $from = 'web', $order_rule = '', $special = '', $tmp = '', $nature = '')
{
    $children = get_children($cat_id);
    /*获取显示商品条件 add by hg for date 2014-03-26 */
    $agency_where = agency_goods();
    if ($agency_where != null) {
        $agency_where = 'g.' . $agency_where;
    }
    $nature_where = '';
    if ($nature == 'new') {
        $nature_where = 'g.is_new = 1 AND ';
    } elseif ($nature == 'best') {
        $nature_where = 'g.is_best = 1 AND ';
    }
    /*end*/
    /* 特殊处理 */
    if ($special) {
        $where = '';
        //后续开发处理
    }
    $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 ' . $nature_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) . ') ';
    $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'];
        /* 折扣节省计算 by ecmoban start */
        if ($row['market_price'] > 0) {
            $discount_arr = get_discount($row['goods_id']);
            //函数get_discount参数goods_id
        }
        $goods[$idx]['zhekou'] = $discount_arr['discount'];
        //zhekou
        $goods[$idx]['jiesheng'] = $discount_arr['jiesheng'];
        //jiesheng
        /* 折扣节省计算 by ecmoban end */
        $goods[$idx]['comments_number'] = $row['comments_number'];
        $goods[$idx]['sales_volume'] = $row['sales_volume'];
        $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;
    /* 获取分类下品牌 */
    $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'], 'price_min' => $price_min, 'price_max' => $price_max, 'filter_attr' => $filter_attr_str), $val['brand_name']);
        $brands[$key]['logo'] = 'data/brandlogo/' . $val['brand_logo'];
        /* 判断品牌是否被选中 */
        if ($brand == $brands[$key]['brand_id']) {
            $brands[$key]['selected'] = 1;
        } else {
            $brands[$key]['selected'] = 0;
        }
    }
    $cat['brands'] = $brands;
    $cat['cat_clild'] = get_clild_list($cat_id);
    return $cat;
}