Announcement.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 = ['gettype','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 gettype(AnnouncementModel $announcementModel){
  16. $this->success('', $announcementModel::getTypeList());
  17. }
  18. //列表
  19. public function list(AnnouncementModel $announcementModel)
  20. {
  21. $typeId = $this->request->param('type_id', 1, 'intval');
  22. $paginator = $announcementModel->where('type_id', $typeId)
  23. ->where('status', 1)->where('to_lang', $this->lan)
  24. ->field('id,to_lang,weigh,img_url,createtime,title as title,introduction,body')
  25. ->order('weigh desc, id desc')
  26. ->paginate($this->pageSize);
  27. $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
  28. }
  29. public function show(int $id)
  30. {
  31. $info = (new AnnouncementModel)
  32. ->where('id', $id)
  33. //->where('status', 1)
  34. ->where('to_lang', $this->lan)
  35. ->field('id,img_url,to_lang,createtime,title,introduction,body')
  36. ->find();
  37. if(empty($info)){
  38. $this->error('公告信息不存');
  39. }
  40. $this->success('', $info);
  41. }
  42. }