Announcement.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. public function list()
  15. {
  16. $paginator = (new AnnouncementModel)
  17. ->where('type_id', 1)
  18. ->where('status', 1)
  19. ->order('id DESC,weigh desc')
  20. ->field('id,img_url,createtime,' . $this->lan.'_title as title')
  21. ->paginate($this->pageSize);
  22. $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
  23. }
  24. public function show(int $id)
  25. {
  26. $info = (new AnnouncementModel)
  27. ->where('id', $id)
  28. ->where('status', 1)
  29. ->field('id,img_url,body,createtime,' . $this->lan.'_title as title')
  30. ->find();
  31. if(empty($info)){
  32. $this->error('公告信息不存');
  33. }
  34. $this->success('', $info);
  35. }
  36. }