Example #1
0
 public function pushNotice($data)
 {
     $receiver = $data["receiver"];
     if (empty($receiver)) {
         return Utils::WrapResultError("接收人不能为空");
     }
     $receiver = explode(',', $receiver);
     if (empty($data["text"])) {
         return Utils::WrapResultError("内容不能为空");
     }
     $files = isset($data["files"]) ? $data["files"] : '';
     if (!empty($files) && is_array($files)) {
         $files = implode(',', $files);
     }
     $noticeid = SysSeq::GetSeqNextValue($this->conn_im, "im_pushnotice_msg", "id");
     $filefix = $this->container->getParameter('FILE_WEBSERVER_URL');
     $senddata = array();
     $senddata = array('noticeid' => $noticeid, 'text' => $data["text"], 'files' => $files, 'receivercount' => count($receiver), 'receiver' => implode(',', $receiver), 'sender' => array('nickname' => $this->user["nick_name"], 'photo' => $this->user["photo_path"], 'jid' => $this->user["jid"], 'date' => date("Y-m-d H:i:s", time())));
     $notice = Utils::WrapMessageNoticeinfo($data["text"], $this->module["appname"], null, $this->module["logo"]);
     $msg = Utils::WrapMessage('push-notice', $senddata, $notice);
     $msgxml = Utils::WrapMessageXml($this->module["jid"], $msg, 'push-notice-' . $noticeid);
     $sql = 'insert into im_pushnotice_msg(id,replyid,msg,created,us,msgid)values(?,0,?,now(),?,?)';
     $para = array((int) $noticeid, (string) $msgxml, (string) $this->user["jid"], 'push-notice-' . $noticeid);
     $sql2 = 'insert into im_pushnotice_memebr(noticeid,employeeid,lastread_reply,receive_time)values';
     $sql2Values = array();
     $staffinfo = new \Justsy\BaseBundle\Management\Staff($this->conn, $this->conn_im, $this->user['login_account'], $this->logger, $this->container);
     foreach ($receiver as $key => $value) {
         $rdata = $staffinfo->getstaffinfo($value);
         if (!empty($rdata)) {
             $receiver[$key] = $rdata['jid'];
             $sql2Values[] = '(' . $noticeid . ',\'' . $rdata['jid'] . '\',0,null)';
         }
     }
     if (count($sql2Values) > 0) {
         $sql2 = $sql2 . implode(',', $sql2Values);
         $this->conn_im->ExecSQLs(array($sql, $sql2), array($para, array()));
         //发送消息
         $receiver[] = $this->user["jid"];
         Utils::findonlinejid($this->conn_im, $receiver);
         if (count($receiver) > 0) {
             $presence = new \Justsy\OpenAPIBundle\Controller\ApiController();
             $presence->setContainer($this->container);
             $presence->sendMsg($this->module["jid"], $receiver, '新通知送达', json_encode($msg));
         }
     }
     return Utils::WrapResultOK(array('noticeid' => $noticeid));
 }
Example #2
0
 public function SendMsgAction()
 {
     $conn = $this->get("we_data_access");
     $conn_im = $this->get("we_data_access_im");
     $request = $this->getRequest();
     $currUser = $this->get('security.context')->getToken();
     if ($currUser == null) {
         $openid = $request->get('openid');
         $staffinfo = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $openid, $this->get("logger"), $this->container);
         $staffdata = $staffinfo->getInfo();
         if (empty($staffdata)) {
             $re = array('returncode' => '9999', 'msg' => '无效的操作人');
             return $this->responseJson(json_encode($re));
         }
         $user = $staffinfo->getSessionUser($staffdata);
     } else {
         $user = $this->get('security.context')->getToken()->getUser();
     }
     //公众号相关参数
     $microObj = $request->get('microObj');
     $microName = $microObj["microName"];
     //接收对象(公众号名称)
     $microNumber = $microObj["microNumber"];
     //接收对象(公众号帐号)
     $microOpenid = $microObj["microOpenid"];
     //接收对象(公众号Openid)
     $microType = $microObj["microType"];
     //接收对象(公众号类型,内部或外部)
     $microUse = $microObj["microUse"];
     //接收对象(是公众号还是微应用)
     $microGroupId = "";
     //$microObj["microGroupId"]; //接收对象(公众号分组主键)
     //消息参数
     $msgType = "";
     //消息类型
     $msgContent = "";
     //消息内容(XML拼接Json字符串,包括标题,图片,摘要等)
     $msgContentHtml = "";
     //消息内容(HTML内容)
     $msgTitle = "";
     //消息标题
     $imgUrl = "";
     //图片地址
     $formid = "";
     //表单编号。推送表单时设置
     $webpage_url = "";
     //网页地址。推送网页地址时设置
     $msgObj_list = $request->get('msgObj');
     //消息对象
     if (!empty($msgObj_list)) {
         foreach ($msgObj_list as $key => $val) {
             if ($key == "type") {
                 $msgType = $val;
             } else {
                 if ($key == "msgContent") {
                     $msgContent = $val;
                 } else {
                     if ($key == "contentHtml") {
                         $msgContentHtml = $val;
                     } else {
                         if ($key == "title") {
                             $msgTitle = $val;
                         } else {
                             if ($key == "imgUrl") {
                                 $imgUrl = $val;
                             } else {
                                 if ($key == "formid") {
                                     $formid = $val;
                                 } else {
                                     if ($key == "webpage_url") {
                                         $webpage_url = $val;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $staffinfo = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, empty($microNumber) ? $microOpenid : $microNumber, $this->get("logger"), $this->container);
     $staffdata = $staffinfo->getInfo();
     if (empty($staffdata)) {
         $re = array('returncode' => '9999', 'msg' => '请选择接收对象');
         return $this->responseJson(json_encode($re));
     } else {
         $microOpenid = $staffdata["openid"];
         $microNumber = $staffdata["login_account"];
     }
     $re = array('returncode' => '0000');
     $sqls = array();
     $paras = array();
     $send_state = '2';
     $id = SysSeq::GetSeqNextValue($conn, 'we_micro_send_message', 'id');
     $sqls[] = "insert into `we_micro_send_message` (`id`, `send_account`, `send_groupid`, `send_datetime`, `send_state`, `send_isbutton`, `send_source`,`send_type`) VALUES (?, ?, ?, now(), ?, ?, ?,?);";
     $paras[] = array($id, $microNumber, $microGroupId, $send_state, false, 'wefafa', $msgType);
     $error = array('returncode' => '9999', 'msg' => '消息内容有误,请检查');
     //处理消息
     switch ($msgType) {
         case 'PICTURE':
             $title = '';
             //标题
             $image_type = '';
             //图片类型  URL或CODE
             $image_value = '';
             //图片地址
             $content = '';
             //摘要
             $link = '';
             //手机端点击之后连接地址
             try {
                 foreach ($msgContent as $key => $value) {
                     if ($key == 'picturemsg') {
                         $picturemsg = $value;
                         //判断参数是否为空。并返回错误提示
                         if (empty($picturemsg)) {
                             return $this->responseJson(json_encode($error));
                         }
                         foreach ($picturemsg as $pkey => $pvalue) {
                             if ($pkey == 'headitem') {
                                 $headitem = $pvalue;
                                 //判断参数是否为空。并返回错误提示
                                 if (empty($headitem)) {
                                     return $this->responseJson(json_encode($error));
                                 }
                                 foreach ($headitem as $hkey => $hvalue) {
                                     if ($hkey == 'title') {
                                         $title = $hvalue;
                                     } else {
                                         if ($hkey == 'image') {
                                             $image = $hvalue;
                                             //判断参数是否为空。并返回错误提示
                                             if (empty($image)) {
                                                 return $this->responseJson(json_encode($error));
                                             }
                                             foreach ($image as $ikey => $ivalue) {
                                                 if ($ikey == 'type') {
                                                     $image_type = $ivalue;
                                                 } else {
                                                     if ($ikey == 'value') {
                                                         $image_value = $ivalue;
                                                     }
                                                 }
                                             }
                                         } else {
                                             if ($hkey == 'content') {
                                                 $content = $hvalue;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } catch (Exception $e) {
                 $this->get('logger')->err($e->getMessage());
                 return $this->responseJson(json_encode($error));
             }
             if (!empty($webpage_url)) {
                 $link = $webpage_url;
                 $uniqid = $webpage_url;
             } else {
                 $uniqid = str_replace('.', '', uniqid('', true));
                 $link = !empty($formid) ? $this->getWebFormLink($formid) : $this->getLink($uniqid);
                 if (!empty($formid)) {
                     $uniqid = $link;
                 }
             }
             $noticeinfo = Utils::WrapMessageNoticeinfo($title, $microName);
             $msgContent = Utils::WrapMessage("mm-picturemsg", array('headitem' => array('title' => $title, 'image' => array('type' => $image_type, 'value' => $image_value), 'content' => $content, 'link' => $link)), $noticeinfo);
             //$msgContent= array('picturemsg'=>array('headitem'=>array('title'=>$title,'image'=>array('type'=>$image_type,'value'=>$image_value),'content'=>$content,'link'=>$link)));
             $msgid = SysSeq::GetSeqNextValue($conn, 'we_micro_message', 'id');
             $sqls[] = "insert into `we_micro_message` (`id`, `send_id`, `msg_title`, `msg_type`, `msg_text`, `msg_content`, `msg_summary`, `msg_img_type`, `msg_img_url`, `msg_web_url`, `ishead`, `isread`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
             $msgContentHtml = $this->SetElementStyle($msgContentHtml);
             $paras[] = array($msgid, $id, $title, $msgType, null, $msgContentHtml, $content, $image_type, $image_value, $uniqid, true, false);
             break;
         case 'TEXTPICTURE':
             try {
                 $headitem = array();
                 $items = array();
                 foreach ($msgContent as $key => $value) {
                     if ($key == 'textpicturemsg') {
                         $textpicturemsg = $value;
                         if (empty($textpicturemsg)) {
                             return $this->responseJson(json_encode($error));
                         }
                         foreach ($textpicturemsg as $tpmkey => $tpmvalue) {
                             if ($tpmkey == 'headitem') {
                                 $headitem = $tpmvalue;
                                 if (empty($headitem)) {
                                     return $this->responseJson(json_encode($error));
                                 }
                                 $head_title = '';
                                 $head_img_type = '';
                                 $head_img_url = '';
                                 $head_contentHtml = '';
                                 $head_link = '';
                                 $formid = "";
                                 foreach ($headitem as $hkey => $hvalue) {
                                     if ($hkey == 'title') {
                                         $head_title = $hvalue;
                                     } else {
                                         if ($hkey == 'image') {
                                             $image = $hvalue;
                                             if (empty($image)) {
                                                 return $this->responseJson(json_encode($error));
                                             }
                                             foreach ($image as $imgkey => $imgvalue) {
                                                 if ($imgkey == 'type') {
                                                     $head_img_type = $imgvalue;
                                                 } else {
                                                     if ($imgkey == 'value') {
                                                         $head_img_url = $imgvalue;
                                                     }
                                                 }
                                             }
                                         } else {
                                             if ($hkey == 'content') {
                                                 $head_contentHtml = $hvalue;
                                             } else {
                                                 if ($hkey == 'formid') {
                                                     $formid = $hvalue;
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 $uniqid = str_replace('.', '', uniqid('', true));
                                 $head_link = !empty($formid) ? $this->getWebFormLink($formid) : $this->getLink($uniqid);
                                 $headitem = array('title' => $head_title, 'image' => array('type' => $head_img_type, 'value' => $head_img_url), 'link' => $head_link);
                                 $msgid = SysSeq::GetSeqNextValue($conn, 'we_micro_message', 'id');
                                 $sqls[] = "insert into `we_micro_message` (`id`, `send_id`, `msg_title`, `msg_type`, `msg_text`, `msg_content`, `msg_summary`, `msg_img_type`, `msg_img_url`, `msg_web_url`, `ishead`, `isread`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
                                 $head_contentHtml = $this->SetElementStyle($head_contentHtml);
                                 $paras[] = array($msgid, $id, $head_title, $msgType, null, $head_contentHtml, null, $head_img_type, $head_img_url, $uniqid, true, false);
                             } else {
                                 if ($tpmkey == 'item') {
                                     $item = $tpmvalue;
                                     if (empty($item)) {
                                         return $this->responseJson(json_encode($error));
                                     }
                                     $item_array = array();
                                     for ($i = 0; $i < count($item); $i++) {
                                         $item_title = '';
                                         $item_img_type = '';
                                         $item_img_url = '';
                                         $item_contentHtml = '';
                                         $item_link = '';
                                         $formid = "";
                                         foreach ($item[$i] as $itemkey => $itemvalue) {
                                             if ($itemkey == 'title') {
                                                 $item_title = $itemvalue;
                                             } else {
                                                 if ($itemkey == 'image') {
                                                     $image = $itemvalue;
                                                     if (empty($image)) {
                                                         return $this->responseJson(json_encode($error));
                                                     }
                                                     foreach ($image as $imgkey => $imgvalue) {
                                                         if ($imgkey == 'type') {
                                                             $item_img_type = $imgvalue;
                                                         } else {
                                                             if ($imgkey == 'value') {
                                                                 $item_img_url = $imgvalue;
                                                             }
                                                         }
                                                     }
                                                 } else {
                                                     if ($itemkey == 'content') {
                                                         $item_contentHtml = $itemvalue;
                                                     } else {
                                                         if ($itemkey == 'formid') {
                                                             $formid = $itemvalue;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                         $uniqid = str_replace('.', '', uniqid('', true));
                                         $item_link = !empty($formid) ? $this->getWebFormLink($formid) : $this->getLink($uniqid);
                                         $item_array = array('title' => $item_title, 'image' => array('type' => $item_img_type, 'value' => $item_img_url), 'link' => $item_link);
                                         array_push($items, $item_array);
                                         $msgid = SysSeq::GetSeqNextValue($conn, 'we_micro_message', 'id');
                                         $sqls[] = "INSERT INTO `we_micro_message` (`id`, `send_id`, `msg_title`, `msg_type`, `msg_text`, `msg_content`, `msg_summary`, `msg_img_type`, `msg_img_url`, `msg_web_url`, `ishead`, `isread`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
                                         $paras[] = array($msgid, $id, $item_title, $msgType, null, $item_contentHtml, null, $item_img_type, $item_img_url, $uniqid, false, false);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $noticeinfo = Utils::WrapMessageNoticeinfo($headitem["title"], $microName);
                 $msgContent = Utils::WrapMessage("mm-textpicturemsg", array('headitem' => $headitem, 'item' => $items), $noticeinfo);
                 //$msgContent= array('textpicturemsg'=>array('headitem'=>$headitem,'item'=>$items));
             } catch (\Exception $e) {
                 $this->get('logger')->err($e->getMessage());
                 return $this->responseJson(json_encode($error));
             }
             break;
         case 'TEXT':
             foreach ($msgContent as $key => $value) {
                 if ($key == 'textmsg') {
                     $textmsg = $value;
                     //判断参数是否为空。并返回错误提示
                     if (empty($textmsg)) {
                         return $this->responseJson(json_encode($error));
                     }
                     foreach ($textmsg as $tkey => $tvalue) {
                         if ($tkey == 'item') {
                             $items = $tvalue;
                             //判断参数是否为空。并返回错误提示
                             if (empty($items)) {
                                 return $this->responseJson(json_encode($error));
                             }
                             $new_items = array();
                             for ($i = 0; $i < count($items); $i++) {
                                 $title = '';
                                 $content = '';
                                 foreach ($items[$i] as $itemkey => $itemvalue) {
                                     if ($itemkey == 'title') {
                                         $title = $itemvalue;
                                     } else {
                                         if ($itemkey == 'content') {
                                             $content = $itemvalue;
                                         }
                                     }
                                 }
                                 if (empty($title)) {
                                     return $this->responseJson(json_encode($error));
                                 }
                                 if (empty($content)) {
                                     return $this->responseJson(json_encode($error));
                                 }
                                 array_push($new_items, array('title' => $title, 'content' => $content));
                                 $msgid = SysSeq::GetSeqNextValue($conn, 'we_micro_message', 'id');
                                 $sqls[] = "INSERT INTO `we_micro_message` (`id`, `send_id`, `msg_title`, `msg_type`, `msg_text`, `msg_content`, `msg_summary`, `msg_img_type`, `msg_img_url`, `msg_web_url`, `ishead`, `isread`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
                                 $paras[] = array($msgid, $id, $title, $msgType, $content, null, null, null, null, null, false, false);
                             }
                             $noticeinfo = Utils::WrapMessageNoticeinfo($title, $microName);
                             $msgContent = Utils::WrapMessage("mm-textmsg", array('item' => $new_items), $noticeinfo);
                             // array('code'=>'textmsg','data'=>array('item'=>$new_items),'noticeinfo'=>'');
                         }
                     }
                 }
             }
             break;
         default:
             //消息类型有误
             return $this->responseJson(json_encode($error));
             break;
     }
     $msgContent = json_encode($msgContent);
     try {
         $staffMgr = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $microNumber, $this->get("logger"), $this->container);
         $microData = $staffMgr->getInfo();
         $mic_jid = $microData["fafa_jid"];
         $msgxml = Utils::WrapMicroMessageXml($mic_jid, $msgContent, $id);
         $im_msg_sql = "insert into im_microaccount_msg(microaccount,msg,created,us,msgid)values(?,?,now(),?,?)";
         $conn_im->ExecSQL($im_msg_sql, array((string) $mic_jid, (string) $msgxml, "", (string) $id));
         $fafa_jids = array();
         $sqls_staff = array();
         $paras_staff = array();
         $apicontroller = new \Justsy\OpenAPIBundle\Controller\ApiController();
         $apicontroller->setContainer($this->container);
         $serviceMgr = new \Justsy\BaseBundle\Management\Service($this->container);
         //$this->get('logger')->err("================1:".time());
         $fafa_jids = $serviceMgr->service_sendjid($mic_jid, true);
         //$this->get('logger')->err("================:".json_encode($fafa_jids));
         if (!empty($fafa_jids)) {
             $jids = array();
             $count = count($fafa_jids);
             for ($i = 0; $i < $count; $i++) {
                 array_push($jids, (string) $fafa_jids[$i]);
                 if ($i > 0 && $i % 5000 == 0) {
                     $re = $apicontroller->sendMsg2($microOpenid, implode(",", $jids), $msgContent, $msgType, false, "0", $id);
                     $jids = array();
                 }
             }
             if (!empty($jids) && count($jids) > 0) {
                 $re = $apicontroller->sendMsg2($microOpenid, implode(",", $jids), $msgContent, $msgType, false, "0", $id);
             }
         }
         //$this->get('logger')->err("================3:".time());
         if (!empty($re['returncode']) && $re['returncode'] == '0000') {
             //添加发送消息数据
             if (!empty($sqls)) {
                 $conn->ExecSQLs($sqls, $paras);
             }
             //添加接收人员
             if (!empty($sqls_staff)) {
                 $conn->ExecSQLs($sqls_staff, $paras_staff);
             }
         }
     } catch (\Exception $e) {
         $this->get('logger')->err($e->getMessage());
         $re = array('returncode' => '9999', 'msg' => '消息发送失败');
     }
     return $this->responseJson(json_encode($re));
 }
Example #3
0
 public function delDefaultGroup($parameter)
 {
     $groupid = $parameter["groupid"];
     $da_im = $this->conn_im;
     $sqls = array();
     $paras = array();
     $to_jid = "";
     //删除群组
     $sql = "select logo from im_group where groupid=?";
     try {
         $ds = $da_im->GetData("table", $sql, array((string) $groupid));
         if ($ds && $ds["table"]["recordcount"] > 0) {
             $fileid = $ds["table"]["rows"][0]["logo"];
             if (!empty($fileid)) {
                 $this->removeFile($fileid);
             }
         }
     } catch (\Exception $e) {
         $this->logger->err($e->getMessage());
     }
     $sql = "delete from im_group where groupid=?";
     array_push($sqls, $sql);
     array_push($paras, array((string) $groupid));
     //删除群成员(删除群成员表时取群用户jid以发送出席)
     $groupObj = $this->getGroupMemberJid($groupid);
     $to_jid = $groupObj["member_jid"];
     $groupname = $groupObj["groupname"];
     $sql = "delete from im_groupemployee where groupid=?;";
     array_push($sqls, $sql);
     array_push($paras, array((string) $groupid));
     //删除群组对应允许加入的部门表
     $sql = "delete from im_group_memberarea where groupid=?;";
     array_push($sqls, $sql);
     array_push($paras, array((string) $groupid));
     $sql = "delete from im_group_msg where groupid=?;";
     array_push($sqls, $sql);
     array_push($paras, array((string) $groupid));
     /*
       	 $sql = "delete from im_groupemployee_covert where groupid=?;";
       	 array_push($sqls,$sql);
       	 array_push($paras,array((string)$groupid));*/
     $success = true;
     $msg = "";
     try {
         $da_im->ExecSQLs($sqls, $paras);
         //解散群组成功后发送出席
         $userinfo = $parameter["user"];
         $send_jid = $userinfo->fafa_jid;
         $title = "remove_group";
         $message = $userinfo->nick_name;
         $message = '管理员解散群组了 ' . $groupname;
         $noticeinfo = Utils::WrapMessageNoticeinfo($message, $userinfo->nick_name, null, null);
         $msg = Utils::WrapMessage($title, array('groupid' => $groupid), $noticeinfo);
         Utils::sendImMessage($send_jid, $to_jid, $title, json_encode($msg), $this->container, "", "", false, Utils::$systemmessage_code);
     } catch (\Exception $e) {
         $this->logger->err($e->getMessage());
         Utils::WrapResultError($e->getMessage());
     }
     return Utils::WrapResultOK("");
 }
Example #4
0
 public function UploadFileAction()
 {
     $da = $this->get('we_data_access');
     $da_im = $this->get('we_data_access_im');
     $request = $this->getRequest();
     $content = $request->get("update_content");
     $version1 = $request->get("version_1");
     $version2 = $request->get("version_2");
     $version3 = $request->get("version_3");
     $version4 = $request->get("version_4");
     $version = $version1 . "." . $version2 . "." . $version3 . "." . $version4;
     $plist_url = $request->get("plist_url");
     $plist_url = empty($plist_url) ? null : $plist_url;
     $openid = $request->get('openid');
     $staffinfo = new \Justsy\BaseBundle\Management\Staff($da, $this->get("we_data_access_im"), $openid, $this->get("logger"), $this->container);
     $staffdata = $staffinfo->getInfo();
     $login_account = $staffdata["login_account"];
     $fileElementName = 'filedata';
     $success = true;
     $msg = "";
     try {
         $filename = $_FILES[$fileElementName]['name'];
         $filesize = $_FILES[$fileElementName]['size'];
         $filetemp = $_FILES[$fileElementName]['tmp_name'];
         //判断文件类型
         $file_name = basename($filename);
         $fixedType = explode(".", strtolower($file_name));
         $fixedType = $fixedType[count($fixedType) - 1];
         $type = 0;
         if ($fixedType == "apk") {
             $type = 1;
         } else {
             if ($fixedType == "ipa") {
                 $type = 2;
             }
         }
         //比较版本号
         $sql = "select max(replace(version,'.','')) version from we_version where type=?;";
         try {
             $ds = $da->GetData("table", $sql, array((string) $type));
             if ($ds && $ds["table"]["recordcount"] > 0) {
                 $old_ver = (int) $ds["table"]["rows"][0]["version"];
                 $new_ver = $version1 . $version2 . $version3 . $version4;
                 $new_ver = (int) $new_ver;
                 if ($new_ver <= $old_ver) {
                     return Utils::WrapResultError("你输入的版本号比数据库里的小,请重新输入");
                 }
             }
         } catch (\Exception $e) {
             return Utils::WrapResultError($e->getMessage());
         }
         $fileid = $this->saveCertificate($filetemp, $filename);
         if (!empty($fileid)) {
             //上传文件成功后返回文件id
             $url = $this->container->getParameter('FILE_WEBSERVER_URL');
             $path = $_SERVER['DOCUMENT_ROOT'] . "/download/app";
             $dir = explode('src', __DIR__);
             if (!is_dir($dir[0] . '/download/app')) {
                 mkdir($dir[0] . '/download/app', 0777, true);
             }
             $path = $path . "/";
             $dowurl = $url . $fileid;
             $id = SysSeq::GetSeqNextValue($da, "we_version", "id");
             $sql = "insert into we_version(id,version,type,update_content,filename,date,staffid,fileid,plist_url)values(?,?,?,?,?,now(),?,?,?)";
             $para = array((string) $id, (string) $version, (string) $type, (string) $content, (string) $file_name, (string) $login_account, (string) $fileid, $plist_url);
             try {
                 $da->ExecSQL($sql, $para);
                 //发送出席
                 $presence = new \Justsy\OpenAPIBundle\Controller\ApiController();
                 $presence->setContainer($this->container);
                 $my_jid = $staffdata['jid'];
                 $sql = "select distinct us from global_session;";
                 $ds = $da_im->GetData("us", $sql);
                 $tojids = array();
                 $title = "";
                 if ($type == 1) {
                     $title = "andorid";
                 } else {
                     if ($type == 2) {
                         $title = "ios";
                     } else {
                         $title = "pc";
                     }
                 }
                 $sendMessage = new \Justsy\BaseBundle\Common\SendMessage($da, $da_im);
                 $body = "有新版本(" . $version . "),请及时更新!";
                 $notice = Utils::WrapMessageNoticeinfo($body, '系统通知', null, null);
                 $msg = json_encode(Utils::WrapMessage('newversion', array('type' => $title), $notice));
                 $parameter = array("eno" => $staffdata['eno'], "flag" => "all", "title" => "newversion", "message" => $msg, "container" => $this->container);
                 $sendMessage->sendImMessage($parameter);
             } catch (\Exception $e) {
                 $success = false;
                 $this->get("logger")->err($e->getMessage());
                 $msg = "添加数据记录失败!";
                 return Utils::WrapResultError($e->getMessage());
             }
         } else {
             $success = false;
             $msg = "上传安装包文件失败";
             return Utils::WrapResultError($msg);
         }
     } catch (\Exception $e) {
         $success = false;
         $msg = "上传安装包失败。";
         $this->get("logger")->err($e->getMessage());
         return Utils::WrapResultError($e->getMessage());
     }
     //删除上传的文件
     @unlink($_FILES[$fileElementName]);
     return Utils::WrapResultOK("");
 }
Example #5
0
 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;
 }