public function setGroupMemberByDept($deptid) { try { //获取部门关联的群组 $sql = 'select groupid from im_group_memberarea where status=1 and objid=?'; $ds = $this->conn_im->GetData("table", $sql, array((string) $deptid)); if ($ds && $ds["table"]["recordcount"] > 0) { $imGroupJoinSql = 'insert into im_groupemployee(employeeid,groupid,grouprole,employeenick,lastreadid)values'; $values = array(); $newMember = array(); foreach ($ds["table"]["rows"] as $key => $value) { $groupid = $value['groupid']; //判断是否是该群组成员 $sql = 'SELECT a.loginname jid,a.employeename nick_name FROM im_employee a where a.deptid=? and not exists(select 1 from im_groupemployee where groupid=? and a.loginname=employeeid)'; $h1 = $this->conn_im->GetData("table2", $sql, array((string) $deptid, (string) $groupid)); foreach ($h1['table2']['rows'] as $key => $value) { $values[] = '(\'' . $value['jid'] . '\',\'' . $groupid . '\',\'normal\',\'' . $value['nick_name'] . '\',0)'; $newMember[] = $value['jid']; } } if (count($values) > 0) { $this->conn_im->ExecSQL($imGroupJoinSql . implode(',', $values), array()); } $groupmgr = new GroupMgr($this->conn, $this->conn_im, $this->container); foreach ($ds["table"]["rows"] as $key => $value) { $members = $groupmgr->getGroupMembersJidByIM($value['groupid']); $this->conn_im->ExecSQL('update im_group set max_number=(select count(1) from im_groupemployee where groupid=?) where groupid=?', array((string) $value['groupid'], (string) $value['groupid'])); $groupinfo = $groupmgr->GetByIM($value['groupid'], true); if (!empty($members)) { //通知这部分成员需要更新群信息 $noticeinfo = array(); $msg = Utils::WrapMessage("update_group", $groupinfo, $noticeinfo); Utils::sendImMessage('', implode(',', $members), "update_group", json_encode($msg), $this->container, "", "", false, ''); } if (count($newMember)) { //向新成员发送入群通知 $iconUrl = $groupinfo['logo']; $noticeinfo = Utils::WrapMessageNoticeinfo('你已自动进入群组 ' . $groupinfo['groupname'], '系统消息', null, $iconUrl); $msg = Utils::WrapMessage("join_group", $groupinfo, $noticeinfo); //添加成员成功发送消息 Utils::sendImMessage('', $newMember, "join_group", json_encode($msg), $this->container, "", "", false, ''); } } } } catch (\Exception $e) { $this->container->get("logger")->err($e); return false; } return true; }
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; }