0
0

ArticlePaper.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. use think\App;
  6. use think\Db;
  7. use think\exception\Handle;
  8. class ArticlePaper extends Base
  9. {
  10. public function __construct(App $app = null) {
  11. parent::__construct($app);
  12. $this->model = new \app\common\model\ArticlePaper();
  13. }
  14. public function queryPaperList(){
  15. $orgId=$this->orgId;
  16. $roleId=input('roleId',0);
  17. $page=input('page/d',1);
  18. $size=input('size/d',10);
  19. $offset = ($page - 1) * $size;
  20. $roles = Db::name('roles')->where('id',$roleId)->where('enable',1)->where('del',0)->find();
  21. if(!$roles){
  22. HelpHander::success([]);
  23. }
  24. $roleId = $roles['parent_id'];
  25. $m[] = ['ap.org_id','=',$orgId];
  26. $m[] = ['ap.del','=',0];
  27. $m[] = ['ap.status','=',2];
  28. $m1 = $m2 = $m3 = $m;
  29. $m1[] = ['','exp',Db::raw("FIND_IN_SET(".$roleId.",a.roles_ids)")];
  30. $m2[] = ['a.roles_ids','=',null];
  31. $m3[] = ['a.roles_ids','=',''];
  32. $ret =Db::name('article_paper')
  33. ->alias('ap')
  34. ->join('article a','a.id = ap.article_id')
  35. ->field('ap.create_time,ap.id,ap.title')
  36. ->whereOr([$m1,$m2,$m3])
  37. ->order('ap.id','DESC')
  38. ->limit($offset,$size)
  39. ->select();
  40. $ret = $ret?$ret:[];
  41. foreach ($ret as $k=>$v){
  42. $quantity=Db::name('article_question')
  43. ->where([
  44. 'article_paper_id'=>$v['id'],
  45. 'del'=>0,
  46. ])
  47. ->count();
  48. $ret[$k]['quantity']=$quantity;
  49. }
  50. HelpHander::success($ret);
  51. }
  52. }