function ec_buysum($goods_id){
$LMonth=strtotime("last month"); //前一個月
$nowTime=time(); //當前時間
$sql="select sum(goods_number) from " . $GLOBALS['ecs']->table('order_goods') . " AS g ,".$GLOBALS['ecs']->table('order_info') . " AS o WHERE o.order_id=g.order_id and g.goods_id = ".$goods_id." and o.pay_status=2 and o.add_time >= ".$LMonth." and o.add_time <= ".$nowTime." group by g.goods_id";
if (($GLOBALS['db']->getOne($sql)) == ""){
return "0";
}
else
{
return $GLOBALS['db']->getOne($sql);
}}
總銷量:
function ec_buysum($goods_id){
$sql = "select sum(goods_number) from " . $GLOBALS['ecs']->table('order_goods') . " AS g ,".$GLOBALS['ecs']->table('order_info') . " AS o WHERE o.order_id=g.order_id and g.goods_id = " . $goods_id . " and o.order_status=5 " ;
if (($GLOBALS['db']->getOne($sql)) == "")
{
return "0";
}
else
{
return $GLOBALS['db']->getOne($sql);
}}
然后,還是在同一個文件里,找到(大約317行)
$goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] :'';
在其下面添加如下代碼:
$goods[$idx]['buy_num']= ec_buysum($row['goods_id']);
這樣,您在模版中可以調(diào)用數(shù)據(jù)了,變量名為: $goods.buy_num
/* 修正商品圖片 */
???????$row['goods_img'] = get_image_path($goods_id, $row['goods_img']);
在其下方添加
/*顯示商品銷量*/
$row['buy_num'] = ec_buysum($row['goods_id']);
就可以了,然后在goods.dwt模板文件中適當?shù)奈恢谜{(diào)用數(shù)據(jù) ,變量名為: $goods.buy_num
$row['buy_num'] = ec_buysum($row['goods_id']);
然后goods_list.lbi庫文件中合適的位置使用 $goods.buy_num 版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: ecshop商品銷量顯示月銷量已銷售或總銷量的方法