服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > ecshop教程 >

获取ecshop某个商品的订单信息或销量

时间:2015-10-15 06:12来源:未知 作者:最模板 点击:
获取ecshop某个商品的订单信息或销量,把以下代码放到 lib_main.php 1.统计某个下单商品的人数 function get_goods_ordernum($goods_id){ $sql = select count(goods_number) from . $GLOBALS[ecs]-table(order_goods) . AS

获取ecshop某个商品的订单信息或销量,把以下代码放到 lib_main.php

1.统计某个下单商品的人数

function get_goods_ordernum($goods_id){
 
        $sql = "select count(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 in(1,5) " ;//o.order_status=1 表示确认了的订单才算 
return $GLOBALS['db']->getAll($sql); 
 
}

注意:如果有3个人下单,数量是5 ,那返回结果是3

2.统计某个下单商品的销量,

function get_goods_ordernum($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 in(1,5) " ;//o.order_status=1 表示确认了的订单才算 
return $GLOBALS['db']->getAll($sql); 
 
}

注意:如果有3个人下单,数量是5 ,那返回结果是5

3.统计某个商品商品订单的详细信息

 
function get_goods_ordernum($goods_id){
 
        $sql = "select * 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 in(1,5) " ;//o.order_status=1 表示确认了的订单才算 
return $GLOBALS['db']->getAll($sql); 
 
}
 
order_status in(1,5)   1表示去人订单,5表示已分单


完整php代码
 
/*获取有效订单信息*/
function sales_goods_order($goods_id){    
    $sql = "select * 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 in(1,5) " ;//o.order_status=1 1表示确认订单,5已分单
return $GLOBALS['db']->getAll($sql); 
}
/*获取某个商品有效订单  销量统计*/
function sales_goods_number($goods_id){    
    $arr = sales_goods_order($goods_id);
    //return array_sum($arr['goods_number']);
    foreach($arr as $k=>$v){
        $val[] = $v['goods_number'];    
    }
    $count = array_sum($val);
    if(!empty($count)){
        return $count;    
    }else{
        return '0';    
    }
}
 

(责任编辑:最模板)
顶一下
(1)
50%
踩一下
(1)
50%
------分隔线----------------------------