Announcement.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\AnnouncementModel;
  5. class Announcement extends Api
  6. {
  7. protected array $noNeedLogin = ['list','show'];
  8. protected string $lan = '';
  9. public function _initialize()
  10. {
  11. parent::_initialize();
  12. $this->lan = $this->request->getLan();
  13. }
  14. //
  15. public function list(AnnouncementModel $announcementModel)
  16. {
  17. $typeId = $this->request->param('type_id', 1, 'intval');
  18. $paginator = $announcementModel->where('type_id', $typeId)
  19. ->where('status', 1)
  20. ->order('id DESC,weigh desc')
  21. ->field('id,img_url,createtime,' . $this->lan.'_title as title,'.$this->lan.'_introduction as introduction,'.$this->lan.'_body as body')
  22. ->paginate($this->pageSize);
  23. $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
  24. }
  25. public function show(int $id)
  26. {
  27. $info = (new AnnouncementModel)
  28. ->where('id', $id)
  29. ->where('status', 1)
  30. ->field('id,img_url,createtime,' . $this->lan.'_title as title,'.$this->lan.'_body as body')
  31. ->find();
  32. if(empty($info)){
  33. $this->error('公告信息不存');
  34. }
  35. $this->success('', $info);
  36. }
  37. }