ecshop 首頁調用指定分類下的銷售排行

來源:互聯網
上載者:User

標籤:des   style   class   blog   code   tar   

/*首頁調用指定分類下的銷售排行*/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}-->

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.