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']);
这样,您在模版中可以调用数据了,变量名为: $goods.buy_num
/* 修正商品图片 */
$row['goods_img'] = get_image_path($goods_id, $row['goods_img']);
在其下方添加
/*显示商品销量*/
$row['buy_num'] = ec_buysum($row['goods_id']);
就可以了,然后在goods.dwt模板文件中适当的位置调用数据 ,变量名为: $goods.buy_num
$row['buy_num'] = ec_buysum($row['goods_id']);
然后goods_list.lbi库文件中合适的位置使用 $goods.buy_num 版权声明: 本站资源均来自互联网或会员发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!
转载请注明: ecshop商品销量显示月销量已销售或总销量的方法