123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\admin\controller\csmadmin;
- use app\common\controller\Backend;
- use addons\csmadmin\library\CsmadminUtils;
- /**
- * 部门管理
- *
- * @icon fa fa-circle-o
- */
- class Depart extends Backend
- {
- /**
- * Depart模型对象
- *
- * @var \app\admin\model\csmadmin\Depart
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\csmadmin\Depart();
- $this->view->assign("fromsysList", $this->model->getFromsysList());
- $this->view->assign("statusList", $this->model->getStatusList());
- }
- private function getSubnode(&$ll,$id,&$allsubnodes){
- $subnodes = [];
- foreach($ll as $item){
- if($item->parent_id==$id){
- $subnodes[] = $item->id;
- $allsubnodes[] = $item->id;
- }
- }
- foreach($subnodes as $node){
- $this->getSubnode($ll,$node,$allsubnodes);
- }
- }
-
- public function index()
- {
- // 设置过滤方法
- $this->request->filter([
- 'strip_tags'
- ]);
- if ($this->request->isAjax()) {
- // 如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
-
- $json = $this->selectpage();
- $data = $json->getData();
-
- $readyqueryids = [];
- foreach ($data['list'] as $value) {
- $readyqueryids[] = $value['id'];
- }
- $ll = CsmadminUtils::getDepartWithParentname($readyqueryids);
-
- foreach ($data['list'] as $k=>$value) {
- $value['name'] = $ll['ID#'.$value['id']];
- $data['list'][$k] = $value;
- }
-
- //修改部门选择父组织,需要把当前节点和子节点去掉@20200620
- $noteqid = $this->request->request('noteqid');
- $ll = $this->model->where('status','=','normal')->field('id,parent_id')->select();
- $allsubnodes = [(int)$noteqid];
- $this->getSubnode($ll, $noteqid, $allsubnodes);
- if($noteqid!=null && $noteqid!=''){
- foreach($allsubnodes as $noteqid){
- foreach($data['list'] as $k=>$item){
- if($item['id']==$noteqid){
- array_splice($data['list'], $k, 1);
- $data['total'] = $data['total'] -1;
- }
- }
- }
- }
- //var_dump($data['list']);
-
- $json->data($data);
- return $json;
- }
- list ($where, $sort, $order, $offset, $limit) = $this->buildparams();
-
-
- $total = $this->model->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- $list = collection($list)->toArray();
- $result = array(
- "total" => $total,
- "rows" => $list
- );
- return json($result);
- }
- return $this->view->fetch();
- }
-
- }
|