Beispiel #1
0
 public function save($parameter)
 {
     $curuser = $parameter["user"];
     $sql = "";
     $para = array();
     $da = $this->conn;
     $result = array();
     try {
         if ($this->existsAppName($curuser->eno, $parameter["appid"], $parameter["appname"])) {
             return Utils::WrapResultError("PUSH应用名称已存在!");
         } else {
             if (empty($appid)) {
                 $appid = Utils::getAppid($curuser->eno, $curuser->login_account);
                 $appkey = Utils::getAppkey();
                 //$MicroAccountMgr=new MicroAccountMgr($da,$this->get('we_data_access_im'),$curuser,$this->get("logger"), $this->container);
                 //$MicroAccountMgr->register("",$number,$name,$type,$micro_use,$introduction,$concern_approval,$salutatory,$level,$password,$filename48,$filename120,$filename24,$factory,$dm,$appid);
                 $sql = "insert into we_appcenter_apps(appid,appkey,logo,appname,state,appdeveloper,appdesc,bindurl,apptype,sortid,createstaffid)values(?,?,?,?,1,?,?,?,?,?,?)";
                 $para = array($appid, $appkey, "", $parameter["appname"], $curuser->eno, "", "", "99", 0, $curuser->login_account);
             } else {
                 $sql = "update we_appcenter_apps set appname=?,logo=?,appdesc=?,bindurl=?,sortid=?,createstaffid=? where appid=?";
                 $para = array($parameter["appname"], "", "", "", 0, $curuser->login_account, $parameter["appid"]);
             }
             if ($sql != "") {
                 $da->ExecSQL($sql, $para);
             }
         }
     } catch (\Exception $e) {
         return Utils::WrapResultError($e->getMessage());
     }
     return Utils::WrapResultOK("");
 }
Beispiel #2
0
 public function register($paraObj)
 {
     $ename = $paraObj["ename"];
     //企业名称不能为空
     if (empty($ename)) {
         return Utils::WrapResultError("请输入企业名称");
     }
     $currUser = $paraObj["user"];
     if (empty($currUser)) {
         return Utils::WrapResultError("请登录后重试", ReturnCode::$NOTLOGIN);
     }
     if ($currUser->eno != Utils::$PUBLIC_ENO) {
         return Utils::WrapResultError("你已成功加入企业,不能创建企业");
     }
     $da = $this->da;
     $en_row = $this->getInfoByName($ename);
     if (!empty($en_row)) {
         return Utils::WrapResultError('企业已存在');
     }
     $da_im = $this->container->get('we_data_access_im');
     $authtype = $paraObj["authtype"];
     $website = $paraObj["website"];
     $phone = $paraObj["phone"];
     $address = $paraObj["address"];
     $eno = SysSeq::GetSeqNextValue($da, "we_enterprise", "eno");
     $auth_level = "S";
     $eno_vip = '1';
     $edomain = $eno;
     $login_account = $currUser->getUsername();
     $sqls[] = "insert into we_enterprise (eno,edomain,ename,sys_manager,create_staff,state_id,eshortname,create_date,vip_level,eno_level,industry,addr,ewww,telephone,mstyle) values(?, ?, ?, ?, ?, ?, ?, now(), ?, ?, ?, ?, ?, ?,'outpriv')";
     $paras[] = array((string) $eno, (string) $edomain, (string) $ename, (string) $login_account, (string) $login_account, (string) "1", (string) $ename, (string) $eno_vip, (string) $auth_level, "", (string) $address, (string) $website, (string) $phone);
     $sqls[] = "insert into we_enterprise_stored (id,enoname,eshortname,eno,auth) values(?, ?, ?, ?, ?)";
     $paras[] = array((string) $eno, (string) $ename, (string) $ename, (string) $eno, (string) $authtype);
     $eshortname = $ename;
     $circleName = $eshortname;
     $circleId = SysSeq::GetSeqNextValue($da, "we_circle", "circle_id");
     $sqls[] = "insert into we_circle (circle_id,circle_name,create_staff,manager,join_method,enterprise_no,network_domain,create_date,fafa_groupid) values (?,?,?,?,?,?,?,now(),?)";
     $paras[] = array((string) $circleId, (string) $circleName, (string) $login_account, (string) $login_account, (string) 1, (string) $eno, (string) $edomain, "");
     if (true) {
         //写入企业
         $im_dept_sqls = array();
         $im_dept_paras = array();
         $subdomain = "fafacn.com";
         //$da_im->ExecSQL($sql, $para);
         //写入IM库部门表
         $depts = array();
         $pdeptid = "v" . $eno;
         $sql = "insert into im_base_dept (deptid, deptname, pid, path, noorder) values (?, ?, ?, ?, ?)";
         $pid = "-10000";
         $pubDeptPath = "/-10000/" . $pdeptid . "/";
         $para = array((string) $pdeptid, (string) $ename, (string) $pid, (string) $pubDeptPath, (string) $eno);
         $im_dept_sqls[] = $sql;
         $im_dept_paras[] = $para;
         $depts[] = "{$pdeptid},{$ename}";
         //创建默认部门:公共帐号
         $pid = $pdeptid;
         $pubDeptID = $pdeptid . "999";
         //公共部门编号
         $pubDeptPath = $pubDeptPath . $pubDeptID . "/";
         //公共部门路径
         $para = array((string) $pubDeptID, (string) "公共帐号", (string) $pid, (string) $pubDeptPath, (double) 1);
         $im_dept_sqls[] = $sql;
         $im_dept_paras[] = $para;
         $depts[] = $pubDeptID . ",公共帐号";
         //创建默认部门:公众号。公共部门子部门
         $pid = $pubDeptID;
         $pubDeptID = $pubDeptID . "888";
         //公共部门子部门“公众号”部门编号
         $pubDeptPath = $pubDeptPath . $pubDeptID . "/";
         $para = array((string) $pubDeptID, (string) "公众号", (string) $pid, (string) $pubDeptPath, (double) 1);
         $im_dept_sqls[] = $sql;
         $im_dept_paras[] = $para;
         $depts[] = $pubDeptID . ",公众号";
         //创建默认部门
         $dnames = explode(",", "体验部门,行政部,销售部,财务部,客服服务部,总经办,技术部");
         $sn = 2;
         foreach ($dnames as $key => $value) {
             if (empty($value)) {
                 continue;
             }
             $deptid = SysSeq::GetSeqNextValue($da_im, "im_base_dept", "deptid");
             $para = array((string) $deptid, (string) $value, (string) $pdeptid, (string) "/-10000/" . $pdeptid . "/" . $deptid . "/", $value == "体验部门" ? (int) $pdeptid : (int) $sn);
             $im_dept_sqls[] = $sql;
             $im_dept_paras[] = $para;
             //$da_im->ExecSQL($sql, $para);
             $depts[] = "{$deptid},{$value}";
             $sn++;
         }
         //写入虚拟人员
         $users = array("service,客服", "admin,管理员", "guest,匿名访客", "front,前台", "sale,销售");
         foreach ($users as $key => $value) {
             if (empty($value)) {
                 continue;
             }
             $ary = explode(",", $value);
             $pwd = strcmp($ary[0], "guest") == 0 ? "ljy20080511" : "";
             $im_dept_sqls[] = "insert into im_employee (employeeid, deptid, loginname, password, employeename) values (?, ?, ?, ?, ?)";
             $im_dept_paras[] = array((string) $pdeptid . "-" . $ary[0], (string) $pdeptid . "999", (string) $ary[0] . "-" . $eno . "@" . $subdomain, (string) $pwd, (string) $ary[1]);
             $im_dept_sqls[] = "insert into users (username, password, created_at) values (?, ?, now())";
             $im_dept_paras[] = array((string) $ary[0] . "-" . $eno . "@" . $subdomain, (string) $pwd);
         }
         $im_dept_sqls[] = "insert into im_dept_stat(deptid,empcount)values(?,6)";
         $im_dept_paras[] = array((string) $pdeptid);
         $da_im->ExecSQLs($im_dept_sqls, $im_dept_paras);
         //we_sns写入部门表
         foreach ($depts as $key => $value) {
             if (empty($value)) {
                 continue;
             }
             $ary = explode(",", $value);
             $deptid = SysSeq::GetSeqNextValue($da, "we_department", "dept_id");
             $sqls[] = "insert into we_department (eno,dept_id,dept_name,parent_dept_id,fafa_deptid,create_staff) values (?,?,?,?,?,?)";
             $paras[] = array((string) $eno, (string) $deptid, (string) $ary[1], (string) $deptid, (string) $ary[0], (string) $login_account);
         }
         try {
             $StaticTrendMgr = new \Justsy\BaseBundle\Management\StaticTrendMgr($da, $da_im);
             $StaticTrendMgr->RegisterPublish($ename, $circleId, $circleName, $login_account, $currUser->nick_name);
         } catch (\Exception $e) {
             $this->get("logger")->err($e);
         }
     }
     $da->ExecSQLs($sqls, $paras);
     //向RBAC跟新用户身份
     //$staffRole=new StaffRole($da,$da_im,$this->logger);
     //$staffRole->InsertStaffRoleByCode($login_account,$auth_level.$eno_vip,$eno);
     //为新企业创建默认的外部公众号
     try {
         //解密
         $pwd = $currUser->t_code;
         $micro_name = $ename;
         $public_number = "_wexin_" . $eno . "@fafatime.com";
         $micro_type = '1';
         $micro_use = '0';
         //
         $concern = '0';
         $create_account = $login_account;
         //企业默认公众号
         $micro = new MicroAccountMgr($da, $da_im, $currUser, $this->logger, $this->container);
         $micro->insertMicroAccount($micro_name, $public_number, $pwd, $micro_type, $micro_use, $concern, '', '', '', '', '', $this->container->get('security.encoder_factory'));
         //创建默认微应用
         $appid = Utils::getAppid($eno, $login_account);
         $appkey = Utils::getAppkey();
         $micro_number = "_push_" . $eno . "@fafatime.com";
         $micro->register(null, $micro_number, "企业推送服务", $micro_type, "1", "", $concern, "", "", $pwd, "", "", "", $this->container->get('security.encoder_factory'), $this->container->get('doctrine.odm.mongodb.document_manager'), $appid);
         $updateSQL[] = "update we_staff set dept_id=(SELECT dept_id FROM we_department where eno=? and fafa_deptid=?),eno=? where login_account in(?,?)";
         $updatePara[] = array((string) $eno, "v" . $eno . "999", (string) $eno, (string) $micro_number, (string) $public_number);
         $updateSQL[] = "update we_micro_account set eno=? where number in(?,?)";
         $updatePara[] = array((string) $eno, (string) $micro_number, (string) $public_number);
         $updateSQL[] = "insert into we_appcenter_apps(appid,appkey,appname,state,appdeveloper,appdesc,apptype) values(?,?,?,?,?,?,?);";
         $updatePara[] = array($appid, $appkey, "企业推送服务", 0, $eno, "企业推送服务", '00');
         $da->ExecSQLs($updateSQL, $updatePara);
     } catch (\Exception $e) {
         $this->logger->err("创建默认公众号发生异常:" . $e);
     }
     //自动选择企业门户
     $App = new \Justsy\BaseBundle\Management\App($this->container);
     $App->portal_template(array("eno" => $eno, "login_account" => $login_account));
     //通知创建者其他设备
     Utils::sendImMessage("", $currUser->fafa_jid, "enterprise_create", $ename, $this->container, "", "", false, '', '0');
     $jid = SysSeq::GetSeqNextValue($da, "we_staff", "fafa_jid");
     $jid .= "-" . $eno . "@fafacn.com";
     $staffObj = new \Justsy\BaseBundle\Management\Staff($da, $da_im, $login_account, $this->logger, $this->container);
     $tr = $staffObj->swtichEno($eno, $circleId);
     //更换企业号
     if ($tr) {
         $staffObj->updateJid($currUser->fafa_jid, $jid);
     }
     //更新im库中的jid
     $data = $staffObj->getInfo(true);
     //更新人员缓存信息
     $data = $this->getInfo($eno);
     //缓存企业信息
     return Utils::WrapResultOK($data);
 }
 public function saveAction($network_domain)
 {
     $conn = $this->get('we_data_access');
     $conn_im = $this->get('we_data_access_im');
     $userinfo = $this->get('security.context')->getToken()->getUser();
     $logger = $this->get("logger");
     $eno = $userinfo->getEno();
     $login_account = $userinfo->getUsername();
     $MicroAccountMgr = new MicroAccountMgr($conn, $conn_im, $userinfo, $logger, $this->container);
     $getRequest = $this->getRequest();
     //$session = $this->get('session');
     $filename120 = $getRequest->get("logo_path_big");
     $filename48 = $getRequest->get("logo_path");
     $filename24 = $getRequest->get("logo_path_small");
     $dm = $this->get('doctrine.odm.mongodb.document_manager');
     //if (!empty($filename120)) $filename120= $this->saveFile($filename120,$dm);
     //if (!empty($filename48)) $filename48=   $this->saveFile($filename48,$dm);
     //if (!empty($filename24)) $filename24=   $this->saveFile($filename24,$dm);
     //$session->remove("avatar_big");
     //$session->remove("avatar_middle");
     //$session->remove("avatar_small");
     $factory = $this->get('security.encoder_factory');
     $micro_id = $getRequest->get("id");
     $number = $getRequest->get('micro_number');
     $name = $getRequest->get('micro_name');
     $type = $getRequest->get('type');
     $introduction = $getRequest->get('introduction');
     $concern_approval = $getRequest->get('concern_approval');
     $salutatory = $getRequest->get('salutatory');
     $level = $getRequest->get('send_status');
     $password = $getRequest->get('password');
     $micro_use = $getRequest->get('micro_use');
     $appid = Utils::getAppid($eno, $login_account);
     $appkey = Utils::getAppkey();
     if (empty($micro_id)) {
         $dataexec = $MicroAccountMgr->register($micro_id, $number, $name, $type, $micro_use, $introduction, $concern_approval, $salutatory, $level, $password, $filename48, $filename120, $filename24, $factory, $dm, $appid);
     } else {
         $dataexec = $MicroAccountMgr->register($micro_id, $number, $name, $type, $micro_use, $introduction, $concern_approval, $salutatory, $level, $password, $filename48, $filename120, $filename24, $factory, $dm);
     }
     $r = array("success" => false);
     if ($dataexec) {
         $r["success"] = true;
         if (empty($micro_id)) {
             try {
                 $sql = "insert into we_appcenter_apps(appid,appkey,appname,state,appdeveloper,appdesc,apptype) values(?,?,?,?,?,?,?);";
                 $para = array($appid, $appkey, $name, 1, $eno, $name, '00');
                 $data = $conn->ExecSQL($sql, $para);
             } catch (Exception $e) {
                 $this->get('logger')->err($e->getMessage());
             }
         }
     } else {
         $r["msg"] = "帐号已经被使用";
     }
     return $this->res(json_encode($r), 'text/html');
 }
 public function editAppsAction(Request $request)
 {
     $appid = $request->get("appid");
     $appname = $request->get("appname");
     $logo = $request->get("applogo");
     $apptype = $request->get("apptype");
     $appdesc = $request->get("appdesc");
     $bindurl = $request->get("bindurl");
     $sortid = $request->get("sortid");
     $createstaff = $request->get("createstaff");
     $curuser = $this->get('security.context')->getToken()->getUser();
     $appdeveloper = $curuser->eno;
     $username = $curuser->getUsername();
     $sql = "";
     $para = array();
     $da = $this->get('we_data_access');
     $result = array();
     try {
         if ($this->existsAppName($appdeveloper, $appid, $appname)) {
             $result = array("s" => "exists");
         } else {
             if (empty($appid)) {
                 $appid = Utils::getAppid($appdeveloper, $username);
                 $appkey = Utils::getAppkey();
                 //$MicroAccountMgr=new MicroAccountMgr($da,$this->get('we_data_access_im'),$curuser,$this->get("logger"), $this->container);
                 //$MicroAccountMgr->register("",$number,$name,$type,$micro_use,$introduction,$concern_approval,$salutatory,$level,$password,$filename48,$filename120,$filename24,$factory,$dm,$appid);
                 $sql = "insert into we_appcenter_apps(appid,appkey,logo,appname,state,appdeveloper,appdesc,bindurl,apptype,sortid,createstaffid)values(?,?,?,?,1,?,?,?,?,?,?)";
                 $para = array($appid, $appkey, $logo, $appname, $appdeveloper, $appdesc, $bindurl, $apptype, $sortid, $createstaff);
                 $result = array("s" => "add", "appid" => $appid);
             } else {
                 $sql = "update we_appcenter_apps set appname=?,logo=?,appdesc=?,bindurl=?,sortid=?,createstaffid=? where appid=?";
                 $para = array($appname, $logo, $appdesc, $bindurl, $sortid, $createstaff, $appid);
                 $result = array("s" => "edit", "appid" => $appid);
             }
             if ($sql != "") {
                 $da->ExecSQL($sql, $para);
             }
         }
     } catch (\Exception $e) {
         $result = array("s" => "error", "msg" => $e->getMessage());
     }
     $resp = new Response(json_encode($result));
     $resp->headers->set('Content-Type', 'text/json');
     //返回值说明:1=>添加成功;2=>修改成功;3=>已存在应用名称;0=>出错
     return $resp;
 }
Beispiel #5
0
 public function register_service($parameter)
 {
     $nick_name = isset($parameter["name"]) ? $parameter["name"] : null;
     $micro_id = isset($parameter["micro_id"]) ? $parameter["micro_id"] : null;
     $login_account = isset($parameter["login_account"]) ? $parameter["login_account"] : null;
     $deptid = isset($parameter["deptid"]) ? $parameter["deptid"] : array();
     $fileid = isset($parameter["fileid"]) ? $parameter["fileid"] : null;
     $fileid = empty($fileid) ? null : $fileid;
     if (empty($login_account)) {
         $re = $this->serviceAccount($parameter);
         if (!empty($re)) {
             $login_account = $re['account'];
         }
     }
     //服务号密码自动生成
     $password = time();
     $staffid = isset($parameter["staffid"]) ? $parameter["staffid"] : array();
     $manager = isset($parameter["manager"]) ? $parameter["manager"] : array();
     $introduction = isset($parameter["desc"]) ? $parameter["desc"] : "";
     //简介
     $user = $parameter["user"];
     $success = true;
     $msg = "";
     $da = $this->conn;
     $type = "0";
     $micro_use = "0";
     $concern_approval = isset($parameter["concern_approval"]) ? $parameter["concern_approval"] : 1;
     //0  表示私密 1  表示开放
     $salutatory = null;
     $level = null;
     //注册服务员或修改服务号信息
     $factory = $this->container->get('security.encoder_factory');
     $dm = $this->container->get('doctrine.odm.mongodb.document_manager');
     $eno = $user->eno;
     $appid = Utils::getAppid($eno, $login_account);
     $appkey = Utils::getAppkey();
     $MicroAccountMgr = new MicroAccountMgr($this->conn, $this->conn_im, $user, $this->container->get("logger"), $this->container);
     $dataexec = $MicroAccountMgr->register($micro_id, $login_account, $nick_name, $type, $micro_use, $introduction, $concern_approval, $salutatory, $level, $password, $fileid, $fileid, $fileid, $factory, $dm, $appid);
     //修改im人员信息表
     $sqls = array();
     $paras = array();
     $fafa_jid = "";
     $staffMgr = new Staff($this->conn, $this->conn_im, $login_account, $this->container->get("logger"), $this->container);
     $ds = $staffMgr->getInfo();
     if (!empty($ds)) {
         $fafa_jid = $ds["fafa_jid"];
         $sql_im = "update im_employee set employeename=?,photo=? where loginname=?;";
         $para_im = array((string) $nick_name, (string) $fileid, (string) $fafa_jid);
         try {
             $this->conn_im->ExecSQL($sql_im, $para_im);
         } catch (\Exception $e) {
         }
     }
     //如果为修改时删除原来的相关记录
     if (!empty($micro_id)) {
         $sql = array("delete from we_service where login_account=?");
         $sql[] = "delete from we_staff_atten where atten_id=?";
         $this->conn->ExecSQLs($sql, array(array((string) $login_account), array((string) $login_account)));
         //$sql =array( "delete from im_microaccount_memebr where microaccount=?");
         //$sql[]="delete from im_microaccount_msg where microaccount=?";
         //$this->conn_im->ExecSQLs($sql,array(array((string)$fafa_jid),array((string)$fafa_jid)));
     }
     //部门的处理
     for ($j = 0; $j < count($deptid); $j++) {
         $sql = "insert into we_service(login_account,objid,`type`)values(?,?,1)";
         $para = array((string) $login_account, (string) $deptid[$j]);
         array_push($sqls, $sql);
         array_push($paras, $para);
     }
     //人员的处理
     for ($j = 0; $j < count($staffid); $j++) {
         $sql = "insert into we_service(login_account,objid,`type`)values(?,?,2)";
         $para = array((string) $login_account, (string) $staffid[$j]);
         array_push($sqls, $sql);
         array_push($paras, $para);
     }
     //管理人员的处理
     for ($j = 0; $j < count($manager); $j++) {
         $sql = "insert into we_service(login_account,objid,`type`)values(?,?,3)";
         $para = array((string) $login_account, (string) $manager[$j]);
         array_push($sqls, $sql);
         array_push($paras, $para);
     }
     try {
         $da->ExecSQLS($sqls, $paras);
         //菜单处理
         for ($j = 0; $j < count($manager); $j++) {
             $sql = "select 1 from mb_staff_menu where menu_id='service' and staff_id=?;";
             $ds = $this->conn->GetData("table", $sql, array((string) $manager[$j]));
             if ($ds && $ds["table"]["recordcount"] == 0) {
                 $sql = "insert into mb_staff_menu(staff_id,menu_id)values(?,'service');";
                 $this->conn->ExecSQL($sql, array((string) $manager[$j]));
             }
         }
         $memberSql = "select employeeid from im_microaccount_memebr where microaccount=?";
         $memberRs = $this->conn_im->getData("m", $memberSql, array((string) $fafa_jid));
         $memberList = array();
         for ($i = 0; $i < $memberRs["m"]["recordcount"]; $i++) {
             $memberList[] = $memberRs["m"]["rows"][$i]["employeeid"];
         }
         $account = $this->service_jid($login_account);
         $sqlffix = "insert into im_microaccount_memebr(employeeid,microaccount,lastreadid,subscribedate)values";
         //获取需要新加的帐号
         $needAdd = Utils::array_diff_ex($account, $memberList);
         //获取需要移除删除的帐号
         $needRemove = Utils::array_diff_ex($memberList, $account);
         //需要移除删除的帐号
         $sqls = array();
         if (count($needRemove) < 500) {
             if (count($needRemove) > 0) {
                 $this->conn_im->ExecSQL("delete from im_microaccount_memebr where employeeid in('" . implode("','", $needRemove) . "') and microaccount='" . $fafa_jid . "'", array());
             }
         } else {
             //使用另外的方式处理删除
             $keep = Utils::array_intersect_ex($account, $memberList);
             $this->conn_im->ExecSQL('delete from im_microaccount_memebr where microaccount=?', array((string) $fafa_jid));
             foreach ($keep as $key => $ac) {
                 $sqls[] = "('" . $ac . "','" . $fafa_jid . "',0,now())";
                 $paras[] = array();
                 if ($i > 0 && $i % 10000 == 0) {
                     try {
                         $this->conn_im->ExecSQL($sqlffix . implode(",", $sqls), array());
                     } catch (\Exception $e) {
                         $this->logger->err($e->getMessage());
                     }
                     $sqls = array();
                     $paras = array();
                 }
                 $i++;
             }
             if (count($sqls) > 0) {
                 try {
                     $this->conn_im->ExecSQL($sqlffix . implode(',', $sqls), array());
                 } catch (\Exception $e) {
                     $this->logger->err($e->getMessage());
                 }
             }
         }
         $sqls = array();
         $paras = array();
         $i = 0;
         //处理新增的帐号
         foreach ($needAdd as $key => $ac) {
             $sqls[] = "('" . $ac . "','" . $fafa_jid . "',0,now())";
             $paras[] = array();
             if ($i > 0 && $i % 10000 == 0) {
                 try {
                     $this->conn_im->ExecSQL($sqlffix . implode(",", $sqls), array());
                 } catch (\Exception $e) {
                     $this->logger->err($e->getMessage());
                 }
                 $sqls = array();
                 $paras = array();
             }
             $i++;
         }
         if (count($sqls) > 0) {
             try {
                 $this->conn_im->ExecSQL($sqlffix . implode(",", $sqls), array());
             } catch (\Exception $e) {
                 $this->logger->err($e->getMessage());
             }
         }
     } catch (\Exception $e) {
         $success = false;
         $msg = "更新用户信息失败!";
         $this->logger->err($e->getMessage());
     }
     return array("success" => $success, "msg" => $msg);
 }