• yii2的多表关联和分页


     /**
         * http://localhost/src/website/legal/admin-list
         *
         */
        public  function actionAdminList()
        {
            $page = parent::getPostParam ( 'page', 1 ); // 当前页数
            Yii::$app->params ['dbSelect'] = 'main'; // 切换到 main 数据库
    
            $query = CompanyModel::find()
                //->leftJoin('p2ps-1-jooyum.legal_company', 'company.company_id = `p2ps-1-jooyum`.`legal_company`.company_id  AND `p2ps-1-jooyum`.`legal_company`.is_valid=1  ')
                ->leftJoin('p2ps-1-jooyum.legal_company_outsource  out1',' out1.`company_id`= `company`.`company_id` AND out1.class=1 ')
                ->leftJoin('p2ps-1-jooyum.legal_company_outsource  out2',' out2.`company_id`= `company`.`company_id`  AND out2.class=2 ')
                ->select(['company.company_id','company.name',"COUNT(out1.`company_id`) AS '招商自然人数'","COUNT(out2.`company_id`) AS '经销商数量'"])
                ->groupBy('`company`.`company_id2`')
                ->where(['company.is_valid'=>VALID,'company.status'=>[1,2]]);
    
    
            $countQuery = clone $query;
            $pages = new Pagination(['totalCount' => $countQuery->count()]);
            $list = $query->offset(($page-1)* Yii::$app->params ['webPageSize'])
                ->limit( Yii::$app->params ['webPageSize'])
                ->asArray()
                ->all();
    
    
    
            var_dump($list);
    
        }
  • 相关阅读:
    C语言C++编程学习:排序原理分析
    Ubuntu下开机进程管理工具sysvrcconf
    康托展开
    USACO 3.2 Magic Squares题解
    『转』ubuntu的电池管理
    poj1061青蛙的约会解题报告
    Dancing Links
    【转】史上最强vim配置文件vimrc
    四柱汉诺塔
    又遇欧拉 转载之
  • 原文地址:https://www.cnblogs.com/polax/p/10796164.html
Copyright © 2020-2023  润新知