model = new \app\common\model\ArticlePaper(); } public function queryPaperList(){ $orgId=$this->orgId; $roleId=input('roleId',0); $page=input('page/d',1); $size=input('size/d',10); $offset = ($page - 1) * $size; $roles = Db::name('roles')->where('id',$roleId)->where('enable',1)->where('del',0)->find(); if(!$roles){ HelpHander::success([]); } $roleId = $roles['parent_id']; $m[] = ['ap.org_id','=',$orgId]; $m[] = ['ap.del','=',0]; $m[] = ['ap.status','=',2]; $m1 = $m2 = $m3 = $m; $m1[] = ['','exp',Db::raw("FIND_IN_SET(".$roleId.",a.roles_ids)")]; $m2[] = ['a.roles_ids','=',null]; $m3[] = ['a.roles_ids','=','']; $ret =Db::name('article_paper') ->alias('ap') ->join('article a','a.id = ap.article_id') ->field('ap.create_time,ap.id,ap.title') ->whereOr([$m1,$m2,$m3]) ->order('ap.id','DESC') ->limit($offset,$size) ->select(); $ret = $ret?$ret:[]; foreach ($ret as $k=>$v){ $quantity=Db::name('article_question') ->where([ 'article_paper_id'=>$v['id'], 'del'=>0, ]) ->count(); $ret[$k]['quantity']=$quantity; } HelpHander::success($ret); } }