1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\hander\HelpHander;
- use think\App;
- use think\Db;
- use think\exception\Handle;
- class ArticlePaper extends Base
- {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->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);
- }
- }
|