Notification.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\admin\controller\ask;
  3. use app\common\controller\Backend;
  4. /**
  5. * 问答通知管理
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Notification extends Backend
  10. {
  11. /**
  12. * Notification模型对象
  13. * @var \app\admin\model\ask\Notification
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\admin\model\ask\Notification;
  20. }
  21. public function index()
  22. {
  23. $this->relationSearch = true;
  24. //设置过滤方法
  25. $this->request->filter(['strip_tags']);
  26. if ($this->request->isAjax()) {
  27. //如果发送的来源是Selectpage,则转发到Selectpage
  28. if ($this->request->request('keyField')) {
  29. return $this->selectpage();
  30. }
  31. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  32. $total = $this->model->with(['fromuser', 'touser'])
  33. ->where($where)
  34. ->order($sort, $order)
  35. ->count();
  36. $list = $this->model->with(['fromuser', 'touser'])
  37. ->where($where)
  38. ->order($sort, $order)
  39. ->limit($offset, $limit)
  40. ->select();
  41. foreach ($list as $index => $item) {
  42. $item->fromuser->visible(['id', 'nickname']);
  43. $item->touser->visible(['id', 'nickname']);
  44. }
  45. $list = collection($list)->toArray();
  46. $result = array("total" => $total, "rows" => $list);
  47. return json($result);
  48. }
  49. return $this->view->fetch();
  50. }
  51. }