Пример #1
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);
 }
Пример #2
0
 public function getConvAction($conv_root_ids, $isshow_relation_static_trend = false)
 {
     //取出每个根会话
     $sqlwherein = array();
     $params = array();
     $sqlwherein[] = '?';
     $params[] = '###';
     for ($i = 0; $i < count($conv_root_ids); $i++) {
         $sqlwherein[] = '?';
         $params[] = (string) $conv_root_ids[$i];
     }
     $sqlwhereinstr = join(',', $sqlwherein);
     $da = $this->get('we_data_access');
     $sql = "select a.conv_id, a.conv_type_id, b.template_controller  \nfrom we_conv_template b,we_convers_list a \nwhere a.conv_type_id=b.conv_type_id\n  and a.conv_id in ({$sqlwhereinstr})\norder by a.post_date desc";
     $ds = $da->GetData("we_convers_list", $sql, $params);
     $tmpArr = array("we_convers_list" => array("rows" => array()));
     if ($isshow_relation_static_trend) {
         $tmp = new \Justsy\BaseBundle\Management\StaticTrendMgr($da, null);
         $list = $tmp->GetStaticRelationTrend();
         for ($i = 0; $i < count($list); $i++) {
             //$sql += " union select '".$list[$i]["info_id"]."' conv_id, '00' conv_type_id, 'JustsyBaseBundle:CDisplayArea:getTrend' template_controller  ";
             $ds["we_convers_list"]["rows"][] = array("conv_id" => $list[$i]["info_id"], "conv_type_id" => "00", "template_controller" => "JustsyBaseBundle:CDisplayArea:getTrend");
         }
     }
     $trend = $this->getRequest()->get("trend");
     return $this->render('JustsyBaseBundle:CDisplayArea:index.html.twig', array('we_convers_list' => $ds["we_convers_list"]["rows"], 'trend' => $trend));
 }