在商品详情页显示累计售出量
1、对于交易量很大的网站,每个商品的“累计售出”个数可能随时都在变化,
所以本方法使用了 insert 函数来实现,以达到能体现实时最新的销售量(也就是销售量不会被缓存)
2、修改 includes/lib_insert.php 文件
在最下面增加一个函数
/**
* 显示销售排行
*
* @access public
* @parameter string 参数由$arr['type']来决定,如果name为空,那么输出所有,否者按照Y,M,D来决定输出年销量,月销量,日销量
* @return string
* @author By Caige in stu 2013.1.28
*/
function insert_goods_sale_num($arr)
{
$timeLimit = "";
//echo $arr['type'];
if($arr['type']){
switch($arr['type']){
case "Y": $timeLimit = strtotime("-1 years"); break;
case "M": $timeLimit = strtotime('-1 months'); break;
case "D": $timeLimit = strtotime('-1 days'); break;
default : $timeLimit ="";
}
$timeLimit = " AND confirm_time between ".$timeLimit." and ".strtotime('now').";";
}
//echo '<br/>'.$timeLimit.'<br/>';
$sql = 'SELECT SUM(goods_number) AS number ' .
' FROM ' . $GLOBALS['ecs']->table('order_goods') ." AS og , " . $GLOBALS['ecs']->table('order_info') ." AS o ".
" WHERE og.order_id = o.order_id and og.goods_id=".$arr['goods_id'].$timeLimit;
//echo '<br/>'.$sql.'<br/>';
$row = $GLOBALS['db']->GetRow($sql);
if ($row)
{
$number = intval($row['number']);
}
else
{
$number = 0;
}
return $number;
}
3、在 goods.dwt 下
加上
<p><span>日销量:</strong>{insert name='goods_sale_num' goods_id=$goods.goods_id type='D'} </p>
<p><span>月销量:</strong>{insert name='goods_sale_num' goods_id=$goods.goods_id type='M'} </p>
<p><span>年销量:</strong>{insert name='goods_sale_num' goods_id=$goods.goods_id type='Y'} </p>
神奇的销量出现了