public function getLeadedDepartments($onlyId = true, $uid = null) { $uid = $uid || getCurrentUid(); $model = D("Department"); $theUser = $this->find($uid); //获取用户所在部门的所有子集部门(包含当前部门) $tmp = $model->getTree($theUser["department_id"]); $leaded = array(); foreach ($tmp as $dep) { if (inExplodeArray($uid, $dep["leader"])) { $leaded[] = $dep["id"]; } } $departments = array(); //遍历查询效率问题 foreach ($leaded as $lead) { $departments = array_merge($departments, (array) $model->getTree($lead)); } if (!$onlyId) { return $departments; } return getArrayField($departments); }
private function initApp($config) { $model = D("User"); $data = $config["admin"]; $data["status"] = 1; $data["password"] = getPwd($data["password"]); $data["department_id"] = 0; $uid = $model->add($data); $m = M(); $sql = "INSERT INTO `%sauth_group_access`(uid, group_id)VALUES(%d, 1)"; $sql = sprintf($sql, $config["db"]["dbpre"], $uid); $m->execute($sql); $authNodesModel = D("AuthRule"); $nodeIds = $authNodesModel->field("id")->select(); $nodeIds = getArrayField($nodeIds, "id"); $authedRule = D("AuthGroupRule"); foreach ($nodeIds as $node) { $authedRule->add(array("group_id" => 1, "rule_id" => $node, "flag" => 0)); } }