Depart.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\admin\controller\csmadmin;
  3. use app\common\controller\Backend;
  4. use addons\csmadmin\library\CsmadminUtils;
  5. /**
  6. * 部门管理
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Depart extends Backend
  11. {
  12. /**
  13. * Depart模型对象
  14. *
  15. * @var \app\admin\model\csmadmin\Depart
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\csmadmin\Depart();
  22. $this->view->assign("fromsysList", $this->model->getFromsysList());
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. }
  25. private function getSubnode(&$ll,$id,&$allsubnodes){
  26. $subnodes = [];
  27. foreach($ll as $item){
  28. if($item->parent_id==$id){
  29. $subnodes[] = $item->id;
  30. $allsubnodes[] = $item->id;
  31. }
  32. }
  33. foreach($subnodes as $node){
  34. $this->getSubnode($ll,$node,$allsubnodes);
  35. }
  36. }
  37. public function index()
  38. {
  39. // 设置过滤方法
  40. $this->request->filter([
  41. 'strip_tags'
  42. ]);
  43. if ($this->request->isAjax()) {
  44. // 如果发送的来源是Selectpage,则转发到Selectpage
  45. if ($this->request->request('keyField')) {
  46. $json = $this->selectpage();
  47. $data = $json->getData();
  48. $readyqueryids = [];
  49. foreach ($data['list'] as $value) {
  50. $readyqueryids[] = $value['id'];
  51. }
  52. $ll = CsmadminUtils::getDepartWithParentname($readyqueryids);
  53. foreach ($data['list'] as $k=>$value) {
  54. $value['name'] = $ll['ID#'.$value['id']];
  55. $data['list'][$k] = $value;
  56. }
  57. //修改部门选择父组织,需要把当前节点和子节点去掉@20200620
  58. $noteqid = $this->request->request('noteqid');
  59. $ll = $this->model->where('status','=','normal')->field('id,parent_id')->select();
  60. $allsubnodes = [(int)$noteqid];
  61. $this->getSubnode($ll, $noteqid, $allsubnodes);
  62. if($noteqid!=null && $noteqid!=''){
  63. foreach($allsubnodes as $noteqid){
  64. foreach($data['list'] as $k=>$item){
  65. if($item['id']==$noteqid){
  66. array_splice($data['list'], $k, 1);
  67. $data['total'] = $data['total'] -1;
  68. }
  69. }
  70. }
  71. }
  72. //var_dump($data['list']);
  73. $json->data($data);
  74. return $json;
  75. }
  76. list ($where, $sort, $order, $offset, $limit) = $this->buildparams();
  77. $total = $this->model->where($where)
  78. ->order($sort, $order)
  79. ->count();
  80. $list = $this->model->where($where)
  81. ->order($sort, $order)
  82. ->limit($offset, $limit)
  83. ->select();
  84. $list = collection($list)->toArray();
  85. $result = array(
  86. "total" => $total,
  87. "rows" => $list
  88. );
  89. return json($result);
  90. }
  91. return $this->view->fetch();
  92. }
  93. }