Ecshop教程:获取某个商品的订单信息或销量

很多人在php空间中建立了一个网站后,都会因为网站后期需要,想要查看单个某一商品的订单信息或者是销售量。类似网站后台报表统计,有个这个的话,对于商品的销量和订单信息就有了一个很好的统计了。因此,要获取ecshop某个商品的订单信息或销量,可以把以下这段代码放到 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 ,那返回结果是32.统计某个下单商品的销量,
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 ,那返回结果是53.统计某个商品商品订单的详细信息,在制作相应ecshop商城模板时就可以用到这个数据
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'; }}
高速度 主机相关文章推荐阅读:ECSHOP如何手动清除缓存ECSHOP测试数据通过SQL语句清除ECSHOP教程:后台管理显示扩展分类

本文地址:https://www.gaosudu.com/ecshop/21083.html