/** * 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); }