Admin.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <?php
  2. namespace app\admin\controller\department;
  3. use app\admin\model\department\Department;
  4. use app\admin\model\department\Department as DepartmentModel;
  5. use app\common\controller\Backend;
  6. use \app\admin\model\department\Admin as DepartmentAdminModel;
  7. use \app\admin\model\department\AuthAdmin as AdminModel;
  8. use fast\Random;
  9. use fast\Tree;
  10. use think\Db;
  11. use think\Model;
  12. use think\Validate;
  13. /**
  14. * 部门成员
  15. */
  16. class Admin extends Backend
  17. {
  18. protected $tree = null;
  19. /**
  20. * 部门人员对象
  21. * @var null
  22. */
  23. protected $dadminModel = null;
  24. protected $childrenGroupIds = [];//权限组
  25. /**
  26. * 部门所有
  27. * @var array
  28. */
  29. protected $allDepartment = [];//
  30. protected $noNeedRight=['selectpage','getDepartmentIds'];
  31. public function _initialize()
  32. {
  33. parent::_initialize();
  34. $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
  35. $this->dadminModel = new DepartmentAdminModel;
  36. $departmentList = [];
  37. $this->allDepartment = \app\admin\model\department\Admin::getAllDepartmentsArray($this->auth->id,($this->auth->isSuperAdmin()||$this->auth->data_scope)?true:false);
  38. $this->allDepartment=collection($this->allDepartment)->toArray();
  39. $departmentdata = [];
  40. foreach ($this->allDepartment as $k => $v) {
  41. $state = ['opened' => true];
  42. $departmentList[] = [
  43. 'id' => $v['id'],
  44. 'parent' => $v['parent_id'] ? $v['parent_id'] : '#',
  45. 'text' =>preg_replace('/&nbsp;|\s*|│|└|├\s*/','',__($v['name'])),//str_replace("&nbsp;",'', __($v['name'])) ,
  46. 'state' => $state
  47. ];
  48. }
  49. $tree = Tree::instance()->init($this->allDepartment, 'parent_id');
  50. $departmentOptions = $tree->getTree(0, "<option model='@model_id' value=@id @selected @disabled>@spacer@name</option>");
  51. $this->view->assign('departmentOptions', $departmentOptions);
  52. $this->assignconfig('departmentList', $departmentList);
  53. $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
  54. foreach ($result as $k => $v) {
  55. $departmentdata[$v['id']] = $v['name'];
  56. }
  57. $this->view->assign('departmentdata', $departmentdata);
  58. //兼容旧版本没有手机号
  59. $database=config('database');
  60. $exits_mobile=\think\Db::query("SELECT 1 FROM information_schema.COLUMNS WHERE table_name='{$database['prefix']}admin' AND COLUMN_NAME='mobile' limit 1");
  61. $this->view->assign('exits_mobile', $exits_mobile?1:0);
  62. $this->assignconfig('exits_mobile', $exits_mobile?1:0);
  63. }
  64. /**
  65. * 成员列表
  66. */
  67. public function index()
  68. {
  69. //设置过滤方法
  70. $this->request->filter(['strip_tags']);
  71. $department_id = $this->request->request("department_id");
  72. if ($this->request->isAjax()) {
  73. $this->model = new \app\admin\model\department\AuthAdmin();
  74. $filter = $this->request->get("filter", '');
  75. $filter = (array)json_decode($filter, true);
  76. $filter_w = [];
  77. if (isset($filter['department_id'])) {
  78. $department_id = $filter['department_id'];
  79. unset($filter['department_id']);
  80. $this->request->get(['filter' => json_encode($filter)]);
  81. }
  82. if ($department_id) {
  83. if (!in_array($department_id,array_column($this->allDepartment,'id'))){
  84. $this->error("您所选的部门没有权限");
  85. }
  86. $admin_ids = $this->dadminModel->where('department_id', 'in', $department_id)->column('admin_id');
  87. $filter_w['id'] = ['in', $admin_ids];
  88. }else if ($this->auth->data_scope!=1&&!$this->auth->isSuperAdmin()){
  89. $this->childrenAdminIds = \app\admin\model\department\Admin::getChildrenAdminIds($this->auth->id, true);
  90. $filter_w['id']=['in',$this->childrenAdminIds];
  91. }
  92. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  93. $total = $this->model
  94. ->where($where)
  95. ->where($filter_w)
  96. ->order($sort, $order)->fetchSql(false)
  97. ->count();
  98. $list = $this->model
  99. ->where($where)
  100. ->with(['dadmin.department'])
  101. ->with(['groups.getGroup'])
  102. ->where($filter_w)
  103. ->order($sort, $order)
  104. ->limit($offset, $limit)->fetchSql(false)
  105. ->select();
  106. $result = array("total" => $total, "rows" => $list);
  107. return json($result);
  108. }
  109. return $this->view->fetch();
  110. }
  111. /**
  112. * 添加
  113. * @return string|\think\response\Json
  114. * @throws \think\Exception
  115. * @throws \think\db\exception\DataNotFoundException
  116. * @throws \think\db\exception\ModelNotFoundException
  117. * @throws \think\exception\DbException
  118. */
  119. public function add()
  120. {
  121. $groupdata = DepartmentModel::getGroupdata(
  122. $this->childrenGroupIds,
  123. $this->auth->isSuperAdmin() ? null : $this->auth->getGroups()
  124. );
  125. if ($this->request->isPost()) {
  126. $adminModel = new AdminModel();
  127. $departmentModel = new DepartmentModel();
  128. $params = $this->request->post("row/a");
  129. if ($params) {
  130. Db::startTrans();
  131. try {
  132. $department_id = $this->request->post("department_id/a");
  133. $is_principal = $this->request->post("is_principal",'0','intval');
  134. //获取部门信息
  135. if (!$department_id) {
  136. exception(__("部门不能为空"));
  137. }
  138. $d_list = $departmentModel->where('id', 'in', $department_id)->select();
  139. if (!$d_list) {
  140. exception(__("部门不能为空"));
  141. }
  142. if (!Validate::is($params['password'], '\S{6,16}')) {
  143. exception(__("Please input correct password"));
  144. }
  145. $params['salt'] = Random::alnum();
  146. $params['password'] = md5(md5($params['password']) . $params['salt']);
  147. $params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。
  148. $result = $adminModel->validate('Admin.add')->save($params);
  149. if ($result === false) {
  150. exception($adminModel->getError());
  151. }
  152. if (!$this->auth->isSuperAdmin()&&isset($params['data_scope'])){
  153. unset($params['data_scope']);//超级管理人才能赋予全部数据权限
  154. }
  155. $admin_id = $adminModel->id;
  156. $dadmin = array();
  157. //添加部门信息
  158. foreach ($d_list as $d_row) {
  159. $dadmin[] = ['is_principal'=>$is_principal==1?1:0,'department_id' => $d_row->id, 'organise_id' => $d_row->organise_id ? $d_row->organise_id : $d_row->id, 'admin_id' => $admin_id];
  160. }
  161. $this->dadminModel->saveAll($dadmin);
  162. $group = $this->request->post("group/a");
  163. //过滤不允许的组别,避免越权
  164. $group = array_intersect($this->childrenGroupIds, $group);
  165. //添加权限默认
  166. if (!$group) {
  167. exception(__('The parent group exceeds permission limit'));
  168. }
  169. $dataset = [];
  170. foreach ($group as $value) {
  171. $dataset[] = ['uid' => $admin_id, 'group_id' => $value];
  172. }
  173. model('AuthGroupAccess')->saveAll($dataset);
  174. Db::commit();
  175. } catch (\Exception $e) {
  176. Db::rollback();
  177. $this->error($e->getMessage());
  178. }
  179. $this->success();
  180. }
  181. $this->error(__('Parameter %s can not be empty', ''));
  182. }
  183. $this->view->assign('groupdata', $groupdata);
  184. return $this->view->fetch();
  185. }
  186. /**
  187. * 修改
  188. * @param null $ids
  189. * @return string|\think\response\Json
  190. * @throws \think\Exception
  191. * @throws \think\db\exception\DataNotFoundException
  192. * @throws \think\db\exception\ModelNotFoundException
  193. * @throws \think\exception\DbException
  194. */
  195. public function edit($ids = null)
  196. {
  197. $this->model = new AdminModel();
  198. $departmentModel = new DepartmentModel();
  199. $row = $this->model->get($ids);
  200. if (!$row) {
  201. $this->error(__('No Results were found'));
  202. }
  203. if (!\app\admin\model\department\Admin::checkDataAuth($this->auth,$row,'id')){
  204. $this->error(__('You have no permission'));
  205. }
  206. if ($this->request->isPost()) {
  207. //判断是不是超级管理员编辑
  208. if (!$this->auth->isSuperAdmin() && DepartmentAdminModel::isSuperAdmin($row->id)) {
  209. $this->error("您无权操作超级管理员");
  210. }
  211. $params = $this->request->post("row/a");
  212. if ($params) {
  213. Db::startTrans();
  214. try {
  215. $department_id = $this->request->post("department_id/a");
  216. //获取部门信息
  217. if (!$department_id) {
  218. exception(__("Department can't null"));
  219. }
  220. $d_list = $departmentModel->where('id', 'in', $department_id)->select();
  221. if (!$d_list) {
  222. exception(__("Department can't null"));
  223. }
  224. if ($params['password']) {
  225. if (!Validate::is($params['password'], '\S{6,16}')) {
  226. exception(__("Please input correct password"));
  227. }
  228. $params['salt'] = Random::alnum();
  229. $params['password'] = md5(md5($params['password']) . $params['salt']);
  230. } else {
  231. unset($params['password'], $params['salt']);
  232. }
  233. if (!$this->auth->isSuperAdmin()&&isset($params['data_scope'])){
  234. unset($params['data_scope']);//超级管理人才能赋予全部数据权限
  235. }
  236. //这里需要针对username和email做唯一验证
  237. $adminValidate = \think\Loader::validate('Admin');
  238. $adminValidate->rule([
  239. 'username' => 'require|regex:\w{3,20}|unique:admin,username,' . $row->id,
  240. 'email' => 'require|email|unique:admin,email,' . $row->id,
  241. 'mobile' => 'regex:1[3-9]\d{9}|unique:admin,mobile,' . $row->id,
  242. 'password' => 'regex:\S{32}',
  243. ]);
  244. $result = $row->validate('Admin.edit')->save($params);
  245. if ($result === false) {
  246. exception($row->getError());
  247. }
  248. $exist_departmentids = $this->dadminModel->where('admin_id', $row->id)->column('department_id');
  249. $dadmin = array();
  250. $deleteids = array_diff($exist_departmentids, $department_id);
  251. //添加部门信息
  252. foreach ($d_list as $d_row) {
  253. if (!in_array($d_row->id, $exist_departmentids)) {
  254. $dadmin[] = ['department_id' => $d_row->id, 'organise_id' => $d_row->organise_id ? $d_row->organise_id : $d_row->id, 'admin_id' => $row->id];
  255. }
  256. }
  257. if ($deleteids) {
  258. $this->dadminModel->where('admin_id', $row->id)->where('department_id', 'in', $deleteids)->delete();
  259. }
  260. if (count($dadmin) > 0) {
  261. $this->dadminModel->saveAll($dadmin);
  262. }
  263. // 先移除所有权限
  264. model('AuthGroupAccess')->where('uid', $row->id)->delete();
  265. $group = $this->request->post("group/a");
  266. // 过滤不允许的组别,避免越权
  267. $group = array_intersect($this->childrenGroupIds, $group);
  268. if (!$group) {
  269. exception(__('The parent group exceeds permission limit'));
  270. }
  271. $dataset = [];
  272. foreach ($group as $value) {
  273. $dataset[] = ['uid' => $row->id, 'group_id' => $value];
  274. }
  275. model('AuthGroupAccess')->saveAll($dataset);
  276. Db::commit();
  277. } catch (\Exception $e) {
  278. Db::rollback();
  279. $this->error($e->getMessage());
  280. }
  281. $this->success();
  282. }
  283. $this->error(__('Parameter %s can not be empty', ''));
  284. }
  285. $groupdata = DepartmentModel::getGroupdata(
  286. $this->childrenGroupIds,
  287. $this->auth->isSuperAdmin() ? null : $this->auth->getGroups()
  288. );
  289. $grouplist = $this->auth->getGroups($row['id']);
  290. $groupids = [];
  291. foreach ($grouplist as $k => $v) {
  292. $groupids[] = $v['id'];
  293. }
  294. $this->view->assign("groupids", $groupids);
  295. $this->view->assign('row', $row);
  296. $this->view->assign('department_ids', $this->dadminModel->getDepartmentIds($ids));
  297. $this->view->assign('groupdata', $groupdata);
  298. return $this->view->fetch();
  299. }
  300. /**
  301. * 删除
  302. */
  303. public function del($ids = "")
  304. {
  305. if (!$this->request->isPost()) {
  306. $this->error(__("Invalid parameters"));
  307. }
  308. $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
  309. $this->model = new AdminModel();
  310. $ids = $ids ? $ids : $this->request->post("ids");
  311. if ($ids) {
  312. $ids = array_intersect($this->childrenAdminIds, array_filter(explode(',', $ids)));
  313. // 避免越权删除管理员
  314. $childrenGroupIds = $this->childrenGroupIds;
  315. $adminList = $this->model->where('id', 'in', $ids)->where('id', 'in', function ($query) use ($childrenGroupIds) {
  316. $query->name('auth_group_access')->where('group_id', 'in', $childrenGroupIds)->field('uid');
  317. })->select();
  318. if ($adminList) {
  319. $deleteIds = [];
  320. foreach ($adminList as $k => $v) {
  321. $deleteIds[] = $v->id;
  322. }
  323. $deleteIds = array_values(array_diff($deleteIds, [$this->auth->id]));
  324. if ($deleteIds) {
  325. Db::startTrans();
  326. try {
  327. $this->model->destroy($deleteIds);
  328. model('AuthGroupAccess')->where('uid', 'in', $deleteIds)->delete();
  329. //删除部门员工信息
  330. $this->dadminModel->where('admin_id', 'in', $deleteIds)->delete();;
  331. Db::commit();
  332. } catch (\Exception $e) {
  333. Db::rollback();
  334. $this->error($e->getMessage());
  335. }
  336. $this->success();
  337. }
  338. $this->error(__('No rows were deleted'));
  339. }
  340. }
  341. $this->error(__('You have no permission'));
  342. }
  343. /**
  344. * 批量更新
  345. */
  346. public function multi($ids = "")
  347. {
  348. $this->model = new AdminModel();
  349. return parent::multi($ids);
  350. }
  351. /**
  352. * 设置部门负责人
  353. */
  354. public function principal($ids = "")
  355. {
  356. $this->model = new AdminModel();
  357. $departmentModel = new DepartmentModel();
  358. $row = $this->model->get($ids);
  359. if ($this->request->isPost()) {
  360. //判断是不是超级管理员编辑
  361. if (!DepartmentAdminModel::isSuperAdmin($this->auth->id) && DepartmentAdminModel::isSuperAdmin($row->id)) {
  362. $this->error("您无权操作超级管理员");
  363. }
  364. $department_id = $this->request->post("department_id/a");
  365. if ($department_id && $department_id[0]) {
  366. Db::startTrans();
  367. try {
  368. $d_list = $departmentModel->where('id', 'in', $department_id)->select();
  369. if (!$d_list) {
  370. exception(__("Department can't null"));
  371. }
  372. //先移除他所有负责的部门
  373. $this->dadminModel->where('admin_id', $row->id)->update(['is_principal' => 0]);
  374. //判断选择的部门是否存在,不存在就先把他加入
  375. $p_departmentids = array_column($d_list, 'id');
  376. $exist_departmentids = $this->dadminModel->where('admin_id', $row->id)->column('department_id');
  377. $dadmin = array();
  378. //添加部门信息
  379. foreach ($d_list as $d_row) {
  380. if (!in_array($d_row->id, $exist_departmentids)) {
  381. $dadmin[] = ['department_id' => $d_row->id, 'organise_id' => $d_row->organise_id ? $d_row->organise_id : $d_row->id, 'admin_id' => $row->id];
  382. }
  383. }
  384. if (count($dadmin) > 0) {
  385. $this->dadminModel->saveAll($dadmin);
  386. }
  387. //更改为负责人
  388. $this->dadminModel->where('admin_id', $row->id)->where('department_id', 'in', $p_departmentids)->update(['is_principal' => 1]);
  389. Db::commit();
  390. } catch (\Exception $e) {
  391. Db::rollback();
  392. $this->error($e->getMessage());
  393. }
  394. } else {
  395. //移除他所有负责的部门
  396. $this->dadminModel->where('admin_id', $row->id)->update(['is_principal' => 0]);
  397. }
  398. $this->success();
  399. }
  400. $this->view->assign('row', $row);
  401. $this->view->assign('department_ids', $this->dadminModel::getPrincipalIds($ids));
  402. return $this->view->fetch();
  403. }
  404. /**
  405. * 获取员工的部门IDs
  406. */
  407. public function getDepartmentIds($id = ""){
  408. $departmentIds=DepartmentAdminModel::getDepartmentIds($id);
  409. //这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮
  410. $this->success("",'',['departmentIds' => $departmentIds]);
  411. }
  412. /**
  413. * 下拉选择
  414. * @Internal
  415. */
  416. public function selectpage()
  417. {
  418. $type=$this->request->request('type');//all代表选择所有
  419. $custom = ['status' => 'normal'];
  420. if ($type != "all") {
  421. $childrenAdminIds = \app\admin\model\department\Admin::getChildrenAdminIds($this->auth->id, true);
  422. $custom['id'] = ['in', $childrenAdminIds];
  423. }
  424. $this->selectpageFields = ['id', 'concat(nickname,"(",id,")") as nickname'];
  425. $this->request->request(['custom' => $custom]);
  426. //搜索字段
  427. $searchfield = (array)$this->request->request("searchField/a");
  428. $searchfield[]='id';
  429. $this->request->request(['searchField'=>$searchfield]);
  430. $this->model = model('admin');
  431. //设置过滤方法
  432. $this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']);
  433. //搜索关键词,客户端输入以空格分开,这里接收为数组
  434. $word = (array)$this->request->request("q_word/a");
  435. //当前页
  436. $page = $this->request->request("pageNumber");
  437. //分页大小
  438. $pagesize = $this->request->request("pageSize");
  439. //搜索条件
  440. $andor = $this->request->request("andOr", "and", "strtoupper");
  441. //排序方式
  442. $orderby = (array)$this->request->request("orderBy/a");
  443. //显示的字段
  444. $field = $this->request->request("showField");
  445. //主键
  446. $primarykey = $this->request->request("keyField");
  447. //主键值
  448. $primaryvalue = $this->request->request("keyValue");
  449. //搜索字段
  450. $searchfield = (array)$this->request->request("searchField/a");
  451. //自定义搜索条件
  452. $custom = (array)$this->request->request("custom/a");
  453. //是否返回树形结构
  454. $istree = $this->request->request("isTree", 0);
  455. $ishtml = $this->request->request("isHtml", 0);
  456. if ($istree) {
  457. $word = [];
  458. $pagesize = 999999;
  459. }
  460. $order = [];
  461. foreach ($orderby as $k => $v) {
  462. $order[$v[0]] = $v[1];
  463. }
  464. $field = $field ? $field : 'name';
  465. //如果有primaryvalue,说明当前是初始化传值
  466. if ($primaryvalue !== null) {
  467. $where = [$primarykey => ['in', $primaryvalue]];
  468. $pagesize = 999999;
  469. } else {
  470. $where = function ($query) use ($word, $andor, $field, $searchfield, $custom) {
  471. $logic = $andor == 'AND' ? '&' : '|';
  472. $searchfield = is_array($searchfield) ? implode($logic, $searchfield) : $searchfield;
  473. $searchfield = str_replace(',', $logic, $searchfield);
  474. $word = array_filter(array_unique($word));
  475. if (count($word) == 1) {
  476. $query->where($searchfield, "like", "%" . reset($word) . "%");
  477. } else {
  478. $query->where(function ($query) use ($word, $searchfield) {
  479. foreach ($word as $index => $item) {
  480. $query->whereOr(function ($query) use ($item, $searchfield) {
  481. $query->where($searchfield, "like", "%{$item}%");
  482. });
  483. }
  484. });
  485. }
  486. if ($custom && is_array($custom)) {
  487. foreach ($custom as $k => $v) {
  488. if (is_array($v) && 2 == count($v)) {
  489. $query->where($k, trim($v[0]), $v[1]);
  490. } else {
  491. $query->where($k, '=', $v);
  492. }
  493. }
  494. }
  495. };
  496. }
  497. $adminIds = $this->getDataLimitAdminIds();
  498. if (is_array($adminIds)) {
  499. $this->model->where($this->dataLimitField, 'in', $adminIds);
  500. }
  501. $list = [];
  502. $total = $this->model->where($where)->count();
  503. if ($total > 0) {
  504. if (is_array($adminIds)) {
  505. $this->model->where($this->dataLimitField, 'in', $adminIds);
  506. }
  507. $fields = is_array($this->selectpageFields) ? $this->selectpageFields : ($this->selectpageFields && $this->selectpageFields != '*' ? explode(',', $this->selectpageFields) : []);
  508. //如果有primaryvalue,说明当前是初始化传值,按照选择顺序排序
  509. if ($primaryvalue !== null && preg_match("/^[a-z0-9_\-]+$/i", $primarykey)) {
  510. $primaryvalue = array_unique(is_array($primaryvalue) ? $primaryvalue : explode(',', $primaryvalue));
  511. //修复自定义data-primary-key为字符串内容时,给排序字段添加上引号
  512. $primaryvalue = array_map(function ($value) {
  513. return '\'' . $value . '\'';
  514. }, $primaryvalue);
  515. $primaryvalue = implode(',', $primaryvalue);
  516. $this->model->orderRaw("FIELD(`{$primarykey}`, {$primaryvalue})");
  517. } else {
  518. $this->model->order($order);
  519. }
  520. $datalist = $this->model->where($where)
  521. ->field($this->selectpageFields)
  522. ->page($page, $pagesize)
  523. ->select();
  524. foreach ($datalist as $index => $item) {
  525. unset($item['password'], $item['salt']);
  526. if ($this->selectpageFields == '*') {
  527. $result = [
  528. $primarykey => isset($item[$primarykey]) ? $item[$primarykey] : '',
  529. $field => isset($item[$field]) ? $item[$field] : '',
  530. ];
  531. } else {
  532. $result = (($item instanceof Model ? $item->toArray() : (array)$item));
  533. }
  534. $result['pid'] = isset($item['pid']) ? $item['pid'] : (isset($item['parent_id']) ? $item['parent_id'] : 0);
  535. $list[] = $result;
  536. }
  537. if ($istree && !$primaryvalue) {
  538. $tree = Tree::instance();
  539. $tree->init(collection($list)->toArray(), 'pid');
  540. $list = $tree->getTreeList($tree->getTreeArray(0), $field);
  541. if (!$ishtml) {
  542. foreach ($list as &$item) {
  543. $item = str_replace('&nbsp;', ' ', $item);
  544. }
  545. unset($item);
  546. }
  547. }
  548. }
  549. //这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮
  550. return json(['list' => $list, 'total' => $total]);
  551. }
  552. }