Announcement.php 1.7 KB

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