Message.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 用户系统消息
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Message extends Backend
  11. {
  12. /**
  13. * Message模型对象
  14. * @var \app\admin\model\Message
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Message;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. /*$alluser = Db::name('user')->field(['id','username','nickname'])->order('id desc')->select();
  23. $newuser = [];
  24. foreach($alluser as $key => $val){
  25. $newuser[$val['id']] = $val['username'].'-'.$val['nickname'];
  26. }
  27. $this->view->assign("alluser", $newuser);*/
  28. }
  29. public function import()
  30. {
  31. parent::import();
  32. }
  33. /**
  34. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  35. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  36. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  37. */
  38. /**
  39. * 查看
  40. */
  41. public function index()
  42. {
  43. //当前是否为关联查询
  44. $this->relationSearch = true;
  45. //设置过滤方法
  46. $this->request->filter(['strip_tags', 'trim']);
  47. if ($this->request->isAjax()) {
  48. //如果发送的来源是Selectpage,则转发到Selectpage
  49. if ($this->request->request('keyField')) {
  50. return $this->selectpage();
  51. }
  52. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  53. $list = $this->model
  54. ->with(['user'])
  55. ->where($where)
  56. ->order($sort, $order)
  57. ->paginate($limit);
  58. foreach ($list as $row) {
  59. $row->getRelation('user')->visible(['username','nickname']);
  60. }
  61. $result = array("total" => $list->total(), "rows" => $list->items());
  62. return json($result);
  63. }
  64. return $this->view->fetch();
  65. }
  66. }