示例#1
0
 public function getPrivateConvsAction()
 {
     $re = array("returncode" => ReturnCode::$SUCCESS);
     $request = $this->getRequest();
     $user = $this->get('security.context')->getToken()->getUser();
     $da = $this->get('we_data_access');
     $circle_id = $request->get("circle_id");
     $last_end_id = $request->get("last_end_id");
     try {
         if (empty($circle_id)) {
             throw new \Exception("param is null");
         }
         $sql = "select a.conv_root_id \nfrom we_convers_list a\nwhere a.conv_id=a.conv_root_id\n  and a.post_to_circle=? and a.post_to_group='PRIVATE' and a.login_account=?";
         $params = array();
         $params[] = (string) $circle_id;
         $params[] = (string) $user->getUserName();
         if ($circle_id == "9999") {
             //从im库中查询好友
             $staffmgr = new \Justsy\BaseBundle\Management\Staff($da, $this->get('we_data_access_im'), $user);
             $getfriendList = $staffmgr->getFriendLoginAccountList("1");
             if ($getfriendList && count($getfriendList) > 0) {
                 $sql .= " and a.login_account in ('" . implode("','", $getfriendList) . "','" . $user->getUserName() . "')";
             } else {
                 $sql .= " and a.login_account=?";
                 $params[] = (string) $user->getUserName();
             }
         }
         if (!empty($last_end_id)) {
             $sql .= " and (0+conv_root_id)<? ";
             $params[] = (double) $last_end_id;
         }
         $sql .= " and a.conv_type_id<>'06'";
         $sql .= " order by (0+a.conv_id) desc";
         $sql .= " limit 0, 15 ";
         $da = $this->get('we_data_access');
         $ds = $da->GetData("we_convers_list", $sql, $params);
         $conv_root_ids = array_map(function ($row) {
             return $row["conv_root_id"];
         }, $ds["we_convers_list"]["rows"]);
         $re["convs"] = $this->getConvAction($conv_root_ids);
     } catch (\Exception $e) {
         $re["returncode"] = ReturnCode::$SYSERROR;
         $this->get('logger')->err($e);
     }
     $response = new Response($request->get('jsoncallback') ? $request->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
 public function getUnreadCircleConversNum($username, $filter)
 {
     $da = $this->get('we_data_access');
     $sql = "select b.circle_id, wc.circle_name, count(*) num \nfrom we_convers_list a, we_circle_staff b, we_circle wc\nwhere a.conv_id=a.conv_root_id  \n  and b.circle_id=wc.circle_id\n  and b.circle_id = a.post_to_circle and b.login_account=?\n  and (a.post_to_group in ('ALL', case when a.login_account=b.login_account then 'PRIVATE' else '' end)\n    or exists(select 1 from we_convers_notify wcn where wcn.conv_id=a.conv_id and wcn.cc_login_account=b.login_account))\n  and (0+a.conv_id) > (0+ifnull(b.last_read_id, 0))\n  and a.login_account<>? and a.post_to_circle!='9999'\n  and 1 = (case when a.post_to_circle='10000' then (case when a.login_account in ('*****@*****.**', '*****@*****.**', '*****@*****.**') then 1 else 0 end) else 1 end) \n  and not exists(select 1 from we_conv_top p where p.conv_id=a.conv_id and p.timeout>now()) ";
     if (!empty($filter)) {
         $sql .= " and a.conv_type_id <>'{$filter}' ";
     }
     $sql .= " and a.conv_type_id<>'99' ";
     //从im库中查询好友
     $staffmgr = new \Justsy\BaseBundle\Management\Staff($da, $this->get('we_data_access_im'), $username, $this->get("logger"), $this->container);
     $getfriendList = $staffmgr->getFriendLoginAccountList("1");
     $roster_sql = "";
     if ($getfriendList && count($getfriendList) > 0) {
         $roster_sql .= " and a.login_account in ('" . implode("','", $getfriendList) . "')";
     } else {
         $roster_sql .= "  and a.login_account=''";
     }
     $sql_9999 = " union select '9999' circle_id,(select circle_name from we_circle where circle_id='9999') circle_name,count(1) num from we_convers_list a,\n      (select ifnull(min(last_read_id),0) last_read_id from we_circle_staff cs where cs.login_account=? and circle_id='9999') cl  where a.post_to_circle='9999' and a.login_account<>?    \n      " . $roster_sql . " and (0+a.conv_id)>cl.last_read_id";
     if (!empty($filter)) {
         $sql_9999 .= " and a.conv_type_id <>'{$filter}' ";
     }
     $sql_9999 .= " and a.conv_type_id<>'99'";
     $sql .= $sql_9999;
     $params = array();
     $params[] = (string) $username;
     $params[] = (string) $username;
     $params[] = (string) $username;
     $params[] = (string) $username;
     $ds = $da->GetData("we_convers_list", $sql, $params);
     return $ds;
 }