Announcement.php 1.3 KB

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