public function updateDepartment($deptinfo) { $result = array(); $deptid = isset($deptinfo["deptid"]) ? $deptinfo["deptid"] : null; $p_deptid = isset($deptinfo["p_deptid"]) ? $deptinfo["p_deptid"] : null; $deptname = isset($deptinfo["deptname"]) ? $deptinfo["deptname"] : null; $manager = isset($deptinfo["manager"]) ? $deptinfo["manager"] : null; $show = isset($deptinfo["show"]) ? $deptinfo["show"] : null; $friend = isset($deptinfi["friend"]) ? $deptinfo["friend"] : null; if (empty($deptid)) { return Utils::WrapResultError('部门id不能为空'); } else { $VersionChange = new VersionChange($this->conn, $this->logger, $this->container); $sql_sns = ""; $sql_im = ""; $para_sns = array(); $para_im = array(); $deptData = $this->getinfo($deptid); $oldPid = $deptData["pid"]; //原来的上级部门 //获得im中的deptid和pid $fafa_deptid = $deptid; // $this->getImDeptid($deptid); $fafa_pid = $p_deptid; //empty($p_deptid)? "" : $this->getImDeptid($p_deptid); if (empty($deptname) && !empty($p_deptid)) { $sql_sns = "update we_department set parent_dept_id=? where dept_id=?"; $para_sns = array((string) $p_deptid, (string) $deptid); $sql_im = "update im_base_dept set pid=?,manager=?,friend=?,`show`=? where deptid=?;"; $para_im = array((string) $fafa_pid, (string) $manager, (string) $friend, (string) $show, (string) $fafa_deptid); } else { if (!empty($deptname) && empty($p_deptid)) { $sql_sns = "update we_department set dept_name=? where dept_id=?"; $para_sns = array((string) $deptname, (string) $deptid); $sql_im = "update im_base_dept set deptname=? where deptid=?"; $para_im = array((string) $deptname, (string) $fafa_deptid); } else { $sql_sns = "update we_department set dept_name=?,parent_dept_id=? where dept_id=?"; $para_sns = array((string) $deptname, (string) $p_deptid, (string) $deptid); $sql_im = "update im_base_dept set deptname=?,pid=?,manager=?,friend=?,`show`=? where deptid=?;"; $para_im = array((string) $deptname, (string) $fafa_pid, (string) $manager, (string) $friend, (string) $show, (string) $fafa_deptid); } } try { //部门变更前变化一下缓存及版本,以便于当更新上级部门时原上级部门的版本更改 $VersionChange->deptchange($deptid); $this->conn->ExecSQL($sql_sns, $para_sns); $this->conn_im->ExecSQL($sql_im, $para_im); if (!empty($p_deptid) && $p_deptid != $oldPid) { $eno = $deptData["eno"]; $this->reset_deptpath($eno, $fafa_pid); } //删除原来的缓存再重新获得 $result = $this->getinfo($deptid, true); //部门变更成功后再更新一次缓存 $VersionChange->deptchange($deptid); } catch (\Exception $e) { return Utils::WrapResultError($e->getMessage()); } return Utils::WrapResultOK($result); } }
public function checkAndUpdate($nick_name, $mobile = null, $deptid = null, $duty = null, $ldap_uid = null, $sex_id = null, $self_desc = null) { $sql = "update we_staff set "; $returnItem = array(); $para = array(); $updateItm = array(); if (!empty($nick_name)) { $updateItm[] = "nick_name=?"; $para[] = (string) $nick_name; $returnItem["nick_name"] = $nick_name; } if ($mobile !== null) { $updateItm[] = "mobile=?, mobile_bind=?"; $para[] = (string) $mobile; $para[] = (string) $mobile; $returnItem["mobile"] = $mobile; } if ($duty !== null) { $updateItm[] = "duty=?"; $para[] = (string) $duty; $returnItem["duty"] = $duty; } if ($ldap_uid != null) { $updateItm[] = "ldap_uid=?"; $para[] = (string) $ldap_uid; } if ($sex_id != null) { $updateItm[] = "sex_id=?"; $para[] = (string) $sex_id; $returnItem["sex_id"] = $sex_id; } if ($self_desc != null) { $updateItm[] = "self_desc=?"; $para[] = (string) $self_desc; $returnItem["self_desc"] = $self_desc; } if ($deptid !== null) { $staffinfo = $this->getInfo(); $this->moveToDept($deptid); } if (empty($updateItm) || count($updateItm) == 0) { return true; } $sql = "update we_staff set " . implode(",", $updateItm) . " where login_account=? or ldap_uid=? or openid=?"; $para[] = (string) $this->account; $para[] = (string) $this->account; $para[] = (string) $this->account; $this->conn->ExecSQL($sql, $para); if (!empty($nick_name)) { $this->conn->ExecSQL("call emp_change_name(?,?)", array((string) $this->account, (string) $nick_name)); $jid = $this->getInfo(); $jid = $jid["fafa_jid"]; $this->conn_im->ExecSQL("call emp_change_name(?,?)", array((string) $jid, (string) $nick_name)); } //刷新缓存 $staffdata = $this->getInfo(true); if (!empty($self_desc) || !empty($nick_name)) { $pinyin = $this->syncAttrsToIM(); $returnItem['spell'] = $pinyin; } $VersionChange = new VersionChange($this->conn, $this->logger, $this->container); $VersionChange->deptchange($staffdata); $returnItem['jid'] = $staffdata['jid']; $msg = json_encode(Utils::WrapMessage('staff-changeinfo', $returnItem, array())); //操作成功发送出席 $sendMessage = new \Justsy\BaseBundle\Common\SendMessage($this->conn, $this->conn_im); $parameter = array("eno" => $staffdata["eno"], "fromjid" => $staffdata["jid"], "flag" => "all", "title" => "staff-changeinfo", "message" => $msg, "container" => $this->container); $sendMessage->sendImMessage($parameter); $parameter = array("eno" => $staffdata["eno"], "fromjid" => $staffdata["jid"], "flag" => "onself", "title" => "staff-changeinfo", "message" => $msg, "container" => $this->container); $sendMessage->sendImPresence($parameter); return true; }