コード例 #1
0
ファイル: Staff.php プロジェクト: 3116246/haolinju
 public function moveToDept($deptid, $fafa_deptid = null)
 {
     $staffinfo = $this->getInfo();
     //判断是否同部门,是则不处理
     if ($staffinfo == null || $staffinfo["dept_id"] == $deptid) {
         return "";
     }
     $jid = $staffinfo["fafa_jid"];
     $deptMgr = new Dept($this->conn, $this->conn_im, $this->container);
     $dept = $deptMgr->getinfo($staffinfo["dept_id"]);
     $olddeptid = $dept["deptid"];
     if (empty($fafa_deptid)) {
         $dept = $deptMgr->getinfo($deptid);
         $fafa_deptid = empty($dept) ? "v" . $staffinfo["eno"] : $dept["deptid"];
     }
     $VersionChange = new VersionChange($this->conn, $this->logger, $this->container);
     $VersionChange->deptchange($staffinfo);
     //更新sns中人员部门编号
     $staff_update_sql = "update we_staff set dept_id=? where login_account=?";
     $this->conn->ExecSQL($staff_update_sql, array((string) $deptid, (string) $this->account));
     //更新IM库中的人员部门信息
     $this->conn_im->ExecSQL("update im_employee set deptid=? where loginname=?", array((string) $fafa_deptid, (string) $jid));
     $staff_update_sql = array();
     $paras = array();
     $staff_update_sql[] = "call dept_emp_stat(?)";
     $paras[] = array((string) $jid);
     $staff_update_sql[] = "call dept_emp_stat(?)";
     $paras[] = array((string) $olddeptid);
     $this->conn_im->ExecSQLs($staff_update_sql, $paras);
     //删除原部门互为好友关系
     $this->delFriend($olddeptid, $jid, $this->logger);
     //新部门互为好友
     $newdept = $deptMgr->getinfo($deptid);
     $deptMgr->setFriendByDept($newdept["deptid"], array("login_account" => $this->account, "fafa_jid" => $jid, 'nick_name' => $staffinfo['nick_name']));
     $groupMgr = new GroupMgr($this->conn, $this->conn_im, $this->container);
     //从原部门默认群组中移除
     $groupMgr->RemoveDefaultGroupMember(array('deptid' => $olddeptid, 'jid' => $jid));
     //加入新部门的默认群组
     $groupMgr->AddDefaultGroup(array('deptid' => $newdept["deptid"], 'jid' => $jid, 'nick_name' => $staffinfo['nick_name']));
     $serviceMgr = new Service($this->container);
     //取消关注原部门关联的公众号
     $serviceMgr->cancel_atten(array('deptid' => $olddeptid, 'jid' => $jid, 'eno' => $staffinfo['eno']));
     //关注新部门关联的公众号
     $serviceMgr->atten_service(array('deptid' => $newdept["deptid"], 'jid' => $jid, 'eno' => $staffinfo['eno']));
     //刷新缓存
     $staffinfo = $this->getInfo(true);
     $VersionChange->deptchange($staffinfo);
     $message = array('jid' => $jid, 'newdeptid' => $deptid, 'olddeptid' => $olddeptid);
     $msg = json_encode(Utils::WrapMessage('staff_move_dept', $message, array()));
     $sendMessage = new \Justsy\BaseBundle\Common\SendMessage($this->conn, $this->conn_im);
     $parameter = array("eno" => $staffinfo['eno'], "flag" => "all", "title" => "staff_move_dept", "message" => $msg, "container" => $this->container);
     $sendMessage->sendImMessage($parameter);
     return $jid;
 }