public function getAllConvUnreadPcAction()
 {
     $user = $this->get('security.context')->getToken()->getUser();
     $request = $this->getRequest();
     $network_domain = $request->get('network_domain');
     $maxid = $request->get('maxid');
     $onlycount = $request->get('onlycount');
     $class = $request->get('class');
     $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=?\n  and (a.post_to_group in ('ALL', case when a.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=?))\n  and exists(select 1 from dual where a.login_account=? union select 1 from we_staff_atten wsa where wsa.login_account=? and wsa.atten_type='01' and wsa.atten_id=a.login_account)\n  and (0+a.conv_root_id)>? and 0<>?";
     if ($class == "conv") {
         //所有会话,无类别区分
         $sql .= " and not exists(select 1 from we_conv_hide b where b.conv_id=a.conv_id and b.login_account=?)";
     } else {
         if ($class == "official") {
             //官方的
             $sql .= " and a.conv_type_id='06'";
         } else {
             if ($class == "ask") {
                 //提问
                 $sql .= " and a.conv_type_id='01'";
             } else {
                 if ($class == "together") {
                     //活动
                     $sql .= " and a.conv_type_id='02'";
                 } else {
                     if ($class == "vote") {
                         //投票
                         $sql .= " and a.conv_type_id='03'";
                     } else {
                         if ($class == "trend") {
                             //动态
                             $sql .= " and a.conv_type_id='00'";
                         }
                     }
                 }
             }
         }
     }
     $params = array();
     $params[] = (string) $user->get_circle_id($network_domain);
     $params[] = (string) $user->getUserName();
     $params[] = (string) $user->getUserName();
     $params[] = (string) $user->getUserName();
     $params[] = (string) $user->getUserName();
     $params[] = (double) $maxid;
     $params[] = (double) $maxid;
     if ($class == 'conv') {
         $params[] = (string) $user->getUserName();
     }
     if ($onlycount) {
         $sql .= " and a.login_account<>? ";
         $params[] = (string) $user->getUserName();
         $sql = "select count(*) c from ({$sql}) as _ttt_";
         $da = $this->get('we_data_access');
         $ds = $da->GetData("we_convers_list", $sql, $params);
         $re = array("unreadcount" => $ds["we_convers_list"]["rows"][0]["c"]);
         $response = new Response(json_encode($re));
         $response->headers->set('Content-Type', 'text/json');
         return $response;
     }
     $sql .= " order by (0+a.conv_id) desc";
     $da = $this->get('we_data_access');
     $ds = $da->GetData("we_convers_list", $sql, $params);
     //生成html返回
     $conv_root_ids = array_map(function ($row) {
         return $row["conv_root_id"];
     }, $ds["we_convers_list"]["rows"]);
     if (count($conv_root_ids) > 0) {
         //更新用户最后读的信息ID
         $conv = new \Justsy\BaseBundle\Business\Conv();
         $conv->updateLastReadID_Circle($da, $user, $user->get_circle_id($network_domain), $conv_root_ids[0]);
     }
     return $this->forward("JustsyBaseBundle:CDisplayArea:getConvPc", array("conv_root_ids" => $conv_root_ids, "trend" => true));
 }
Example #2
0
 public function getUnreadConvAction()
 {
     $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");
     $group_id = $request->get("group_id");
     $max_id = $request->get("max_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=?";
         $params = array();
         $params[] = (string) $circle_id;
         if ($circle_id == "9999") {
             //从im库中查询好友
             $staffmgr = new \Justsy\BaseBundle\Management\Staff($da, $this->get('we_data_access_im'), $user, $this->get("logger"), $this->container);
             $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($group_id)) {
             $sql .= " and a.post_to_group = ? ";
             $params[] = (string) $group_id;
         } else {
             $sql .= " and (a.post_to_group in ('ALL', case when a.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=?)) ";
             $params[] = (string) $user->getUserName();
             $params[] = (string) $user->getUserName();
         }
         $sql .= " and (0+conv_root_id)>? and 0<>?";
         $params[] = (double) $max_id;
         $params[] = (double) $max_id;
         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);
         if (count($conv_root_ids) > 0 && empty($last_end_id)) {
             //更新用户最后读的信息ID
             $conv = new \Justsy\BaseBundle\Business\Conv();
             if (empty($group_id)) {
                 $conv->updateLastReadID_Circle($da, $user, $circle_id, $conv_root_ids[0]);
             } else {
                 $conv->updateLastReadID_Group($da, $user, $group_id, $conv_root_ids[0]);
             }
         }
     } 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;
 }