首页 > 网站 > 建站经验 > 正文

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

2024-04-25 20:43:33
字体:
来源:转载
供稿:网友

获取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.统计某个商品商品订单的详细信息,在制作相应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';

}

}

以上就是本文章的内容,希望对大家有所帮助

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表