Announcement.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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)->where('to_lang', $this->lan)
  20. ->order('id DESC,weigh desc')
  21. ->field('id,to_lang,img_url,createtime,title as title,introduction,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)->where('to_lang', $this->lan)
  30. ->field('id,img_url,to_lang,createtime,title,introduction,body')
  31. ->find();
  32. if(empty($info)){
  33. $this->error('公告信息不存');
  34. }
  35. $this->success('', $info);
  36. }
  37. }