コード例 #1
0
 public function circlestafflimitAction()
 {
     $re = array("returncode" => ReturnCode::$SUCCESS);
     $request = $this->getRequest();
     $circle_id = $request->get("circle_id");
     $page = $request->get("page");
     $like = $request->get("like");
     $da = $this->get('we_data_access');
     if (empty($circle_id)) {
         $re["returncode"] = ReturnCode::$SYSERROR;
         $response = new Response($request->get('jsoncallback') ? $request->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
         $response->headers->set('Content-Type', 'text/json');
         return $response;
     }
     $currUser = $this->get('security.context')->getToken();
     if (!empty($currUser)) {
         $user = $currUser->getUser();
         $userAccount = $user->getUserName();
     } else {
         //当应用通过api接口调用时,不用登录,只能通过openid获取人员信息
         $ds = $this->getstaffinfo($request->get("Openid") . $request->get("openid"));
         $userAccount = $ds["login_account"];
     }
     if ($circle_id == '9999') {
         $staffMgr = new \Justsy\BaseBundle\Management\Staff();
         $list = $staffMgr->getFriendBaseinfoList();
         if (empty($list)) {
             $list = array();
         }
         $result = array();
         $startPos = 0;
         if (!empty($page)) {
             $startPos = (double) $page * 30;
         }
         for ($i = $startPos; $i < min(count($list), $startPos + 30); $i++) {
             $result[] = $list[$i];
         }
         $re["staffs"] = $result;
     } else {
         $sql = "select * from (";
         $sql .= "select a.login_account,a.nick_name,c.eshortname,a.photo_path,a.photo_path_small,a.photo_path_big,a.fafa_jid from we_staff a inner join we_enterprise c on a.eno=c.eno ";
         $sql .= " inner join we_circle_staff b on a.login_account=b.login_account  where b.circle_id=? ";
         if (!empty($like)) {
             if (strlen($like) == mb_strlen($like, "utf-8")) {
                 $sql .= " and (a.nick_name like CONCAT('{$like}','%') or a.login_account like CONCAT('{$like}','%'))";
             } else {
                 $sql .= " and a.nick_name like CONCAT('{$like}','%')";
             }
         }
         $sql .= " and not exists(select 1 from we_micro_account  where we_micro_account.number=a.login_account) ";
         $sql .= " ) rsp order by 1";
         if (!empty($page)) {
             $page = (double) $page * 30;
             $sql .= " limit {$page}, 30";
         } else {
             $sql .= " limit 0, 30";
         }
         $ds = $da->GetData("we_staff", $sql, array((string) $circle_id));
         $re["staffs"] = $ds["we_staff"]["rows"];
     }
     $response = new Response($request->get('jsoncallback') ? $request->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }