訂單產品 明細統計 分頁

tp3.2的。mysql

很少說了,這個方法必定要列出來。mysql 的借鑑。sql

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();
}
相關文章
相關標籤/搜索