コード例 #1
0
 public function getCommentList($locusId, $count, $maxId)
 {
     if ($maxId == '') {
         $commList = $this->commentModel->getCommentList($locusId, $count);
     } else {
         $commList = $this->commentModel->getCommentBymaxId($locusId, $maxId, $count);
     }
     //返回评论的数量
     $count = $this->locusModel->getCommentAndPraiseCount($locusId);
     if (!$count) {
         $comments = 0;
     } else {
         $comments = $count['comments'];
     }
     $userIds = array_map(function ($v) {
         return $v['u_id'];
     }, $commList);
     if (!empty($userIds)) {
         $swoole = new SwooleUserClient($this->di['sysconfig']['swooleConfig']['ip'], $this->di['sysconfig']['swooleConfig']['port']);
         $userInfos = $swoole->userInfoByIds(implode(',', $userIds))['data'];
         $listNum = sizeof($commList);
         $picNum = sizeof($userInfos);
         for ($i = 0; $i < $listNum; $i++) {
             for ($j = 0; $j < $picNum; $j++) {
                 if ($commList[$i]['u_id'] == $userInfos[$j]['u_id']) {
                     $commList[$i]['u_pic'] = UserHelper::checkPic($this->di, $userInfos[$j]['u_pic']);
                     if ($userInfos[$j]['u_name'] == '') {
                         $commList[$i]['u_name'] = $userInfos[$j]['u_mobi'];
                     } else {
                         $commList[$i]['u_name'] = $userInfos[$j]['u_name'];
                     }
                     break;
                 }
             }
         }
     }
     //将result重新排序,addtime较小的排在前面
     usort($commList, function ($a, $b) {
         return strcmp($a['time'], $b['time']);
     });
     return array('flag' => self::SUCCESS, 'commlist' => $commList, 'comments' => $comments);
 }