这时候我们修改一下 写成一个函数放到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>
ecshop调用商品的购买次数方法