zoukankan      html  css  js  c++  java
  • ecshop在商品列表显示购买记录

    遇到这样的需求不用自己写代码,很多都是官方写好的,商品详细页本来就有个购买记录,我们打开goods.php就会看到

     

    ------------------------------------------------------------------------------------------------------------------------

          $sql = 'SELECT count(*) ' .


                   'FROM ' . $ecs->table('order_info') . ' AS oi LEFT JOIN ' . $ecs->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $ecs->table('order_goods') . ' AS og ' .


                   'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $goods_id;


            $count = $db->getOne($sql);

     

    ------------------------------------------------------------------------------------------------------------------------

     

    这时候我们修改一下 写成一个函数放到lib_goods.php 这样就可以随便调用了

     

    ------------------------------------------------------------------------------------------------------------------------

    /**获得购买次数*/

    function get_goods_ordernum($goods_id)

    {
     
            $sql = 'SELECT count(*) ' .

                   'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS oi LEFT JOIN ' . $GLOBALS['ecs']->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $GLOBALS['ecs']->table('order_goods') . ' AS
    og ' .

                   'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $goods_id;

            $count = $GLOBALS['db']->getOne($sql);

      return $count;
     

    }

     

    ------------------------------------------------------------------------------------------------------------------------

    函数写好我们下来开始调用。比如我们在最新商品下显示购买记录

    在lib_goods.php找到get_recommend_goods这个函数 342行左右加入
     
     
    $goods[$idx]['order_num']    = get_goods_ordernum($row['goods_id']);
     
     
     
    到此程序部分完成
     
    -----------------------------------------------------------------------------------------------------------------------------
     
     
     
    模板部分是:<span style="color:#0066FF;">{if $goods.order_num}已经有{$goods.order_num}人购买过{else}暂无人购买{/if}</span>

    作者:沐雪
    文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。本文版权归作者和博客园共有,如需转载恳请注明。
    如果您觉得阅读这篇博客让你有所收获,请点击右下方【推荐】
    找一找教程网-随时随地学软件编程 http://www.zyiz.net/

  • 相关阅读:
    yanghui杨辉三角--(一维数组
    yanghui杨辉三角--(一维数组)探索1 2
    yanghui杨辉三角--(二维数组
    Fiber VS Coroutine VS Green Thread
    Java8-Reference
    Boolean
    Java-相等
    java.lang.Cloneable
    java.lang.CharSequence
    java.lang.AutoCloseable
  • 原文地址:https://www.cnblogs.com/puzi0315/p/2644795.html
Copyright © 2011-2022 走看看