Announcement.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\admin\controller\general;
  3. use app\common\controller\Backend;
  4. /**
  5. * 文件管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Announcement extends Backend
  10. {
  11. /**
  12. * Banner模型对象 茶说、公告、合成公告、轮播图
  13. * @var \app\admin\model\Banner
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\common\model\AnnouncementModel;
  20. $this->view->assign("typeList", $this->model ::getTypeList());
  21. }
  22. /**
  23. * 查
  24. * @return string|Json
  25. * @throws \think\Exception
  26. * @throws DbException
  27. */
  28. public function index()
  29. {
  30. //设置过滤方法
  31. $this->request->filter(['strip_tags', 'trim']);
  32. if (false === $this->request->isAjax()) {
  33. return $this->view->fetch();
  34. }
  35. //如果发送的来源是 Selectpage,则转发到 Selectpage
  36. if ($this->request->request('keyField')) {
  37. return $this->selectpage();
  38. }
  39. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  40. $map = [];
  41. $type = $this->request->param('type_id/d');
  42. if($type > 0) $map['type_id'] = $type;
  43. $list = $this->model
  44. ->where($where)->where($map)
  45. ->order($sort, $order)
  46. ->paginate($limit);
  47. $result = ['total' => $list->total(), 'rows' => $list->items()];
  48. return json($result);
  49. }
  50. }