Ecshop homepage calls the sales ranking under the specified category

Source: Internet
Author: User
/* Call the sales ranking under the specified category on the homepage */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 ('ymmd', gmtime ()-365*86400 ). "'"; break; Case 2: // half a year $ top10_time = "and O. order_sn> = '". date ('ymmd', gmtime ()-180*86400 ). "'"; break; Case 3: // three months $ top10_time = "and O. order_sn> = '". date ('ymmd', gmtime ()-90*86400 ). "'"; break; Case 4: // one month $ top10_time =" Nd o. order_sn> = '". date ('ymmd', 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 "; // checks whether inventory is enabled, whether the inventory quantity is greater than 0 if ($ globals ['_ CFG'] ['use _ store'] = 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'] = $ Globa Ls ['_ 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;}/* homepage call the sales ranking under the specified category */

Template call method:

<!-- {foreach name=top from=$top_goods6 item=goods}--><div class="box"><div class="box_2">

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.