订单产品 明细统计 分页

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

tp3.2的。

不多说了,这个方法一定要列出来。mysql 的借鉴。

public function product_list(){
    $condition['status']=array('gt',2);
    $productOb=M('s_order_product');
    $count=$productOb
        ->field("product_id,typeid,status,name,p.product_num,sum(p.product_num) as g_num")
        ->alias('p')
        ->join('LEFT JOIN yu_s_order o ON o.id=p.order_id')
        ->join('LEFT JOIN yu_s_product c ON c.id=p.product_id')
        ->where($condition)
        ->count('DISTINCT product_id');
    $page=new Page($count,20);
    $page->setConfig('prev','上一页');
    $page->setConfig('next','下一页');

    $products=$productOb
            ->field("product_id,typeid,status,name,p.product_num,sum(p.product_num) as g_num")
            ->alias('p')
            ->join('LEFT JOIN yu_s_order o ON o.id=p.order_id')
            ->join('LEFT JOIN yu_s_product c ON c.id=p.product_id')
            ->where($condition)
            ->group('product_id')
            ->order('g_num desc')
            ->limit($page->firstRow.','.$page->listRows)
            ->select();
    $this->assign(array(
        'list'=>$products,
        'count'=>$count,
        'page'=>$page->show()
    ));
    $this->display();
}

转载于:https://my.oschina.net/u/3660147/blog/1552775

你可能感兴趣的:(订单产品 明细统计 分页)