User.php 1.4 KB

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