• 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';    
        }
    }
  • 相关阅读:
    没有纳入spring管理的类如何注入spring管理的对象
    Servlet里面url-pattern的通配符*的使用规则
    【转】request和response的页面跳转传参
    Mybatis-Generator逆向生成Po,Mapper,XMLMAPPER(一)
    Sae上传war包找不到编译文件
    Maven配置中scope说明
    Spring配置中的classpath和classpath*的区别
    国内的ntp服务器
    U盘拷贝文件大小有限制吗?
    Genymotion安装教程
  • 原文地址:https://www.cnblogs.com/wesky/p/4861883.html
Copyright © 2020-2023  润新知