User.php 2.6 KB

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