//*************************函数指定模板的调用列表*************************//
//获得相应类别的最新文章和数量(无,需添加)
$smarty->assign(‘haoyue_articles2′, index_get_new_articles(26, 3));
//获得相应类别的推荐的最新商品和数量(lib_goods.lbi)
$smarty->assign(‘haoyue_reco1′, get_category_recommend_goods(‘best’,get_children(1),’limit 4′));
// 销售排行(lib_goods.lbi)
$smarty->assign(‘top_goods_haoyue1′, get_top10(1));
//点击数排(无,需添加)
$smarty->assign(‘click_goods_haoyue1′, click_goods(1,4));
//商品输出(lib_goods.lbi)
$smarty->assign(‘haoyue_goods1′, assign_cat_goods(1,8,’wap’));
//栏目输出(lib_goods.lbi)
$smarty->assign(‘haoyue_tree1′, get_child_tree(1));
//发货查询(lib_goods.lbi)
$smarty->assign(‘invoice_list’, index_get_invoice_query()); // 发货查询
//******************************获得相应分类的最新文章列表**************************//
function index_get_new_articles($cat_list=”, $cat_num=6)
{
$sql_cat=$cat_list?’ AND ac.cat_id in(‘.$cat_list.’)':”;
$sql = ‘SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id ‘ .
‘ FROM ‘ . $GLOBALS[‘ecs’]->table(‘article’) . ‘ AS a, ‘ .
$GLOBALS[‘ecs’]->table(‘article_cat’) . ‘ AS ac’ .
‘ WHERE a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1 ‘ .$sql_cat .
‘ ORDER BY a.article_type DESC, a.add_time DESC LIMIT ‘ .$cat_num ;
$res = $GLOBALS[‘db’]->getAll($sql);
$arr = array();
foreach ($res AS $idx => $row)
{
$arr[$idx][‘id’] = $row[‘article_id’];
$arr[$idx][‘title’] = $row[‘title’];
$arr[$idx][‘short_title’] = $GLOBALS[‘_CFG’][‘article_title_length’] > 0 ?
sub_str($row[‘title’], $GLOBALS[‘_CFG’][‘article_title_length’]) : $row[‘title’];
$arr[$idx][‘cat_name’] = $row[‘cat_name’];
$arr[$idx][‘add_time’] = local_date($GLOBALS[‘_CFG’][‘date_format’], $row[‘add_time’]);
$arr[$idx][‘url’] = $row[‘open_type’] != 1 ?
build_uri(‘article’, array(‘aid’ => $row[‘article_id’]), $row[‘title’]) : trim($row[‘file_url’]);
$arr[$idx][‘cat_url’] = build_uri(‘article_cat’, array(‘acid’ => $row[‘cat_id’]), $row[‘cat_name’]);
}
return $arr;
}
//****************************销售排行榜函数******************************//
/**
* 调用当前分类的销售排行榜
*
* @access public
* @param string $cats 查询的分类
* @return array
*/
function get_top10($cats = ”)
{
$cats = get_children($cats);
$where = !empty($cats) ? “AND ($cats OR ” . get_extension_goods($cats) . “) ” : ”;
/* 排行统计的时间 */
switch ($GLOBALS[‘_CFG’][‘top10_time’])
{
case 1: // 一年
$top10_time = “AND o.order_sn >= ‘” . date(‘Ymd’, gmtime() – 365 * 86400) . “‘”;
break;
case 2: // 半年
$top10_time = “AND o.order_sn >= ‘” . date(‘Ymd’, gmtime() – 180 * 86400) . “‘”;
break;
case 3: // 三个月
$top10_time = “AND o.order_sn >= ‘” . date(‘Ymd’, gmtime() – 90 * 86400) . “‘”;
break;
case 4: // 一个月
$top10_time = “AND o.order_sn >= ‘” . date(‘Ymd’, gmtime() – 30 * 86400) . “‘”;
break;
default:
$top10_time = ”;
}
$sql = ‘SELECT g.goods_id, g.goods_name, g.shop_price, g.goods_thumb, SUM(og.goods_number) as goods_number ‘ .
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘goods’) . ‘ AS g, ‘ .
$GLOBALS[‘ecs’]->table(‘order_info’) . ‘ AS o, ‘ .
$GLOBALS[‘ecs’]->table(‘order_goods’) . ‘ AS og ‘ .
“WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 $where $top10_time ” ;
//判断是否启用库存,库存数量是否大于0
if ($GLOBALS[‘_CFG’][‘use_storage’] == 1)
{
$sql .= ” AND g.goods_number > 0 “;
}
$sql .= ‘ AND og.order_id = o.order_id AND og.goods_id = g.goods_id ‘ .
“AND (o.order_status = ‘” . OS_CONFIRMED . “‘ OR o.order_status = ‘” . OS_SPLITED . “‘) ” .
“AND (o.pay_status = ‘” . PS_PAYED . “‘ OR o.pay_status = ‘” . PS_PAYING . “‘) ” .
“AND (o.shipping_status = ‘” . SS_SHIPPED . “‘ OR o.shipping_status = ‘” . SS_RECEIVED . “‘) ” .
‘GROUP BY g.goods_id ORDER BY goods_number DESC, g.goods_id DESC LIMIT ‘ . $GLOBALS[‘_CFG’][‘top_number’];
$arr = $GLOBALS[‘db’]->getAll($sql);
for ($i = 0, $count = count($arr); $i < $count; $i++)
{
$arr[$i][‘short_name’] = $GLOBALS[‘_CFG’][‘goods_name_length’] > 0 ?
sub_str($arr[$i][‘goods_name’], $GLOBALS[‘_CFG’][‘goods_name_length’]) : $arr[$i][‘goods_name’];
$arr[$i][‘url’] = build_uri(‘goods’, array(‘gid’ => $arr[$i][‘goods_id’]), $arr[$i][‘goods_name’]);
$arr[$i][‘thumb’] = get_image_path($arr[$i][‘goods_id’], $arr[$i][‘goods_thumb’],true);
$arr[$i][‘price’] = price_format($arr[$i][‘shop_price’]);
}
return $arr;
}
//*************************调用栏目输出排行榜***********************//
/**
* 调用栏目输出排行榜
*
*/
function get_child_tree($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 ‘ .
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘category’) .
“WHERE parent_id = ‘$tree_id’ AND is_show = 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 assign_cat_goods($cat_id, $num = 0, $from = ‘web’, $order_rule = ”)
{
$children = get_children($cat_id);
$sql = ‘SELECT g.goods_id, g.goods_name, g.goods_sn, 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][‘id’] = $row[‘goods_id’];
$goods[$idx][‘name’] = $row[‘goods_name’];
$goods[$idx][‘goods_sn’] = $row[‘goods_sn’];
$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’];
$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;
return $cat;
}
//*************************按点击数输出商品*******************************//
/**
* 按点击数输出商品
*
* @access public
* @param string $goods_id
* @param array $spec_goods_attr_id
* @return array
*/
function click_goods($cat_id, $num = 0)
{
$children = get_children($cat_id);
$sql = ‘SELECT g.goods_id, g.goods_name, g.click_count, 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 BY g.click_count DESC';
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’];
$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’]);
}
return $goods;//直接返回产品信息
}
/以下为二次开发
//***********************************首页促销倒计时商品********************************//
/**
* 首页促销倒计时商品
*
* @access public
* @return array
*/
function index_promote_goods($cats = ”)
{
$time = gmtime();
$order_type = $GLOBALS[‘_CFG’][‘recommend_order’];
/* 取得促销lbi的数量限制 */
$num = get_library_number(“recommend_promotion”);
$sql = ‘SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ‘ .
“IFNULL(mp.user_price, g.shop_price * ‘$_SESSION[discount]’) AS shop_price, “.
“promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, ” .
“g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd ” .
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘goods’) . ‘ AS g ‘ .
‘LEFT JOIN ‘ . $GLOBALS[‘ecs’]->table(‘brand’) . ‘ AS b ON b.brand_id = g.brand_id ‘ .
“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 g.is_promote = 1 AND promote_start_date <= ‘$time’ AND promote_end_date >= ‘$time’ “;
$sql .= $order_type == 0 ? ‘ ORDER BY g.sort_order, g.last_update DESC’ : ‘ ORDER BY rnd';
$sql .= ” LIMIT $num “;
$result = $GLOBALS[‘db’]->getAll($sql);
$goods = array();
foreach ($result 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’];
$goods[$idx][‘brand_name’] = $row[‘brand_name’];
$goods[$idx][‘goods_style_name’] = add_style($row[‘goods_name’],$row[‘goods_name_style’]);
$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][‘short_style_name’] = add_style($goods[$idx][‘short_name’],$row[‘goods_name_style’]);
$goods[$idx][‘market_price’] = price_format($row[‘market_price’]);
$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’]);
$goods[$idx][‘sy’] =price_format(ceil($row[‘shop_price’]-$row[‘promote_price’]));
/* 促销时间倒计时 */
$time = gmtime();
if ($time >= $row[‘promote_start_date’] && $time <= $row[‘promote_end_date’])
{
$goods[$idx][‘gmt_end_time’] = local_date(‘M d, Y H:i:s’,$row[‘promote_end_date’]);
}
else
{
$goods[$idx][‘gmt_end_time’] = 0;
}
}
return $goods;
}
//**************************首页品论输出*************************************//
/**
* 首页品论输出
*
* @access public
* @param array $goods_list
* @return array
*/
function get_index_pl()
{
$arr = array();
$sql = “select c.comment_type,c.comment_id,c.id_value,c.status,c.content,c.add_time,count(c.comment_rank) as rank,g.goods_id,g.goods_name,g.goods_thumb from ” .$GLOBALS[‘ecs’]->table(‘comment’). “as c left join ” .$GLOBALS[‘ecs’]->table(‘goods’). “as g on c.id_value = g.goods_id where c.status = 1 group by g.goods_id order by c.add_time desc limit 0,6″;
$res = $GLOBALS[‘db’]->query($sql);
while ($row = $GLOBALS[‘db’]->fetchRow($res))
{
$arr[$row[‘comment_id’]][‘goods_name’] = $row[‘goods_name’];
$arr[$row[‘comment_id’]][‘url’] = build_uri(‘goods’, array(‘gid’=>$row[‘goods_id’]), $row[‘goods_name’]);
$arr[$row[‘comment_id’]][‘goods_thumb’] = get_image_path($row[‘goods_id’], $row[‘goods_thumb’], true);
$arr[$row[‘comment_id’]][‘content’] = sub_str($row[‘content’],38);
$arr[$row[‘comment_id’]][‘rank’] = $row[‘rank’];
}
return $arr;
}
//*******************************************************调用发货单查询*******************************************************//
/**
* 调用发货单查询
*
* @access private
* @return array
*/
function index_get_invoice_query()
{
$sql = ‘SELECT o.order_sn, o.invoice_no, s.shipping_code FROM ‘ . $GLOBALS[‘ecs’]->table(‘order_info’) . ‘ AS o’ .
‘ LEFT JOIN ‘ . $GLOBALS[‘ecs’]->table(‘shipping’) . ‘ AS s ON s.shipping_id = o.shipping_id’ .
” WHERE invoice_no > ” AND shipping_status = ” . SS_SHIPPED .
‘ ORDER BY shipping_time DESC LIMIT 10′;
$all = $GLOBALS[‘db’]->getAll($sql);
foreach ($all AS $key => $row)
{
$plugin = ROOT_PATH . ‘includes/modules/shipping/’ . $row[‘shipping_code’] . ‘.php';
if (file_exists($plugin))
{
include_once($plugin);
$shipping = new $row[‘shipping_code’];
$all[$key][‘invoice_no’] = $shipping->query((string)$row[‘invoice_no’]);
}
}
clearstatcache();
return $all;
}
//***************************************************获得指定分类下的推荐商品***************************************//
/**
* 获得指定分类下的推荐商品
*
* @access public
* @param string $type 推荐类型,可以是 best, new, hot, promote
* @param string $cats 分类的ID
* @param integer $brand 品牌的ID
* @param integer $min 商品价格下限
* @param integer $max 商品价格上限
* @param string $ext 商品扩展查询
* @return array
*/
function get_category_recommend_goods($type = ”, $cats = ”, $brand = 0, $min =0, $max = 0, $ext=”)
{
$brand_where = ($brand > 0) ? ” AND g.brand_id = ‘$brand'” : ”;
$price_where = ($min > 0) ? ” AND g.shop_price >= $min ” : ”;
$price_where .= ($max > 0) ? ” AND g.shop_price <= $max ” : ”;
$sql = ‘SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ‘ .
“IFNULL(mp.user_price, g.shop_price * ‘$_SESSION[discount]’) AS shop_price, “.
‘promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name ‘ .
‘FROM ‘ . $GLOBALS[‘ecs’]->table(‘goods’) . ‘ AS g ‘ .
‘LEFT JOIN ‘ . $GLOBALS[‘ecs’]->table(‘brand’) . ‘ AS b ON b.brand_id = g.brand_id ‘ .
“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 ‘ . $brand_where . $price_where . $ext;
$num = 0;
$type2lib = array(‘best’=>’recommend_best’, ‘new’=>’recommend_new’, ‘hot’=>’recommend_hot’, ‘promote’=>’recommend_promotion’);
$num = get_library_number($type2lib[$type]);
switch ($type)
{
case ‘best':
$sql .= ‘ AND is_best = 1′;
break;
case ‘new':
$sql .= ‘ AND is_new = 1′;
break;
case ‘hot':
$sql .= ‘ AND is_hot = 1′;
break;
case ‘promote':
$time = gmtime();
$sql .= ” AND is_promote = 1 AND promote_start_date <= ‘$time’ AND promote_end_date >= ‘$time'”;
break;
}
if (!empty($cats))
{
$sql .= ” AND (” . $cats . ” OR ” . get_extension_goods($cats) .”)”;
}
$order_type = $GLOBALS[‘_CFG’][‘recommend_order’];
$sql .= ($order_type == 0) ? ‘ ORDER BY g.sort_order, g.last_update DESC’ : ‘ ORDER BY RAND()';
$res = $GLOBALS[‘db’]->selectLimit($sql, $num);
$idx = 0;
$goods = 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’]);
$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’];
$goods[$idx][‘brand_name’] = $row[‘brand_name’];
$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][‘market_price’] = price_format($row[‘market_price’]);
$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’]);
$goods[$idx][‘short_style_name’] = add_style($goods[$idx][‘short_name’], $row[‘goods_name_style’]);
$idx++;
}
return $goods;
}
//***************************************************获得相应品牌和促销列表***************************************//
//品牌 <!–{foreach from=get_brands1($GLOBALS[‘smarty’]->_var[‘cat’][‘id’]) item=bchilder}–>
{$bchilder.url}”>{$bchilder.brand_name|escape:html}
<!–{/foreach}–>
//促销活动 <!– {foreach from=$promotion_info1 item=item1 key=key} –>
<!– {if $item1.type eq “snatch”} –>
<a href=”snatch.php” title=”{$lang.$item1.type}”>{$lang.snatch_promotion}</a>
<!– {elseif $item1.type eq “group_buy”} –>
<a href=”group_buy.php” title=”{$lang.$item1.type}”>{$lang.group_promotion}</a>
<!– {elseif $item1.type eq “auction”} –>
<a href=”auction.php” title=”{$lang.$item1.type}”>{$lang.auction_promotion}</a>
<!– {elseif $item1.type eq “favourable”} –>
<a href=”activity.php” title=”{$lang.$item1.type}”>{$lang.favourable_promotion}</a>
<!– {elseif $item1.type eq “package”} –>
<a href=”package.php” title=”{$lang.$item1.type}”>{$lang.package_promotion}</a>
<!– {/if} –>
{$item1.url} {$item1.act_name} {$item1.time} {$item1.act_name}
<!– {/foreach} –>
<?php
function get_brands1($cat = 0, $app = ‘brand’)
{
$children = ($cat > 0) ? ‘ AND ‘ . get_children($cat) : ”;
$sql = “SELECT b.brand_id, b.brand_name, b.brand_logo, b.brand_desc, COUNT(*) AS goods_num, IF(b.brand_logo > ”, ‘1’, ‘0’) AS tag “.
“FROM ” . $GLOBALS[‘ecs’]->table(‘brand’) . “AS b, “.
$GLOBALS[‘ecs’]->table(‘goods’) . ” AS g “.
“WHERE g.brand_id = b.brand_id $children AND 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 tag DESC, b.sort_order ASC”;
$row = $GLOBALS[‘db’]->getAll($sql);
foreach ($row AS $key => $val)
{
$row[$key][‘url’] = build_uri($app, array(‘cid’ => $cat, ‘bid’ => $val[‘brand_id’]), $val[‘brand_name’]);
$row[$key][‘brand_desc’] = htmlspecialchars($val[‘brand_desc’],ENT_QUOTES);
}
return $row;
}
//
function get_promotion_info1($goods_id = ”)
{
$snatch = array();
$group = array();
$auction = array();
$package = array();
$favourable = array();
$gmtime = gmtime();
$sql = ‘SELECT act_id, act_name, act_type, start_time, end_time FROM ‘ . $GLOBALS[‘ecs’]->table(‘goods_activity’) . ” WHERE is_finished=0 AND start_time <= ‘$gmtime’ AND end_time >= ‘$gmtime'”;
if(!empty($goods_id))
{
$sql .= ” AND goods_id = ‘$goods_id'”;
}
$res = $GLOBALS[‘db’]->getAll($sql);
foreach ($res as $data)
{
switch ($data[‘act_type’])
{
case GAT_SNATCH: //夺宝奇兵
$snatch[$data[‘act_id’]][‘act_name’] = $data[‘act_name’];
$snatch[$data[‘act_id’]][‘url’] = build_uri(‘snatch’, array(‘sid’ => $data[‘act_id’]));
$snatch[$data[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $data[‘start_time’]), local_date(‘Y-m-d’, $data[‘end_time’]));
$snatch[$data[‘act_id’]][‘sort’] = $data[‘start_time’];
$snatch[$data[‘act_id’]][‘type’] = ‘snatch';
break;
case GAT_GROUP_BUY: //团购
$group[$data[‘act_id’]][‘act_name’] = $data[‘act_name’];
$group[$data[‘act_id’]][‘url’] = build_uri(‘group_buy’, array(‘gbid’ => $data[‘act_id’]));
$group[$data[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $data[‘start_time’]), local_date(‘Y-m-d’, $data[‘end_time’]));
$group[$data[‘act_id’]][‘sort’] = $data[‘start_time’];
$group[$data[‘act_id’]][‘type’] = ‘group_buy';
break;
case GAT_AUCTION: //拍卖
$auction[$data[‘act_id’]][‘act_name’] = $data[‘act_name’];
$auction[$data[‘act_id’]][‘url’] = build_uri(‘auction’, array(‘auid’ => $data[‘act_id’]));
$auction[$data[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $data[‘start_time’]), local_date(‘Y-m-d’, $data[‘end_time’]));
$auction[$data[‘act_id’]][‘sort’] = $data[‘start_time’];
$auction[$data[‘act_id’]][‘type’] = ‘auction';
break;
case GAT_PACKAGE: //礼包
$package[$data[‘act_id’]][‘act_name’] = $data[‘act_name’];
$package[$data[‘act_id’]][‘url’] = ‘package.php#’ . $data[‘act_id’];
$package[$data[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $data[‘start_time’]), local_date(‘Y-m-d’, $data[‘end_time’]));
$package[$data[‘act_id’]][‘sort’] = $data[‘start_time’];
$package[$data[‘act_id’]][‘type’] = ‘package';
break;
}
}
$user_rank = ‘,’ . $_SESSION[‘user_rank’] . ‘,';
$favourable = array();
$sql = ‘SELECT act_id, act_range, act_range_ext, act_name, start_time, end_time FROM ‘ . $GLOBALS[‘ecs’]->table(‘favourable_activity’) . ” WHERE start_time <= ‘$gmtime’ AND end_time >= ‘$gmtime'”;
if(!empty($goods_id))
{
$sql .= ” AND CONCAT(‘,’, user_rank, ‘,’) LIKE ‘%” . $user_rank . “%'”;
}
$res = $GLOBALS[‘db’]->getAll($sql);
if(empty($goods_id))
{
foreach ($res as $rows)
{
$favourable[$rows[‘act_id’]][‘act_name’] = $rows[‘act_name’];
$favourable[$rows[‘act_id’]][‘url’] = ‘activity.php';
$favourable[$rows[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $rows[‘start_time’]), local_date(‘Y-m-d’, $rows[‘end_time’]));
$favourable[$rows[‘act_id’]][‘sort’] = $rows[‘start_time’];
$favourable[$rows[‘act_id’]][‘type’] = ‘favourable';
}
}
else
{
$sql = “SELECT cat_id, brand_id FROM ” . $GLOBALS[‘ecs’]->table(‘goods’) .
“WHERE goods_id = ‘$goods_id'”;
$row = $GLOBALS[‘db’]->getRow($sql);
$category_id = $row[‘cat_id’];
$brand_id = $row[‘brand_id’];
foreach ($res as $rows)
{
if ($rows[‘act_range’] == FAR_ALL)
{
$favourable[$rows[‘act_id’]][‘act_name’] = $rows[‘act_name’];
$favourable[$rows[‘act_id’]][‘url’] = ‘activity.php';
$favourable[$rows[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $rows[‘start_time’]), local_date(‘Y-m-d’, $rows[‘end_time’]));
$favourable[$rows[‘act_id’]][‘sort’] = $rows[‘start_time’];
$favourable[$rows[‘act_id’]][‘type’] = ‘favourable';
}
elseif ($rows[‘act_range’] == FAR_CATEGORY)
{
/* 找出分类id的子分类id */
$id_list = array();
$raw_id_list = explode(‘,’, $rows[‘act_range_ext’]);
foreach ($raw_id_list as $id)
{
$id_list = array_merge($id_list, array_keys(cat_list($id, 0, false)));
}
$ids = join(‘,’, array_unique($id_list));
if (strpos(‘,’ . $ids . ‘,’, ‘,’ . $category_id . ‘,’) !== false)
{
$favourable[$rows[‘act_id’]][‘act_name’] = $rows[‘act_name’];
$favourable[$rows[‘act_id’]][‘url’] = ‘activity.php';
$favourable[$rows[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $rows[‘start_time’]), local_date(‘Y-m-d’, $rows[‘end_time’]));
$favourable[$rows[‘act_id’]][‘sort’] = $rows[‘start_time’];
$favourable[$rows[‘act_id’]][‘type’] = ‘favourable';
}
}
elseif ($rows[‘act_range’] == FAR_BRAND)
{
if (strpos(‘,’ . $rows[‘act_range_ext’] . ‘,’, ‘,’ . $brand_id . ‘,’) !== false)
{
$favourable[$rows[‘act_id’]][‘act_name’] = $rows[‘act_name’];
$favourable[$rows[‘act_id’]][‘url’] = ‘activity.php';
$favourable[$rows[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $rows[‘start_time’]), local_date(‘Y-m-d’, $rows[‘end_time’]));
$favourable[$rows[‘act_id’]][‘sort’] = $rows[‘start_time’];
$favourable[$rows[‘act_id’]][‘type’] = ‘favourable';
}
}
elseif ($rows[‘act_range’] == FAR_GOODS)
{
if (strpos(‘,’ . $rows[‘act_range_ext’] . ‘,’, ‘,’ . $goods_id . ‘,’) !== false)
{
$favourable[$rows[‘act_id’]][‘act_name’] = $rows[‘act_name’];
$favourable[$rows[‘act_id’]][‘url’] = ‘activity.php';
$favourable[$rows[‘act_id’]][‘time’] = sprintf($GLOBALS[‘_LANG’][‘promotion_time’], local_date(‘Y-m-d’, $rows[‘start_time’]), local_date(‘Y-m-d’, $rows[‘end_time’]));
$favourable[$rows[‘act_id’]][‘sort’] = $rows[‘start_time’];
$favourable[$rows[‘act_id’]][‘type’] = ‘favourable';
}
}
}
}
$sort_time = array();
$arr = array_merge($snatch, $group, $auction, $package, $favourable);
foreach($arr as $key => $value)
{
$sort_time[] = $value[‘sort’];
}
array_multisort($sort_time, SORT_NUMERIC, SORT_DESC, $arr);
return $arr;
}
$this->assign(‘promotion_info1′, get_promotion_info1());
?>