遇到这样的需求不用自己写代码,很多都是官方写好的,商品详细页本来就有个购买记录,我们打开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)
{
'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
'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;
}
------------------------------------------------------------------------------------------------------------------------
函数写好我们下来开始调用。比如我们在最新商品下显示购买记录