/*首页调用指定分类下的销售排行*/ function get_cats_top10($cat = ‘‘) { $sql = ‘SELECT cat_id, cat_name ‘ . ‘FROM ‘ . $GLOBALS[‘ecs‘]->table(‘category‘) . "WHERE parent_id = ‘$cat‘ ORDER BY sort_order ASC, cat_id ASC LIMIT 3"; $res = $GLOBALS[‘db‘]->getAll($sql); foreach ($res AS $row) { $cats = get_children($row[‘cat_id‘]); $cat_arr[$row[‘cat_id‘]][‘name‘] = mb_substr($row[‘cat_name‘] , 0, 10 ,"gbk"); $cat_arr[$row[‘cat_id‘]][‘id‘] = $row[‘cat_id‘]; $where = !empty($cats) ? "AND ($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_brief, g.goods_name, g.goods_img, g.goods_thumb, g.shop_price, g.promote_price, g.promote_start_date, g.promote_end_date, 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 . "‘ " . "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); foreach ($arr as $row1) { $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘short_name‘] = $GLOBALS[‘_CFG‘][‘goods_name_length‘] > 0 ? sub_str($row1[‘goods_name‘], $GLOBALS[‘_CFG‘][‘goods_name_length‘]) : $row1[‘goods_name‘]; $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘url‘] = build_uri(‘goods‘, array(‘gid‘ => $row1[‘goods_id‘]), $row1[‘goods_name‘]); $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘goods_img‘] = get_image_path($row1[‘goods_id‘], $row1[‘goods_img‘]); $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘goods_thumb‘] = get_image_path($row1[‘goods_id‘], $row1[‘goods_thumb‘]); $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘shop_price‘] = price_format($row1[‘shop_price‘]); $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘goods_name‘] = $row1[‘goods_name‘]; $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘goods_name‘] = $row1[‘goods_name‘]; $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘goods_brief‘] = $row1[‘goods_brief‘]; if ($row1[‘promote_price‘] > 0) { $promote_price = bargain_price($row1[‘promote_price‘], $row1[‘promote_start_date‘], $row1[‘promote_end_date‘]); $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘promote_price‘] = $promote_price > 0 ? price_format($promote_price) : ‘‘; } else { $cat_arr[$row[‘cat_id‘]][‘children‘][$row1[‘goods_id‘]][‘promote_price‘] = ‘‘; } } } return $cat_arr; } /*首页调用指定分类下的销售排行*/
模板调用处方法:
<!-- {foreach name=top from=$top_goods6 item=goods}--> <div class="box"> <div class="box_2"> <h3><span>{$goods.name}</span></h3> <div class="top10List clearfix"> <!-- {foreach from=$goods.children item=children name=top_goods}--> <ul class="clearfix"> <img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration" /> <!-- {if $smarty.foreach.top_goods.iteration<4}--> <li class="topimg"> <a href="{$children.url}"><img src="{$children.goods_thumb}" alt="{$children.name|escape:html}" class="samllimg" /></a> </li> <!-- {/if} --> <li {if $smarty.foreach.top_goods.iteration<4}class="iteration1"{/if}> <a href="{$children.url}" title="{$children.name|escape:html}">{$children.short_name}</a><br /> {$lang.shop_price}<font class="f1">{$children.price}</font><br /> </li> </ul> <!--{/foreach}--> </div> </div> </div> <div class="blank5"></div> <!--{/foreach}-->
ecshop 首页调用指定分类下的销售排行
时间: 2024-12-22 19:25:43